* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: var(--lh-tight); font-weight: var(--fw-semibold); }
h1 { font-size: var(--fs-xl); letter-spacing: var(--tracking-heading); }
h2 { font-size: var(--fs-lg); }
p { margin: 0; }
a { color: var(--acc-ink); }
code, .mono { font-family: var(--font-mono); font-size: var(--fs-sm); }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.num { font-variant-numeric: tabular-nums; }
svg.i { width: var(--icon); height: var(--icon); stroke: currentColor; stroke-width: var(--icon-stroke); fill: none; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav svg.i, .tabbar svg.i { width: var(--icon-lg); height: var(--icon-lg); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: var(--ctl-h); padding: 0 var(--space-4); border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surf); color: var(--text);
  font: inherit; font-weight: var(--fw-medium); cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--hover); }
.btn:active { transform: scale(var(--press-scale)); }
.btn.primary { background: var(--acc); border-color: var(--acc); color: var(--acc-text); }
.btn.primary:hover { background: var(--acc-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.danger { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad-ink); }
.btn.icon { width: var(--ctl-h); padding: 0; }
.btn.small { height: var(--ctl-h-sm); padding: 0 var(--space-3); font-size: var(--fs-sm); }
.btn.small.icon { width: var(--ctl-h-sm); padding: 0; }
.btn[aria-busy="true"] { pointer-events: none; }
.btn[aria-busy="true"]::after {
  content: ""; width: 12px; height: 12px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 700ms linear infinite; opacity: 0; animation-delay: var(--spinner-delay); animation-fill-mode: forwards;
}
@keyframes spin { from { transform: rotate(0); opacity: 1; } to { transform: rotate(360deg); opacity: 1; } }

label.field { display: grid; gap: var(--space-1); font-size: var(--fs-sm); font-weight: var(--fw-medium); }
input[type="text"], input[type="password"], input[type="tel"], input[type="search"], input[type="number"], textarea, select {
  height: var(--ctl-h); padding: 0 var(--space-3); border-radius: var(--r-md);
  border: 1px solid var(--line-strong); background: var(--surf-2); color: var(--text); font: inherit; width: 100%;
}
textarea { height: auto; min-height: 96px; padding: var(--space-2) var(--space-3); resize: vertical; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: none; border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }
.err { color: var(--bad-ink); font-size: var(--fs-sm); font-weight: var(--fw-regular); }
.check { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--acc); margin: 0; }

.tag {
  display: inline-flex; align-items: center; gap: var(--space-1); padding: 2px 10px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: var(--fw-medium); white-space: nowrap; border: 1px solid var(--line); color: var(--muted);
}
.tag.ok { background: var(--ok-soft); color: var(--ok-ink); border-color: var(--ok-line); }
.tag.warn { background: var(--warn-soft); color: var(--warn-ink); border-color: var(--warn-line); }
.tag.bad { background: var(--bad-soft); color: var(--bad-ink); border-color: var(--bad-line); }
.tag svg.i { width: 12px; height: 12px; }

.card { background: var(--surf); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--space-4); }
.stack { display: grid; gap: var(--space-3); }
.row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100dvh; }
.side { background: var(--side); border-right: 1px solid var(--line); padding: var(--space-4) var(--space-3); display: flex; flex-direction: column; gap: var(--space-4); position: sticky; top: 0; height: 100dvh; }
.brand { display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-2); font-weight: var(--fw-semibold); font-size: var(--fs-md); }
.brand img { width: 24px; height: 24px; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: var(--space-3); height: var(--ctl-h); padding: 0 var(--space-3); border-radius: var(--r-md); color: var(--muted); text-decoration: none; font-weight: var(--fw-medium); transition: background-color var(--dur-fast) var(--ease); }
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a[aria-current="page"] { background: var(--hover); color: var(--text); }
.side .me { margin-top: auto; }
.main { min-width: 0; display: flex; flex-direction: column; }
.head { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: var(--space-5) var(--space-6) var(--space-3); display: flex; align-items: center; gap: var(--space-3); transition: padding var(--dur-fast) var(--ease); }
.head.tight { padding-top: var(--space-3); border-bottom: 1px solid var(--line); }
.head.tight h1 { transform: scale(.8); transform-origin: left center; }
.head h1 { transition: transform var(--dur-fast) var(--ease); }
.content { padding: var(--space-3) var(--space-6) var(--space-7); display: grid; gap: var(--space-4); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: var(--space-4); align-items: start; }
.tabbar { display: none; }

/* toolbar + lists */
.toolbar { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surf-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 3px; gap: 2px; position: relative; }
.seg button { position: relative; z-index: 1; height: calc(var(--ctl-h) - 8px); padding: 0 var(--space-3); border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); font: inherit; font-size: var(--fs-sm); font-weight: var(--fw-medium); cursor: pointer; display: inline-flex; gap: var(--space-1); align-items: center; }
.seg button[aria-pressed="true"] { color: var(--text); }
.seg .pill { position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 0; border-radius: var(--r-sm); background: var(--surf); border: 1px solid var(--line); transition: transform var(--dur-base) var(--ease), width var(--dur-base) var(--ease); }
.seg .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.search { position: relative; flex: 1; min-width: 180px; max-width: 320px; }
.search svg.i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search input { padding-left: 34px; padding-right: 34px; }
.search .clear { position: absolute; right: 2px; top: 2px; height: calc(var(--ctl-h) - 4px); width: calc(var(--ctl-h) - 4px); }

