:root {
  --navy: #1f4e79; --navy-dark: #163a5a; --ink: #1c2530; --muted: #5d6b7a; --line: #d9dee5;
  --bg: #f3f5f8; --card: #ffffff; --accent: #2f80ed;
  --free: #e8eef5; --free-ink: #4a5a6a;
  --partial: #d9f0e3; --partial-ink: #1e6b3f;
  --full: #fde9c8; --full-ink: #8a5300;
  --over: #f9d6d5; --over-ink: #a11f1f;
  --off: #e4e6ea; --off-ink: #7a838d;
  --ok: #1e8e4e; --warn: #c77700; --bad: #c62828;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.4; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--ink); }
h1, h2, h3 { margin: 0 0 8px; font-weight: 600; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.loading { padding: 60px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: Consolas, "Courier New", monospace; }
.nowrap { white-space: nowrap; }

/* top bar */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 52px; position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; font-size: 16px; letter-spacing: .02em; display: flex; align-items: center; gap: 10px; }
.brand .logo { width: 26px; height: 26px; border-radius: 6px; background: #fff; color: var(--navy); display: inline-flex; align-items: center; justify-content: center; font-weight: 800; }
.nav { display: flex; gap: 2px; margin-left: 10px; }
.nav button { background: transparent; border: 0; color: #d6e2ef; padding: 8px 12px; border-radius: 6px; font-weight: 500; }
.nav button:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav button.active { background: rgba(255,255,255,.18); color: #fff; }
.nav .badge { background: #f2b134; color: #222; border-radius: 10px; padding: 0 6px; font-size: 11px; margin-left: 6px; font-weight: 700; }
.spacer { flex: 1; }
.userchip { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.12); padding: 4px 10px 4px 4px; border-radius: 20px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #f2b134; color: #222; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; }
.userchip .who { line-height: 1.15; }
.userchip .who b { display: block; font-size: 13px; }
.userchip .who span { font-size: 11px; color: #d6e2ef; }
.userchip button { background: transparent; border: 1px solid rgba(255,255,255,.4); color: #fff; border-radius: 12px; padding: 2px 8px; font-size: 11px; }
.modepill { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: rgba(255,255,255,.15); color: #d6e2ef; }
.modepill.live { background: #1e8e4e; color: #fff; }

/* layout */
.page { max-width: 1440px; margin: 0 auto; padding: 18px 20px 60px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.col { flex: 1; min-width: 280px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.card h2 { display: flex; align-items: center; gap: 10px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar label { color: var(--muted); font-size: 12px; display: flex; flex-direction: column; gap: 3px; }
.toolbar select, .toolbar input[type=text], .toolbar input[type=search] { min-width: 150px; }
input[type=text], input[type=search], input[type=number], select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; }
input[type=number] { width: 90px; }
textarea { width: 100%; min-height: 60px; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 12px; color: var(--ink); }
.btn:hover { background: #f4f6f9; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-dark); }
.btn.danger { color: var(--bad); border-color: #f0b7b7; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.weeknav { display: inline-flex; align-items: center; gap: 6px; }
.weeknav .label { font-weight: 600; min-width: 190px; text-align: center; }

/* tables */
table { border-collapse: collapse; width: 100%; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: #fafbfc; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f6f8fb; }
.table-wrap { overflow-x: auto; }

/* arithmetic block (journey A) */
.arith { display: grid; grid-template-columns: 1fr auto; row-gap: 4px; column-gap: 24px; font-size: 15px; }
.arith .line { display: contents; }
.arith .line > div:first-child { display: block; }
.arith .line .note { display: block; }
.arith .line .note { font-size: 12px; color: var(--muted); }
.arith .line .val { font-variant-numeric: tabular-nums; text-align: right; }
.arith .total { border-top: 2px solid var(--ink); font-weight: 600; padding-top: 6px; margin-top: 4px; }
.arith .total.val { border-top: 2px solid var(--ink); }
.arith .minus::before { content: "−  "; color: var(--muted); }
.arith .equals::before { content: "=  "; color: var(--muted); }
.bigval { font-size: 30px; font-weight: 700; line-height: 1; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.tag.free { background: var(--free); color: var(--free-ink); }
.tag.partial { background: var(--partial); color: var(--partial-ink); }
.tag.full { background: var(--full); color: var(--full-ink); }
.tag.over { background: var(--over); color: var(--over-ink); }
.tag.off { background: var(--off); color: var(--off-ink); }
.tag.role { background: #e6edf5; color: var(--navy); }
.tag.status-Pending { background: var(--full); color: var(--full-ink); }
.tag.status-Approved { background: var(--partial); color: var(--partial-ink); }
.tag.status-Rejected { background: var(--over); color: var(--over-ink); }

/* capacity grid (journey C) */
.grid-wrap { overflow: auto; max-height: calc(100vh - 260px); border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.grid { border-collapse: separate; border-spacing: 0; font-size: 12px; }
.grid th, .grid td { border-bottom: 1px solid var(--line); border-right: 1px solid #eef1f4; padding: 0; }
.grid thead th { position: sticky; top: 0; background: #fafbfc; z-index: 3; text-align: center; padding: 6px 4px; }
.grid thead th.cur { background: #e6edf5; color: var(--navy); }
.grid th.emp, .grid td.emp { position: sticky; left: 0; background: #fff; z-index: 2; min-width: 210px; text-align: left; padding: 4px 8px; }
.grid thead th.emp { z-index: 4; }
.grid td.emp b { display: block; font-weight: 600; }
.grid td.emp span { color: var(--muted); font-size: 11px; }
.grid td.cell { min-width: 62px; height: 40px; text-align: center; cursor: pointer; }
.grid td.cell > div { height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 2px; line-height: 1.15; }
.grid td.cell b { font-size: 13px; }
.grid td.cell small { font-size: 10px; opacity: .8; }
.grid td.cell.free > div { background: #fff; color: var(--free-ink); }
.grid td.cell.partial > div { background: var(--partial); color: var(--partial-ink); }
.grid td.cell.full > div { background: var(--full); color: var(--full-ink); }
.grid td.cell.over > div { background: var(--over); color: var(--over-ink); font-weight: 600; }
.grid td.cell.off > div { background: repeating-linear-gradient(135deg, #eceef1 0 4px, #f7f8fa 4px 8px); color: var(--off-ink); }
.grid td.cell.hl > div { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid td.cell:hover > div { filter: brightness(.95); }
.grid tfoot td { position: sticky; bottom: 0; background: #fafbfc; font-weight: 600; text-align: center; padding: 6px 4px; z-index: 3; border-top: 2px solid var(--line); }
.grid tfoot td.emp { z-index: 4; text-align: left; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); align-items: center; }
.legend .sw { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -3px; margin-right: 4px; border: 1px solid var(--line); }
.legend .sw.free { background: #fff; } .legend .sw.partial { background: var(--partial); } .legend .sw.full { background: var(--full); }
.legend .sw.over { background: var(--over); } .legend .sw.off { background: repeating-linear-gradient(135deg, #eceef1 0 3px, #f7f8fa 3px 6px); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.kpi .v { font-size: 26px; font-weight: 700; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.bad .v { color: var(--bad); } .kpi.ok .v { color: var(--ok); } .kpi.warn .v { color: var(--warn); }

/* budget bars (journey B) */
.budget { margin: 6px 0 10px; }
.budget .lbl { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 3px; }
.bar { height: 10px; background: #e9edf2; border-radius: 5px; overflow: hidden; position: relative; }
.bar > i { display: block; height: 100%; background: var(--ok); }
.bar.b80 > i { background: var(--warn); }
.bar.b90 > i { background: #e65100; }
.bar.b100 > i { background: var(--bad); }
.bar .m { position: absolute; top: 0; bottom: 0; width: 1px; background: rgba(0,0,0,.25); }
.signal { font-weight: 700; }
.signal.b80 { color: var(--warn); } .signal.b90 { color: #e65100; } .signal.b100 { color: var(--bad); } .signal.ok { color: var(--ok); }

/* project grid */
.pgrid td.cell { text-align: center; cursor: pointer; min-width: 52px; font-variant-numeric: tabular-nums; }
.pgrid td.cell:hover { background: #eef3fa; }
.pgrid td.cell.has { background: #e6edf5; font-weight: 600; }
.pgrid td.cell.over { background: var(--over); color: var(--over-ink); }
.pgrid th.cur { background: #e6edf5; color: var(--navy); }

/* sign in */
.signin { max-width: 1100px; margin: 30px auto; }
.signin .intro { margin-bottom: 20px; }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.person { display: flex; gap: 10px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; text-align: left; }
.person:hover { border-color: var(--navy); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.person .avatar { background: #e6edf5; color: var(--navy); width: 36px; height: 36px; }
.person b { display: block; }
.person span { color: var(--muted); font-size: 12px; }
.person.suggested { border-color: #f2b134; background: #fff9ec; }

/* modal */
#modal-root:empty { display: none; }
.modal-back { position: fixed; inset: 0; background: rgba(20,30,40,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 760px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { max-width: 960px; }
.modal header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; flex: 1; }
.modal header button { border: 0; background: transparent; font-size: 20px; color: var(--muted); }
.modal .body { padding: 16px 18px; }
.modal footer { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); }
.form { display: grid; grid-template-columns: 160px 1fr; gap: 10px 14px; align-items: center; }
.form label { color: var(--muted); font-size: 13px; }
.form .full { grid-column: 1 / -1; }
.hint { background: #f4f7fb; border: 1px solid #dfe7f1; border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.hint.warn { background: #fff6e5; border-color: #f2d59b; }
.hint.bad { background: #fdecec; border-color: #f0b7b7; }
.hint.ok { background: #e9f7ee; border-color: #b9e2c8; }
.option { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.option h3 { margin-bottom: 6px; text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 14px; }
.option h3 .n { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; background: var(--navy); color: #fff; align-items: center; justify-content: center; font-size: 12px; margin-right: 8px; }
.option.disabled { opacity: .55; }

/* toasts */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: 380px; }
.toast { background: #1c2530; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.25); font-size: 13px; animation: in .2s ease-out; }
.toast.remote { background: var(--navy); border-left: 4px solid #f2b134; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
.toast b { display: block; font-size: 11px; opacity: .8; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
@keyframes in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* notifications */
.notif { border-left: 3px solid var(--accent); padding: 8px 10px; margin-bottom: 8px; background: #f7f9fc; border-radius: 0 6px 6px 0; }
.notif .when { color: var(--muted); font-size: 11px; }

.empty { color: var(--muted); padding: 20px; text-align: center; }
.inline-edit { width: 70px; }
@media (max-width: 720px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .page { padding: 12px; }
  .form { grid-template-columns: 1fr; }
}
