:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --ink: #172033;
  --muted: #637083;
  --line: #d8e0ea;
  --brand: #0f766e;
  --brand-2: #1d4ed8;
  --danger: #b91c1c;
  --ok: #15803d;
  --warn: #b45309;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: 58px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  width: min(1180px, calc(100vw - 32px));
  height: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; letter-spacing: 0; }
.brand-subtitle { font-size: 12px; color: var(--muted); font-weight: 650; }
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #0f766e;
  color: white;
  font-weight: 900;
}
.portal-indigo .brand-mark { background: #4f46e5; }
.portal-blue .brand-mark { background: #1d4ed8; }
.portal-teal .brand-mark { background: #0f766e; }
.top-meta {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: flex-end;
}
.top-meta-copy { display: grid; gap: 2px; justify-items: end; }
.top-meta strong { color: var(--ink); font-size: 13px; }
.language-switch {
  display: inline-flex;
  align-items: center;
}
.language-switch select {
  appearance: none;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--ink);
  border-radius: 8px;
  padding: 5px 24px 5px 8px;
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 12px) 50%,
    calc(100% - 8px) 50%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
.content {
  width: min(1180px, calc(100vw - 32px));
  margin: 24px auto 40px;
}
.portal-footer {
  width: min(1180px, calc(100vw - 32px));
  margin: auto auto 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
}
.hero h1 { margin: 0; font-size: 28px; line-height: 1.15; }
.hero p { margin: 6px 0 0; color: var(--muted); }
.eyebrow {
  margin-bottom: 6px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.portal-indigo .eyebrow { color: #4f46e5; }
.portal-blue .eyebrow { color: #1d4ed8; }
.portal-hero { align-items: center; margin-bottom: 14px; }
.pin-auth {
  width: min(460px, 100%);
  margin: 10vh auto 0;
}
.pin-auth .card-body { display: grid; gap: 14px; }
.pin-actions { align-items: stretch; }
.pin-actions button { flex: 1; }
.pin-help { margin: 0; font-size: 12px; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: minmax(0, 1fr) minmax(320px, 0.45fr); align-items: start; }
.grid.home-grid { grid-template-columns: minmax(0, 1fr) minmax(320px, 0.44fr); align-items: start; margin-top: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-header h2 { margin: 0; font-size: 16px; }
.card-body { padding: 18px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stats.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat strong { display: block; margin-top: 5px; font-size: 18px; }
.muted { color: var(--muted); margin-top: 4px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
}
.pill.ok { color: var(--ok); background: #dcfce7; }
.pill.warn { color: var(--warn); background: #fef3c7; }
.pill.danger { color: var(--danger); background: #fee2e2; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 750; color: #334155; }
.field-hint { margin: -2px 0 0; color: var(--muted); font-size: 11px; line-height: 1.35; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  outline: none;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12); }

.button-row { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
button, .button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--brand-2);
  color: #fff;
  font-weight: 750;
  cursor: pointer;
  text-decoration: none;
}
button.secondary { background: #e2e8f0; color: #1e293b; }
button.success { background: var(--ok); }
button.danger { background: var(--danger); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.compact { padding: 9px 11px; min-width: 64px; white-space: nowrap; }

.fiscal-lookup-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}
.lookup-status {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  background: #f8fafc;
  border: 1px solid var(--line);
  color: #334155;
}
.lookup-status.ok { background: #f0fdf4; border-color: #bbf7d0; color: var(--ok); }
.lookup-status.warn { background: #fffbeb; border-color: #fde68a; color: var(--warn); }
.lookup-status.error { background: #fef2f2; border-color: #fecaca; color: var(--danger); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 11px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f8fafc; color: #475569; font-size: 11px; text-transform: uppercase; letter-spacing: 0.02em; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }

.notice {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: #334155;
  margin-bottom: 14px;
}
.notice.error { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.notice.success { background: #f0fdf4; border-color: #bbf7d0; color: var(--ok); }
.notice.warn { background: #fffbeb; border-color: #fde68a; color: var(--warn); }

.token-launch {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin: 16px 0;
}

.capability-grid {
  display: grid;
  gap: 12px;
}

.mini-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 13px;
}
.mini-card strong { display: block; margin-bottom: 5px; color: var(--ink); }
.mini-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.stepper {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 16px;
}
.step {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}
.step span {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 850;
}
.step strong { font-size: 12px; color: #334155; line-height: 1.2; }

.summary-box {
  margin-top: 14px;
  padding: 13px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
}
.summary-box span { display: block; color: #1e40af; font-size: 12px; font-weight: 800; }
.summary-box strong { display: block; margin-top: 4px; font-size: 20px; color: #1e3a8a; }
.summary-box p { margin: 4px 0 0; color: #475569; font-size: 12px; }

.attachment-field input[type="file"] {
  padding: 8px;
  background: #f8fafc;
}
.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
}
.file-list span,
.attachment-readonly-list span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: #334155;
  font-size: 11px;
  font-weight: 750;
}
.file-list em,
.attachment-readonly-list em {
  color: var(--muted);
  font-style: normal;
  font-weight: 650;
}
.file-list.error {
  display: block;
  color: var(--danger);
  font-size: 12px;
  font-weight: 750;
}
.attachment-readonly-list {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}
.attachment-readonly-list strong {
  width: 100%;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.readonly-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.readonly-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.readonly-grid .full { grid-column: 1 / -1; }
.readonly-grid span { display: block; color: var(--muted); font-size: 12px; font-weight: 750; }
.readonly-grid strong { display: block; margin-top: 4px; }
.readonly-grid p { margin: 5px 0 0; color: #334155; }

.access-gate {
  max-width: 460px;
  margin: 64px auto;
}
.boot {
  min-height: 100vh;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
}
.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid #dbeafe;
  border-top-color: var(--brand-2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.admin-login {
  width: min(460px, calc(100vw - 32px));
  margin: 10vh auto 0;
}
.admin-login-card { box-shadow: var(--shadow); }
.admin-login-form { display: grid; gap: 14px; }
.admin-content { display: grid; gap: 16px; }
.admin-topbar button { padding: 8px 12px; }
.admin-stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.admin-stat {
  text-align: left;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: pointer;
}
.admin-stat.active {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}
.admin-record-header { align-items: flex-start; }
.admin-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.admin-toolbar input {
  width: min(320px, 46vw);
  padding: 8px 10px;
}
.admin-key {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  word-break: break-all;
}
.admin-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}
.admin-actions button {
  padding: 6px 8px;
  font-size: 12px;
}
.admin-empty {
  min-height: 160px;
  display: grid;
  place-items: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}
.admin-recent-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.admin-log-list {
  display: grid;
  gap: 10px;
  max-height: 360px;
  overflow: auto;
}
.admin-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.58);
}
.admin-modal {
  width: min(980px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.admin-modal .card-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.admin-json {
  min-height: min(62vh, 620px);
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 860px) {
  .topbar { height: auto; min-height: 58px; padding: 8px 10px; }
  .topbar-inner { width: min(100vw - 20px, 1180px); align-items: flex-start; }
  .hero { grid-template-columns: 1fr; }
  .grid.two, .grid.home-grid, .form-grid, .stats, .stats.compact, .stepper, .token-launch, .readonly-grid, .admin-recent-grid { grid-template-columns: 1fr; }
  .content { width: min(100vw - 20px, 1180px); margin-top: 14px; }
  .portal-footer { width: min(100vw - 20px, 1180px); flex-direction: column; align-items: flex-start; margin-bottom: 12px; }
  .top-meta strong { display: none; }
  .admin-toolbar, .admin-toolbar input { width: 100%; }
  .fiscal-lookup-grid { grid-template-columns: minmax(0, 1fr) minmax(64px, auto) minmax(64px, auto); }
}