.list { background: var(--surf); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--muted); padding: 0; border-bottom: 1px solid var(--line); }
th button { all: unset; display: inline-flex; align-items: center; gap: var(--space-1); padding: var(--row-pad); cursor: pointer; }
th button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
th span.plain { display: inline-block; padding: var(--row-pad); }
td { padding: var(--row-pad); border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; transition: background-color var(--dur-fast) var(--ease); }
tbody tr.click:hover { background: var(--hover); }
tbody tr[aria-selected="true"] { background: var(--hover); }
td.r, th.r { text-align: right; }
.fade { animation: fade var(--dur-slow) var(--ease) both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.empty { padding: var(--space-7) var(--space-5); display: grid; gap: var(--space-3); justify-items: start; }
.empty h2 { font-size: var(--fs-md); }

.banner { display: flex; gap: var(--space-3); align-items: center; padding: var(--space-3) var(--space-4); border-radius: var(--r-lg); border: 1px solid var(--warn-line); background: var(--warn-soft); color: var(--warn-ink); }
.banner.acc { border-color: var(--acc-line); background: var(--acc-soft); color: var(--acc-ink); }
.banner .grow { color: var(--text); }

.events { display: grid; }
.ev { display: grid; grid-template-columns: 52px 1fr; gap: var(--space-2); padding: var(--space-2) 0; border-bottom: 1px solid var(--line); }
.ev:last-child { border-bottom: 0; }
.ev time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: var(--fs-sm); }
.ev .day { grid-column: 1 / -1; color: var(--muted); font-size: var(--fs-xs); font-weight: var(--fw-medium); padding-top: var(--space-2); }

/* auth + qr */
.center { min-height: 100dvh; display: grid; place-items: center; padding: var(--space-5); }
.auth { width: min(400px, 100%); display: grid; gap: var(--space-4); }
.auth .brand { padding: 0; }
.code { font-family: var(--font-mono); font-size: 40px; letter-spacing: .12em; font-variant-numeric: tabular-nums; font-weight: var(--fw-semibold); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-3); align-items: end; }
.days { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.section { display: grid; gap: var(--space-3); }
.section + .section { border-top: 1px solid var(--line); padding-top: var(--space-4); }
.linkbox { display: flex; gap: var(--space-2); align-items: center; padding: var(--space-2) var(--space-3); border: 1px solid var(--acc-line); background: var(--acc-soft); border-radius: var(--r-md); }
.linkbox code { flex: 1; min-width: 0; overflow-wrap: anywhere; color: var(--text); }

#toasts { position: fixed; right: var(--space-5); bottom: var(--space-5); display: grid; gap: var(--space-2); z-index: 50; }
.toast { background: var(--text); color: var(--bg); padding: var(--space-3) var(--space-4); border-radius: var(--r-md); box-shadow: var(--shadow-float); animation: fade var(--dur-base) var(--ease) both; max-width: 360px; }
.toast.out { opacity: 0; transition: opacity var(--dur-fast) var(--ease); }

dialog { border: 1px solid var(--line); background: var(--raised); color: var(--text); border-radius: var(--r-lg); box-shadow: var(--shadow-float); padding: var(--space-5); width: min(440px, calc(100% - 32px)); }
dialog::backdrop { background: var(--scrim); }

@media (max-width: 1100px) {
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .head { padding: var(--space-4) var(--space-4) var(--space-2); }
  .content { padding: var(--space-2) var(--space-4) calc(var(--space-8) + 24px); }
  .tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--side); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { display: grid; justify-items: center; gap: 2px; padding: var(--space-2) 0; min-height: 56px; color: var(--muted); text-decoration: none; font-size: var(--fs-xs); font-weight: var(--fw-medium); }
  .tabbar a[aria-current="page"] { color: var(--text); }
  input[type="text"], input[type="password"], input[type="tel"], input[type="search"], input[type="number"], textarea, select { font-size: var(--fs-md); height: var(--touch); }
  .btn { height: var(--touch); }
  .btn.icon { width: var(--touch); }
  .btn.small { height: var(--touch); }
  .btn.small.icon { width: var(--touch); }
  .hide-sm { display: none; }
  .search { max-width: none; }
  .search .clear { height: calc(var(--touch) - 4px); width: calc(var(--touch) - 4px); }
  .seg button { height: calc(var(--touch) - 8px); }
  #toasts { left: var(--space-4); right: var(--space-4); bottom: calc(72px + env(safe-area-inset-bottom)); }
}
.block { display: block; }
code.big { font-size: var(--fs-md); }
.row.end { justify-content: flex-end; }
.narrow { max-width: 760px; }
.start { justify-self: start; }
.seg button { white-space: nowrap; }
.section + .section { margin-top: var(--space-4); }
@media (max-width: 768px) {
  .toolbar .seg { flex: 1 1 100%; min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .content, .main { overflow-x: clip; }
}
