/* GuideLock workspace (app.html + auth.html). Builds on tokens.css. */

/* ---------------------------------------------------------------- local tokens */
.ws {
  --sidebar-w: 252px;
  --tabbar-h: 64px;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --grid: rgba(13, 20, 17, 0.07); --axis: rgba(13, 20, 17, 0.22);
  --focus: 0 0 0 3px color-mix(in srgb, var(--blue) 38%, transparent);
  --hover: color-mix(in srgb, var(--ink) 5%, transparent);
  --press: color-mix(in srgb, var(--ink) 9%, transparent);
  --scrim: rgba(8, 12, 10, 0.42);
  --shimmer-a: color-mix(in srgb, var(--ink) 5%, transparent);
  --shimmer-b: color-mix(in srgb, var(--ink) 10%, transparent);
  --t: 220ms;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ws {
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --grid: rgba(238, 242, 239, 0.07); --axis: rgba(238, 242, 239, 0.22); --scrim: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] .ws {
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --grid: rgba(238, 242, 239, 0.07); --axis: rgba(238, 242, 239, 0.22); --scrim: rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}
:root[data-theme="light"] .ws { color-scheme: light; }

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; }
body.ws {
  font: 400 15px/1.55 var(--f-text); color: var(--ink); background: var(--paper);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility;
  min-height: 100vh; min-height: 100dvh;
}
.ws h1, .ws h2, .ws h3, .ws h4 { font-family: var(--f-display); font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; margin: 0; }
.ws h1 { font-size: clamp(1.55rem, 2.6vw, 2rem); }
.ws h2 { font-size: 1.12rem; letter-spacing: -0.01em; }
.ws h3 { font-size: 0.98rem; letter-spacing: -0.005em; }
.ws p { margin: 0; }
.ws a { color: inherit; }
.ws img { max-width: 100%; }
.ws code, .ws kbd, .ws .mono { font-family: var(--f-mono); font-size: 0.86em; }
.ws kbd { border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; background: var(--card); color: var(--ink-2); font-size: 0.75rem; }
.ws ::selection { background: color-mix(in srgb, var(--hl) 60%, transparent); color: var(--ink); }
.ws :focus { outline: none; }
.ws :focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
.ws [hidden] { display: none !important; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.76rem; }
.num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.stack > * { min-width: 0; }
.ico { width: 20px; height: 20px; flex: none; stroke: currentColor; stroke-width: 1.75; fill: none; stroke-linecap: round; stroke-linejoin: round; display: block; }
.ico.sm { width: 16px; height: 16px; }
.ico.xs { width: 14px; height: 14px; }
.eyebrow { font: 600 0.72rem/1 var(--f-text); letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }

/* ---------------------------------------------------------------- buttons */
.btn {
  --bg: var(--ink); --fg: var(--paper);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border: 1px solid transparent; border-radius: 999px; background: var(--bg); color: var(--fg);
  font: 600 0.92rem/1 var(--f-text); letter-spacing: -0.005em; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform 160ms var(--ease), background var(--t) var(--ease), box-shadow var(--t) var(--ease), opacity var(--t), border-color var(--t);
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:hover { box-shadow: 0 6px 18px color-mix(in srgb, var(--ink) 18%, transparent); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { border-radius: 999px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; box-shadow: none; transform: none; }
.btn.ghost { --bg: transparent; --fg: var(--ink); border-color: var(--line-2); }
.btn.ghost:hover { background: var(--hover); box-shadow: none; }
.btn.soft { --bg: var(--card-2); --fg: var(--ink); border-color: var(--line); }
.btn.soft:hover { background: var(--paper-2); box-shadow: none; }
.btn.danger { --bg: var(--red); --fg: #fff; }
.btn.green { --bg: var(--green); --fg: #fff; }
.btn.sm { min-height: 36px; padding: 0 14px; font-size: 0.85rem; }
.btn.block { width: 100%; }
.btn .spin { width: 16px; height: 16px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent;
  color: var(--ink-2); cursor: pointer; transition: background var(--t) var(--ease), color var(--t) var(--ease), transform 160ms var(--ease);
  -webkit-tap-highlight-color: transparent; flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn:active { transform: scale(0.94); background: var(--press); }
.icon-btn[aria-pressed="true"] { color: var(--ink); background: var(--press); }
.icon-btn.sm { width: 36px; height: 36px; border-radius: 10px; }
.icon-btn[disabled] { opacity: 0.35; cursor: not-allowed; }
.link {
  background: none; border: 0; padding: 0; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; transition: text-decoration-color var(--t);
}
.link:hover { text-decoration-color: currentColor; }

/* ---------------------------------------------------------------- form fields */
.field { display: grid; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 0.82rem; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 0.78rem; color: var(--muted); }
.field .err { font-size: 0.8rem; color: var(--red-ink); display: flex; gap: 6px; align-items: flex-start; }
.input, .ws select.input, .ws textarea.input {
  width: 100%; min-height: 44px; padding: 10px 14px; border: 1px solid var(--line-2); border-radius: 12px;
  background: var(--card); color: var(--ink); font: 400 0.95rem/1.4 var(--f-text);
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease), background var(--t);
  -webkit-appearance: none; appearance: none;
}
.ws select.input {
  padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%237f8782' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
}
.ws textarea.input { resize: vertical; min-height: 88px; }
.input::placeholder { color: var(--muted); }
.input:hover { border-color: color-mix(in srgb, var(--ink) 28%, transparent); }
.input:focus { border-color: var(--blue); box-shadow: var(--focus); outline: none; border-radius: 12px; }
.input[aria-invalid="true"] { border-color: var(--red); }
.input-group { display: flex; min-width: 0; }
.input-group .input { border-radius: 12px 0 0 12px; min-width: 0; }
.input-group .input:focus { border-radius: 12px 0 0 12px; z-index: 1; }
.ws .input-group > .input:last-child:not(:first-child):focus { border-radius: 0 12px 12px 0; }
.input-group > .input:first-child { flex: 1 1 auto; }
.ws .input-group > :last-child:not(:first-child) { border-radius: 0 12px 12px 0; border-left: 0; flex: none; width: auto; }
.input-group .suffix { display: grid; place-items: center; padding: 0 14px; border: 1px solid var(--line-2); border-left: 0; border-radius: 0 12px 12px 0; color: var(--muted); font-size: 0.88rem; background: var(--card-2); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

/* segmented control */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--paper-2); border-radius: 12px; border: 1px solid var(--line); position: relative; }
.seg button {
  min-height: 36px; padding: 0 14px; border: 0; border-radius: 9px; background: transparent; color: var(--ink-2);
  font: 600 0.84rem/1 var(--f-text); cursor: pointer; transition: background var(--t) var(--ease), color var(--t), box-shadow var(--t); display: inline-flex; gap: 6px; align-items: center;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow-1); }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; min-height: 44px; user-select: none; font-size: 0.88rem; color: var(--ink-2); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; left: 0; top: 50%; margin: 0; }
.switch .track { width: 36px; height: 22px; border-radius: 999px; background: var(--line-2); position: relative; transition: background var(--t) var(--ease); flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform var(--t) var(--ease); }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }
.check { position: relative; display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 0.92rem; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); margin: 0; }

