/* Blue & orange — management UI
   Quiet surfaces, one strong action color (ink), identity colors only where they mean Blue / orange. */

:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface: #ffffff;
  --surface-2: #f9f8f6;
  --surface-3: #efeee9;
  --hover: rgba(26, 26, 24, 0.045);
  --border: #e5e3dd;
  --border-strong: #d2cfc7;
  --text: #1a1a18;
  --text-2: #5c5a54;
  --text-3: #8d8b84;
  --ink: #1a1a18;
  --ink-text: #ffffff;
  --blue: #2a6fe0;
  --blue-soft: #e9f0fd;
  --blue-ink: #1f58bb;
  --orange: #e8621f;
  --orange-soft: #fdefe6;
  --orange-ink: #b04a12;
  --ok: #1d8a4b;
  --ok-soft: #e3f3e9;
  --warn: #a86f00;
  --warn-soft: #fbf1db;
  --danger: #c93636;
  --danger-soft: #fbe7e7;
  --series-1: #eb6834;
  --series-track: #f6d9c9;
  --grid: #ecebe6;
  --focus: 0 0 0 3px rgba(42, 111, 224, 0.28);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-pop: 0 16px 40px rgba(0, 0, 0, 0.14), 0 2px 8px rgba(0, 0, 0, 0.06);
  --font: "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Yu Gothic UI", "Noto Sans JP", Meiryo, system-ui, sans-serif;
  --mono: "Cascadia Mono", "SF Mono", Consolas, "BIZ UDGothic", monospace;
  --nav-w: 216px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1a19;
  --surface-2: #1f1f1e;
  --surface-3: #272725;
  --hover: rgba(236, 235, 230, 0.06);
  --border: #2d2c2a;
  --border-strong: #3d3c39;
  --text: #ecebe6;
  --text-2: #aaa8a1;
  --text-3: #7a7872;
  --ink: #ecebe6;
  --ink-text: #111110;
  --blue: #5d92f2;
  --blue-soft: #1a2640;
  --blue-ink: #8db4ff;
  --orange: #f07a36;
  --orange-soft: #3a2416;
  --orange-ink: #ffab78;
  --ok: #43b774;
  --ok-soft: #16301f;
  --warn: #d9a23a;
  --warn-soft: #33280f;
  --danger: #e66262;
  --danger-soft: #3a1818;
  --series-1: #d95926;
  --series-track: #3a2416;
  --grid: #262624;
  --focus: 0 0 0 3px rgba(93, 146, 242, 0.35);
  --shadow: none;
  --shadow-pop: 0 16px 40px rgba(0, 0, 0, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #1f1f1e;
    --surface-3: #272725;
    --hover: rgba(236, 235, 230, 0.06);
    --border: #2d2c2a;
    --border-strong: #3d3c39;
    --text: #ecebe6;
    --text-2: #aaa8a1;
    --text-3: #7a7872;
    --ink: #ecebe6;
    --ink-text: #111110;
    --blue: #5d92f2;
    --blue-soft: #1a2640;
    --blue-ink: #8db4ff;
    --orange: #f07a36;
    --orange-soft: #3a2416;
    --orange-ink: #ffab78;
    --ok: #43b774;
    --ok-soft: #16301f;
    --warn: #d9a23a;
    --warn-soft: #33280f;
    --danger: #e66262;
    --danger-soft: #3a1818;
    --series-1: #d95926;
    --series-track: #3a2416;
    --grid: #262624;
    --focus: 0 0 0 3px rgba(93, 146, 242, 0.35);
    --shadow: none;
    --shadow-pop: 0 16px 40px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--blue-soft); }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.row.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 8px; }
