:root {
  --bg: #0b1020; --panel: #0f172a; --card: #1b2336; --muted-bg: #272f42; --border: #334155;
  --text: #f8fafc; --fg-2: #cbd5e1; --muted: #94a3b8;
  --accent: #22c55e; --on-accent: #0f172a;
  --ok: #22c55e; --warn: #fbbf24; --danger: #f87171; --info: #60a5fa;
  --r: 8px; --ease: cubic-bezier(.2, .7, .2, 1);
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
h1, h2 { margin: 0; }
svg { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.pad { padding: 0 16px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.s-ok { color: var(--ok); } .s-warn { color: var(--warn); } .s-bad { color: var(--danger); }

[hidden] { display: none !important; }

/* controls */
button {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--r); background: var(--card);
  color: inherit; font: inherit; white-space: nowrap; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
button:hover:not(:disabled) { background: var(--muted-bg); border-color: #475569; }
button:active:not(:disabled) { transform: scale(.97); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: #4ade80; border-color: #4ade80; }
button.danger { color: var(--danger); }
button.ghost { background: none; border-color: transparent; color: var(--fg-2); }
button.icon { width: 36px; padding: 0; justify-content: center; }
input[type="text"] {
  flex: 1 1 100%; min-width: 0; min-height: 36px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--r); background: var(--panel); color: inherit; font: inherit;
}
input[type="text"]::placeholder { color: var(--muted); }
input[type="text"]:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(34, 197, 94, .25); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.msg { min-height: 1.5em; margin: 0; color: var(--danger); font-size: .9rem; }
.msg:empty { display: none; }
.pill { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 2px 10px; border-radius: 999px; background: var(--muted-bg); color: var(--fg-2); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 500; }
.tag.running { background: rgba(34, 197, 94, .15); color: #4ade80; }
.tag.complete { background: var(--muted-bg); color: var(--fg-2); }
.tag.incomplete { background: rgba(251, 191, 36, .15); color: var(--warn); }

/* top bar */
.top { position: sticky; top: 0; z-index: 30; height: 48px; display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.top h1 { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; }
.top h1 svg { color: var(--accent); }
.top .sub { color: var(--muted); font-size: 13px; }
.top .sp { flex: 1; }

/* 3-column shell */
.shell { display: grid; grid-template-columns: minmax(260px, 300px) minmax(0, 1fr) minmax(300px, 380px); height: calc(100vh - 48px); min-height: 560px; }
.col { min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--panel); }
.col:last-child { border-right: 0; }
.col.mid { background: var(--bg); }
.col-head { display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.col-head h2 { flex: 1; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.scroll { flex: 1; min-height: 0; overflow: auto; }

/* sessions */
.sess { list-style: none; margin: 0; padding: 8px; }
.sess li { margin-bottom: 4px; }
.sess button { width: 100%; display: grid; gap: 4px; padding: 10px 12px; border-color: transparent; background: none; text-align: left; white-space: normal; }
.sess button:hover:not(:disabled) { background: var(--card); border-color: transparent; }
.sess button[aria-current="true"] { background: var(--card); border-color: var(--border); box-shadow: inset 3px 0 0 var(--accent); }
.sess .t { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 500; }
.sess .m { display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 12px; }
.bar { height: 4px; border-radius: 2px; background: var(--muted-bg); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .3s var(--ease); }

/* current scan */
.mid-in { display: grid; gap: 16px; align-content: start; padding: 20px 24px; }
.hero { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.hero-top { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.hero-top .grow { flex: 1; min-width: 180px; }
.hero-top strong { display: block; font-size: 16px; }
.hero-top span.mono { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.progress { display: flex; align-items: center; gap: 12px; }
progress { flex: 1; height: 8px; accent-color: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--card); }
.stat b { display: block; font: 600 20px/1.2 var(--mono); }
.stat span { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }

/* log + summary */
.logpanel { overflow: hidden; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.logbox { display: grid; gap: 6px; max-height: 340px; overflow: auto; padding: 12px; font: 12px/1.5 var(--mono); color: var(--fg-2); }
.logbox:empty::before { content: "No log yet."; color: var(--muted); padding: 0 4px; }
.logbox > div { display: flex; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--card); overflow-wrap: anywhere; }
.logbox > div > span:last-child { min-width: 0; }
.logbox .t { flex: none; color: var(--muted); }
.logbox .warn { border-left: 3px solid var(--warn); } .logbox .bad { border-left: 3px solid var(--danger); color: var(--danger); }
.seg { display: flex; gap: 4px; padding: 2px; border-radius: var(--r); background: var(--card); }
.seg button { min-height: 28px; padding: 2px 10px; border: 0; border-radius: 6px; background: none; font-size: 12px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--muted-bg); color: var(--text); }
.sum { display: grid; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
.sum[hidden] { display: none; }
.sum label { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
textarea { display: block; width: 100%; min-height: 110px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--bg); color: var(--fg-2); font: 12px/1.6 var(--mono); resize: vertical; }
.sum .row .danger { margin-left: auto; }

/* links (right column): always stacked cards, the column is narrow */
.links-in { display: grid; gap: 12px; align-content: start; padding: 12px; }
.add { display: flex; flex-wrap: wrap; gap: 8px; }
.links { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.link-row {
  display: grid; grid-template-columns: 36px minmax(0, 1fr) auto 36px; align-items: center; column-gap: 4px;
  min-height: 40px; padding: 0 2px; border: 1px solid var(--border); border-radius: var(--r); background: var(--panel);
}
.link-row.dragging { opacity: .4; }
.link-row .handle, .link-row .del { justify-content: center; width: 36px; min-height: 36px; padding: 0; border: 0; background: none; color: var(--muted); }
.link-row .handle { cursor: grab; touch-action: none; }
.link-row .url { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 13px/1.4 var(--mono); }
.link-row .del:hover { color: var(--danger); }
.link-row.disabled .url { opacity: .45; text-decoration: line-through; }
.sw { appearance: none; width: 40px; height: 24px; min-height: 0; margin: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--muted-bg); position: relative; cursor: pointer; transition: background .15s; }
.sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--fg-2); transition: transform .15s var(--ease); }
.sw:checked { background: var(--accent); border-color: var(--accent); }
.sw:checked::after { transform: translateX(16px); background: var(--on-accent); }

.banner { position: sticky; top: 0; z-index: 40; padding: 10px 16px; background: var(--danger); color: #000; text-align: center; }
.toast { position: fixed; left: 50%; bottom: 20px; z-index: 60; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 8px 16px; border-radius: var(--r); background: var(--text); color: var(--bg); }
.toast:empty { display: none; }

/* small-screen-only controls */
.only-sm { display: none; }
.backdrop { display: none; }

/* ≤1100px: sessions become a slide-in drawer; scan + links stack */
@media (max-width: 1100px) {
  .only-sm { display: inline-flex; }
  .col-head .only-sm { margin-left: auto; }
  .new-bottom { display: none; }
  .top .sub { display: none; }
  .shell { grid-template-columns: minmax(0, 1fr); height: auto; }
  .col { border-right: 0; }
  .col.right { border-top: 1px solid var(--border); }
  .col.left-col {
    position: fixed; inset: 0 auto 0 0; z-index: 50; width: min(340px, 88vw); border-right: 1px solid var(--border);
    transform: translateX(-100%); visibility: hidden; transition: transform .22s var(--ease), visibility 0s .22s;
    box-shadow: 12px 0 40px rgba(0, 0, 0, .5);
  }
  body.sess-open .col.left-col { transform: none; visibility: visible; transition: transform .22s var(--ease); }
  .backdrop { position: fixed; inset: 0; z-index: 40; display: block; background: rgba(0, 0, 0, .6); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.sess-open .backdrop { opacity: 1; pointer-events: auto; }
  body.sess-open { overflow: hidden; }
}

/* ≤720px: phone */
@media (max-width: 720px) {
  .top { gap: 8px; padding: 0 12px; }
  .top h1 .nm, .top .sp { display: none; }
  .top .pill { flex: 1; min-width: 0; justify-content: center; }
  .top .pill .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .top button { padding: 0 10px; }
  button { min-height: 44px; }
  button.icon { width: 44px; }
  .link-row { grid-template-columns: 44px minmax(0, 1fr) auto 44px; min-height: 44px; }
  .link-row .handle, .link-row .del { width: 44px; min-height: 44px; }
  .mid-in { padding: 12px; }
  .hero { padding: 12px; }
  input[type="text"] { flex-basis: 100%; min-height: 44px; font-size: 16px; } /* 16px stops iOS auto-zoom */
  .add button { flex: 1; justify-content: center; }
  .seg button { min-height: 36px; padding: 2px 14px; }
  .sess button { padding: 14px 12px; }
  .sum .row button { flex: 1; justify-content: center; }
  .sum .row .danger { flex-basis: 100%; margin-left: 0; }
  textarea { font-size: 13px; }
}
@media (max-width: 420px) { .top h1 { display: none; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