/* ---------------------------------------------------------------- cards, chips, badges */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.card.pad { padding: 22px; }
@media (max-width: 560px) { .card.pad { padding: 18px; } }
.card-head { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 14px; }
.card-head .sub { font-size: 0.82rem; color: var(--muted); }

.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 9px; border-radius: 8px; vertical-align: middle;
  border: 1px solid var(--line-2); background: var(--card-2); color: var(--ink-2);
  font: 500 0.72rem/1 var(--f-mono); letter-spacing: -0.01em; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background var(--t) var(--ease), border-color var(--t), color var(--t), transform 160ms var(--ease);
  position: relative;
}
.chip::after { content: ""; position: absolute; inset: -9px -2px; } /* 44px tap target without visual bulk */
.chip:hover { background: var(--card); border-color: var(--ink-2); color: var(--ink); }
.chip:active { transform: scale(0.96); }
.chip:focus-visible { border-radius: 8px; }
.chip .ico { width: 12px; height: 12px; stroke-width: 2; }
.chip.on-red { background: color-mix(in srgb, var(--red) 10%, var(--card)); border-color: color-mix(in srgb, var(--red) 35%, transparent); color: var(--red-ink); }
.chip.on-green { background: color-mix(in srgb, var(--green) 10%, var(--card)); border-color: color-mix(in srgb, var(--green) 35%, transparent); color: var(--green-ink); }

.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px; font: 600 0.7rem/1 var(--f-text); letter-spacing: 0.03em; text-transform: uppercase; background: var(--paper-2); color: var(--ink-2); white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green-ink); }
.badge.red { background: var(--red-soft); color: var(--red-ink); }
.badge.amber { background: var(--amber-soft); color: var(--amber-ink); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag { display: inline-flex; align-items: center; height: 18px; padding: 0 6px; border-radius: 5px; font: 500 0.66rem/1 var(--f-mono); background: var(--paper-2); color: var(--muted); }
.tag.code { background: var(--green-soft); color: var(--green-ink); }
.tag.openai { background: var(--blue-soft); color: var(--blue); }

/* ---------------------------------------------------------------- skeleton / spinner */
.sk { position: relative; overflow: hidden; background: var(--shimmer-a); border-radius: 8px; }
.sk::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--shimmer-b), transparent); animation: shimmer 1.4s infinite; }
.sk.line { height: 12px; margin: 8px 0; }
.sk.title { height: 22px; width: 40%; margin-bottom: 14px; }
.sk.block { height: 120px; border-radius: var(--r-md); }
@keyframes shimmer { to { transform: translateX(100%); } }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--ink); animation: spin 0.7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- app shell */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.side {
  position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 6px;
  padding: 18px 14px 14px; border-right: 1px solid var(--line); background: color-mix(in srgb, var(--card) 70%, var(--paper));
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; text-decoration: none; color: var(--ink); }
.brand svg { width: 28px; height: 28px; color: var(--ink); flex: none; }
.brand b { font: 700 1.2rem/1 var(--f-display); letter-spacing: -0.03em; }
.nav { display: grid; gap: 2px; }
.nav a, .nav button.navbtn {
  display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px; border-radius: 12px; text-decoration: none;
  color: var(--ink-2); font-weight: 550; font-size: 0.93rem; border: 0; background: none; cursor: pointer; width: 100%; text-align: left; font-family: inherit;
  transition: background var(--t) var(--ease), color var(--t);
}
.nav a:hover, .nav button.navbtn:hover { background: var(--hover); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow-1); border: 1px solid var(--line); }
.nav a[aria-current="page"] .ico { color: var(--ink); }
.nav .sep { height: 1px; background: var(--line); margin: 10px 8px; }
.nav .kbd { margin-left: auto; }
.side-foot { margin-top: auto; display: grid; gap: 4px; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; text-decoration: none; color: inherit; transition: background var(--t); min-width: 0; }
.me:hover { background: var(--hover); }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font: 700 0.82rem/1 var(--f-display); background: var(--ink); color: var(--paper); flex: none; letter-spacing: 0; }
.me .who { min-width: 0; }
.me .who b { display: block; font-size: 0.88rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .who span { display: block; font-size: 0.76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; position: relative; }
.view { animation: viewIn 320ms var(--ease) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.page { max-width: 1120px; margin: 0 auto; padding: 32px 32px 64px; }
.page.narrow { max-width: 860px; }
.page-head { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; margin-bottom: 24px; }
.page-head p { color: var(--ink-2); margin-top: 6px; max-width: 62ch; }

/* mobile top bar + bottom tabs */
.topbar { display: none; }
.tabbar { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .topbar {
    display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 30; height: 56px; padding: 0 8px 0 16px;
    background: color-mix(in srgb, var(--paper) 86%, transparent); backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
    border-bottom: 1px solid var(--line);
  }
  .topbar .brand { padding: 0; }
  .topbar .brand svg { width: 24px; height: 24px; }
  .topbar .brand b { font-size: 1.08rem; }
  .topbar .title { font: 650 0.95rem/1 var(--f-display); color: var(--ink-2); margin-left: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .icon-btn:first-of-type { margin-left: auto; }
  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--card) 90%, transparent);
    backdrop-filter: saturate(1.4) blur(16px); -webkit-backdrop-filter: saturate(1.4) blur(16px); border-top: 1px solid var(--line);
  }
  .tabbar a, .tabbar button {
    display: grid; justify-items: center; align-content: center; gap: 3px; min-height: 52px; border-radius: 12px; border: 0; background: none;
    color: var(--muted); text-decoration: none; font: 600 0.7rem/1 var(--f-text); cursor: pointer; transition: color var(--t), background var(--t);
  }
  .tabbar .ico { width: 22px; height: 22px; }
  .tabbar [aria-current="page"] { color: var(--ink); }
  .tabbar [aria-current="page"] .ico { stroke-width: 2.1; }
  .main { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .page { padding: 20px 16px 40px; }
  .page-head { margin-bottom: 18px; }
}

/* ---------------------------------------------------------------- overlay: drawer, modal, sheet */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 80; opacity: 0; transition: opacity 280ms var(--ease); }
.scrim.open { opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 90; width: min(760px, 100vw); display: flex; flex-direction: column;
  background: var(--card); border-left: 1px solid var(--line); box-shadow: var(--shadow-2);
  transform: translateX(104%); transition: transform 340ms var(--ease); will-change: transform;
}
.drawer.open { transform: none; }
.drawer.sm { width: min(520px, 100vw); }
.drawer.left { right: auto; left: 0; border-left: 0; border-right: 1px solid var(--line); transform: translateX(-104%); width: min(340px, 88vw); }
.drawer.left.open { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--line); min-height: 64px; }
.drawer-head h2 { font-size: 1.02rem; }
.drawer-body { flex: 1 1 auto; overflow: auto; overscroll-behavior: contain; }
@media (max-width: 860px) { .drawer:not(.left) { width: 100vw; border-left: 0; } }