.gap-4 { gap: 4px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-4 { margin-top: 4px; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; }
@media (max-width: 760px) { .hide-sm { display: none !important; } }
.ic { width: 18px; height: 18px; flex: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------------------------------------------------------------- shell */
.shell { display: flex; min-height: 100vh; }
.nav {
  position: sticky; top: 0; height: 100vh; width: var(--nav-w); flex: 0 0 var(--nav-w);
  display: flex; flex-direction: column; gap: 2px; padding: 16px 10px 12px;
  border-right: 1px solid var(--border); background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 650; letter-spacing: 0.01em; }
.brand .dots { position: relative; width: 26px; height: 16px; }
.brand .dots i { position: absolute; top: 0; width: 16px; height: 16px; border-radius: 50%; }
.brand .dots i:first-child { left: 0; background: var(--blue); }
.brand .dots i:last-child { left: 10px; background: var(--orange); mix-blend-mode: multiply; }
:root[data-theme="dark"] .brand .dots i:last-child { mix-blend-mode: screen; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .brand .dots i:last-child { mix-blend-mode: screen; } }
.brand b { font-weight: 650; }
.brand b .o { color: var(--orange); }
.brand b .b { color: var(--blue); }

.nav a.item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px;
  color: var(--text-2); text-decoration: none; font-weight: 500; position: relative;
}
.nav a.item:hover { background: var(--hover); color: var(--text); }
.nav a.item.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow), inset 0 0 0 1px var(--border); }
.nav a.item svg { width: 18px; height: 18px; flex: none; }
.nav a.item .badge { margin-left: auto; }
.nav .sep { height: 1px; background: var(--border); margin: 10px 8px; }
.nav .foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 10px; font-size: 12.5px; color: var(--text-2); }
.nav .foot .bot { display: flex; align-items: center; gap: 8px; }
.nav .kbd-hint { color: var(--text-3); font-size: 11.5px; }

.main { flex: 1 1 auto; min-width: 0; padding: 24px 32px 80px; outline: none; }
.page { max-width: 1120px; margin: 0 auto; }
.page.wide { max-width: 1320px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .nav {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; width: auto; z-index: 40;
    flex-direction: row; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); overflow-x: auto; gap: 0;
  }
  .nav .brand, .nav .sep, .nav .foot { display: none; }
  .nav a.item { flex: 1 1 0; min-width: 0; flex-direction: column; gap: 2px; font-size: 10px; padding: 6px 1px; justify-content: center; letter-spacing: -0.02em; }
  .nav a.item span { overflow: hidden; text-overflow: clip; white-space: nowrap; max-width: 100%; }
  .nav a.item.active { box-shadow: none; background: var(--surface); }
  .nav a.item .badge { position: absolute; top: 1px; right: calc(50% - 22px); margin: 0; min-width: 16px; height: 16px; font-size: 10px; }
  .main { padding: 16px 16px 96px; }
}

