/* Polish pass: focus, touch, tooltips, dark tokens, skeletons, toasts, onboarding, menus, phone chrome. */
:root { --teal: #14b8a6; --good-soft: color-mix(in srgb, var(--good) 14%, transparent); --bad-soft: color-mix(in srgb, var(--bad) 14%, transparent); --warn-soft: color-mix(in srgb, var(--warn) 16%, transparent); }
:root[data-theme="dark"] { --good: #4ade80; --bad: #f87171; --warn: #fbbf24; --line: #33313f; }
.delta.up { background: var(--good-soft); } .delta.down { background: var(--bad-soft); }
.brand .logo, .goalbar i { background: linear-gradient(135deg, var(--accent), var(--teal)); }
.kpi .value { font-family: var(--sans); font-weight: 650; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
table.t td { font-variant-numeric: tabular-nums; }
.kpi .vs { font-size: 11.5px; color: var(--muted); margin-left: 4px; font-weight: 400; }
.kpi .more { font-size: 12px; color: var(--accent); opacity: 0; transition: .15s; }
.kpi:hover .more, .kpi:focus-visible .more { opacity: 1; }
.kpi .foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 11.5px; color: var(--muted); }
.kpi .foot .more { margin-left: auto; }

:where(button, a, [tabindex], .ws-item, .choice, summary):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:active { transform: translateY(1px); }
.kpi:active { transform: scale(.985); }
@media (hover: none) { .kpi:hover { transform: none; } .kpi .more { opacity: 1; } }
@media (pointer: coarse) {
  .btn, .seg button, .nav button { min-height: 42px; }
  .icon-btn { min-width: 40px; min-height: 40px; display: inline-grid; place-items: center; }
  .swatches button { width: 36px; height: 36px; }
  input, select, textarea { font-size: 16px; }
  .kbd { display: none; }
}

/* tooltip */
.tip { background: var(--panel); color: var(--ink); border: 1px solid var(--line); box-shadow: 0 12px 32px #0000002a; border-radius: 10px; font-variant-numeric: tabular-nums; padding: 8px 11px; }
.tip .th { font-size: 11px; color: var(--muted); margin-bottom: 5px; }
.tip .r { gap: 14px; line-height: 1.7; }
.tip .r > span { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }

/* skeletons */
.skel { position: relative; overflow: hidden; background: var(--panel-2); border-radius: var(--radius); border: 1px solid var(--line); }
.skel::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--ink) 7%, transparent), transparent); animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .skel::after, .drv-bar i { animation: none; } }

/* toasts */
.toast { display: flex; align-items: center; gap: 12px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-left: 3px solid var(--accent); box-shadow: 0 12px 32px #0000002a; transition: opacity .15s, transform .15s; max-width: calc(100vw - 32px); }
.toast.ok { border-left-color: var(--good); } .toast.err { border-left-color: var(--bad); }
.toast.leaving { opacity: 0; transform: translate(-50%, 6px); }
.toast-act { border: 0; background: var(--accent-soft); color: var(--accent); font-weight: 600; padding: 4px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; }

/* nav subtitles */
.nav button { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.25; }
.nav-sub { font-size: 10.5px; opacity: .7; font-weight: 400; }
@media (max-width: 1280px) { .nav-sub { display: none; } }

/* info tips */
.info { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); font-size: 10px; font-weight: 700; cursor: help; position: relative; vertical-align: middle; margin-left: 4px; padding: 0; font-family: var(--sans); }
.info:hover::after, .info:focus::after { content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 6px); transform: translateX(-50%); width: max-content; max-width: 240px; white-space: normal; text-align: left;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; font-size: 12px; font-weight: 400; line-height: 1.45; box-shadow: 0 10px 28px #0003; z-index: 20; }
.stat .tech { display: block; font-size: 10.5px; color: var(--muted); opacity: .85; margin-top: 1px; }

/* empty states & onboarding */
.empty-card { text-align: center; padding: 36px 18px; color: var(--muted); }
.empty-card .ei { font-size: 34px; }
.empty-card h3 { color: var(--ink); margin: 8px 0 4px; font-family: var(--serif); font-size: 18px; }
.empty-card p { max-width: 460px; margin: 6px auto 16px; }
.chart .chart-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted); font-size: 13px; }
.onb { background: linear-gradient(135deg, var(--accent-soft), transparent 70%), var(--panel); margin-bottom: 18px; }
.onb-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-top: 12px; }
.onb-step { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; text-align: left; }
.onb-step:hover { border-color: var(--accent); }
.onb-step .ck { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; border: 2px solid var(--line); flex: none; font-size: 12px; }
.onb-step.done { opacity: .6; } .onb-step.done .ck { background: var(--good); border-color: var(--good); color: #fff; }
.onb-step b { display: block; font-size: 13px; } .onb-step small { color: var(--muted); font-size: 11.5px; }

/* folds & verdict */
details.adv > summary { cursor: pointer; list-style: none; font-weight: 600; display: flex; align-items: center; gap: 8px; }
details.adv > summary::-webkit-details-marker { display: none; }
details.adv > summary::before { content: "▸"; transition: .15s; color: var(--muted); }
details.adv[open] > summary::before { transform: rotate(90deg); }
details.adv[open] > summary { margin-bottom: 14px; }
.verdict { border-color: color-mix(in srgb, var(--good) 40%, var(--line)); background: linear-gradient(135deg, var(--good-soft), transparent 65%), var(--panel); }
.verdict p { margin: 6px 0; font-size: 15px; }
.verdict.unsure { border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); background: linear-gradient(135deg, var(--warn-soft), transparent 65%), var(--panel); }

