:root {
  --bg: #eef1f6;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --ink: #1e293b;
  --ink-soft: #475569;
  --muted: #64748b;
  --line: #dbe2ea;
  --line-soft: #eaeff5;
  --brand: #0b5394;
  --brand-dark: #083c6b;
  --brand-soft: #e7f0f9;
  --accent: #0f766e;
  --ok: #15803d;
  --ok-bg: #e9f7ef;
  --bad: #b91c1c;
  --bad-bg: #fdeceb;
  --warn: #b45309;
  --warn-bg: #fdf4e3;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .06);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .08);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial,
    "Noto Sans", "Microsoft YaHei", "Malgun Gothic", sans-serif;
  --mono: "Cascadia Mono", "Consolas", "SFMono-Regular", "Menlo", monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: linear-gradient(180deg, #0d5fa6 0%, var(--brand) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(8, 35, 62, .22);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand .logo {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .3);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .5px;
}

.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-text p {
  margin: 0;
  font-size: 11.5px;
  opacity: .82;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.lang-wrap { display: flex; align-items: center; }
.lang-wrap select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255, 255, 255, .14)
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M0 0l5 6 5-6z' fill='white'/></svg>")
    no-repeat right 9px center;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .38);
  border-radius: var(--radius-sm);
  padding: 7px 26px 7px 10px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.lang-wrap select option { color: #1e293b; background: #fff; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease;
}
.btn svg { width: 15px; height: 15px; flex: 0 0 auto; }
.btn-ghost {
  background: rgba(255, 255, 255, .12);
  border-color: rgba(255, 255, 255, .38);
  color: #fff;
}
.btn-ghost:hover { background: rgba(255, 255, 255, .22); text-decoration: none; }
.btn-solid { background: #fff; color: var(--brand-dark); }
.btn-solid:hover { background: #eaf2fb; text-decoration: none; }

/* ---------- Layout ---------- */
.layout {
  display: flex;
  align-items: flex-start;
  gap: 0;
  min-height: calc(100vh - 58px);
}

.sidebar {
  flex: 0 0 268px;
  width: 268px;
  align-self: stretch;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 14px 10px 28px;
  position: sticky;
  top: 58px;
  max-height: calc(100vh - 58px);
  overflow-y: auto;
}

.nav-group + .nav-group { margin-top: 16px; }
.nav-group-title {
  padding: 4px 10px 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: 13.2px;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--panel-2); text-decoration: none; color: var(--ink); }
.nav-item.active {
  background: var(--brand-soft);
  border-left-color: var(--brand);
  color: var(--brand-dark);
  font-weight: 600;
}
.nav-item .ico { flex: 0 0 auto; width: 17px; height: 17px; opacity: .85; }

.sidebar-foot {
  margin: 20px 8px 0;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

/* ---------- Main ---------- */
.main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 22px 26px 48px;
  max-width: 1180px;
}

.page-head { margin-bottom: 16px; }
.page-head h2 {
  margin: 0 0 4px;
  font-size: 21px;
  font-weight: 650;
  color: var(--ink);
}
.page-head p { margin: 0; color: var(--muted); font-size: 13.5px; }

.disclaimer-banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0 0 18px;
  padding: 10px 13px;
  background: var(--warn-bg);
  border: 1px solid #f0d9a8;
  border-left: 3px solid var(--warn);
  border-radius: var(--radius-sm);
  font-size: 12.2px;
  color: #6b4a12;
}
.disclaimer-banner svg { flex: 0 0 auto; width: 16px; height: 16px; margin-top: 1px; }

/* ---------- Cards & grid ---------- */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 18px; }

.card-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel-2);
  display: flex;
  align-items: center;
  gap: 9px;
}
.card-head h3 { margin: 0; font-size: 14px; font-weight: 650; color: var(--ink); }
.card-head .hint { margin-left: auto; font-size: 11.5px; color: var(--muted); font-weight: 400; }

.card-body { padding: 16px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }

.field label {
  display: block;
  margin-bottom: 5px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
}
.field .help {
  display: block;
  margin-top: 4px;
  font-size: 11.2px;
  color: var(--muted);
  line-height: 1.45;
}
.opt-tag {
  margin-left: 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--accent);
  background: #e6f4f1;
  border-radius: 3px;
  padding: 1px 5px;
  vertical-align: 1px;
}

input[type="number"], input[type="text"], select {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input[type="number"]:focus, input[type="text"]:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(11, 83, 148, .13);
}
input[readonly] { background: var(--panel-2); color: var(--ink-soft); }

