/* Munshian VAT design system */
:root {
  /* Brand */
  --primary: #114688;
  --primary-hover: #0d3a72;
  --primary-press: #0a2f5d;
  --navy: #192B4F;
  --midnight: #0B0A27;
  --coral: #EA5246;

  /* Surfaces */
  --bg: #F7F9FC;
  --card: #FFFFFF;
  --subtle: #F1F4F8;
  --blue-surface: #EEF4FB;

  /* Text */
  --text: #192B4F;
  --text-2: #667085;
  --text-3: #98A2B3;

  /* Lines */
  --line: #E5EAF1;
  --line-strong: #CDD5E1;

  /* Status */
  --ok: #067647;
  --ok-bg: #ECFDF3;
  --ok-line: #ABEFC6;
  --err: #B42318;
  --err-bg: #FEF3F2;
  --err-line: #FECDCA;
  --warn: #93370D;
  --warn-bg: #FFFAEB;
  --warn-line: #FEDF89;

  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 1px 3px rgba(16, 24, 40, 0.06), 0 8px 24px -12px rgba(25, 43, 79, 0.12);
  --focus: 0 0 0 3px rgba(17, 70, 136, 0.18);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 400 14.5px/1.55 var(--font);
  font-feature-settings: 'cv11', 'ss01';
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Typography */
h1 { font-size: 28px; line-height: 1.2; font-weight: 650; letter-spacing: -0.02em; color: var(--navy); margin: 0 0 8px; }
h2 { font-size: 18px; line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; color: var(--navy); margin: 32px 0 12px; }
p { margin: 0 0 14px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
strong { font-weight: 600; }
code { font: 12.5px var(--mono); background: var(--subtle); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; color: var(--navy); }
pre { white-space: pre-wrap; word-break: break-word; font: 12.5px/1.6 var(--mono); background: var(--subtle); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; color: var(--navy); }
ul, ol { padding-left: 20px; margin: 0 0 14px; }
li { margin: 4px 0; }
.muted { color: var(--text-2); font-size: 13px; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Header */
.topbar { position: sticky; top: 0; z-index: 10; background: rgba(255, 255, 255, 0.96); border-bottom: 1px solid var(--line); backdrop-filter: saturate(1.2) blur(6px); }
.topbar-inner { max-width: 1160px; margin: 0 auto; height: 60px; padding: 0 24px; display: flex; align-items: center; gap: 20px; }
.brand { display: inline-flex; align-items: flex-end; gap: 8px; color: var(--navy); font-weight: 650; font-size: 15.5px; letter-spacing: -0.01em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { display: block; height: 36px; width: auto; }
.env { font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; padding: 3px 8px; border-radius: var(--r-sm); background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-line); white-space: nowrap; }
.topbar nav { display: flex; gap: 2px; margin-left: 8px; overflow-x: auto; scrollbar-width: none; }
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 10px; border-radius: var(--r-sm); color: var(--text-2); font-weight: 500; font-size: 14px; white-space: nowrap; transition: background-color .15s, color .15s; }
.topbar nav a:hover { background: var(--subtle); color: var(--navy); text-decoration: none; }
.topbar nav a[aria-current="page"] { color: var(--primary); background: var(--blue-surface); }
.topbar nav svg { width: 16px; height: 16px; flex: none; }
.topbar form { margin-left: auto; }
.signout { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; color: var(--text-2) !important; font-weight: 500; }
.signout:hover { color: var(--navy) !important; }
.signout svg { width: 16px; height: 16px; }

/* Page */
main { max-width: 1160px; margin: 0 auto; padding: 36px 24px 64px; }
.page-head { margin-bottom: 24px; }
.page-head p { color: var(--text-2); max-width: 720px; margin: 0; }
.page-head p + p { margin-top: 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); padding: 20px 24px; margin-bottom: 20px; }
.card > :last-child { margin-bottom: 0; }
.card-title { font-size: 15.5px; font-weight: 600; color: var(--navy); margin: 20px 0 10px; }
.card-title:first-child { margin-top: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-title { padding: 16px 20px 0; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0 0 14px; }
.back { margin-top: 24px; font-size: 14px; }

/* Signed-out screens */
body.auth main { max-width: 460px; padding-top: 56px; }
body.auth .card { padding: 32px; box-shadow: var(--shadow-md); }
body.auth h1 { font-size: 24px; }
body.auth .page-head { margin-bottom: 20px; }
.auth-foot { text-align: center; margin-top: 20px; }

/* Buttons */
.button, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border: 1px solid var(--primary); border-radius: var(--r-md);
  background: var(--primary); color: #fff; font: 500 14px/1 var(--font); text-decoration: none; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: background-color .15s, border-color .15s, box-shadow .15s;
}
.button:hover, button:hover { background: var(--primary-hover); border-color: var(--primary-hover); text-decoration: none; }
.button:active, button:active { background: var(--primary-press); }
.button:focus-visible, button:focus-visible { outline: none; box-shadow: var(--focus); }
button:disabled { background: var(--line-strong); border-color: var(--line-strong); cursor: not-allowed; }
.button.secondary { background: var(--card); color: var(--navy); border-color: var(--line-strong); }
.button.secondary:hover { background: var(--subtle); }
button.link { height: auto; padding: 0; border: 0; background: none; box-shadow: none; color: var(--primary); font-weight: 500; }
button.link:hover { background: none; text-decoration: underline; text-underline-offset: 2px; }
button.link:focus-visible { box-shadow: none; outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 2px; }
a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 3px; }

