:root {
  --coat: #3E4C5E; --coat-soft: #D9DFE6;
  --fawn: #A8743E; --fawn-soft: #F1E4D3;
  --mist: #EDF0F2; --surface: #FFFFFF; --sidebar: #E3E8EC;
  --ink: #18202A; --muted: #5B6673; --line: #D3D9DF;
  --alert: #B4372E; --alert-soft: #F6DEDB;
  --ok: #3F7A4F; --ok-soft: #DCEBDF;
  --soon: #8A5A10; --soon-soft: #F5E7C8;
  --on-coat: #FFFFFF;
  --radius-lg: 18px; --radius-sm: 8px;
  --nav-h: 64px;
  --display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: light;
  box-sizing: border-box;
}
@media (prefers-color-scheme: dark) {
  :root {
    --coat: #9FB2C8; --coat-soft: #2A3442;
    --fawn: #D9A86C; --fawn-soft: #3A2E20;
    --mist: #12161C; --surface: #1B2129; --sidebar: #161B22;
    --ink: #E7EBEF; --muted: #9AA5B1; --line: #2E3743;
    --alert: #F08A80; --alert-soft: #3E2220;
    --ok: #8CCB9B; --ok-soft: #1F3326;
    --soon: #E8C070; --soon-soft: #3A2F18;
    --on-coat: #12161C;
    color-scheme: dark;
  }
}
*, *::before, *::after { box-sizing: inherit; }
html { height: 100%; }
body { margin: 0; min-height: 100%; background: var(--mist); color: var(--ink); font: 17px/1.5 var(--body); font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0; }
h2 { font-size: 1.15rem; font-weight: 800; }
h3 { font-size: 1rem; font-weight: 800; margin-top: .5rem; }
.muted { color: var(--muted); margin: 0; }
.small-text { font-size: .9rem; }
.opt { color: var(--muted); font-weight: 400; font-size: .85em; }
:focus-visible { outline: 3px solid var(--fawn); outline-offset: 2px; }
code, pre { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .85rem; }

/* ---------- shell: menu across the top ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 21; background: var(--surface); }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 0 1rem; display: grid; grid-template-columns: 1fr auto; align-items: center; }
.brand { display: flex; align-items: center; gap: .55rem; padding: .7rem 0; font-family: var(--display); font-weight: 800; font-size: 1.1rem; color: var(--coat); white-space: nowrap; }
.who { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.who-name { font-weight: 700; max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { grid-column: 1 / -1; grid-row: 2; display: grid; grid-template-columns: repeat(5, 1fr); margin: 0 -1rem; border-top: 1px solid var(--line); }
.tabs button {
  font: inherit; font-size: .72rem; font-weight: 700; background: none; border: 0; color: var(--muted); cursor: pointer;
  display: grid; place-items: center; gap: 2px; padding: .45rem 0 .4rem; border-bottom: 3px solid transparent;
}
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-current="page"] { color: var(--coat); border-bottom-color: var(--coat); }
.tabs .long { display: none; }
@media (max-width: 599px) { .who-name { display: none; } }

.masthead, main { max-width: 1180px; margin: 0 auto; }
.masthead { padding: 1.25rem 1.25rem .25rem; }
.masthead h1 { font-size: clamp(1.9rem, 7vw, 2.6rem); font-weight: 800; letter-spacing: -0.03em; color: var(--coat); font-variation-settings: "opsz" 96; }
main { padding: .75rem 1.25rem 3rem; }
section { display: grid; gap: 1rem; }
section > * { min-width: 0; }

@media (min-width: 900px) {
  .topbar-inner { grid-template-columns: auto 1fr auto; gap: 1.5rem; padding: 0 2rem; }
  .tabs { grid-column: 2; grid-row: 1; display: flex; justify-content: center; gap: .25rem; margin: 0; border-top: 0; }
  .tabs button { display: flex; gap: .5rem; font-size: .95rem; padding: 1.05rem .8rem .85rem; }
  .tabs svg { width: 19px; height: 19px; }
  .tabs .long { display: inline; } .tabs .short { display: none; }
  .masthead { padding: 2rem 2rem .25rem; }
  main { padding: 1rem 2rem 3rem; }
  .account-panel { display: none; }
  .layout-today { grid-template-columns: 1fr 1fr; }
  .layout-today .quick-form { grid-column: 1 / -1; }
  .layout-split { grid-template-columns: minmax(320px, 380px) 1fr; align-items: start; }
  .layout-settings { grid-template-columns: 1fr 1fr; align-items: start; }
}
@media (min-width: 1280px) {
  .layout-today { grid-template-columns: 1fr 1fr 1.15fr; align-items: start; }
  .layout-today .quick-form { grid-column: auto; }
}

/* ---------- day / month picker ---------- */
.period { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem .9rem; margin-bottom: 1rem; }
.stepper { display: flex; align-items: center; gap: .35rem; }
.stepper .arrow {
  font: inherit; font-size: 1.15rem; line-height: 1; width: 38px; height: 38px; border-radius: 50%;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; display: grid; place-items: center;
}
.stepper .arrow:disabled { opacity: .35; cursor: default; }
.stepper input[type="date"], .stepper select {
  font: inherit; font-weight: 700; padding: .45rem .6rem; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: var(--mist); color: var(--ink); width: auto;
}
.stepper select:focus, .stepper input:focus { border-color: var(--coat); outline: none; box-shadow: 0 0 0 3px var(--coat-soft); }
.period .jump { font: inherit; font-size: .9rem; font-weight: 700; color: var(--coat); background: none; border: 0; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; padding: .25rem; }
.period-label { color: var(--muted); font-size: .9rem; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border-radius: var(--radius-lg); padding: 1.25rem; border: 1px solid var(--line); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }

.latest { display: flex; align-items: center; gap: 1.25rem; margin-top: .75rem; flex-wrap: wrap; }
.fraction { display: inline-grid; justify-items: center; font-family: var(--display); font-weight: 800; line-height: 1; }
.fraction .top { font-size: 3.4rem; color: var(--coat); }
.fraction .bar { width: 100%; height: 4px; border-radius: 2px; background: var(--ink); margin: .35rem 0; }
.fraction .bottom { font-size: 2.4rem; color: var(--fawn); }
.fraction.is-alert .top, .fraction.is-alert .bottom { color: var(--alert); }
.latest-meta { display: grid; gap: .2rem; justify-items: start; }
.latest-meta strong { font-size: 1.05rem; }
.flag { display: inline-block; font-size: .85rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; white-space: nowrap; }
.flag.alert { background: var(--alert-soft); color: var(--alert); }
.flag.ok { background: var(--ok-soft); color: var(--ok); }
.flag.soon { background: var(--soon-soft); color: var(--soon); }

.due-list { list-style: none; padding: 0; margin: .75rem 0 0; display: grid; gap: .75rem; }
.due-list li { display: grid; grid-template-columns: 1fr auto; gap: .1rem .75rem; align-items: center; padding-bottom: .75rem; border-bottom: 1px solid var(--line); }
.due-list li:last-child { border-bottom: 0; padding-bottom: 0; }
.due-list .when { grid-column: 1; color: var(--muted); font-size: .9rem; }
.due-list .flag { grid-row: 1 / span 2; grid-column: 2; }

/* ---------- forms ---------- */
.form { display: grid; gap: .9rem; align-content: start; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; }
.row > label { flex: 1 1 8rem; }
.row > label.grow { flex: 2 1 14rem; }
.bp-row { flex-wrap: nowrap; }
.bp-row > label { flex: 1 1 0; }
.over { font-family: var(--display); font-size: 2rem; color: var(--muted); padding-bottom: .2rem; }
label { display: grid; gap: .3rem; font-weight: 700; font-size: .95rem; }
label.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; }
label.check input { width: 20px; height: 20px; margin: .1rem 0 0; flex: none; accent-color: var(--coat); }
input {
  font: inherit; font-weight: 400; width: 100%; min-width: 0;
  padding: .65rem .75rem; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: var(--mist); color: var(--ink);
}
input:focus { border-color: var(--coat); outline: none; box-shadow: 0 0 0 3px var(--coat-soft); }
.error { color: var(--alert); margin: 0; font-weight: 700; }
.error:empty { display: none; }
.btn-row { display: flex; gap: .6rem; flex-wrap: wrap; }

.btn {
  font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; text-align: center;
  padding: .75rem 1.2rem; border-radius: 999px; border: 1.5px solid transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: .55rem; justify-self: start;
}
.btn:disabled { opacity: .6; cursor: progress; }
.btn.primary { background: var(--coat); color: var(--on-coat); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--coat); border-color: var(--line); }
.btn.small { padding: .4rem .85rem; font-size: .9rem; }
.btn.danger { background: transparent; color: var(--alert); border-color: var(--line); }
.btn.ms { background: var(--surface); color: var(--ink); border-color: var(--line); border-radius: 6px; justify-self: stretch; }
.btn.ms:hover { background: var(--mist); }
.btn.del, .linklike { background: none; border: 0; color: var(--muted); padding: .25rem 0; font: inherit; font-size: .85rem; text-decoration: underline; cursor: pointer; justify-self: start; text-align: left; }
.btn.del:hover { color: var(--alert); }
.linklike:hover { color: var(--ink); }