/* ---------------------------------------------------------------- surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 16px 18px; }
.card + .card, .section + .section { margin-top: 16px; }
.card-head { display: flex; align-items: center; gap: 8px; padding: 14px 18px 0; }
.card-head h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-2); letter-spacing: 0.02em; }
.card-head .spacer { flex: 1; }
.card-body { padding: 12px 18px 16px; }
h2.sec { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 28px 0 10px; letter-spacing: 0.02em; }
h2.sec:first-child { margin-top: 0; }
h3.sec { font-size: 12.5px; font-weight: 600; color: var(--text-2); margin: 18px 0 4px; }
.warn-text { color: var(--warn); }
.grid { display: grid; gap: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1080px) { .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .grid.two, .grid.three, .grid.four { grid-template-columns: minmax(0, 1fr); } }
.divider { height: 1px; background: var(--border); margin: 12px 0; }

/* ---------------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 550; cursor: pointer; white-space: nowrap; text-decoration: none; transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:focus-visible, .input:focus, .select:focus, textarea.input:focus, .chip:focus-visible, .toggle input:focus-visible + span { outline: none; box-shadow: var(--focus); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--ink); color: var(--ink-text); border-color: var(--ink); }
.btn.primary:hover { opacity: 0.88; }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.orange { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn.lg { height: 42px; padding: 0 18px; font-size: 15px; }
.btn.icon { width: 34px; padding: 0; }
.btn.sm.icon { width: 28px; }
.btn[disabled], .btn.busy { opacity: 0.5; pointer-events: none; }
.btn.busy::after { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.input, .select, textarea.input {
  height: 34px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface);
  width: 100%; min-width: 0; transition: border-color .12s, box-shadow .12s;
}
.input::placeholder, textarea.input::placeholder { color: var(--text-3); }
textarea.input { height: auto; min-height: 90px; padding: 9px 11px; line-height: 1.6; resize: vertical; }
.select { padding-right: 30px; appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%238d8b84' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.input.sm, .select.sm { height: 28px; font-size: 12.5px; padding: 0 9px; }
.select.sm { padding-right: 26px; }
.input.lg { height: 48px; font-size: 16px; padding: 0 16px; border-radius: 10px; }
.input.invalid { border-color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); line-height: 1.5; }
.field .hint a { color: var(--blue-ink); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 16px; }
.fields .full { grid-column: 1 / -1; }

.setting { display: grid; grid-template-columns: minmax(180px, 280px) minmax(0, 1fr); gap: 8px 24px; padding: 14px 0; border-top: 1px solid var(--border); align-items: start; }
.setting:first-child { border-top: 0; padding-top: 4px; }
.setting .k { font-weight: 550; }
.setting .k .hint { display: block; font-weight: 400; font-size: 12px; color: var(--text-3); margin-top: 2px; line-height: 1.5; }
.setting .v { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.setting .v > .input, .setting .v > .select { max-width: 420px; }
@media (max-width: 760px) { .setting { grid-template-columns: minmax(0, 1fr); } }
.saved-tick { color: var(--ok); font-size: 12px; opacity: 0; transition: opacity .2s; }
.saved-tick.show { opacity: 1; }

.toggle { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle span { width: 34px; height: 20px; border-radius: 20px; background: var(--border-strong); position: relative; transition: background .15s; flex: none; }
.toggle span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.toggle input:checked + span { background: var(--ok); }
.toggle.blue input:checked + span { background: var(--blue); }
.toggle.orange input:checked + span { background: var(--orange); }
.toggle input:checked + span::after { transform: translateX(14px); }
.toggle em { font-style: normal; }

.seg { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--surface-3); gap: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 12px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-weight: 550; font-size: 13px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 13px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: 12.5px; cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.on { background: var(--ink); color: var(--ink-text); border-color: var(--ink); }
.chip .n { color: inherit; opacity: 0.6; font-variant-numeric: tabular-nums; }

.tag { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 7px; border-radius: 6px; font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.tag.blue { background: var(--blue-soft); color: var(--blue-ink); }
.tag.orange { background: var(--orange-soft); color: var(--orange-ink); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.pdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); display: inline-block; flex: none; }
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.warn, .dot.starting, .dot.reconnecting { background: var(--warn); }
.dot.error, .dot.bad_token, .dot.intents { background: var(--danger); }
.dot.no_token, .dot.stopped { background: var(--text-3); }

.kbd { font: 11px var(--mono); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border-strong); color: var(--text-2); background: var(--surface); }

/* ---------------------------------------------------------------- lists */
.list { display: flex; flex-direction: column; }
.list .li { display: flex; align-items: center; gap: 12px; padding: 10px 18px; border-top: 1px solid var(--border); min-width: 0; }
.list .li:first-child { border-top: 0; }
.list .li.click { cursor: pointer; }
.list .li.click:hover { background: var(--surface-2); }
.list .li.sel { background: var(--blue-soft); }
.list .empty { padding: 28px 18px; text-align: center; color: var(--text-3); }
.favicon { width: 28px; height: 28px; border-radius: 7px; flex: none; object-fit: cover; background: var(--surface-3); border: 1px solid var(--border); }
.favicon.sm { width: 20px; height: 20px; border-radius: 5px; }
.favicon.fallback { display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; font-size: 13px; border: 0; }
.thumb { width: 88px; height: 56px; border-radius: 8px; object-fit: cover; flex: none; background: var(--surface-3); border: 1px solid var(--border); }
.li .title { font-weight: 550; }
.li .sub { font-size: 12.5px; color: var(--text-2); }
.li .meta { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 12px; flex: none; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { text-align: left; font-weight: 600; font-size: 12px; color: var(--text-2); padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.tbl td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl td.r, table.tbl th.r { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl tr.click { cursor: pointer; }
table.tbl tr.click:hover td { background: var(--surface-2); }
.tbl-wrap { overflow-x: auto; }

/* ---------------------------------------------------------------- stat tiles */
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.stat .label { font-size: 12.5px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 26px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.15; }
.stat .value small { font-size: 14px; font-weight: 500; color: var(--text-2); margin-left: 4px; }
.stat .foot { font-size: 12px; color: var(--text-3); }
.hero-value { font-size: 44px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; }

.meter { height: 8px; border-radius: 4px; background: var(--series-track); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--series-1); border-radius: 4px; transition: width .3s; }
.meter.warn { background: var(--warn-soft); } .meter.warn i { background: var(--warn); }
.meter.over { background: var(--danger-soft); } .meter.over i { background: var(--danger); }

/* ---------------------------------------------------------------- hero input (add feed) */
.adder { position: relative; }
.adder .input.lg { padding-left: 46px; padding-right: 120px; }
.adder > svg { position: absolute; left: 15px; top: 14px; width: 20px; height: 20px; color: var(--text-3); pointer-events: none; }
.adder .go { position: absolute; right: 5px; top: 5px; height: 38px; }
.adder-hint { margin-top: 8px; font-size: 12.5px; color: var(--text-3); display: flex; gap: 12px; flex-wrap: wrap; }
.adder-hint b { color: var(--text-2); font-weight: 550; }

.preview { margin-top: 12px; }
.preview .head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; }
.preview .head .favicon { width: 40px; height: 40px; border-radius: 10px; }
.preview .items { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); grid-auto-rows: auto; gap: 10px; padding: 0 18px 14px; }
@media (max-width: 760px) { .preview .items { grid-template-columns: repeat(2, minmax(0, 1fr)); } .preview .items > :nth-child(n + 5) { display: none; } }
.pitem { display: flex; flex-direction: column; gap: 6px; min-width: 0; text-decoration: none; }
.pitem img, .pitem .noimg { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; background: var(--surface-3); border: 1px solid var(--border); }
.pitem .t { font-size: 12.5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pitem .d { font-size: 11.5px; color: var(--text-3); }
.preview .opts { border-top: 1px solid var(--border); padding: 14px 18px; }
.preview .actions { border-top: 1px solid var(--border); padding: 12px 18px; display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 10px; font-size: 13px; line-height: 1.55; }
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.notice.info { background: var(--blue-soft); color: var(--blue-ink); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.danger { background: var(--danger-soft); color: var(--danger); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice .grow { color: var(--text); }
.notice b { color: inherit; }

/* ---------------------------------------------------------------- toolbar */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 20px 0 12px; }
.toolbar .search { position: relative; flex: 1 1 220px; max-width: 340px; }
.toolbar .search svg { position: absolute; left: 10px; top: 9px; width: 16px; height: 16px; color: var(--text-3); }
.toolbar .search .input { padding-left: 32px; }
.bulkbar { position: sticky; top: 8px; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; background: var(--ink); color: var(--ink-text); margin-bottom: 10px; flex-wrap: wrap; }
.bulkbar .btn { background: transparent; color: var(--ink-text); border-color: color-mix(in srgb, var(--ink-text) 30%, transparent); }
.bulkbar .btn:hover { background: color-mix(in srgb, var(--ink-text) 12%, transparent); }
.bulkbar .select { width: auto; background-color: transparent; color: var(--ink-text); border-color: color-mix(in srgb, var(--ink-text) 30%, transparent); }
.bulkbar .select option { color: var(--text); background: var(--surface); }

input[type="checkbox"].cb { width: 16px; height: 16px; accent-color: var(--blue); cursor: pointer; flex: none; margin: 0; }

/* ---------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 12px; color: var(--text-2); font-weight: 550; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--text); }

/* ---------------------------------------------------------------- overlay: modal / drawer / palette */
.backdrop { position: fixed; inset: 0; background: rgba(10, 10, 9, 0.36); z-index: 60; animation: fade .12s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal {
  position: fixed; left: 50%; top: 8vh; transform: translateX(-50%); width: min(680px, calc(100vw - 24px)); max-height: 84vh; z-index: 61;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column; animation: pop .14s ease-out;
}
.modal.lg { width: min(980px, calc(100vw - 24px)); }
.modal.sm { width: min(440px, calc(100vw - 24px)); top: 18vh; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 6px); } }
.modal .m-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal .m-head h3 { margin: 0; font-size: 15px; font-weight: 650; flex: 1; }
.modal .m-body { padding: 16px; overflow: auto; }
.modal .m-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); z-index: 61; background: var(--surface);
  border-left: 1px solid var(--border); box-shadow: var(--shadow-pop); display: flex; flex-direction: column; animation: slide .16s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.drawer .d-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.drawer .d-body { flex: 1; overflow: auto; padding: 16px 18px 40px; }

