/* Cockpit — modern responsive dark UI. Design tokens → components → responsive. */
:root {
  --bg: #0b0e14;
  --panel: #141922;
  --panel2: #1b2330;
  --panel3: #232d3d;
  --border: #2a3444;
  --border2: #3a4658;
  --text: #e6edf3;
  --muted: #93a1b3;
  --faint: #64748b;
  --accent: #3b82f6;
  --accent-hi: #60a5fa;
  --green: #34d399;
  --red: #f87171;
  --yellow: #fbbf24;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;

  --r-sm: 8px; --r: 12px; --r-lg: 16px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.25);
  --ring: 0 0 0 3px rgba(59,130,246,.35);
  --topbar-h: 56px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  overflow-wrap: break-word; word-break: break-word;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
a { color: var(--accent-hi); }
h1, h2, h3, h4 { line-height: 1.25; }

/* Buttons */
button {
  cursor: pointer; border: 1px solid transparent; background: var(--accent); color: #fff;
  padding: 9px 15px; border-radius: var(--r-sm); font-size: 14px; font-weight: 500;
  font-family: inherit; transition: background .15s, border-color .15s, transform .05s;
  min-height: 38px;
}
button:hover { background: var(--accent-hi); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: none; box-shadow: var(--ring); }
button.ghost { background: transparent; color: var(--muted); border-color: var(--border); }
button.ghost:hover { background: var(--panel2); color: var(--text); border-color: var(--border2); }

/* Inputs */
input, textarea, select {
  background: var(--panel2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 12px; border-radius: var(--r-sm); font-size: 15px; font-family: inherit; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
textarea { resize: vertical; }

/* ── Login ── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--s4); }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: clamp(24px, 5vw, 36px); width: min(380px, 100%); box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 var(--s1); font-size: 26px; }
.login-card input { margin: var(--s4) 0 var(--s2); }
.login-card button { width: 100%; margin-bottom: var(--s2); }
.msg { min-height: 18px; font-size: 13px; margin: var(--s2) 0 0; }
.msg.err { color: var(--red); } .msg.ok { color: var(--green); }

/* ── Topbar ── */
.topbar {
  display: flex; align-items: center; gap: var(--s3);
  padding: 0 clamp(12px, 3vw, 20px); height: var(--topbar-h);
  background: rgba(20,25,34,.85); backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.spacer { flex: 1; }
.tabs { display: flex; gap: var(--s1); overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent; color: var(--muted); border: none; padding: 7px 13px;
  border-radius: 999px; white-space: nowrap; font-weight: 500; min-height: 34px;
}
.tab:hover { background: var(--panel2); color: var(--text); }
.tab.active { background: var(--accent); color: #fff; }
.ver { font-family: var(--mono); font-size: 12px; color: var(--muted); padding: 5px 9px; min-height: 30px; }
#whoami { white-space: nowrap; font-size: 13px; }
.hamburger { display: none; font-size: 18px; padding: 6px 11px; }
.menu-foot { display: none; }

main { padding: clamp(14px, 3vw, 26px); max-width: 1180px; margin: 0 auto; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); flex-wrap: wrap; }
.pane-head h2 { margin: 0; font-size: clamp(17px, 3vw, 20px); }
.pane-head h3 { margin: 0; font-size: 16px; }

/* ── Cards / lists ── */
.list { display: flex; flex-direction: column; gap: var(--s2); }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r);
  padding: var(--s3) var(--s4); transition: border-color .15s, background .15s;
}
.card.click { cursor: pointer; }
.card.click:hover { border-color: var(--border2); background: var(--panel2); }
.row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.pill { font-size: 11px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border2); color: var(--muted); white-space: nowrap; font-weight: 500; }
.pill.on, .pill.success { color: var(--green); border-color: color-mix(in srgb, var(--green) 50%, transparent); background: color-mix(in srgb, var(--green) 12%, transparent); }
.pill.running { color: var(--yellow); border-color: color-mix(in srgb, var(--yellow) 50%, transparent); background: color-mix(in srgb, var(--yellow) 12%, transparent); }
.pill.failed { color: var(--red); border-color: color-mix(in srgb, var(--red) 50%, transparent); background: color-mix(in srgb, var(--red) 12%, transparent); }
.pill.pending, .pill.cancelled { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 44px 20px; border: 1px dashed var(--border2); border-radius: var(--r); }

/* ── Split views ── */
.live-grid, .convo-grid { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: var(--s3); align-items: start; }
.runlist, .contactlist { max-height: calc(100dvh - var(--topbar-h) - 120px); overflow-y: auto; }
.runview {
  background: #05070b; border: 1px solid var(--border); border-radius: var(--r); padding: var(--s3);
  font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
  max-height: calc(100dvh - var(--topbar-h) - 120px); overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
}
.logline { color: #c3ccd6; padding: 1px 0; }
.logline .t { color: var(--faint); margin-right: 8px; }

/* ── Conversations ── */
.thread {
  display: flex; flex-direction: column; height: calc(100dvh - var(--topbar-h) - 120px);
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r); overflow: hidden;
}
.msgs { flex: 1; overflow-y: auto; padding: var(--s4); display: flex; flex-direction: column; gap: var(--s2); }
.bubble { max-width: min(78%, 520px); padding: 8px 12px; border-radius: var(--r); font-size: 14px; overflow-wrap: anywhere; }
.bubble.me { align-self: flex-end; background: #0d3b2e; border: 1px solid #14543f; }
.bubble.them { align-self: flex-start; background: var(--panel2); border: 1px solid var(--border); }
.bubble .time { display: block; font-size: 10px; color: var(--muted); margin-top: 4px; }
.composer { display: flex; gap: var(--s2); padding: var(--s3); border-top: 1px solid var(--border); background: var(--panel); }
.composer input { flex: 1; }
.testbar { font-size: 12.5px; color: var(--yellow); padding: 8px var(--s4); border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--yellow) 8%, transparent); }