/* widget menu */
.wmenu-wrap { position: relative; margin-left: auto; }
.wmenu { position: absolute; right: 0; top: calc(100% + 4px); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 14px 36px #0003; padding: 6px; z-index: 15; min-width: 200px; }
.wmenu button { display: flex; width: 100%; gap: 8px; border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; text-align: left; }
.wmenu button:hover { background: var(--accent-soft); }
.wmenu .sizes { display: flex; gap: 4px; padding: 4px 4px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.wmenu .sizes button { justify-content: center; border: 1px solid var(--line); padding: 4px 0; }
.wmenu .sizes button.on { border-color: var(--accent); color: var(--accent); }
.wmenu .lbl { font-size: 11px; color: var(--muted); padding: 4px 10px 2px; }
.wmenu .danger { color: var(--bad); }

/* range */
.range-wrap { position: relative; }
.range-pop { position: absolute; z-index: 15; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 14px 36px #0003; padding: 14px; width: 290px; margin-top: 6px; left: 0; }
.range-label { font-size: 12.5px; color: var(--muted); }

/* trials grid */
.grid-t thead th { z-index: 3; }
.grid-t td:nth-child(1), .grid-t th:nth-child(1) { position: sticky; left: 0; width: 36px; min-width: 36px; background: var(--panel); z-index: 2; }
.grid-t td:nth-child(2), .grid-t th:nth-child(2) { position: sticky; left: 36px; background: var(--panel); z-index: 2; box-shadow: 1px 0 0 var(--line); }
.grid-t thead th:nth-child(1), .grid-t thead th:nth-child(2) { z-index: 4; }
.grid-t tbody tr:focus-within td { background: color-mix(in srgb, var(--accent) 7%, var(--panel)); }
.cell.missing { background: repeating-linear-gradient(135deg, var(--warn-soft) 0 6px, transparent 6px 12px); }
.cell.err { outline: 2px solid var(--bad); }
.trial-cards { display: grid; gap: 10px; }
.trial-card .tc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.trial-card .tc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.trial-card label { font-size: 11.5px; color: var(--muted); display: block; }
.trial-card label.oc { color: var(--accent); font-weight: 600; }
.trial-card .cell { border-color: var(--line); background: var(--panel-2); min-width: 0; }

/* drawer & phone chrome */
.side-scrim { position: fixed; inset: 0; background: #0b0a1055; z-index: 29; opacity: 0; pointer-events: none; transition: opacity .2s; }
.side-scrim.open { opacity: 1; pointer-events: auto; }
.bottom-nav, .top-search { display: none; }
@media (max-width: 760px) {
  .topbar { padding: 8px 12px; flex-wrap: nowrap; gap: 8px; }
  .topbar h1 { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .nav { display: none; }
  .top-search { display: inline-flex; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: color-mix(in srgb, var(--panel) 92%, transparent);
    backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav button { border: 0; background: none; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; color: var(--muted); cursor: pointer; }
  .bottom-nav .bi { font-size: 18px; line-height: 1; filter: grayscale(1); opacity: .7; }
  .bottom-nav button.on { color: var(--accent); font-weight: 600; } .bottom-nav button.on .bi { filter: none; opacity: 1; }
  .content { padding-bottom: 92px; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .overlay { place-items: end stretch; }
  .modal, .modal.wide { width: 100% !important; max-height: 92dvh; border-radius: 20px 20px 0 0; padding-bottom: 0; }
  .modal-foot { position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); margin: 18px -18px 0; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; justify-content: center; min-height: 44px; }
  .palette { margin-top: 8vh; }
  .range-pop { position: fixed; left: 12px; right: 12px; width: auto; top: 120px; }
}
.modal.wide { width: min(760px, calc(100vw - 32px)); }

.btn.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-solid:hover { filter: brightness(1.08); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
@media (max-width: 760px) {
  .onb-steps { grid-template-columns: 1fr 1fr; gap: 8px; }
  .onb-step { padding: 8px 10px; } .onb-step small { display: none; }
  .toolbar .seg { display: flex; width: 100%; }
  .toolbar .seg button { flex: 1 1 auto; padding: 6px 8px; }
  .range-wrap { width: 100%; }
  .range-label { width: 100%; }
}
@media (max-width: 760px) {
  .kpi { padding: 12px; }
  .kpi .foot { display: block; line-height: 1.4; }
  .kpi .more, .kpi .vs, .kpi .label .chip { display: none; }
  .kpi .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
}

.trial-card .tc-head { flex-wrap: wrap; }
.trial-card .tc-head [data-k="t"] { flex: 1; width: auto !important; }
.trial-card .tc-head select { order: 5; flex: 1 1 100% !important; }

/* Fill the window: without this the shell (and sidebar) is only as tall as its content. */
#app { height: 100%; }
.shell { height: 100dvh; }