.palette { position: fixed; left: 50%; top: 12vh; transform: translateX(-50%); width: min(620px, calc(100vw - 24px)); z-index: 70; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-pop); overflow: hidden; }
.palette .input { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; height: 52px; font-size: 16px; padding: 0 18px; box-shadow: none !important; }
.palette .results { max-height: 52vh; overflow: auto; padding: 6px; }
.palette .opt { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.palette .opt svg { width: 16px; height: 16px; color: var(--text-3); flex: none; }
.palette .opt.on { background: var(--surface-3); }
.palette .opt .k { margin-left: auto; font-size: 11.5px; color: var(--text-3); }
.palette .grp { padding: 8px 12px 4px; font-size: 11.5px; font-weight: 600; color: var(--text-3); }

/* ---------------------------------------------------------------- toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
@media (max-width: 860px) { .toasts { bottom: 84px; left: 16px; align-items: stretch; } }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 460px; padding: 10px 12px 10px 14px; border-radius: 10px; background: var(--ink); color: var(--ink-text); box-shadow: var(--shadow-pop); animation: pop2 .16s ease-out; font-size: 13.5px; }
.toast.error { background: var(--danger); color: #fff; }
.toast .grow { line-height: 1.5; }
.toast button { background: none; border: 0; color: inherit; font-weight: 700; cursor: pointer; padding: 4px 6px; border-radius: 6px; text-decoration: underline; text-underline-offset: 3px; }
@keyframes pop2 { from { opacity: 0; transform: translateY(6px); } }

/* ---------------------------------------------------------------- setup */
.setup { border: 1px solid var(--border); }
.setup .steps { display: flex; flex-direction: column; }
.step { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 12px; padding: 14px 18px; border-top: 1px solid var(--border); }
.step:first-child { border-top: 0; }
.step .n { width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--border-strong); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--text-2); }
.step.done .n { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.done .n svg { width: 14px; height: 14px; }
.step .t { font-weight: 600; }
.step.done .t { color: var(--text-2); }
.step .b { margin-top: 8px; display: none; flex-direction: column; gap: 10px; }
.step.open .b { display: flex; }
.progressbar { height: 4px; background: var(--surface-3); border-radius: 2px; overflow: hidden; }
.progressbar i { display: block; height: 100%; background: var(--ok); transition: width .3s; }

/* ---------------------------------------------------------------- items */
.items-list .li { align-items: flex-start; }
.item-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.item-body .title { font-weight: 600; line-height: 1.45; text-decoration: none; }
.item-body .title:hover { text-decoration: underline; text-underline-offset: 3px; }
.item-body .snip { font-size: 12.5px; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item-body .ai { font-size: 13px; line-height: 1.65; background: var(--orange-soft); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; }
.item-actions { display: flex; gap: 4px; flex: none; }

/* ---------------------------------------------------------------- chat */
.chat { display: flex; flex-direction: column; height: min(70vh, 720px); }
.chat .msgs { flex: 1; overflow: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 82%; display: flex; flex-direction: column; gap: 4px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg .bubble { padding: 10px 14px; border-radius: 14px; background: var(--surface-3); white-space: pre-wrap; line-height: 1.65; word-break: break-word; }
.msg.user .bubble { background: var(--ink); color: var(--ink-text); }
.msg.assistant .bubble { background: var(--surface-2); border: 1px solid var(--border); }
.msg .meta { font-size: 11.5px; color: var(--text-3); display: flex; gap: 8px; flex-wrap: wrap; }
.chat .composer { border-top: 1px solid var(--border); padding: 12px; display: flex; gap: 8px; align-items: flex-end; }
.chat .composer textarea { min-height: 42px; max-height: 200px; }

/* ---------------------------------------------------------------- models */
.model-row { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 0.9fr) 150px 90px 120px; gap: 12px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--border); cursor: pointer; }
.model-row:hover { background: var(--surface-2); }
.model-row.cur { background: var(--orange-soft); }
.model-row .nm { font-weight: 600; }
.model-row .id { font-size: 11.5px; color: var(--text-3); font-family: var(--mono); }
.caps { display: flex; gap: 4px; flex-wrap: wrap; }
.iq { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.iq .bar { width: 48px; height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.iq .bar i { display: block; height: 100%; background: var(--text-2); }
@media (max-width: 760px) { .model-row { grid-template-columns: minmax(0, 1fr) auto; } .model-row .hide-sm { display: none; } }
.role-card .model-name { font-size: 16px; font-weight: 650; }
.star { background: none; border: 0; cursor: pointer; color: var(--text-3); padding: 4px; border-radius: 6px; display: inline-flex; }
.star.on { color: #e5a100; }
.star:hover { background: var(--hover); }
.star svg { width: 16px; height: 16px; }

/* ---------------------------------------------------------------- chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axis { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series-1); }
.chart .bar.future { fill: var(--grid); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart g.on .bar { filter: brightness(1.12); }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-pop); border-radius: 8px; padding: 8px 10px; font-size: 12px; z-index: 5; white-space: nowrap; transform: translate(-50%, -100%); }
.tip .v { font-size: 14px; font-weight: 650; }
.tip .r { display: flex; align-items: center; gap: 6px; color: var(--text-2); }
.tip .r i { width: 10px; height: 2px; background: var(--series-1); display: inline-block; }

/* ---------------------------------------------------------------- logs */
.logs { font: 12.5px/1.6 var(--mono); }
.logs .l { display: grid; grid-template-columns: 74px 64px 90px minmax(0, 1fr); gap: 10px; padding: 4px 14px; border-top: 1px solid var(--border); }
.logs .l:first-child { border-top: 0; }
.logs .l.WARNING { background: var(--warn-soft); }
.logs .l.ERROR, .logs .l.CRITICAL { background: var(--danger-soft); }
.logs .l .m { white-space: pre-wrap; word-break: break-word; }
.logs details summary { cursor: pointer; color: var(--text-3); }
@media (max-width: 760px) { .logs .l { grid-template-columns: 60px minmax(0, 1fr); } .logs .l .lv, .logs .l .src { display: none; } }

/* ---------------------------------------------------------------- agenda */
.agenda .day { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 12px; padding: 12px 18px; border-top: 1px solid var(--border); }
.agenda .day:first-child { border-top: 0; }
.agenda .day .d { font-weight: 650; }
.agenda .day .d small { display: block; font-weight: 500; color: var(--text-3); font-size: 12px; }
.agenda .day.today .d { color: var(--orange); }
.agenda .ev { display: flex; gap: 10px; align-items: baseline; padding: 3px 0; min-width: 0; }
.agenda .ev .tm { width: 92px; flex: none; color: var(--text-2); font-variant-numeric: tabular-nums; font-size: 13px; }
.agenda .ev .cal { width: 3px; align-self: stretch; border-radius: 2px; background: var(--orange); flex: none; }
.agenda .ev .cal.ext { background: var(--blue); }

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-2); }
.empty-state svg { width: 40px; height: 40px; color: var(--text-3); margin-bottom: 8px; }
.empty-state h4 { margin: 0 0 6px; font-size: 15px; color: var(--text); }

.skeleton { background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 6px; height: 14px; }
@keyframes sk { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ================================================================ phone & touch
   Fingers, not cursors: bigger hit areas, no iOS input zoom, sheets instead of floating dialogs. */
.toolbar .chips { display: contents; }
.li .picker { flex: none; }
@keyframes sheet { from { transform: translateY(28px); opacity: 0; } }

@media (max-width: 860px), (pointer: coarse) {
  /* iOS Safari zooms into any field under 16px */
  .input, .select, textarea.input, .palette .input { font-size: 16px; }
}

@media (pointer: coarse) {
  .btn { height: 40px; }
  .btn.sm { height: 36px; padding: 0 12px; }
  .btn.icon { width: 40px; }
  .btn.sm.icon { width: 36px; }
  .input, .select { height: 40px; }
  .input.sm, .select.sm { height: 36px; }
  .chip { height: 34px; padding: 0 12px; }
  .seg button { padding: 7px 14px; }
  .tabs button { padding: 12px 12px; }
  .toggle span { width: 42px; height: 26px; border-radius: 13px; }
  .toggle span::after { width: 22px; height: 22px; }
  .toggle input:checked + span::after { transform: translateX(16px); }
  input[type="checkbox"].cb { width: 20px; height: 20px; }
  .star { padding: 9px; }
  .hide-touch { display: none !important; }
}

@media (max-width: 760px) {
  .modal, .modal.lg, .modal.sm {
    top: auto; bottom: 0; left: 0; transform: none; width: 100vw; max-height: 92vh;
    border-radius: 16px 16px 0 0; border-bottom: 0; animation: sheet .18s ease-out;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 14px; }
  .stat .value { font-size: 21px; }
  .hero-value { font-size: 38px; }
  .toolbar .search { max-width: none; flex-basis: 100%; }
  .toolbar .chips { display: flex; gap: 8px; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin: 0 -16px; padding: 2px 16px; }
  .toolbar .chips::-webkit-scrollbar { display: none; }
  .adder .input.lg { padding-right: 112px; }
  .list .li { padding: 10px 14px; gap: 10px; }
  /* feed rows in the channel view: the destination picker drops to its own line */
  .li.has-picker { flex-wrap: wrap; row-gap: 8px; }
  .li.has-picker > .grow { flex: 1 1 0; }  /* basis 0: the name shrinks on line 1 instead of wrapping */
  .li.has-picker .picker { order: 10; flex: 1 1 100%; padding-left: 68px; }  /* aligned under the name */
  .li.has-picker .picker .select { width: 100% !important; }
  .toasts { bottom: calc(84px + env(safe-area-inset-bottom)); }
  .setting { padding: 12px 0; }
  .chat { height: calc(100dvh - 230px); min-height: 360px; }
}

/* launched from the home screen: content starts below the status bar */
@media (display-mode: standalone) and (max-width: 860px) {
  .main { padding-top: calc(12px + env(safe-area-inset-top)); }
  .drawer .d-head { padding-top: calc(16px + env(safe-area-inset-top)); }
}

/* on-screen keyboard: give the space back to what is being typed */
@media (max-width: 860px) {
  body.kb .nav { display: none; }
  body.kb .main { padding-bottom: 24px; }
}
