@font-face { font-family: "Plex Sans"; src: url("fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }

:root {
  --paper: #EBEFEC;
  --surface: #FFFFFF;
  --sunk: #F4F6F4;
  --ink: #17201D;
  --muted: #56635E;
  --line: #D3DAD6;
  --accent: #0E6E62;
  --accent-ink: #FFFFFF;
  --accent-soft: #D7EBE7;
  --good: #2D7A3A;
  --warn: #9A5B00;
  --warn-soft: #FBEBD2;
  --bad: #B3261E;
  --bad-soft: #F9DEDB;
  --window: #E7B65C;
  --sans: "Plex Sans", "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "Plex Mono", "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r-sm: 4px;
  --r-md: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111715;
    --surface: #19211F;
    --sunk: #141B19;
    --ink: #E2E9E6;
    --muted: #94A39E;
    --line: #2B3633;
    --accent: #4FBFAE;
    --accent-ink: #0B1A17;
    --accent-soft: #1C3833;
    --good: #72C27D;
    --warn: #E5A949;
    --warn-soft: #3A2C14;
    --bad: #F27A70;
    --bad-soft: #3D1C1A;
    --window: #8C6A2A;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 15px/1.5 var(--sans); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; line-height: 1.2; }
h2 { font-size: 1.1rem; line-height: 1.3; }
h3 { font-size: 0.95rem; }
p { margin: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; background: linear-gradient(to right, var(--surface) 228px, transparent 228px); }
.side { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 600; padding: 0 8px 22px; }
.brand-mark { width: 26px; height: 26px; border-radius: 6px; background: var(--accent); position: relative; flex: none; }
.brand-mark::before { content: ""; position: absolute; left: 4px; right: 4px; top: 11px; height: 4px; border-radius: 2px; background: var(--accent-ink); opacity: .35; }
.brand-mark::after { content: ""; position: absolute; left: 4px; width: 11px; top: 11px; height: 4px; border-radius: 2px; background: var(--accent-ink); }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: var(--ink); text-decoration: none; padding: 8px 10px; border-radius: var(--r-sm); font-weight: 500; }
.side nav a:hover { background: var(--sunk); }
.side nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding: 14px 8px 0; display: flex; flex-direction: column; gap: 6px; }
.who { color: var(--ink); text-decoration: none; display: flex; flex-direction: column; }
.who .role { color: var(--muted); font-size: 0.85rem; }
main { padding: 32px clamp(16px, 4vw, 48px) 64px; max-width: 1180px; width: 100%; min-width: 0; }
main:focus { outline: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head p { margin-top: 4px; }
.crumb { font-size: 0.9rem; margin-bottom: 6px; display: inline-block; }
section + section { margin-top: 36px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

/* ---------- controls ---------- */
.btn { font: 500 0.92rem/1 var(--sans); border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 9px 14px; border-radius: var(--r-sm); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; cursor: pointer; text-align: left; }
.link:hover { color: var(--ink); text-decoration: underline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 500; font-size: 0.92rem; }
.field small { color: var(--muted); font-size: 0.84rem; }
input[type=text], input[type=password], input[type=number], input[type=time], select, textarea {
  font: 400 0.95rem/1.4 var(--sans); color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 8px 10px; width: 100%;
}
textarea { font-family: var(--mono); font-size: 0.82rem; min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { margin-top: 4px; accent-color: var(--accent); }
.check small { display: block; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 24px; }
.form-grid .full { grid-column: 1 / -1; }
fieldset { border: 0; margin: 0; padding: 0; }
fieldset + fieldset { border-top: 1px solid var(--line); padding-top: 22px; margin-top: 26px; }
legend { font-weight: 600; font-size: 1rem; margin-bottom: 14px; padding: 0; }
.form-error { color: var(--bad); font-size: 0.9rem; min-height: 0; }
.form-error:empty { display: none; }
.form-foot { display: flex; gap: 10px; margin-top: 26px; align-items: center; flex-wrap: wrap; }
.push-right { margin-left: auto; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 22px; }
.notice { border-left: 3px solid var(--warn); background: var(--warn-soft); padding: 12px 16px; border-radius: 0 var(--r-sm) var(--r-sm) 0; display: flex; gap: 16px; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-bottom: 20px; }
.notice.bad { border-color: var(--bad); background: var(--bad-soft); }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 0.84rem; font-weight: 500; white-space: nowrap; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.tone-good { color: var(--good); }
.tone-warn { color: var(--warn); }
.tone-bad { color: var(--bad); }
.tone-muted { color: var(--muted); }
.tone-accent { color: var(--accent); }
.badge.tone-accent::before { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- automation strip ---------- */
.automation { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 16px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); margin-bottom: 28px; }
.automation .state { display: flex; align-items: center; gap: 12px; }
.switch-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 4px color-mix(in srgb, var(--muted) 18%, transparent); }
.automation.on .switch-dot { background: var(--good); box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 22%, transparent); }
.automation .text strong { display: block; }
.automation .text span { color: var(--muted); font-size: 0.9rem; }
.automation .actions { margin-left: auto; }
@media (max-width: 760px) { .automation .actions { margin-left: 0; } .ll-scale span:nth-child(2) { display: none; } }

/* ---------- certificate rows & lifeline ---------- */
.cert-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.cert-row { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(320px, 2.2fr) 128px; gap: 24px; align-items: center; padding: 18px 20px; color: inherit; text-decoration: none; }
.cert-row + .cert-row { border-top: 1px solid var(--line); }
.cert-row:hover { background: var(--sunk); }
.cert-row .who-cert strong { display: block; font-weight: 600; }
.cert-row .who-cert .mono { color: var(--muted); font-size: 0.82rem; overflow-wrap: anywhere; }
.days { text-align: right; }
.days strong { display: block; font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.days span { font-size: 0.84rem; color: var(--muted); }

.lifeline { min-width: 0; }
.ll-track { position: relative; height: 10px; border-radius: 5px; background: var(--sunk); border: 1px solid var(--line); overflow: visible; }
.ll-window { position: absolute; top: -1px; bottom: -1px; border-radius: 0 5px 5px 0;
  background: repeating-linear-gradient(-45deg, var(--window) 0 3px, transparent 3px 7px); opacity: .55; }
.ll-elapsed { position: absolute; left: -1px; top: -1px; bottom: -1px; border-radius: 5px; background: currentColor; transform-origin: left center; }
.ll-now { position: absolute; top: -5px; width: 2px; height: 18px; margin-left: -1px; background: var(--ink); border-radius: 1px; }
.ll-scale { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 0.8rem; color: var(--muted); }
.ll-scale span:nth-child(2) { color: var(--warn); }
.ll-empty { font-size: 0.9rem; color: var(--muted); }
.reveal .ll-elapsed { animation: grow 1.1s cubic-bezier(.2, .75, .2, 1) both; }
.reveal .cert-row:nth-child(2) .ll-elapsed { animation-delay: .08s; }
.reveal .cert-row:nth-child(3) .ll-elapsed { animation-delay: .16s; }
.reveal .cert-row:nth-child(n+4) .ll-elapsed { animation-delay: .24s; }
@keyframes grow { from { transform: scaleX(0); } }

.cert-hero { padding: 24px; }
.cert-hero .ll-track { height: 16px; border-radius: 8px; }
.cert-hero .ll-elapsed { border-radius: 8px; }
.cert-hero .ll-now { top: -6px; height: 26px; }
.cert-hero-top { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.cert-hero-top .big { font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- details & tables ---------- */
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 10px 20px; margin: 0; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 11px 14px; vertical-align: middle; }
th { font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--sunk); white-space: nowrap; }
tbody tr + tr td { border-top: 1px solid var(--line); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--sunk); }
td.nowrap { white-space: nowrap; }
td .sub { display: block; color: var(--muted); font-size: 0.84rem; }
td select { width: auto; padding: 5px 8px; }

.empty { padding: 36px 24px; text-align: center; border: 1px dashed var(--line); border-radius: var(--r-md); background: var(--surface); }
.empty p { color: var(--muted); margin: 6px auto 16px; max-width: 46ch; }
.loading { color: var(--muted); padding: 24px 0; }
.error-panel { border: 1px solid var(--bad); background: var(--bad-soft); padding: 16px 18px; border-radius: var(--r-md); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: min(400px, 100%); }
.login .brand { padding: 0 0 24px; font-size: 1.1rem; }
.login form { display: flex; flex-direction: column; gap: 16px; }
.login h1 { font-size: 1.4rem; margin-bottom: 4px; }

/* ---------- dialogs ---------- */
dialog { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: var(--ink); padding: 0; max-width: min(520px, calc(100vw - 32px)); width: 100%; }
dialog::backdrop { background: rgb(10 16 14 / .45); }
.modal-body { padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
dialog.drawer { margin: 0 0 0 auto; height: 100vh; max-height: 100vh; max-width: min(760px, 100vw); border-radius: 0; border-width: 0 0 0 1px; }
.drawer-body { display: flex; flex-direction: column; height: 100%; }
.drawer-body header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.drawer-body header p { margin-top: 4px; }
.log { flex: 1; margin: 0; overflow: auto; padding: 16px 22px 40px; font: 400 0.82rem/1.65 var(--mono); background: var(--sunk); white-space: pre-wrap; overflow-wrap: anywhere; }
.log .ln { display: block; padding-left: 1.4em; text-indent: -1.4em; }
.log .ts { color: var(--muted); margin-right: 10px; }
.log .lv { display: inline-block; width: 1.4em; text-indent: 0; }
.log .lv-ok .lv { color: var(--good); }
.log .lv-warn { color: var(--warn); }
.log .lv-fail { color: var(--bad); }
.log .lv-info .lv { color: var(--muted); }

#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; pointer-events: none; }
.toast { background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--r-sm); font-size: 0.92rem; animation: toast-in .2s ease-out; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .cert-row { grid-template-columns: 1fr auto; }
  .cert-row .lifeline { grid-column: 1 / -1; grid-row: 2; }
  .detail-grid, .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); background: none; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 12px 0 0; }
  .side nav { flex-direction: row; overflow-x: auto; flex: 1 1 100%; order: 3; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; flex-direction: row; align-items: center; gap: 12px; }
  .who .role { display: none; }
  main { padding-top: 20px; }
  dialog.drawer { max-width: 100vw; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
