:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e1e5ec;
  --text: #1c2430;
  --muted: #667085;
  --primary: #1447d4;
  --primary-dark: #0f38a8;
  --navy: #0b1f3f;
  --series-1: #1447d4;
  --series-2: #eb6834;
  --good: #17804a;
  --bad: #c0362c;
  --warn: #b26a00;
  --track: #e8ecf2;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.good { color: var(--good); }
.bad { color: var(--bad); }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--navy);
  color: #c9d2e3;
  padding: 14px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.brand { background: #fff; border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; }
.brand img { display: block; width: 100%; height: auto; }
.sidebar a {
  color: inherit;
  text-decoration: none;
  padding: 9px 12px;
  border-radius: 8px;
}
.sidebar a:hover { background: #17305a; }
.sidebar a.active { background: var(--primary); color: #fff; }
.sidebar .spacer { flex: 1; }
.sidebar .who { padding: 10px 12px; font-size: 13px; }
.sidebar .who strong { color: #fff; display: block; }
.main { padding: 24px 28px 48px; min-width: 0; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 { margin-bottom: 18px; }

/* forms */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #c9d0db;
  border-radius: 8px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9dbcf0; border-color: var(--primary); }
textarea { resize: vertical; min-height: 64px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.check { display: flex; align-items: center; gap: 6px; font-weight: 400; margin-top: 6px; }
.check input { width: auto; }
.error { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 10px; }

button, .btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid #c9d0db;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .btn:hover { background: #f1f4f8; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.link { border: 0; background: none; padding: 2px 4px; color: var(--primary); font-weight: 500; }
button.link.danger { color: var(--bad); }
button:disabled { opacity: .6; cursor: default; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
th.num { text-align: right; }
tbody tr:hover { background: #fafbfd; }
tfoot td { font-weight: 700; border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: #eef2f8; font-size: 12px; white-space: nowrap; }
.tag.warn { background: #fdf1dc; color: var(--warn); }
.tag.good { background: #e3f4ea; color: var(--good); }
.tag.bad { background: #fbe6e4; color: var(--bad); }
button.tag { border: 0; font-weight: 400; cursor: pointer; text-decoration: underline; }
button.tag.bad:hover { background: #f6d3d0; }
.sub { color: var(--muted); font-size: 13px; }

/* bars */
.bar-row { margin-bottom: 12px; }
.bar-row .top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.track { height: 8px; background: var(--track); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.fill { height: 100%; background: var(--primary); border-radius: 999px; }
.fill.over { background: var(--bad); }
.trend { display: flex; align-items: flex-end; gap: 10px; height: 190px; }
.trend .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; min-width: 0; }
.trend .amt { font-size: 11px; color: var(--muted); white-space: nowrap; }
.trend .bar { width: 100%; max-width: 46px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; }
.trend .lbl { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* auth */
.auth { max-width: 380px; margin: 9vh auto; padding: 0 16px; }
.auth .card { padding: 26px; }
.auth h1 { margin-bottom: 4px; }
.auth .logo { display: block; width: 200px; height: auto; margin: 0 auto 18px; }
.auth .field { margin-top: 14px; }
.auth button { width: 100%; margin-top: 18px; }

/* modal & toast */
dialog {
  border: 0;
  border-radius: 12px;
  padding: 22px;
  width: min(560px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(16, 24, 40, .3);
}
dialog::backdrop { background: rgba(16, 24, 40, .45); }
dialog h2 { font-size: 18px; margin-bottom: 16px; }
#toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #172033;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
#toast.show { opacity: 1; }
#toast.err { background: var(--bad); }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .brand { width: 150px; margin: 0 100% 6px 0; padding: 6px 10px; }
  .sidebar .spacer { display: none; }
  .main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}

/* charts */
.chart { display: block; width: 100%; height: auto; }
.chart text { font-size: 11px; fill: var(--muted); }
.chart .grid { stroke: var(--track); stroke-width: 1; }
.chart .axis { stroke: #c3cad6; stroke-width: 1; }
.legend { display: flex; gap: 16px; font-size: 13px; margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
#tip {
  position: fixed;
  z-index: 50;
  background: var(--navy);
  color: #fff;
  font-size: 12px;
  line-height: 1.45;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: pre-line;
  pointer-events: none;
}

/* alerts, notices, scan results */
.alerts, .notes { list-style: none; margin: 0; padding: 0; }
.alerts li { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--border); }
.alerts li:last-child { border-bottom: 0; }
.alerts li span:nth-child(2) { flex: 1; }
.alerts .mark {
  flex: none;
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: var(--muted);
}
.alerts .bad .mark { background: var(--bad); }
.alerts .warn .mark { background: var(--warn); }
.notes li { padding: 6px 0 6px 16px; position: relative; }
.notes li::before { content: "•"; position: absolute; left: 2px; color: var(--muted); }
.notice { background: #fdf1dc; color: #7a4a00; border-radius: 8px; padding: 10px 14px; margin-bottom: 18px; font-size: 14px; }
.scan { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: #eef2f8; font-size: 14px; border-left: 4px solid var(--muted); }
.scan.good { background: #e3f4ea; border-color: var(--good); }
.scan.bad { background: #fbe6e4; border-color: var(--bad); }
.scan.warn { background: #fdf1dc; border-color: var(--warn); }
.scan ul { margin: 6px 0 8px; padding-left: 18px; }
.scan button { padding: 5px 10px; font-size: 13px; }

/* notes, help, salary slip */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.note { margin-bottom: 0; display: flex; flex-direction: column; gap: 8px; }
.note-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.note-head h2 { margin: 0; }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.pinned { padding: 8px 0; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.help { margin: 0; padding-left: 20px; }
.help li { padding: 4px 0; }
.slip { max-width: 760px; }
a.link { color: var(--primary); text-decoration: none; padding: 2px 4px; }
input[type="month"] { width: auto; }

/* monthly report header */
.report-head { display: flex; align-items: center; gap: 18px; margin-bottom: 18px; }
.report-head img { width: 170px; height: auto; background: #fff; border-radius: 8px; padding: 6px 10px; border: 1px solid var(--border); }
.report-head .title { font-size: 22px; font-weight: 700; }
select#month { width: auto; }

@media print {
  body { background: #fff; }
  #tip { display: none !important; }
  .report-head img { border: 0; padding: 0; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .shell { display: block; }
  .sidebar, .no-print, #toast { display: none !important; }
  .main { padding: 0; }
  .card, .stat { break-inside: avoid; }
}
