:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #667085; --line: #e4e7ec;
  --primary: #1f5eff; --primary-dark: #1546c4; --danger: #d92d20; --ok: #079455; --warn: #b54708;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { display: grid; place-items: center; min-height: 60vh; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: #101828; color: #d0d5dd; padding: 1rem .75rem; display: flex; flex-direction: column; gap: .25rem; }
.sidebar .brand { color: #fff; font-weight: 700; font-size: 1.05rem; padding: .25rem .6rem 1rem; }
.sidebar a { color: #d0d5dd; padding: .55rem .7rem; border-radius: 8px; display: block; }
.sidebar a:hover { background: #1d2939; text-decoration: none; }
.sidebar a.active { background: var(--primary); color: #fff; }
.sidebar .spacer { flex: 1; }
.main { padding: 1.5rem 2rem; max-width: 1300px; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.topbar h1 { margin: 0; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 1rem; }
.cards { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; }
  .sidebar .spacer { display: none; }
  .main { padding: 1rem; }
  .two { grid-template-columns: 1fr; }
}

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: .25rem; }
.mb { margin-bottom: 1rem; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .8rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f9fafb; }
td.actions { white-space: nowrap; text-align: right; }
tfoot td { font-weight: 700; background: #fafbfc; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

/* forms */
button, .btn {
  font: inherit; border: 1px solid var(--line); background: #fff; color: var(--text); padding: .5rem .9rem;
  border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap;
}
button:hover, .btn:hover { background: #f2f4f7; text-decoration: none; }
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--primary-dark); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--primary); padding: .2rem .4rem; }
button.link.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea {
  font: inherit; width: 100%; padding: .5rem .65rem; border: 1px solid #d0d5dd; border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d7fe; border-color: var(--primary); }
input[type=checkbox] { width: auto; }
label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; }
.field { margin-bottom: .85rem; }
.field .help { font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: .25rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
.filters input, .filters select { width: auto; min-width: 180px; }

/* badges */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #f2f4f7; color: #344054; }
.badge.current, .badge.posted { background: #dcfae6; color: var(--ok); }
.badge.past { background: #f2f4f7; color: var(--muted); }
.badge.future, .badge.calculated { background: #e0eaff; color: var(--primary-dark); }
.badge.draft { background: #fef0c7; color: var(--warn); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(16,24,40,.5); display: grid; place-items: center; padding: 1rem; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: min(720px, 100%); max-height: 92vh; overflow: auto; padding: 1.5rem; }
.modal.wide { width: min(1000px, 100%); }
.modal .footer { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.error { background: #fef3f2; color: var(--danger); padding: .6rem .8rem; border-radius: 8px; margin-bottom: .8rem; }
.notice { background: #eff4ff; color: #1d2939; padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }

.toast { position: fixed; bottom: 1.25rem; right: 1.25rem; background: #101828; color: #fff; padding: .75rem 1rem; border-radius: 8px; z-index: 60; max-width: 420px; }
.toast.err { background: var(--danger); }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth .card { width: min(420px, 100%); padding: 2rem; }
.tabs { display: flex; gap: .25rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs a, .tabs button { border: 0; background: none; padding: .55rem .8rem; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); }
.tabs a.active, .tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tabs a:hover { text-decoration: none; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
details summary { cursor: pointer; color: var(--primary); }
.weights { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
a.plain { color: inherit; text-decoration: none; }
a.plain:hover { text-decoration: none; box-shadow: 0 2px 6px rgba(16,24,40,.15); }
.sidebar .who { padding: .5rem .7rem; }
.m0 { margin: 0; }
.main.centered { margin: 0 auto; }
