:root {
  --bg: #EFF8FF;
  --surface: #FFFFFF;
  --ink: #0F2A43;
  --ink-2: #4A5F73;
  --line: #D5E3EF;
  --line-2: #E6EFF7;
  --brand: #0F2A43;
  --accent: #B8893B;
  --accent-soft: #F6EEDD;
  --ok: #1D7A4D;
  --ok-soft: #E3F4EA;
  --warn: #9A5B00;
  --warn-soft: #FFF1D6;
  --bad: #B3261E;
  --bad-soft: #FDE8E6;
  --focus: #2563EB;
  --radius: 10px;
  --gutter: max(16px, env(safe-area-inset-left, 0px));
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* top bar */
.bar {
  position: sticky; top: 0; z-index: 20; background: var(--brand); color: #fff;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px var(--gutter);
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  border-bottom: 3px solid var(--accent);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand b { display: block; font-size: 1.05rem; letter-spacing: 0.01em; }
.brand small { display: block; font-size: 0.72rem; opacity: 0.75; letter-spacing: 0.06em; text-transform: uppercase; }
.mark {
  width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: var(--brand);
  display: grid; place-items: center; font-weight: 800; font-size: 0.95rem; letter-spacing: 0.02em;
}
.nav { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; }
.nav a {
  color: #fff; text-decoration: none; padding: 8px 14px; border-radius: 8px; opacity: 0.85;
  white-space: nowrap; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,0.1); opacity: 1; }
.nav a[aria-current="page"] { background: rgba(255,255,255,0.16); opacity: 1; }
.who { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; margin-left: auto; }
.who .role { background: rgba(255,255,255,0.14); padding: 2px 8px; border-radius: 99px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; }

/* page */
main {
  max-width: 1100px; margin: 0 auto;
  padding-block: 24px 64px;
  padding-left: var(--gutter); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head p { margin: 4px 0 0; color: var(--ink-2); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.gold { height: 2px; background: var(--accent); border: 0; margin: 0 0 16px; width: 56px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff; cursor: pointer; font-weight: 600; text-decoration: none;
}
.btn:hover { filter: brightness(1.15); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.ghost:hover { background: var(--line-2); filter: none; }
.btn.danger { background: var(--bad); border-color: var(--bad); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 0.85rem; }
.bar .btn.ghost { color: #fff; border-color: rgba(255,255,255,0.4); }
.bar .btn.ghost:hover { background: rgba(255,255,255,0.12); }

/* forms */
.grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fld > span { font-weight: 600; font-size: 0.85rem; }
.fld > span i { color: var(--bad); font-style: normal; }
.fld em { font-style: normal; font-size: 0.78rem; color: var(--ink-2); }
.fld .err { font-size: 0.78rem; color: var(--bad); font-weight: 600; min-height: 0; }
.fld .err:empty { display: none; }
input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="search"], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid #B7C9D9; border-radius: 8px;
  background: #fff; font-size: 16px;
}
textarea { min-height: 72px; resize: vertical; }
input[disabled], select[disabled] { background: var(--line-2); color: var(--ink-2); }
input.bad { border-color: var(--bad); background: var(--bad-soft); }
.seg { display: inline-flex; border: 1px solid #B7C9D9; border-radius: 8px; overflow: hidden; background: #fff; }
.seg label { padding: 10px 16px; cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: #fff; }
.seg label:has(input:checked) { background: var(--brand); color: #fff; }
.seg label:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: -3px; }
.sect { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line-2); }
.sect:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.sect > h2 { margin-bottom: 4px; }
.sect > .sub { margin: 0 0 14px; color: var(--ink-2); font-size: 0.85rem; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.note { background: var(--accent-soft); border-left: 3px solid var(--accent); padding: 10px 12px; border-radius: 6px; font-size: 0.85rem; }
.banner { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 500; }
.banner.bad { background: var(--bad-soft); color: var(--bad); border: 1px solid #F3C2BE; }
.banner.ok { background: var(--ok-soft); color: var(--ok); border: 1px solid #BFE3CE; }

/* chips */
.chip { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.03em; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.off { background: var(--line-2); color: var(--ink-2); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.info { background: #E1EEFB; color: #1B4F8A; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.88em; }
.calc { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 28px; font-size: 0.85rem; }

/* list / table */
.tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.tools .grow { flex: 1; min-width: 200px; width: auto; }
.tools select { width: auto; min-width: 140px; }
.tools .count { color: var(--ink-2); font-size: 0.85rem; margin-left: auto; }
.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tbl th { text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-2); background: #F6FAFD; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover { background: #F6FAFD; }
.tbl .name { font-weight: 600; }
.tbl .sub { color: var(--ink-2); font-size: 0.82rem; }
.empty { text-align: center; padding: 40px 16px; color: var(--ink-2); }

/* home tiles */
.tiles { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.tile { display: block; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.tile:hover { border-color: var(--accent); }
.tile h2 { margin-bottom: 4px; }
.tile p { margin: 0; color: var(--ink-2); font-size: 0.88rem; }
.tile.soon { opacity: 0.6; pointer-events: none; }

/* sign-in */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px var(--gutter); }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .brand { margin-bottom: 18px; }
.auth .brand b { color: var(--ink); }
.auth .brand small { color: var(--ink-2); opacity: 1; }
.auth form { display: flex; flex-direction: column; gap: 14px; }
.auth .swap { margin-top: 16px; text-align: center; font-size: 0.88rem; color: var(--ink-2); }
.link { background: none; border: 0; color: var(--brand); text-decoration: underline; cursor: pointer; padding: 0; font: inherit; }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(15,42,67,0.5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal .card { max-width: 440px; width: 100%; }
.modal .actions { justify-content: flex-end; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  background: var(--brand); color: #fff; padding: 11px 18px; border-radius: 8px; z-index: 60; max-width: 92vw;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
}
.toast.bad { background: var(--bad); }

.spin { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: sp 0.7s linear infinite; vertical-align: -3px; }
@keyframes sp { to { transform: rotate(360deg); } }
.loading { padding: 40px; text-align: center; color: var(--ink-2); }

/* phone */
@media (max-width: 720px) {
  main { padding-top: 16px; }
  .tbl thead { display: none; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl tr { padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
  .tbl td { padding: 2px 0; border: 0; }
  .tbl td[data-l]::before { content: attr(data-l) ": "; color: var(--ink-2); font-size: 0.78rem; }
  .who { width: 100%; justify-content: space-between; margin-left: 0; }
  .nav { order: 3; width: 100%; flex: none; }
}
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 2s; } }
