:root {
  --bg: #0b101b;
  --panel: #131c2e;
  --panel-alt: #1a263d;
  --border: #2a3b5c;
  --border-hi: #38bdf8;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #0284c7;
  --accent-hi: #38bdf8;
  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.35;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

/* Explicit horizontal gutter — never use shorthand padding on .wrap */
.wrap {
  max-width: 1440px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 14px;
  padding-right: 14px;
}

/* Compact Top Bar */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 16, 27, 0.96);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding-top: 4px;
  padding-bottom: 4px;
}

.app-bar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.03em;
  color: var(--text);
  text-decoration: none;
  min-height: 40px;
  padding: 0 4px;
}

.brand-badge {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  color: #fff;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

.top-menus {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.user-pill {
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 8px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Buttons — always >= 40px tap target */
.btn {
  appearance: none;
  background: linear-gradient(180deg, #1e293b 0%, #131c2e 100%);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  min-height: 40px;
  min-width: 44px;
  padding: 0 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.12s, background 0.12s;
}

.btn:hover:not(:disabled) {
  border-color: var(--border-hi);
  background: #1e293b;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #0284c7 0%, #0369a1 100%);
  border-color: #38bdf8;
  color: #fff;
}

.btn-ok {
  background: linear-gradient(180deg, #059669 0%, #047857 100%);
  border-color: #34d399;
  color: #fff;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}

/* Form Inputs — 16px on mobile to avoid iOS zoom, crisp monospace on desktop */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  background: #080c14;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 7px;
  font-size: 16px;
  font-family: var(--sans);
  min-height: 40px;
}

input.mono,
textarea.mono,
.hex-in {
  font-family: var(--mono);
  text-transform: uppercase;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--border-hi);
  background: #0d1524;
}

/* Classic CAS3 Top Split: Left (File area + DME ISN) | Right (CAS3 C3 info Data) */
.cas-top-layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  gap: 10px;
  margin-top: 8px;
  margin-bottom: 8px;
}

.left-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.group-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  position: relative;
}

.group-legend {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-hi);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.file-btn-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin-bottom: 6px;
}

.file-name-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: #080c14;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
}

/* CAS3 C3 info Data Box (matches original 2-column info + right buttons) */
.info-box-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 165px;
  gap: 10px;
  align-items: center;
}

.info-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.info-kv {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #080c14;
  border: 1px solid rgba(42, 59, 92, 0.7);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 12.5px;
}

.info-k {
  color: var(--muted);
  font-weight: 600;
}

.info-v {
  font-family: var(--mono);
  font-weight: 700;
  color: #fff;
}

.info-btn-col {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.long-isn-banner {
  margin-top: 6px;
  text-align: center;
  font-weight: 700;
  font-size: 12.5px;
  padding: 4px 8px;
  border-radius: 4px;
  background: #080c14;
  border: 1px solid var(--border);
}

/* Key info 1..10 Table (Single-Screen inline editable like cas3v13.exe) */
.key-table-head {
  display: grid;
  grid-template-columns: 28px 1.15fr 1.15fr 0.75fr 1.15fr 0.48fr 0.48fr 0.48fr 1.25fr 0.75fr 1.15fr 0.75fr 1.15fr 86px 86px;
  gap: 4px;
  align-items: center;
  padding: 4px 6px;
  background: var(--panel-alt);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.key-rows-container {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-top: 4px;
}

.key-row {
  display: grid;
  grid-template-columns: 28px 1.15fr 1.15fr 0.75fr 1.15fr 0.48fr 0.48fr 0.48fr 1.25fr 0.75fr 1.15fr 0.75fr 1.15fr 86px 86px;
  gap: 4px;
  align-items: center;
  padding: 2px 4px;
  border-radius: 4px;
  background: #0c1322;
  border: 1px solid rgba(42, 59, 92, 0.55);
}

.key-row.used-row {
  border-color: rgba(16, 185, 129, 0.4);
  background: rgba(16, 185, 129, 0.04);
}

.key-idx {
  font-weight: 800;
  font-size: 13px;
  text-align: center;
  color: var(--accent-hi);
  font-family: var(--mono);
}

.key-row .hex-in {
  width: 100%;
  min-height: 34px;
  padding: 2px 4px;
  font-size: 12.5px;
  text-align: center;
  background: #070a10;
  color: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 3px;
}

.key-row .status-sel {
  width: 100%;
  min-height: 40px;
  padding: 2px 4px;
  font-size: 12px;
  font-weight: 600;
  background: #131c2e;
  color: #fff;
}

.key-row .btn-key-act {
  min-height: 40px;
  padding: 0 6px;
  font-size: 12px;
  width: 100%;
}

.cell-caption {
  display: none;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 1px;
}

/* Badges & Status */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--mono);
  background: #1e293b;
  color: var(--text);
  border: 1px solid var(--border);
}

.badge-ok {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.45);
}

.badge-warn {
  background: rgba(245, 158, 11, 0.16);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.45);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.16);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.45);
}

.badge-tag {
  background: rgba(56, 189, 248, 0.14);
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.35);
}

/* Modals (Data Editing..., Edit 16-Byte ISN, DME ISN, Cloud Vault, Accounts, Help) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(5, 8, 15, 0.82);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.modal-backdrop.open {
  display: flex;
}

.modal-window {
  background: var(--panel);
  border: 1px solid var(--border-hi);
  border-radius: 8px;
  width: 100%;
  max-width: 660px;
  padding: 14px 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
  max-height: 92vh;
  overflow-y: auto;
}

.modal-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent-hi);
  margin: 0;
}

.data-edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.field-box {
  display: flex;
  flex-direction: column;
  background: #080c14;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 8px;
}

.field-tag {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field-box input,
.field-box select {
  border: none;
  background: transparent;
  padding: 2px 0 0 0;
  min-height: 40px;
  font-size: 16px;
  color: var(--text);
  width: 100%;
}

/* Dense Rows inside Modals (Vault / Accounts / Checksums) */
.row-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: #090d16;
}

.list-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.list-row:last-child {
  border-bottom: none;
}

.row-line-1 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.row-line-2 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

.chk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 5px;
  font-family: var(--mono);
  font-size: 12px;
}

.chk-cell {
  background: #080c14;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 7px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Login Screen */
.login-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-top: 24px;
  padding-bottom: 24px;
}

.login-box {
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 16px;
}

.alert-box {
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
}

.alert-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

/* Responsive Layout for Tablets & Phones (< 1100px) so mobile-audit.js is 100% clean */
@media (max-width: 1100px) {
  .cas-top-layout {
    grid-template-columns: 1fr;
  }

  .info-box-grid {
    grid-template-columns: 1fr 1fr;
  }

  .info-btn-col {
    grid-column: 1 / -1;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .info-btn-col .btn {
    flex: 1 1 auto;
  }

  .key-table-head {
    display: none;
  }

  .key-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
  }

  .key-idx {
    text-align: left;
    font-size: 14px;
  }

  .cell-caption {
    display: block;
  }

  .key-row .hex-in {
    min-height: 40px;
    font-size: 16px;
  }
}

@media (max-width: 640px) {
  .info-box-grid {
    grid-template-columns: 1fr;
  }

  .data-edit-grid {
    grid-template-columns: 1fr;
  }

  .key-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