/* ── Cars ── */
.car-card.is-rejected { opacity: .7; }
.car-main { display: flex; gap: var(--s4); align-items: stretch; }
.car-thumb { width: 104px; min-width: 104px; align-self: stretch; height: auto; object-fit: cover;
  border-radius: var(--r-sm); background: var(--panel2); aspect-ratio: 4 / 3; }
.car-body { flex: 1; min-width: 0; }
.car-card .row2 { margin-top: var(--s3); display: flex; gap: var(--s2); flex-wrap: wrap; }
.car-card .row2 button { flex: 0 0 auto; }  /* natural width on desktop; full-width only on mobile (see @640) */
.car-card .row2 a { display: inline-flex; align-items: center; padding: 9px 15px; border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--muted); font-size: 14px; text-decoration: none; min-height: 38px; }
.car-card .row2 a:hover { background: var(--panel2); color: var(--text); border-color: var(--border2); }
.draftbox {
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
  background: var(--panel2); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: var(--s4); font-size: 14.5px; line-height: 1.7; margin-top: var(--s2);
  direction: rtl; text-align: right; max-height: 46vh; overflow-y: auto;
}
.draftbox a { overflow-wrap: anywhere; }

/* ── Settings ── */
.settings-block { max-width: 780px; margin-bottom: var(--s6); }
.settings-block h3 { margin: 0; font-size: 16px; }
.grouprow, .connrow { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.grouprow input { flex: 1 1 160px; min-width: 0; }

/* ── Version / reload banner ── */
.reload-banner {
  display: flex; align-items: center; gap: var(--s3); justify-content: center;
  background: linear-gradient(90deg, #16233f, #1a2b4d); border-bottom: 1px solid var(--accent);
  padding: 10px var(--s4); font-size: 13.5px; flex-wrap: wrap; text-align: center;
}

/* ── Modal ── */
.modal { position: fixed; inset: 0; background: rgba(3,6,12,.72); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 40; padding: var(--s4); }
.modal-card {
  background: var(--panel); border: 1px solid var(--border2); border-radius: var(--r-lg);
  padding: clamp(18px, 4vw, 26px); width: min(560px, 100%); max-height: 90dvh; overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-card.wide { width: min(680px, 100%); }
.modal-card.draft { width: min(760px, 100%); }
.modal-card h3 { margin: 0 0 var(--s4); font-size: 19px; }
.modal-card label { display: block; font-size: 12.5px; color: var(--muted); margin: var(--s3) 0 var(--s1); }
.modal-actions { display: flex; gap: var(--s2); justify-content: flex-end; margin-top: var(--s5); flex-wrap: wrap; }

.changelog-entry { border-bottom: 1px solid var(--border); padding: var(--s3) 0; }
.changelog-entry:last-child { border-bottom: none; }
.changelog-entry h4 { margin: 0 0 var(--s1); font-size: 14.5px; }
.changelog-entry ul { margin: var(--s1) 0 0; padding-left: 20px; }
.changelog-entry li { font-size: 13.5px; color: var(--muted); margin: 2px 0; }

/* ── Toasts ── */
#toasts { position: fixed; top: calc(var(--topbar-h) + 12px); right: 16px; z-index: 60;
  display: flex; flex-direction: column; gap: var(--s2); max-width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto; background: var(--panel3); border: 1px solid var(--border2);
  border-left: 3px solid var(--accent); border-radius: var(--r-sm); padding: 11px 14px;
  font-size: 13.5px; box-shadow: var(--shadow); overflow-wrap: anywhere;
  animation: toast-in .18s ease-out; transition: opacity .2s, transform .2s;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.leaving { opacity: 0; transform: translateX(12px); }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* ── Responsive ── */
@media (max-width: 900px) {
  .live-grid, .convo-grid { grid-template-columns: 1fr; }
  .runlist, .contactlist { max-height: 34vh; }
  .runview { max-height: 52vh; }
  .thread { height: calc(100dvh - var(--topbar-h) - 90px); }
}
@media (max-width: 640px) {
  body { font-size: 14px; }
  #toasts { left: 12px; right: 12px; top: auto; bottom: 12px; max-width: none; }
  .brand { font-size: 15px; }
  #whoami, #logoutBtn { display: none; }
  .ver { padding: 5px 7px; font-size: 11px; }
  .hamburger { display: inline-flex; }
  /* Tabs collapse into a scrollable dropdown toggled by the hamburger */
  .tabs { display: none; position: absolute; top: var(--topbar-h); right: 8px; left: 8px;
    flex-direction: column; gap: 2px; background: var(--panel); border: 1px solid var(--border2);
    border-radius: var(--r); padding: 8px; max-height: 72vh; overflow-y: auto; box-shadow: var(--shadow); z-index: 30; }
  .tabs.open { display: flex; }
  .tabs .tab { text-align: left; border-radius: var(--r-sm); padding: 11px 13px; }
  .menu-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px;
    margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--border); }
  .car-main { gap: var(--s3); }
  .car-thumb { width: 76px; min-width: 76px; }
  .car-card .row2 { flex-direction: column; }
  .car-card .row2 button, .car-card .row2 a { flex: 1 1 100%; width: 100%; justify-content: center; }
  .bubble { max-width: 86%; }
  .modal { padding: var(--s2); align-items: flex-end; }
  .modal-card { border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92dvh; width: 100%; }
  .modal-actions button { flex: 1; }
}
@media (max-width: 380px) {
  .tab { padding: 7px 10px; }
}
