:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #16202c;
  --ink-soft: #5a6b7c;
  --line: #dfe5ec;
  --brand: #1f5f8b;
  --brand-dark: #16455f;
  --brand-soft: #e8f1f7;
  --good: #1f7a4d;
  --good-soft: #e6f4ec;
  --warn: #9a6a00;
  --warn-soft: #fdf3dd;
  --bad: #b03030;
  --bad-soft: #fbeaea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 6px 18px rgba(16, 32, 48, .06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--brand); }

/* ----------------------------- sign-in ------------------------------- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, #eaf1f6 0%, #f4f6f8 55%);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 32px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 24px; }
.auth-card .sub { color: var(--ink-soft); margin: 0 0 24px; font-size: 15px; }

/* ------------------------------ layout ------------------------------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--brand-dark);
  color: #dce8f0;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sidebar .brand {
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  line-height: 1.3;
  padding: 4px 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,.14);
  margin-bottom: 12px;
}
.sidebar .brand small { display: block; font-weight: 400; font-size: 12px; color: #a9c4d6; margin-top: 4px; }
.sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #cfe0ec;
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 15px;
}
.sidebar a:hover { background: rgba(255,255,255,.09); color: #fff; }
.sidebar a.active { background: #fff; color: var(--brand-dark); font-weight: 600; }
.sidebar .spacer { flex: 1; }
.sidebar .who { font-size: 13px; color: #a9c4d6; padding: 12px; border-top: 1px solid rgba(255,255,255,.14); line-height: 1.7; }
.sidebar .who a { display: inline; padding: 0; border-radius: 0; font-size: 13px; color: #a9c4d6; text-decoration: underline; }
.sidebar .who a:hover { background: none; color: #fff; }

.main { padding: 26px 30px 60px; max-width: 1180px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0 0 4px; font-size: 26px; }
.page-head p { margin: 0; color: var(--ink-soft); font-size: 15px; max-width: 62ch; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------ pieces ------------------------------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.card > h2 { margin: 0 0 4px; font-size: 18px; }
.card > h2 + .hint { margin-top: 0; }
.hint { color: var(--ink-soft); font-size: 14px; margin: 0 0 16px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat .label { font-size: 13px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 27px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.stat .note { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.stat.good .value { color: var(--good); }
.stat.bad .value { color: var(--bad); }

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); font-weight: 600; background: #fafbfc; }
tbody tr:hover { background: #fbfcfd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: none; }
.table-wrap { overflow-x: auto; }
.card > .table-wrap { margin: 0 -20px -20px; }
.card > .table-wrap th:first-child, .card > .table-wrap td:first-child { padding-left: 20px; }
.card > .table-wrap th:last-child, .card > .table-wrap td:last-child { padding-right: 20px; }

.empty { text-align: center; padding: 34px 16px; color: var(--ink-soft); }
.empty strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

/* ------------------------------ forms -------------------------------- */
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 5px; }
label .opt { font-weight: 400; color: var(--ink-soft); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=file], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #c7d1db;
  border-radius: 8px;
  font: inherit;
  font-size: 15px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
textarea { min-height: 110px; resize: vertical; }
.field { margin-bottom: 14px; }
.field-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: auto; }

button, .btn {
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
button:hover, .btn:hover { background: var(--brand-dark); }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--brand); border-color: #bcd0de; }
.btn-secondary:hover { background: var(--brand-soft); color: var(--brand-dark); }
.btn-quiet { background: transparent; color: var(--ink-soft); border-color: transparent; padding: 6px 10px; }
.btn-quiet:hover { background: #eef1f4; color: var(--ink); }
.btn-danger { background: var(--bad); }
.btn-danger:hover { background: #8d2626; }
.btn-sm { padding: 5px 10px; font-size: 14px; }

/* ------------------------------ chips -------------------------------- */
.chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  background: #eef1f4;
  color: var(--ink-soft);
  white-space: nowrap;
}
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.brand { background: var(--brand-soft); color: var(--brand); }

.banner {
  border-radius: var(--radius);
  padding: 13px 16px;
  margin-bottom: 18px;
  font-size: 15px;
  border: 1px solid transparent;
}
.banner.info { background: var(--brand-soft); border-color: #c6dced; color: var(--brand-dark); }
.banner.good { background: var(--good-soft); border-color: #b9dfc9; color: var(--good); }
.banner.warn { background: var(--warn-soft); border-color: #ecd9a5; color: var(--warn); }
.banner.bad  { background: var(--bad-soft); border-color: #edc2c2; color: var(--bad); }
.banner a { color: inherit; }

/* ------------------------------ modal -------------------------------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(16,32,48,.45);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal {
  background: #fff; border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.25);
  width: 100%; max-width: 560px; max-height: 88vh; overflow: auto;
}
.modal header { padding: 18px 22px 6px; }
.modal header h3 { margin: 0; font-size: 19px; }
.modal .body { padding: 8px 22px 4px; }
.modal footer { padding: 14px 22px 20px; display: flex; justify-content: flex-end; gap: 8px; }

.toast-wrap { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 9px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 15px; max-width: 380px;
}
.toast.bad { background: var(--bad); }
.toast.good { background: var(--good); }

.loading { padding: 40px; text-align: center; color: var(--ink-soft); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button {
  background: transparent; color: var(--ink-soft); border: none; border-bottom: 3px solid transparent;
  border-radius: 0; padding: 9px 14px;
}
.tabs button:hover { background: #edf1f4; color: var(--ink); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); background: transparent; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 15px; }
.kv dt { color: var(--ink-soft); }
.kv dd { margin: 0; font-weight: 600; }

.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-soft); }
.small { font-size: 14px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; }
.mb0 { margin-bottom: 0; }

/* ------------------------- printable documents ------------------------ */
.sheet {
  background: #fff; max-width: 8.5in; margin: 20px auto; padding: 0.6in 0.7in;
  box-shadow: var(--shadow); border-radius: 4px; color: #111;
}
.sheet h1 { font-size: 22px; margin: 0 0 2px; }
.sheet h2 { font-size: 16px; margin: 26px 0 8px; border-bottom: 2px solid #111; padding-bottom: 4px; }
.sheet .doc-head { display: flex; justify-content: space-between; gap: 24px; border-bottom: 3px solid #111; padding-bottom: 12px; }
.sheet table { font-size: 13.5px; }
.sheet th, .sheet td { padding: 6px 8px; }
.sheet table td:first-child { white-space: nowrap; }
.sheet .doc-title { font-size: 19px; font-weight: 700; white-space: nowrap; }
.sheet .footnote { margin-top: 30px; font-size: 12px; color: #555; border-top: 1px solid #ccc; padding-top: 10px; }
.print-bar { max-width: 8.5in; margin: 16px auto 0; display: flex; gap: 8px; justify-content: flex-end; }

@media print {
  .sidebar, .print-bar, .page-head .head-actions, .toast-wrap { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; max-width: none; }
  body { background: #fff; }
  .sheet { box-shadow: none; margin: 0; max-width: none; padding: 0; }
  .card { box-shadow: none; border: none; page-break-inside: avoid; }
  h2 { page-break-after: avoid; }
  table { page-break-inside: auto; }
  tr { page-break-inside: avoid; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; padding: 12px; gap: 4px; }
  .sidebar .brand { width: 100%; border-bottom: none; padding-bottom: 8px; margin-bottom: 4px; }
  .sidebar .spacer { display: none; }
  .sidebar .who { width: 100%; border-top: 1px solid rgba(255,255,255,.14); }
  .sidebar a { padding: 7px 11px; font-size: 14px; }
  .main { padding: 18px 16px 50px; }
}