.modal-wrap { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; pointer-events: none; }
.modal {
  pointer-events: auto; width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-xl); box-shadow: var(--shadow-2); padding: 24px; opacity: 0; transform: translateY(10px) scale(0.98);
  transition: opacity 260ms var(--ease), transform 300ms var(--ease);
}
.modal.open { opacity: 1; transform: none; }
.modal h2 { font-size: 1.25rem; margin-bottom: 6px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }

/* sheet (mobile "More") */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90; background: var(--card); border-radius: 24px 24px 0 0; padding: 10px 12px calc(16px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-2); transform: translateY(104%); transition: transform 320ms var(--ease);
}
.sheet.open { transform: none; }
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line-2); margin: 2px auto 10px; }
.sheet .nav a, .sheet .nav button.navbtn { min-height: 52px; font-size: 1rem; }

/* toasts */
.toasts { position: fixed; z-index: 200; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
@media (max-width: 860px) { .toasts { bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); } }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 11px 16px 11px 14px; border-radius: 14px; background: var(--ink); color: var(--paper);
  font-size: 0.88rem; font-weight: 550; box-shadow: var(--shadow-2); animation: toastIn 300ms var(--ease) both; max-width: 100%;
}
.toast .ico { width: 18px; height: 18px; }
.toast.good .ico { color: var(--green-glow); }
.toast.bad .ico { color: #ff8c7e; }
.toast.out { animation: toastOut 220ms var(--ease) both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(0.96); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px) scale(0.97); } }

/* ---------------------------------------------------------------- empty / error states */
.empty { display: grid; justify-items: center; text-align: center; gap: 10px; padding: 44px 20px; color: var(--ink-2); }
.empty .em-ico { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--paper-2); color: var(--ink-2); margin-bottom: 4px; }
.empty .em-ico .ico { width: 24px; height: 24px; }
.empty h3 { font-size: 1.05rem; color: var(--ink); }
.empty p { max-width: 46ch; font-size: 0.92rem; }
.empty .btn { margin-top: 8px; }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md); font-size: 0.9rem; background: var(--paper-2); color: var(--ink-2); }
.alert .ico { margin-top: 1px; }
.alert.amber { background: var(--amber-soft); color: var(--amber-ink); }
.alert.red { background: var(--red-soft); color: var(--red-ink); }
.alert.green { background: var(--green-soft); color: var(--green-ink); }
.alert.blue { background: var(--blue-soft); color: var(--ink); }
.alert.blue .ico { color: var(--blue); }