.row { display: flex; gap: 10px; }
.row > * { flex: 1 1 0; min-width: 0; }
.row.tight { gap: 8px; }

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #fff;
}
.seg button {
  border: 0;
  background: transparent;
  padding: 7px 14px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--brand); color: #fff; }

.form-actions {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  margin-top: 18px;
  padding-top: 15px;
  border-top: 1px solid var(--line-soft);
}
.btn-primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-secondary {
  background: #fff;
  color: var(--ink-soft);
  border-color: var(--line);
}
.btn-secondary:hover { background: var(--panel-2); color: var(--ink); }

/* ---------- Results ---------- */
.result-list { display: flex; flex-direction: column; }
.result-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 9px 2px;
  border-bottom: 1px dashed var(--line-soft);
}
.result-row:last-child { border-bottom: 0; }
.result-row .k { flex: 1 1 auto; font-size: 12.8px; color: var(--ink-soft); }
.result-row .v {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--brand-dark);
  text-align: right;
  white-space: nowrap;
}
.result-row .v small { font-weight: 500; color: var(--muted); font-size: 11.5px; margin-left: 3px; }
.result-row.strong { background: var(--brand-soft); border-radius: var(--radius-sm); padding: 10px 12px; border-bottom: 0; margin-bottom: 4px; }
.result-row.strong .k { font-weight: 600; color: var(--brand-dark); }
.result-row.strong .v { font-size: 15.5px; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }

.result-empty { color: var(--muted); font-size: 12.8px; padding: 10px 2px; }

.note-box {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  font-size: 11.6px;
  color: var(--muted);
  line-height: 1.55;
}

.err-box {
  margin-top: 12px;
  padding: 9px 12px;
  background: var(--bad-bg);
  border: 1px solid #f3c9c6;
  border-radius: var(--radius-sm);
  color: var(--bad);
  font-size: 12.5px;
  font-weight: 600;
}

/* ---------- Home ---------- */
.hero {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 28px;
  margin-bottom: 20px;
}
.hero h2 { margin: 0 0 8px; font-size: 23px; font-weight: 650; }
.hero p { margin: 0; color: var(--muted); max-width: 74ch; font-size: 13.6px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(285px, 1fr));
  gap: 16px;
}
.tile {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 17px;
  color: inherit;
  transition: transform .13s ease, box-shadow .13s ease, border-color .13s ease;
}
.tile:hover {
  text-decoration: none;
  transform: translateY(-2px);
  border-color: #b9d2ea;
  box-shadow: var(--shadow);
}
.tile .t-ico {
  width: 38px; height: 38px;
  border-radius: 9px;
  background: var(--brand-soft);
  color: var(--brand);
  display: grid; place-items: center;
  margin-bottom: 12px;
}
.tile .t-ico svg { width: 20px; height: 20px; }
.tile h3 { margin: 0 0 6px; font-size: 14.5px; font-weight: 650; }
.tile p { margin: 0 0 14px; font-size: 12.6px; color: var(--muted); line-height: 1.5; flex: 1 1 auto; }
.tile .t-go { font-size: 12.5px; font-weight: 650; color: var(--brand); display: inline-flex; align-items: center; gap: 5px; }
.tile .t-go svg { width: 14px; height: 14px; }