/* Forms */
label { color: var(--text-2); font-size: 13px; font-weight: 500; }
input, select {
  font: 400 14px var(--font); color: var(--text); height: 40px; padding: 0 12px;
  background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: var(--text-3); }
input:hover, select:hover { border-color: #b4bfcf; }
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; margin: 0; box-shadow: none; accent-color: var(--primary); cursor: pointer; flex: none; }
input[type="file"] { height: auto; padding: 6px; width: 100%; max-width: 420px; color: var(--text-2); }
input[type="file"]::file-selector-button { font: 500 13px var(--font); height: 30px; padding: 0 12px; margin-right: 12px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--subtle); color: var(--navy); cursor: pointer; }
input[type="file"]::file-selector-button:hover { background: var(--line); }
.filters { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; margin: 0; }
.filters label { display: flex; flex-direction: column; gap: 6px; }
.stack { display: flex; flex-direction: column; gap: 16px; margin: 0; }
.stack label { display: flex; flex-direction: column; gap: 6px; }
.stack button { width: 100%; margin-top: 4px; }
input[name="code"] { font-variant-numeric: tabular-nums; letter-spacing: 0.2em; font-size: 16px; }

/* Messages */
.error, .notice { display: block; border: 1px solid; border-radius: var(--r-md); padding: 12px 14px; margin: 0 0 16px; font-size: 14px; }
.error { background: var(--err-bg); border-color: var(--err-line); color: var(--err); }
.error strong { color: var(--err); }
.error pre { margin: 10px 0 0; background: #fff; border-color: var(--err-line); color: var(--navy); }
.notice { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.problems { margin: 6px 0 0; padding-left: 16px; font-size: 13px; color: var(--err); }
.problems li { margin: 2px 0; }

/* Status tags */
.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; line-height: 20px; padding: 0 8px; border-radius: var(--r-sm); border: 1px solid; white-space: nowrap; }
.tag::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag.open { background: var(--err-bg); border-color: var(--err-line); color: var(--err); }
.tag.done { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); margin-bottom: 20px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 500; color: var(--text-2); background: var(--subtle); white-space: nowrap; padding-top: 10px; padding-bottom: 10px; }
tbody tr:last-child > td { border-bottom: 0; }
.table-wrap > table > tbody > tr:hover > td { background: #FAFBFD; }
td .muted { font-size: 12.5px; }
tr.detail td { padding-top: 0; }
tr.has-errors + tr.detail td, tr:has(+ tr.detail) td { border-bottom: 0; }
.table-wrap > table > tbody > tr:has(+ tr.detail):hover > td, .table-wrap > table > tbody > tr:has(+ tr.detail):hover + tr.detail > td,
.table-wrap > table > tbody > tr.detail:hover > td { background: #FAFBFD; }
table.boxes { width: auto; min-width: 360px; margin: 8px 0 4px; border: 1px solid var(--line); border-radius: var(--r-md); border-collapse: separate; border-spacing: 0; overflow: hidden; }
table.boxes td { padding: 6px 12px; font-size: 13px; border-bottom: 1px solid var(--line); background: var(--card) !important; }
table.boxes tr:last-child td { border-bottom: 0; }
table.boxes td:first-child { color: var(--text-2); white-space: nowrap; }
details summary { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--primary); font-size: 13px; font-weight: 500; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: ''; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
details[open] summary::before { transform: rotate(45deg); }
td form.inline { display: inline; margin-left: 10px; }
form.inline { display: inline; margin-left: 8px; }

.pdf-link { white-space: nowrap; font-weight: 500; }

/* Upload summary */
.summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 6px; }
.summary .file { font-weight: 600; color: var(--navy); }
.summary .count { color: var(--text-2); }
.summary .count strong { color: var(--navy); }

/* Declaration */
.declaration { margin-top: 4px; padding: 20px 24px; background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--coral); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.declaration h2 { margin: 0 0 8px; font-size: 16px; }
.declaration p { color: var(--text-2); }
.declaration label { display: flex; gap: 10px; align-items: flex-start; color: var(--text); font-size: 14px; font-weight: 400; line-height: 1.5; margin-bottom: 18px; }
.declaration label input { margin-top: 3px; }
.declaration p:last-child { margin: 0; }

/* Dashboard */
.connection { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; }
.connection p { margin: 8px 0 0; }
.connection .actions { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 8px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); padding: 16px 20px; }
.stat-label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.stat-value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; color: var(--navy); font-variant-numeric: tabular-nums; margin: 4px 0 2px; }
.stat-note { font-size: 12px; color: var(--text-3); }
.dash-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.dash-grid h2 { margin-top: 24px; }
.quick { padding: 6px; }
.quick a { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md); color: var(--navy); transition: background-color .15s; }
.quick a:hover { background: var(--subtle); text-decoration: none; }
.quick a > svg { width: 18px; height: 18px; color: var(--primary); flex: none; margin-top: 2px; }
.quick a > span { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.quick strong { font-weight: 500; }

/* MFA setup */
.qr { display: inline-block; padding: 10px; background: #fff; border: 1px solid var(--line); border-radius: var(--r-md); margin: 4px 0 12px; }
.qr img { display: block; }
.steps { color: var(--text-2); }
.secret code { word-spacing: 4px; display: inline-block; margin-top: 4px; }

@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
}

@media (max-width: 760px) {
  .topbar-inner { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 8px 12px; }
  .topbar nav { order: 3; width: 100%; margin: 0 -4px; }
  .topbar nav a { height: 34px; padding: 0 10px; }
  .brand img { height: 28px; }
  .env { font-size: 10.5px; padding: 2px 6px; }
  main { padding: 24px 16px 48px; }
  h1 { font-size: 24px; }
  .card { padding: 16px; }
  body.auth main { padding-top: 32px; }
  body.auth .card { padding: 24px 20px; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters input, .filters select, .filters button { width: 100%; }
  .declaration { padding: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .stat { padding: 14px 16px; }
  .stat-value { font-size: 24px; }
  .dash-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  table.boxes { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media print {
  .topbar, button { display: none; }
  body { background: #fff; }
  .table-wrap, .card { box-shadow: none; border-color: #ccc; }
  th { background: #f3f3f3; }
}
.button svg { width: 16px; height: 16px; flex: none; }