.seg { display: inline-flex; background: var(--mist); border-radius: 999px; padding: 3px; border: 1px solid var(--line); }
.seg button, .seg label span { font: inherit; font-size: .9rem; background: none; border: 0; color: var(--muted); padding: .35rem .8rem; border-radius: 999px; cursor: pointer; display: block; font-weight: 700; }
.seg button[aria-pressed="true"], .seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.seg.wide { justify-self: start; }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:focus-visible + span { outline: 3px solid var(--fawn); }

/* ---------- Microsoft 365 panel ---------- */
.status-line { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem .9rem; margin: 0; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.code-box { position: relative; }
.code-box pre { margin: 0; padding: .9rem; padding-right: 4.5rem; background: var(--mist); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow-x: auto; white-space: pre; line-height: 1.55; }
.code-box .btn { position: absolute; top: .5rem; right: .5rem; }
.device-code { display: grid; gap: .6rem; padding: 1rem; border-radius: var(--radius-sm); background: var(--coat-soft); }
.device-code .code { font-family: var(--display); font-weight: 800; font-size: 2rem; letter-spacing: .08em; color: var(--ink); }
.steps { margin: 0; padding-left: 1.2rem; display: grid; gap: .3rem; font-size: .95rem; }
details summary { cursor: pointer; font-weight: 700; color: var(--coat); }
details[open] summary { margin-bottom: .75rem; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--coat); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* ---------- stats + charts ---------- */
.stats { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.stat { display: grid; }
.stat b { font-family: var(--display); font-size: 1.5rem; font-weight: 800; }
.stat span { color: var(--muted); font-size: .85rem; }
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--body); }
.chart .sys { stroke: var(--coat); fill: none; stroke-width: 2.5; }
.chart .dia { stroke: var(--fawn); fill: none; stroke-width: 2.5; }
.chart .dot-sys { fill: var(--coat); } .chart .dot-dia { fill: var(--fawn); } .chart .dot-alert { fill: var(--alert); }
.chart .alertline { stroke: var(--alert); stroke-dasharray: 5 4; stroke-width: 1.5; }
.chart .empty { fill: var(--muted); font-size: 14px; font-family: var(--body); }
.legend { margin: .5rem 0 0; color: var(--muted); font-size: .85rem; display: flex; gap: .4rem 1rem; flex-wrap: wrap; align-items: center; }
.legend > span { white-space: nowrap; }
.key { display: inline-block; width: 18px; height: 3px; border-radius: 2px; margin-right: .3rem; vertical-align: middle; }
.key.sys { background: var(--coat); } .key.dia { background: var(--fawn); }
.key.alert { background: repeating-linear-gradient(90deg, var(--alert) 0 5px, transparent 5px 9px); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th { text-align: left; color: var(--muted); font-weight: 700; font-size: .85rem; padding: .4rem .5rem; border-bottom: 1px solid var(--line); }
td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
td:first-child { white-space: nowrap; }
td.num { font-weight: 700; white-space: nowrap; }
td.alert { color: var(--alert); }
td.notes { color: var(--muted); }
tr:last-child td { border-bottom: 0; }
.empty-row td { color: var(--muted); padding: 1rem .5rem; white-space: normal; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; padding-top: calc(1.25rem + env(safe-area-inset-top, 0px)); }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 2rem 1.75rem; width: min(100%, 400px); display: grid; gap: 1rem; }
.login-mark { border-radius: 12px; }
.login-title { font-size: 2rem; font-weight: 800; color: var(--coat); letter-spacing: -0.02em; }
#loginForm { display: grid; gap: 1rem; }
.or { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .9rem; margin: 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.toast {
  position: fixed; left: 50%; bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 1rem); z-index: 30;
  background: var(--ink); color: var(--surface); padding: .65rem 1.1rem; border-radius: 999px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 2rem); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
#m365Body { display: grid; gap: .9rem; }
.form, #m365Body { grid-template-columns: minmax(0, 1fr); }
a { color: var(--coat); text-underline-offset: 2px; }
.btn.primary, .btn.ghost, .btn.ms { text-decoration: none; }
.account-panel { display: grid; gap: .6rem; justify-items: start; }
fieldset.every { border: 0; padding: 0; margin: 0; min-width: 0; flex: 1 1 12rem; display: grid; gap: .3rem; }
fieldset.every legend { font-weight: 700; font-size: .95rem; padding: 0; margin-bottom: .3rem; }
.every-inputs { display: flex; gap: .5rem; }
.every-inputs input { flex: 0 1 5.5rem; }
.every-inputs select, .every-inputs input { min-width: 0; }
.every-inputs select {
  font: inherit; flex: 1 1 7rem; padding: .65rem .75rem; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: var(--mist); color: var(--ink);
}
.every-inputs select:focus { border-color: var(--coat); outline: none; box-shadow: 0 0 0 3px var(--coat-soft); }