/* ---------------------------------------------------------------- tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); -webkit-overflow-scrolling: touch; }
.ws table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
.ws th { text-align: left; font: 600 0.72rem/1.2 var(--f-text); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 11px 14px; background: var(--card-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.ws td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ws tr:last-child td { border-bottom: 0; }
.ws td.num, .ws th.num { text-align: right; }
.ws tr.match td { background: var(--green-soft); }
.ws tr.match td:first-child { box-shadow: inset 3px 0 0 var(--green); }

/* ---------------------------------------------------------------- ASK */
.ask { display: grid; grid-template-columns: 286px minmax(0, 1fr); height: 100vh; height: 100dvh; }
.hist { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: color-mix(in srgb, var(--paper) 60%, var(--card)); }
.hist-head { padding: 18px 16px 10px; display: grid; gap: 12px; }
.hist-head .row { justify-content: space-between; }
.hist-list { flex: 1 1 auto; overflow: auto; padding: 4px 10px 16px; display: grid; gap: 2px; align-content: start; }
.hist-group { font: 600 0.7rem/1 var(--f-text); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.hitem { position: relative; display: flex; align-items: center; border-radius: 12px; transition: background var(--t) var(--ease); }
.hitem:hover { background: var(--hover); }
.hitem.active { background: var(--card); box-shadow: var(--shadow-1); }
.hitem > a { flex: 1 1 auto; min-width: 0; display: grid; gap: 3px; padding: 10px 6px 10px 12px; text-decoration: none; color: var(--ink); min-height: 44px; }
.hitem .t { font-size: 0.88rem; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hitem .m { font-size: 0.74rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.hitem .m .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line-2); }
.hitem .m .dot.red { background: var(--red); }
.hitem .m .dot.green { background: var(--green); }
.hitem .del { opacity: 0; transition: opacity var(--t); margin-right: 2px; }
.hitem:hover .del, .hitem:focus-within .del, .hitem.active .del { opacity: 1; }
@media (hover: none) { .hitem .del { opacity: 0.7; } }

.thread-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.thread-head { display: flex; align-items: center; gap: 8px; padding: 12px 20px; min-height: 64px; border-bottom: 1px solid transparent; transition: border-color var(--t); }
.thread-head.scrolled { border-bottom-color: var(--line); }
.thread-head h2 { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-head .hist-btn { display: none; }
.thread { flex: 1 1 auto; overflow: auto; overscroll-behavior: contain; scroll-behavior: smooth; }
.thread-inner { max-width: 820px; margin: 0 auto; padding: 8px 28px 28px; display: grid; gap: 22px; }
.composer-wrap { padding: 0 28px 18px; background: linear-gradient(to bottom, transparent, var(--paper) 22px); }
.composer {
  max-width: 820px; margin: 0 auto; background: var(--card); border: 1px solid var(--line-2); border-radius: 22px; box-shadow: var(--shadow-2);
  transition: border-color var(--t), box-shadow var(--t);
}
.composer:focus-within { border-color: color-mix(in srgb, var(--ink) 35%, transparent); }
.composer textarea {
  display: block; width: 100%; border: 0; background: transparent; resize: none; color: var(--ink); font: 400 1rem/1.5 var(--f-text);
  padding: 16px 18px 6px; max-height: 220px; min-height: 56px; outline: none;
}
.composer textarea:focus-visible { box-shadow: none; }
.composer textarea::placeholder { color: var(--muted); }
.composer .tools { display: flex; align-items: center; gap: 6px; padding: 4px 8px 8px 10px; }
.composer .tools .grow { flex: 1; }
.composer select.mini {
  min-height: 36px; border: 1px solid var(--line); border-radius: 10px; padding: 0 30px 0 10px; background: var(--card-2); color: var(--ink-2); font: 600 0.8rem/1 var(--f-text); cursor: pointer;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%237f8782' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 16px;
}
.composer .switch .lbl-short { display: none; }
.composer .switch { min-height: 36px; font-size: 0.8rem; font-weight: 600; padding: 0 6px; }
.composer .switch .track { width: 30px; height: 18px; }
.composer .switch .track::after { width: 12px; height: 12px; }
.composer .switch input:checked + .track::after { transform: translateX(12px); }
.send { width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center; background: var(--ink); color: var(--paper); cursor: pointer; transition: transform 160ms var(--ease), opacity var(--t), background var(--t); flex: none; }
.send:hover { transform: scale(1.05); }
.send:active { transform: scale(0.94); }
.send[disabled] { opacity: 0.25; cursor: not-allowed; transform: none; }
.mic.rec { color: #fff; background: var(--red); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--red) 22%, transparent); } }
.disclaim { max-width: 820px; margin: 8px auto 0; text-align: center; font-size: 0.74rem; color: var(--muted); }

.welcome { display: grid; justify-items: center; text-align: center; gap: 12px; padding: 7vh 0 18px; }
.welcome .mark { --mk-bg: var(--ink); --mk-fg: var(--paper); width: 54px; height: 54px; border-radius: 18px; display: grid; place-items: center; background: var(--ink); color: var(--paper); box-shadow: var(--shadow-2); margin-bottom: 6px; }
.welcome .mark svg { width: 30px; height: 30px; color: var(--mk-fg); --paper: var(--mk-bg); }
.welcome h1 { font-size: clamp(1.7rem, 3.4vw, 2.3rem); letter-spacing: -0.035em; }
.welcome p { color: var(--ink-2); max-width: 52ch; }
.starters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: 100%; margin-top: 18px; }
.starter {
  text-align: left; display: grid; gap: 8px; padding: 14px 16px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font: 500 0.92rem/1.35 var(--f-text); cursor: pointer; box-shadow: var(--shadow-1);
  transition: transform 200ms var(--ease), box-shadow var(--t) var(--ease), border-color var(--t);
}
.starter:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--line-2); }
.starter .k { display: flex; gap: 6px; align-items: center; font: 600 0.7rem/1 var(--f-text); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.starter .k .ico { width: 14px; height: 14px; }
.starter .k.red { color: var(--red-ink); }
.starter .k.green { color: var(--green-ink); }
@media (max-width: 560px) { .starters { grid-template-columns: 1fr; } }

.msg-user { justify-self: end; max-width: min(80%, 560px); background: var(--ink); color: var(--paper); padding: 11px 16px; border-radius: 20px 20px 6px 20px; font-size: 0.97rem; white-space: pre-wrap; overflow-wrap: anywhere; animation: bubbleIn 300ms var(--ease) both; }
.msg-user .meta { display: block; font-size: 0.72rem; opacity: 0.6; margin-top: 3px; }
@keyframes bubbleIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

.answer { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); overflow: hidden; animation: bubbleIn 360ms var(--ease) both; }
.answer-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px 0; }
.answer-head .who { display: flex; gap: 8px; align-items: center; font: 650 0.86rem/1 var(--f-display); }
.answer-head .who svg { width: 18px; height: 18px; }
.answer-body { padding: 14px 18px 16px; display: grid; gap: 14px; }
.answer-foot > span { display: inline-flex; align-items: center; gap: 6px; }
.answer-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 12px 10px 18px; border-top: 1px solid var(--line); background: var(--card-2); font-size: 0.8rem; color: var(--muted); }
.answer-foot .ok { color: var(--green-ink); font-weight: 650; display: inline-flex; gap: 6px; align-items: center; }
.answer-foot .warn { color: var(--amber-ink); font-weight: 650; display: inline-flex; gap: 6px; align-items: center; }
.answer-foot .acts { margin-left: auto; display: flex; gap: 2px; }

.steps { display: grid; gap: 2px; padding: 4px 0; }
.step { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 10px; align-items: center; min-height: 30px; font-size: 0.88rem; animation: stepIn 260ms var(--ease) both; }
.step .st { width: 20px; height: 20px; display: grid; place-items: center; }
.step .st .spin { width: 14px; height: 14px; border-width: 2px; }
.step .st .okc { width: 18px; height: 18px; border-radius: 50%; background: var(--green-soft); color: var(--green-ink); display: grid; place-items: center; animation: pop 280ms var(--ease) both; }
.step .st .okc .ico { width: 12px; height: 12px; stroke-width: 2.6; }
.step .st .bad { background: var(--amber-soft); color: var(--amber-ink); }
.step .lbl { display: flex; gap: 8px; align-items: center; min-width: 0; color: var(--ink-2); }
.step .lbl span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step .ms { font: 500 0.72rem/1 var(--f-mono); color: var(--muted); }
.step.live .lbl { color: var(--ink); }
@keyframes stepIn { from { opacity: 0; transform: translateX(-4px); } }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } }

.refer {
  border-radius: var(--r-md); background: var(--red-soft); border: 1px solid color-mix(in srgb, var(--red) 30%, transparent); overflow: hidden;
}
.refer-top { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--red); color: #fff; font: 700 0.8rem/1 var(--f-text); letter-spacing: 0.1em; text-transform: uppercase; }
.refer-top .ico { width: 18px; height: 18px; stroke-width: 2.2; }
.refer-body { padding: 14px 16px; display: grid; gap: 12px; }
.refer-text { font-size: 1.02rem; line-height: 1.5; color: var(--ink); font-weight: 550; }
.refer-text q { quotes: "“" "”"; }
.refer .verb { font-size: 0.74rem; color: var(--red-ink); font-weight: 600; }
.refer details { border-top: 1px solid color-mix(in srgb, var(--red) 20%, transparent); padding-top: 10px; }
.refer summary { color: var(--red-ink); }
.refer .acts { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.dose { border-radius: var(--r-md); background: var(--green-soft); border: 1px solid color-mix(in srgb, var(--green) 30%, transparent); padding: 14px 16px; display: grid; gap: 8px; }
.dose .k { display: flex; gap: 8px; align-items: center; font: 700 0.72rem/1 var(--f-text); letter-spacing: 0.09em; text-transform: uppercase; color: var(--green-ink); }
.dose .k .ico { width: 16px; height: 16px; stroke-width: 2.2; }
.dose .v { font: 650 1.25rem/1.3 var(--f-display); letter-spacing: -0.015em; color: var(--ink); }
.dose .b { font-size: 0.85rem; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.points { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.points li { display: grid; grid-template-columns: 8px minmax(0, 1fr); gap: 12px; line-height: 1.55; }
.points li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ink-2); margin-top: 0.62em; }
.points .en { display: block; font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
.points .chip { margin-left: 6px; }

.need { border-radius: var(--r-md); border: 1px solid color-mix(in srgb, var(--blue) 30%, transparent); background: var(--blue-soft); padding: 14px 16px; display: grid; gap: 12px; }
.need p { font-weight: 600; color: var(--ink); }
.need form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.need .field { flex: 1 1 140px; }
.need .input { background: var(--card); }

.excerpt { border-left: 3px solid var(--line-2); padding: 4px 0 4px 14px; display: grid; gap: 8px; }
.excerpt .t { white-space: pre-wrap; color: var(--ink); }
.lbtext { white-space: pre-wrap; font: 400 0.92rem/1.55 var(--f-text); background: var(--paper-2); border-radius: var(--r-md); padding: 12px 14px; }
.notes { display: grid; gap: 6px; }
.notes .alert { font-size: 0.84rem; padding: 10px 12px; }
.msgtext { color: var(--ink); }

details.disc > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 0.84rem; font-weight: 600; color: var(--ink-2); min-height: 32px; user-select: none; border-radius: 8px; }
details.disc > summary::-webkit-details-marker { display: none; }
details.disc > summary .chev { transition: transform var(--t) var(--ease); width: 16px; height: 16px; }
details.disc[open] > summary .chev { transform: rotate(90deg); }
details.disc > .disc-body { animation: discIn 260ms var(--ease) both; }
@keyframes discIn { from { opacity: 0; transform: translateY(-4px); } }
.signs { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 3px; font-size: 0.92rem; }

.howcheck { border-top: 1px solid var(--line); padding: 4px 18px; }
.howcheck > summary { min-height: 44px; width: 100%; }
.howcheck .disc-body { display: grid; gap: 18px; padding: 4px 0 18px; }
.howcheck h4 { font: 600 0.72rem/1 var(--f-text); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.timeline { display: grid; gap: 0; position: relative; }
.timeline .step { min-height: 32px; }
.timeline .detail { grid-column: 2 / -1; font-size: 0.78rem; color: var(--muted); margin: -4px 0 4px; }
.passages { display: grid; gap: 8px; }
.passage { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 10px 12px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--line); text-align: left; color: var(--ink); cursor: pointer; font: inherit; transition: border-color var(--t), background var(--t); width: 100%; }
.passage:hover { border-color: var(--line-2); background: var(--card); }
.passage .s { font-weight: 600; font-size: 0.85rem; }
.passage .x { grid-column: 1 / -1; font-size: 0.8rem; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.passage .sc { display: flex; align-items: center; gap: 8px; font: 500 0.74rem/1 var(--f-mono); color: var(--muted); }
.scorebar { width: 54px; height: 5px; border-radius: 4px; background: var(--line); overflow: hidden; }
.scorebar i { display: block; height: 100%; background: var(--ink-2); border-radius: 4px; }
.checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.checkrow { display: flex; gap: 8px; align-items: center; font-size: 0.82rem; padding: 6px 8px; border-radius: 10px; background: var(--card-2); }
.checkrow b { font: 600 0.72rem/1 var(--f-mono); color: var(--muted); width: 22px; }
.checkrow .ico { width: 16px; height: 16px; stroke-width: 2.4; }
.checkrow.pass .ico { color: var(--green); }
.checkrow.fail { background: var(--amber-soft); }
.checkrow.fail .ico { color: var(--amber-ink); }
@media (max-width: 560px) { .checks { grid-template-columns: 1fr; } }

@media (max-width: 1180px) {
  .ask { grid-template-columns: minmax(0, 1fr); }
  .ask > .hist { display: none; }
  .thread-head .hist-btn { display: inline-grid; }
}
@media (max-width: 860px) {
  .ask { height: calc(100dvh - 56px - var(--tabbar-h) - env(safe-area-inset-bottom)); }
  .thread-inner { padding: 4px 16px 20px; }
  .composer-wrap { padding: 0 10px 10px; }
  .thread-head { padding: 6px 8px 6px 12px; min-height: 52px; }
  .welcome { padding-top: 3vh; }
  .composer .switch .lbl-long { display: none; }
  .composer .switch .lbl-short { display: inline; }
  .msg-user { max-width: 88%; }
  .answer-head, .answer-body { padding-left: 14px; padding-right: 14px; }
  .howcheck { padding: 4px 14px; }
}
.drawer .hist-list { padding: 8px 10px 20px; }

/* ---------------------------------------------------------------- page viewer */
.viewer .drawer-head { gap: 6px; }
.viewer .vt { min-width: 0; flex: 1 1 auto; }
.viewer .vt b { display: block; font: 650 0.95rem/1.25 var(--f-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer .vt span { display: block; font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vbar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--card-2); flex-wrap: wrap; }
.vbar .pg { font: 500 0.8rem/1 var(--f-mono); color: var(--ink-2); min-width: 92px; text-align: center; }
.vbar .sp { flex: 1; }
.vstage { background: var(--paper-2); min-height: 100%; padding: 18px; display: grid; justify-items: center; align-content: start; }
.vpage { position: relative; width: 100%; max-width: 1000px; background: #fff; border-radius: 6px; box-shadow: 0 2px 6px rgba(0,0,0,.08), 0 16px 40px rgba(0,0,0,.12); overflow: hidden; aspect-ratio: 1000 / 1294; transition: max-width 280ms var(--ease); }
.vpage.actual { max-width: none; width: 1000px; }
.vpage img { display: block; width: 100%; height: auto; opacity: 0; transition: opacity 260ms var(--ease); }
.vpage img.ready { opacity: 1; }
.vpage .sk { position: absolute; inset: 0; border-radius: 0; background: #f2f2ef; }
.vpage .sk::after { background: linear-gradient(90deg, transparent, rgba(0,0,0,.05), transparent); }
.vpage.loaded { aspect-ratio: auto; }
.vnote { width: 100%; max-width: 1000px; margin-bottom: 12px; }
.vquote { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); font-size: 0.86rem; color: var(--ink-2); }
.vquote mark { background: color-mix(in srgb, var(--hl) 70%, transparent); color: #111; padding: 0 2px; border-radius: 3px; }

/* ---------------------------------------------------------------- dose calculator */
.calc { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 20px; align-items: start; }
@media (max-width: 960px) { .calc { grid-template-columns: 1fr; } }
.drugs { display: flex; flex-wrap: wrap; gap: 8px; }
.drugpick { min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--card); color: var(--ink); font: 600 0.92rem/1 var(--f-text); cursor: pointer; transition: all var(--t) var(--ease); display: inline-flex; align-items: center; gap: 8px; }
.drugpick:hover { border-color: var(--ink-2); }
.drugpick[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.readout { position: relative; overflow: hidden; border-radius: var(--r-xl); padding: 26px; min-height: 260px; display: grid; align-content: start; gap: 14px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow-1); transition: background 300ms var(--ease), border-color 300ms; }
.readout.ok { background: var(--green-soft); border-color: color-mix(in srgb, var(--green) 35%, transparent); }
.readout .big { font: 700 clamp(1.8rem, 4.2vw, 2.7rem)/1.08 var(--f-display); letter-spacing: -0.035em; color: var(--ink); animation: viewIn 360ms var(--ease) both; }
.readout .freq { font: 550 1.1rem/1.35 var(--f-text); color: var(--ink-2); }
.readout .facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 4px; }
.fact { background: color-mix(in srgb, var(--card) 70%, transparent); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.fact .l { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.fact .v { font: 550 0.92rem/1.35 var(--f-text); margin-top: 4px; }
.noai { display: flex; gap: 10px; align-items: flex-start; font-size: 0.84rem; color: var(--ink-2); }
.noai .ico { color: var(--green); margin-top: 1px; }

/* ---------------------------------------------------------------- referral */
.refgrid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1060px) { .refgrid { grid-template-columns: 1fr; } }
.preview { position: sticky; top: 20px; }
.preview iframe { width: 100%; height: 760px; border: 0; border-radius: var(--r-md); background: #fff; display: block; box-shadow: 0 2px 6px rgba(0,0,0,.06), 0 16px 40px rgba(0,0,0,.08); transition: opacity 200ms; }
.preview iframe.stale { opacity: 0.6; }
@media (max-width: 1060px) { .preview { position: static; } .preview iframe { height: 620px; } }
.srcref { display: grid; gap: 8px; padding: 14px 16px; border-radius: var(--r-md); background: var(--red-soft); border-left: 4px solid var(--red); }
.srcref .q { font-size: 0.82rem; color: var(--ink-2); }

/* ---------------------------------------------------------------- library */
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.doc { text-align: left; display: grid; gap: 10px; padding: 20px; border-radius: var(--r-lg); background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow-1); color: var(--ink); cursor: pointer; font: inherit; transition: transform 220ms var(--ease), box-shadow var(--t), border-color var(--t); text-decoration: none; }
.doc:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--line-2); }
.doc .code { display: inline-grid; place-items: center; min-width: 44px; height: 44px; padding: 0 10px; border-radius: 12px; background: var(--ink); color: var(--paper); font: 600 0.82rem/1 var(--f-mono); justify-self: start; }
.doc h3 { font-size: 1.02rem; line-height: 1.3; }
.doc .meta { font-size: 0.8rem; color: var(--muted); display: flex; gap: 6px 12px; flex-wrap: wrap; }
.searchbox { position: relative; }
.searchbox .ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.searchbox .input { padding-left: 44px; min-height: 52px; font-size: 1rem; border-radius: 16px; }
.searchbox .input:focus { border-radius: 16px; }
.searchbox .spin { position: absolute; right: 14px; top: 50%; margin-top: -9px; }
.results { display: grid; gap: 8px; margin-top: 12px; }
.result { text-align: left; display: grid; gap: 6px; padding: 14px 16px; border-radius: var(--r-md); background: var(--card); border: 1px solid var(--line); cursor: pointer; font: inherit; color: var(--ink); transition: border-color var(--t), box-shadow var(--t), transform 200ms var(--ease); width: 100%; }
.result:hover { border-color: var(--line-2); box-shadow: var(--shadow-1); }
.result .s { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 0.82rem; color: var(--muted); }
.result .s b { color: var(--ink); font-weight: 650; font-size: 0.9rem; }
.result .x { font-size: 0.9rem; color: var(--ink-2); white-space: pre-line; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.result mark, .hlq { background: color-mix(in srgb, var(--hl) 55%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }
.reader { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 0; border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--card); box-shadow: var(--shadow-1); }
.outline { border-right: 1px solid var(--line); max-height: calc(100dvh - 180px); overflow: auto; padding: 10px; position: sticky; top: 0; }
.outline button { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; width: 100%; text-align: left; min-height: 40px; padding: 8px 10px; border: 0; border-radius: 10px; background: none; color: var(--ink-2); font: 500 0.86rem/1.3 var(--f-text); cursor: pointer; transition: background var(--t), color var(--t); }
.outline button:hover { background: var(--hover); color: var(--ink); }
.outline button.d0 { font-weight: 650; color: var(--ink); }
.outline button.d1 { padding-left: 20px; }
.outline button.d2 { padding-left: 32px; }
.outline button[aria-current="true"] { background: var(--paper-2); color: var(--ink); }
.outline .pg { font: 500 0.72rem/1 var(--f-mono); color: var(--muted); }
.reader-main { min-width: 0; }
.reader-main .vstage { min-height: 500px; }
@media (max-width: 900px) {
  .reader { grid-template-columns: 1fr; }
  .outline { position: static; max-height: 240px; border-right: 0; border-bottom: 1px solid var(--line); }
}

/* ---------------------------------------------------------------- dashboard */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ws .filters .input { width: auto; min-width: 160px; min-height: 40px; padding-top: 6px; padding-bottom: 6px; }
.demo-banner { margin-bottom: 18px; }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1100px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { text-align: left; display: grid; gap: 6px; align-content: start; padding: 16px 18px; border-radius: var(--r-lg); background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow-1); color: var(--ink); font: inherit; transition: transform 220ms var(--ease), box-shadow var(--t), border-color var(--t); }
button.tile { cursor: pointer; }
button.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--line-2); }
.tile .l { font-size: 0.8rem; color: var(--ink-2); min-height: 2.4em; }
.tile .n { font: 700 2.1rem/1 var(--f-display); letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.tile .d { font-size: 0.76rem; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.tile.refer .n { color: var(--red-ink); }
.dash-cols { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); margin-top: 16px; }
@media (max-width: 1000px) { .dash-cols { grid-template-columns: 1fr; } }
.dash-cols > div { display: grid; gap: 16px; align-content: start; min-width: 0; }
.flag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font: 700 0.66rem/1 var(--f-text); letter-spacing: 0.06em; white-space: nowrap; }
.flag.rising { background: var(--amber-soft); color: var(--amber-ink); }
.flag.new { background: var(--amber-soft); color: var(--amber-ink); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--amber) 50%, transparent); }
.flagitem { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 14px 0; border-top: 1px solid var(--line); }
.flagitem:first-child { border-top: 0; padding-top: 2px; }
.flagitem .what { font-weight: 650; }
.flagitem .why { font-size: 0.84rem; color: var(--ink-2); margin-top: 2px; }
@media (max-width: 560px) { .flagitem { grid-template-columns: minmax(0, 1fr); gap: 6px; } }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.8rem; color: var(--ink-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font: 11px var(--f-text); font-variant-numeric: tabular-nums; }
.chart [data-i] { cursor: default; }
.chart .colhl { fill: var(--hover); opacity: 0; transition: opacity 120ms; }
.chart .colhl.on { opacity: 1; }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--paper); font-size: 0.78rem; padding: 8px 10px; border-radius: 10px; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); z-index: 5; line-height: 1.5; box-shadow: var(--shadow-2); transition: left 90ms linear, top 90ms linear; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.multiples { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.multiple { padding: 12px; border-radius: var(--r-md); background: var(--card-2); }
.multiple h3 { font-size: 0.88rem; font-family: var(--f-text); font-weight: 650; letter-spacing: 0; }
.multiple .n { font-size: 0.8rem; color: var(--ink-2); margin: 2px 0 6px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.barlist { display: grid; gap: 4px; }
.barrow { display: grid; grid-template-columns: minmax(0, 1fr) 42px; gap: 6px 10px; align-items: center; background: none; color: var(--ink); font: inherit; text-align: left; padding: 8px 10px; margin: 0 -10px; border-radius: 12px; border: 0; transition: background var(--t); }
button.barrow { cursor: pointer; }
button.barrow:hover { background: var(--hover); }
.barrow .name { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.barrow .val { text-align: right; font: 600 0.88rem/1 var(--f-mono); }
.barrow .track { grid-column: 1 / -1; height: 8px; background: var(--paper-2); border-radius: 4px; overflow: hidden; }
.barrow .fill { display: block; height: 100%; border-radius: 4px; transform-origin: left; animation: grow 600ms var(--ease) both; }
@keyframes grow { from { transform: scaleX(0); } }
.gap-i { padding: 12px 0; border-top: 1px solid var(--line); }
.gap-i:first-child { border-top: 0; padding-top: 2px; }
.gap-i q { font-weight: 600; }
.report { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.qi { padding: 14px 20px; border-bottom: 1px solid var(--line); }
.qi .m { font-size: 0.78rem; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- admin */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 22px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 0.9rem; white-space: nowrap; transition: color var(--t); }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); }
.tabs a[aria-current="page"]::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--ink); }
.tabs .count { font: 600 0.7rem/1 var(--f-mono); background: var(--amber-soft); color: var(--amber-ink); border-radius: 999px; padding: 3px 7px; }
.people td { vertical-align: middle; }
.people .input { min-height: 36px; padding: 4px 30px 4px 10px; width: auto; font-size: 0.85rem; background-position: right 8px center; }
.drop { display: grid; justify-items: center; gap: 8px; text-align: center; padding: 32px 20px; border: 1.5px dashed var(--line-2); border-radius: var(--r-lg); background: var(--card-2); cursor: pointer; transition: border-color var(--t), background var(--t), transform 200ms var(--ease); }
.drop:hover, .drop.over { border-color: var(--ink-2); background: var(--card); }
.drop.over { transform: scale(1.01); }
.drop .em-ico { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--paper-2); }
.filepill { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-md); background: var(--card-2); border: 1px solid var(--line); }
.progress { height: 8px; border-radius: 6px; background: var(--paper-2); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ink); border-radius: 6px; transition: width 160ms linear; }
.progress.indet i { width: 35% !important; animation: indet 1.2s var(--ease-in-out) infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
.review { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0; overflow: hidden; }
.review .left { padding: 22px; display: grid; gap: 14px; align-content: start; }
.review .right { background: var(--paper-2); padding: 14px; border-left: 1px solid var(--line); display: grid; align-content: start; gap: 8px; }
.review .right img { border-radius: 6px; box-shadow: var(--shadow-1); background: #fff; cursor: zoom-in; }
.review dl { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 8px 12px; margin: 0; font-size: 0.9rem; }
.review dt { color: var(--muted); font-size: 0.8rem; font-weight: 600; padding-top: 2px; }
.review dd { margin: 0; }
.review pre { white-space: pre-wrap; margin: 0; font: 0.8rem/1.5 var(--f-mono); background: var(--card-2); border-radius: 10px; padding: 10px 12px; border: 1px solid var(--line); }
@media (max-width: 900px) { .review { grid-template-columns: 1fr; } .review .right { border-left: 0; border-top: 1px solid var(--line); } .review dl { grid-template-columns: 1fr; gap: 2px; } .review dd { margin-bottom: 8px; } }
.gates { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.gate { padding: 16px; border-radius: var(--r-lg); border: 1px solid var(--line); background: var(--card); display: grid; gap: 6px; }
.gate .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.gate .n { font: 700 1.7rem/1 var(--f-display); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.gate .l { font-size: 0.85rem; color: var(--ink-2); }
.gate .g { font-size: 0.74rem; color: var(--muted); }
.gate.pass { border-color: color-mix(in srgb, var(--green) 35%, transparent); }
.gate.fail { border-color: color-mix(in srgb, var(--amber) 55%, transparent); background: var(--amber-soft); }
.audit-row summary { cursor: pointer; list-style: none; display: grid; grid-template-columns: 150px 140px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 16px; min-height: 48px; transition: background var(--t); }
.audit-row summary::-webkit-details-marker { display: none; }
.audit-row summary:hover { background: var(--hover); }
.audit-row + .audit-row { border-top: 1px solid var(--line); }
.audit-row pre { margin: 0 16px 14px; padding: 12px 14px; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; font: 0.78rem/1.5 var(--f-mono); overflow: auto; max-height: 360px; white-space: pre-wrap; word-break: break-word; }
.audit-row .sum { font-size: 0.85rem; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 700px) { .audit-row summary { grid-template-columns: minmax(0, 1fr) auto; } .audit-row .when { grid-column: 1 / -1; order: 3; } .audit-row .sum { grid-column: 1 / -1; } }
.secret { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--amber-soft); }
.secret code { flex: 1; font-size: 0.92rem; word-break: break-all; color: var(--ink); }

/* ---------------------------------------------------------------- settings */
.settings-grid { display: grid; gap: 16px; }
.setrow { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; padding: 22px 0; border-top: 1px solid var(--line); }
.setrow:first-child { border-top: 0; padding-top: 0; }
.setrow h2 { font-size: 1rem; }
.setrow p { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
@media (max-width: 760px) { .setrow { grid-template-columns: 1fr; gap: 12px; } }
.theme-pick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; max-width: 460px; }
.theme-opt { display: grid; gap: 8px; padding: 8px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--card); cursor: pointer; font: 600 0.84rem/1 var(--f-text); color: var(--ink); text-align: center; transition: border-color var(--t); }
.theme-opt[aria-pressed="true"] { border-color: var(--ink); }
.theme-opt .sw { height: 54px; border-radius: 10px; border: 1px solid var(--line); }
.theme-opt .sw.l { background: linear-gradient(135deg, #f2f0eb 50%, #fbfaf7 50%); }
.theme-opt .sw.d { background: linear-gradient(135deg, #0b100e 50%, #17211d 50%); }
.theme-opt .sw.s { background: linear-gradient(135deg, #f2f0eb 50%, #0b100e 50%); }

/* ---------------------------------------------------------------- command palette */
.palette-wrap { position: fixed; inset: 0; z-index: 150; display: grid; justify-items: center; align-items: start; padding: 12vh 16px 16px; pointer-events: none; }
.palette { pointer-events: auto; width: min(620px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-2); overflow: hidden; opacity: 0; transform: translateY(-8px) scale(0.98); transition: opacity 220ms var(--ease), transform 260ms var(--ease); }
.palette.open { opacity: 1; transform: none; }
.palette .pin { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.palette .pin input { flex: 1; min-height: 56px; border: 0; background: transparent; color: var(--ink); font: 400 1.02rem/1 var(--f-text); outline: none; }
.palette .pin input:focus-visible { box-shadow: none; }
.palette .plist { max-height: min(56vh, 460px); overflow: auto; padding: 8px; }
.palette .pg { font: 600 0.68rem/1 var(--f-text); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 10px 10px 6px; }
.palette .pi { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; cursor: pointer; min-height: 44px; color: var(--ink-2); }
.palette .pi .t { flex: 1; min-width: 0; }
.palette .pi .t b { display: block; font-weight: 550; color: var(--ink); font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette .pi .t span { display: block; font-size: 0.78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette .pi[aria-selected="true"] { background: var(--paper-2); color: var(--ink); }
.palette .pfoot { display: flex; gap: 14px; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 0.74rem; color: var(--muted); background: var(--card-2); }

/* ---------------------------------------------------------------- boot */
.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--paper); z-index: 300; transition: opacity 300ms var(--ease); }
.boot.gone { opacity: 0; pointer-events: none; }
.boot svg { width: 40px; height: 40px; color: var(--ink); animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(0.92); opacity: 0.6; } }

/* ---------------------------------------------------------------- AUTH */
.auth { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.auth-form { display: flex; flex-direction: column; padding: 28px clamp(20px, 6vw, 72px); }
.auth-form .brand { padding: 0; }
.auth-inner { width: 100%; max-width: 420px; margin: auto; padding: 40px 0; display: grid; gap: 22px; animation: viewIn 420ms var(--ease) both; }
.auth-inner h1 { font-size: clamp(1.8rem, 3.2vw, 2.3rem); letter-spacing: -0.035em; }
.auth-inner .lede { color: var(--ink-2); margin-top: 8px; }
.auth-foot { font-size: 0.78rem; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; justify-content: space-between; }
.auth-foot a { color: var(--muted); }
.pwhint { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.78rem; color: var(--muted); }
.pwhint span { display: inline-flex; gap: 5px; align-items: center; transition: color var(--t); }
.pwhint span .ico { width: 14px; height: 14px; stroke-width: 2.2; }
.pwhint span.ok { color: var(--green-ink); }
.pwwrap { position: relative; }
.pwwrap .input { padding-right: 52px; }
.pwwrap .icon-btn { position: absolute; right: 2px; top: 0; }
.firstnote { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md); background: var(--blue-soft); font-size: 0.88rem; }
.firstnote .ico { color: var(--blue); }
.auth-art {
  position: relative; overflow: hidden; background: var(--night); color: var(--on-night); display: flex; flex-direction: column; justify-content: space-between; padding: 40px clamp(28px, 5vw, 64px);
}
.auth-art::before { content: ""; position: absolute; inset: -20%; background:
  radial-gradient(40% 35% at 75% 20%, rgba(62, 224, 143, 0.13), transparent 70%),
  radial-gradient(45% 40% at 20% 85%, rgba(47, 111, 228, 0.12), transparent 70%); pointer-events: none; }
.auth-art::after { content: ""; position: absolute; inset: 0; background-image: linear-gradient(var(--night-line) 1px, transparent 1px), linear-gradient(90deg, var(--night-line) 1px, transparent 1px); background-size: 44px 44px; mask-image: radial-gradient(70% 60% at 50% 45%, #000, transparent); -webkit-mask-image: radial-gradient(70% 60% at 50% 45%, #000, transparent); pointer-events: none; opacity: 0.6; }
.auth-art > * { position: relative; z-index: 1; }
.auth-art .promise { font: 600 clamp(1.6rem, 2.8vw, 2.4rem)/1.12 var(--f-display); letter-spacing: -0.035em; max-width: 17ch; }
.auth-art .promise em { font-style: normal; color: var(--green-glow); }
.auth-art .small { color: var(--on-night-2); }
.demo-card { width: 100%; max-width: 440px; align-self: center; background: var(--night-2); border: 1px solid var(--night-line); border-radius: 22px; padding: 16px; box-shadow: 0 30px 80px rgba(0,0,0,.45); display: grid; gap: 12px; animation: floatIn 700ms 120ms var(--ease) both; }
@keyframes floatIn { from { opacity: 0; transform: translateY(18px); } }
.demo-card .q { justify-self: end; background: var(--on-night); color: var(--night); padding: 9px 14px; border-radius: 18px 18px 6px 18px; font-size: 0.9rem; max-width: 85%; }
.demo-card .ref { border-radius: 14px; overflow: hidden; background: rgba(229, 64, 47, 0.12); border: 1px solid rgba(229, 64, 47, 0.35); }
.demo-card .ref .top { background: var(--red); color: #fff; font: 700 0.72rem/1 var(--f-text); letter-spacing: 0.1em; padding: 9px 12px; display: flex; gap: 8px; align-items: center; }
.demo-card .ref .bd { padding: 12px; font-size: 0.9rem; line-height: 1.5; color: var(--on-night); display: grid; gap: 10px; }
.demo-card .chip { background: rgba(238,242,239,.06); border-color: var(--night-line); color: var(--on-night-2); cursor: default; }
.demo-card .ok { display: flex; gap: 8px; align-items: center; font-size: 0.82rem; color: var(--green-glow); font-weight: 600; padding: 2px 4px; }
.demo-card .ok .ico { width: 16px; height: 16px; stroke-width: 2.4; }
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
}

/* ---------------------------------------------------------------- print + motion */
@media print { .side, .tabbar, .topbar, .composer-wrap { display: none !important; } }
@media (prefers-reduced-motion: reduce) {
  .ws *, .ws *::before, .ws *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .sk::after { animation: none; }
}

/* number inputs: no spinners */
.ws input[type="number"] { -moz-appearance: textfield; }
.ws input[type="number"]::-webkit-inner-spin-button, .ws input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.ws a.btn { color: var(--fg); }

/* the view region takes focus after navigation for screen readers; it needs no visible ring */
#view:focus { outline: none; }
