:root {
  --bg: #f5f6f8;
  --panel: #fff;
  --ink: #1d2433;
  --muted: #5f6b7a;
  --line: #dde1e7;
  --accent: #0b5cad;
  --accent-soft: #e6f0fa;
  --todo: #6b778c;
  --todo-bg: #eef0f3;
  --prog: #0b5cad;
  --prog-bg: #e3eefb;
  --done: #1d7a46;
  --done-bg: #e3f4ea;
  --warn: #9a5b00;
  --warn-bg: #fff3dc;
  --bad: #b3261e;
  --bad-bg: #fdecea;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 8px; }
h3 { font-size: 14px; margin: 12px 0 6px; }
p { margin: 6px 0; }
pre { white-space: pre-wrap; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { border: 1px solid var(--line); border-radius: 4px; padding: 5px 7px; background: #fff; max-width: 100%; }
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button { border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 4px; padding: 5px 12px; cursor: pointer; }
button.secondary { background: #fff; color: var(--accent); }
button.link { border: 0; background: none; color: var(--accent); padding: 2px 0; text-decoration: underline; }
button:disabled { opacity: .55; cursor: default; }
.muted { color: var(--muted); }
.pad { padding: 16px; }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.error { color: var(--bad); }
.hidden { display: none !important; }

/* Header */
.top { display: flex; align-items: center; gap: 16px; padding: 0 16px; background: #14213d; color: #fff; min-height: 48px; position: sticky; top: 0; z-index: 20; }
.brand { color: #fff; font-weight: 600; text-decoration: none; white-space: nowrap; }
#nav { display: flex; flex-wrap: wrap; gap: 2px; flex: 1; }
#nav a { color: #cfd8e8; text-decoration: none; padding: 13px 8px; border-bottom: 3px solid transparent; white-space: nowrap; }
#nav a:hover { color: #fff; }
#nav a.active { color: #fff; border-bottom-color: #f2b705; }
.who { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.who button { background: transparent; border-color: #5a6b8c; padding: 3px 8px; }
.nav-toggle { display: none; background: transparent; border-color: #5a6b8c; }

main { padding: 16px; max-width: 1500px; margin: 0 auto; }
.page-head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head .spacer { flex: 1; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; min-width: 0; }
.card > h2 { display: flex; gap: 8px; align-items: baseline; }
.card > h2 .count { color: var(--muted); font-weight: normal; font-size: 13px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); gap: 14px; align-items: start; }
.cols > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 14px; }

/* Status */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap; }
.cat-todo { background: var(--todo-bg); color: var(--todo); }
.cat-in-progress { background: var(--prog-bg); color: var(--prog); }
.cat-done { background: var(--done-bg); color: var(--done); }
select.status { border-radius: 10px; padding: 1px 6px; font-size: 12px; border-color: transparent; }
.tag { display: inline-block; padding: 0 6px; border-radius: 3px; font-size: 11px; background: var(--todo-bg); color: var(--muted); margin-right: 4px; white-space: nowrap; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.ok { background: var(--done-bg); color: var(--done); }

/* Tables */
.table-wrap { overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; }
table.grid th, table.grid td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; cursor: default; user-select: none; background: #fafbfc; position: sticky; top: 0; }
table.grid th[aria-sort], table.grid th.sortable { cursor: pointer; }
table.grid tr:hover td { background: #f8fafc; }
table.grid td.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
table.grid tr.row-overdue td:first-child { box-shadow: inset 3px 0 var(--bad); }
table.grid tr.row-waiting td:first-child { box-shadow: inset 3px 0 var(--warn); }
.empty { color: var(--muted); font-style: italic; margin: 6px 0; }
.ilink { text-decoration: none; }
.ilink:hover { text-decoration: underline; }
.key { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* Filters and forms */
.filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.filters input[type=search] { min-width: 200px; }
.chk { display: inline-flex; gap: 4px; align-items: center; white-space: nowrap; }
.multi { display: flex; flex-wrap: wrap; gap: 4px 12px; }
form.quick { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; padding: 10px; background: var(--accent-soft); border-radius: var(--radius); margin: 8px 0 12px; }
form.quick .quick-title { font-weight: 600; align-self: center; margin-right: 4px; }
form.quick input[type=text] { min-width: 220px; }
form.quick label.fld { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 1px; }
.form-grid { display: grid; grid-template-columns: 160px 1fr; gap: 6px 10px; align-items: start; }
.form-grid > label { color: var(--muted); font-size: 12px; padding-top: 6px; }
.form-grid input:not([type=checkbox]), .form-grid select { width: 100%; }

/* Home */
.milestones { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 14px; }
.ms { flex: 0 0 190px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; border-top: 4px solid var(--todo); }
.ms.next { border-top-color: var(--accent); box-shadow: 0 1px 6px rgba(11, 92, 173, .18); }
.ms.late { border-top-color: var(--bad); }
.ms.done { border-top-color: var(--done); opacity: .75; }
.ms .days { font-size: 22px; font-weight: 600; line-height: 1.2; }
.ms .name { font-weight: 600; min-height: 38px; }
.meter { height: 8px; background: var(--todo-bg); border-radius: 4px; overflow: hidden; min-width: 80px; }
.meter > span { display: block; height: 100%; background: var(--done); }
.meter.low > span { background: var(--bad); }
.meter.mid > span { background: #d18a00; }
details.team { border-top: 1px solid var(--line); padding: 6px 0; }
details.team summary { cursor: pointer; font-weight: 600; }

/* Stacked bar */
.stackbar { display: flex; height: 18px; border-radius: 3px; overflow: hidden; background: var(--todo-bg); min-width: 200px; }
.stackbar > span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* Matrix and timeline */
table.matrix td, table.matrix th { text-align: center; }
table.matrix td:first-child, table.matrix th:first-child { text-align: left; }
.timeline { position: relative; }
.tl-row { display: grid; grid-template-columns: minmax(180px, 30%) 1fr; align-items: center; min-height: 24px; border-bottom: 1px solid #eef0f3; }
.tl-label { padding: 2px 8px 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.tl-label.child { padding-left: 18px; color: var(--muted); }
.tl-track { position: relative; height: 22px; }
.tl-bar { position: absolute; top: 5px; height: 12px; border-radius: 3px; background: var(--prog); min-width: 4px; }
.tl-bar.cat-done { background: var(--done); }
.tl-bar.cat-todo { background: #8a96a8; }
.tl-bar.late { background: var(--bad); }
.tl-mark { position: absolute; top: 0; bottom: 0; border-left: 1px dashed #b9c2cf; }
.tl-mark.critical { border-left-color: var(--bad); }
.tl-mark.today { border-left: 2px solid #f2b705; }
.tl-head .tl-track { height: 44px; }
.tl-head .tl-mark span { position: absolute; top: 0; left: 3px; font-size: 11px; white-space: nowrap; color: var(--muted); transform-origin: left top; }

/* Meetings */
.split { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 14px; align-items: start; }
.mlist { list-style: none; margin: 0; padding: 0; }
.mlist li { border-bottom: 1px solid var(--line); }
.mlist a { display: block; padding: 8px; text-decoration: none; color: inherit; }
.mlist a.active { background: var(--accent-soft); }
.mlist .when { font-size: 12px; color: var(--muted); }

/* Drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); background: var(--panel); border-left: 1px solid var(--line); box-shadow: -4px 0 18px rgba(0, 0, 0, .12); z-index: 40; overflow-y: auto; padding: 14px 16px 40px; }
.drawer-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.drawer-head .spacer { flex: 1; }
.drawer h2 { margin-top: 18px; font-size: 14px; }
.icon { background: none; border: 0; color: var(--muted); font-size: 22px; line-height: 1; padding: 0 4px; }
.comment { border-left: 3px solid var(--line); padding: 2px 10px; margin: 8px 0; }

/* Upload */
.steps .card h2 .n { display: inline-block; width: 22px; height: 22px; border-radius: 11px; background: var(--accent); color: #fff; text-align: center; font-size: 13px; line-height: 22px; }
.progress { height: 10px; background: var(--todo-bg); border-radius: 5px; overflow: hidden; margin: 8px 0; }
.progress > span { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.counts { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.counts > div { background: var(--bg); border-radius: var(--radius); padding: 8px 14px; min-width: 110px; }
.counts b { display: block; font-size: 20px; }
.change { font-size: 12px; }
.change del { color: var(--bad); }
.change ins { color: var(--done); text-decoration: none; }

/* Login */
.login { max-width: 380px; margin: 10vh auto; }
.login form { display: grid; gap: 10px; }
.login label { display: grid; gap: 3px; font-size: 13px; color: var(--muted); }

/* Toasts */
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 6px; z-index: 60; }
.toast { background: #14213d; color: #fff; padding: 8px 14px; border-radius: 4px; box-shadow: 0 2px 8px rgba(0, 0, 0, .2); max-width: 90vw; }
.toast.error { background: var(--bad); }

@media (max-width: 900px) {
  .nav-toggle { display: inline-block; }
  .top { flex-wrap: wrap; }
  #nav { display: none; flex-basis: 100%; flex-direction: column; }
  #nav.open { display: flex; }
  #nav a { padding: 8px; }
  .cols { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  main { padding: 10px; }
}

@media print {
  .top, .filters, form.quick, .drawer, button { display: none !important; }
}
