:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #62707e;
  --primary: #1f6feb;
  --primary-d: #1858c4;
  --accent: #0a7d6b;
  --line: #dbe2ea;
  --warn: #b4541b;
  --shadow: 0 1px 3px rgba(16, 30, 54, .08), 0 6px 18px rgba(16, 30, 54, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    "PingFang SC", "Microsoft YaHei", "Hiragino Sans", "Noto Sans CJK", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 20px;
  background: linear-gradient(120deg, #0d2b4e, #14457a);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  font-size: 30px;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.3));
  animation: spin 14s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.brand-text h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: .2px; }
.brand-text .sub { margin: 2px 0 0; font-size: 12.5px; opacity: .82; }

.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lang-pick { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.lang-pick select {
  background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.3);
  border-radius: 7px; padding: 5px 8px; font-size: 13px; cursor: pointer;
}
.lang-pick select option { color: #1f2933; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.16); color: #fff; text-decoration: none;
  border: 1px solid rgba(255,255,255,.28); border-radius: 8px;
  padding: 7px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:hover { background: rgba(255,255,255,.28); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary-d); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn-home::before { content: "\2302"; font-size: 15px; }
.btn-mail::before { content: "\2709"; font-size: 15px; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  padding: 10px 16px 0; background: var(--bg);
  position: sticky; top: 64px; z-index: 40;
}
.tab {
  border: 1px solid var(--line); border-bottom: none;
  background: #e9eef4; color: var(--muted);
  padding: 9px 16px; border-radius: 10px 10px 0 0; cursor: pointer;
  font-size: 14px; font-weight: 600; transition: background .15s, color .15s;
}
.tab:hover { background: #dfe6ee; }
.tab.active { background: var(--panel); color: var(--primary-d); box-shadow: 0 -2px 6px rgba(16,30,54,.05); }

/* ---------- Layout ---------- */
main { padding: 0 16px 28px; }
.panel { display: none; }
.panel.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.panel > h2 { font-size: 18px; margin: 18px 4px 12px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px; box-shadow: var(--shadow);
}
.card > h3 { margin: 0 0 12px; font-size: 14px; color: var(--accent); text-transform: uppercase; letter-spacing: .4px; }

.form { display: flex; flex-direction: column; gap: 10px; }
.form.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 4px; }
.form label span { font-weight: 600; color: var(--ink); }
.form input, .form select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; color: var(--ink); background: #fff;
}
.form input:focus, .form select:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.form .check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-weight: 600; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.btn-row .btn { background: #eef2f7; color: var(--ink); border-color: var(--line); }
.btn-row .btn:hover { background: #e2e9f1; }
.btn-row .btn.primary { color: #fff; }

.svg-wrap { width: 100%; background: #fbfcfe; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.svg-wrap svg { width: 100%; height: auto; display: block; }
.svg-wrap canvas { display: block; max-width: 100%; height: auto; margin: 0 auto; background: #fbfcfe; }
.note { font-size: 12px; color: var(--muted); margin: 10px 2px 0; font-style: italic; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; max-height: 420px; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { position: sticky; top: 0; background: #eef2f7; color: var(--ink); font-weight: 700; }
tbody tr:nth-child(even) { background: #f8fafc; }
td:first-child, th:first-child { text-align: left; }

/* ---------- Results ---------- */
.results { display: flex; flex-direction: column; gap: 8px; }
.res-row { display: flex; justify-content: space-between; align-items: baseline;
  padding: 9px 12px; background: #f6f9fc; border: 1px solid var(--line); border-radius: 8px; }
.res-row .k { font-size: 13px; color: var(--muted); font-weight: 600; }
.res-row .v { font-size: 15px; font-weight: 700; color: var(--primary-d); font-variant-numeric: tabular-nums; }
.res-row .u { font-size: 12px; color: var(--muted); margin-left: 4px; }
.res-row .v.fail { color: #c0392b; font-weight: 800; }
.res-row .v.ok { color: #1f7a3d; font-weight: 700; }
.res-row .u.fail { color: #c0392b; font-weight: 800; }
.res-row .u.ok { color: #1f7a3d; font-weight: 700; }

.foot { text-align: center; padding: 18px; color: var(--muted); font-size: 12.5px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
  .form.two { grid-template-columns: 1fr; }
  .topbar { position: static; }
  .tabs { position: static; }
  .brand-text .sub { display: none; }
}

/* ---------- Print / PDF report ---------- */
@media print {
  body { background: #fff; }
  .topbar, .tabs, .foot, .btn-row, .lang-pick { display: none !important; }
  main { padding: 0; }
  .panel { display: none !important; }
  .panel.active { display: block !important; animation: none; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .grid { grid-template-columns: 1fr 1fr; }
  .svg-wrap { border: none; }
  .note { color: #444; }
}

/* ---------- Calculation sheet (report) ---------- */
.report-sheet { display: none; }
body.print-report .report-sheet {
  display: block; padding: 24px 28px; max-width: 820px; margin: 0 auto;
  color: #16202b; font-size: 13px; line-height: 1.5;
}
body.print-report .report-sheet h2 { font-size: 20px; margin: 0 0 2px; color: #14457a; }
body.print-report .report-sheet .rep-sub { color: #62707e; font-size: 12px; margin-bottom: 14px; }
body.print-report .report-sheet h3 {
  font-size: 14px; margin: 18px 0 6px; color: #0a7d6b;
  border-bottom: 2px solid #e2e8ee; padding-bottom: 3px;
}
body.print-report .report-sheet .rep-tbl { width: 100%; border-collapse: collapse; margin-top: 4px; }
body.print-report .report-sheet .rep-tbl td { padding: 6px 10px; border: 1px solid #dbe2ea; font-size: 13px; }
body.print-report .report-sheet .rep-tbl td.k { font-weight: 600; color: #444; width: 46%; background: #f6f9fc; }
body.print-report .report-sheet .rep-tbl td.v { font-weight: 700; font-variant-numeric: tabular-nums; }
body.print-report .report-sheet .rep-tbl td.u { color: #1f7a3d; font-weight: 700; width: 16%; text-align: center; }
body.print-report .report-sheet .rep-charts { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 6px; }
body.print-report .report-sheet .rep-cap { font-size: 12px; font-weight: 700; color: #444; margin-bottom: 2px; }
body.print-report .report-sheet .rep-verdict {
  font-size: 15px; font-weight: 800; padding: 10px 14px; border-radius: 8px; display: inline-block;
}
body.print-report .report-sheet .rep-verdict.ok { background: #e6f6ec; color: #1f7a3d; border: 1px solid #9fd9b4; }
body.print-report .report-sheet .rep-verdict.bad { background: #fdece6; color: #b4361b; border: 1px solid #f0b6a3; }
body.print-report .report-sheet svg { width: 100%; height: auto; border: 1px solid #dbe2ea; border-radius: 8px; }

/* When generating the calculation sheet, hide the app chrome and show only the sheet */
@media print {
  body.print-report .topbar,
  body.print-report .tabs,
  body.print-report .foot,
  body.print-report main,
  body.print-report .btn-row,
  body.print-report .lang-pick { display: none !important; }
}