.group-title {
  margin: 26px 0 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.group-title:first-of-type { margin-top: 4px; }

/* ---------- Disclaimer section ---------- */
.legal { margin-top: 30px; }
.legal .card-body p { margin: 0 0 11px; font-size: 12.7px; color: var(--ink-soft); line-height: 1.62; }
.legal .card-body p:last-child { margin-bottom: 0; }

/* ---------- Footer ---------- */
.app-foot {
  padding: 18px 26px 30px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 11.8px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.app-foot .dot { opacity: .5; }

/* ---------- Responsive ---------- */
@media (max-width: 940px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .sidebar { flex-basis: 224px; width: 224px; }
}

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar {
    position: static;
    width: 100%;
    flex-basis: auto;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 10px 14px;
  }
  .main { padding: 18px 16px 40px; }
  .brand-text p { display: none; }
  .header-actions { width: 100%; margin-left: 0; justify-content: flex-start; }
  .app-header { flex-wrap: wrap; }
  .hero { padding: 20px; }
}

@media (max-width: 480px) {
  .brand-text h1 { font-size: 13.5px; white-space: normal; }
  .btn { padding: 6px 10px; font-size: 12px; }
  .page-head h2 { font-size: 18px; }
}

/* ---------- Print ----------
   Shared print sheet: drop the app chrome, flatten the cards into one
   column, and keep the legal notice. Declared last so these rules win over
   the narrow-viewport media queries, which also match the print page width. */
.print-foot { display: none; }

@media print {
  @page { size: A4 portrait; margin: 12mm 12mm 14mm; }

  html {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  html, body { height: auto !important; }
  body {
    background: #fff !important;
    color: #000;
    font-size: 10.5pt;
    line-height: 1.4;
  }

  /* the sheet is the page content only */
  .app-header, .sidebar, .app-foot { display: none !important; }
  .layout { display: block; min-height: 0; }
  .main { max-width: none; padding: 0; }

  /* legal notice is kept, in plain ink */
  .disclaimer-banner {
    background: #fff !important;
    border: 1px solid #888;
    border-left: 3px solid #444;
    color: #000;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .page-head { break-after: avoid; page-break-after: avoid; }
  .page-head h2 { font-size: 15pt; }
  .page-head p { color: #333; font-size: 9.5pt; }

  /* one card per row, no shadows or tinted panels. Cards are allowed to flow
     across pages so long ones do not leave a blank page tail; the fine-grained
     break guards below (rows, badges, tiles) keep their content intact. */
  .grid { display: block; }
  .card {
    box-shadow: none !important;
    border-color: #888;
  }
  .card + .card { margin-top: 8mm; }
  .card-head {
    background: #f1f1f1 !important;
    border-bottom-color: #888;
    break-after: avoid;
    page-break-after: avoid;
  }
  .card-head h3 { font-size: 11.5pt; }
  .card-head .hint { color: #444; }
  .card-body { padding: 10px 12px; }

  /* form controls stay readable so the sheet is self-documenting */
  .field { margin-bottom: 10px; }
  .field label { color: #000; font-size: 9.5pt; }
  .field .help { color: #444; font-size: 8.8pt; }
  .row { display: flex; gap: 8px; }
  input[type="number"], input[type="text"], select {
    background: #fff !important;
    border-color: #999;
    color: #000;
    padding: 5px 8px;
    font-size: 10pt;
  }
  .seg { background: #fff; border-color: #999; }
  .seg button { color: #000; padding: 5px 10px; font-size: 9.8pt; }
  .seg button + button { border-left-color: #999; }
  .seg button.active {
    background: #dbe7f3 !important;
    color: #083c6b !important;
    box-shadow: inset 0 0 0 1px #7fa6c9;
  }
  .opt-tag { background: #fff; border: 1px solid #999; color: #000; }

  /* action buttons only make sense on screen */
  .form-actions { display: none !important; }

  /* results */
  .result-row {
    padding: 5px 2px;
    border-bottom-color: #ccc;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .result-row .k { color: #333; font-size: 9.8pt; }
  .result-row .v { color: #000; font-size: 10.5pt; }
  .result-row.strong {
    background: #eef4fb !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .result-row.strong .k,
  .result-row.strong .v { color: #000; }
  .result-empty { color: #555; }
  .badge { border: 1px solid #999; }
  .badge.ok { background: #eef7f1 !important; color: #14532d; }
  .badge.bad { background: #fdecec !important; color: #7f1d1d; }

  .note-box {
    background: #fff !important;
    border-color: #bbb;
    color: #333;
    font-size: 8.6pt;
  }
  .err-box { background: #fff !important; border-color: #999; color: #000; }

  /* home page */
  .hero { box-shadow: none !important; border-color: #888; padding: 14px 16px; }
  .hero h2 { font-size: 15pt; }
  .hero p { color: #333; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile {
    box-shadow: none !important;
    border-color: #999;
    padding: 10px 12px;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .tile .t-go { display: none; }
  .tile .t-ico { width: 26px; height: 26px; margin-bottom: 6px; }
  .tile .t-ico svg { width: 15px; height: 15px; }
  .tile h3 { font-size: 10.5pt; }
  .tile p { margin-bottom: 0; color: #333; font-size: 9.4pt; }
  .group-title {
    margin: 12px 0 6px;
    color: #333;
    break-after: avoid;
    page-break-after: avoid;
  }
  .legal { margin-top: 12px; }
  .legal .card-body p { color: #000; font-size: 9.4pt; }

  /* print-only source line, injected by app.js */
  .print-foot {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 6mm;
    padding-top: 2mm;
    border-top: 1px solid #999;
    font-size: 8.4pt;
    color: #444;
  }
}
