/* ════════════════════════════════════════════════════════════════════════════
   ASP — "Warm Study" design system
   A cozy, classic, clean light theme: cream paper, warm charcoal ink, a clay
   accent and earthy status colors. Editorial serif for the wordmark + headings,
   a clean humanist sans for the UI, monospace for identifiers.
   Full token reference & usage guidance: DESIGN-SYSTEM.md
   ════════════════════════════════════════════════════════════════════════════ */
:root {
  /* ── Surfaces (warm paper) ───────────────────────────────────────────────── */
  --bg: #f6f1e7;          /* page — warm cream */
  --panel: #fffdf8;       /* cards, bars — near-white warm */
  --panel-2: #efe7d8;     /* raised / hover */
  --border: #e3d8c4;      /* hairline */
  --border-strong: #d6c8ad;

  /* ── Ink ─────────────────────────────────────────────────────────────────── */
  --text: #2c2622;        /* warm near-black */
  --muted: #7a6f63;       /* secondary ink */

  /* ── Brand ───────────────────────────────────────────────────────────────── */
  --accent: #b5512f;      /* clay / terracotta */
  --accent-2: #9d4427;    /* clay, pressed/hover */
  --accent-soft: rgba(181, 81, 47, 0.10);
  --sage: #5e6e54;        /* secondary, calm olive */

  --shadow: 0 6px 26px rgba(74, 52, 30, 0.12);
  --shadow-sm: 0 2px 8px rgba(74, 52, 30, 0.08);

  /* ── Status (earthy, legible) ───────────────────────────────────────────── */
  --ok: #3f7a3f;          /* olive green */
  --warn: #9a6a14;        /* amber */
  --run: #2f6a8a;         /* slate blue */
  --bad: #a8392b;         /* brick */
  --idle: #8a7d6d;        /* stone */
  --pending: #c4b7a3;     /* unrun step */

  /* ── Type ────────────────────────────────────────────────────────────────── */
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, ui-serif, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* ── Geometry ──────────────────────────────────────────────────────────────*/
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --topbar-h: 61px;   /* measured live in app.js (syncTopbarHeight) for docked drawers */
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win, even over components that set their
   own `display` (e.g. .drawer/.login-view use flex/grid). Without this, those
   panels render on page load regardless of the attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }

/* ── Brand ─────────────────────────────────────────────────────────────────── */
.brand {
  font-family: var(--font-serif);
  font-weight: 600; font-size: 19px; letter-spacing: 0.2px;
  display: flex; align-items: center; gap: 9px; color: var(--text);
}
.brand-mark { display: inline-flex; width: 26px; height: 26px; flex: 0 0 auto; }
.brand-mark svg { width: 100%; height: 100%; display: block; }

/* ── Login ─────────────────────────────────────────────────────────────────── */
.login-view {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1100px 560px at 50% -8%, #fbeedd 0%, var(--bg) 58%);
}
.login-card {
  width: 360px; max-width: 100%; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 30px 28px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
  border-top: 3px solid var(--accent);
}
.login-card .brand { font-size: 22px; }
.login-sub { margin: -6px 0 8px; color: var(--muted); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.login-card input {
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 10px 12px;
  color: var(--text); font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button[type="submit"] {
  margin-top: 6px; background: var(--accent); color: #fff; border: none; border-radius: var(--r-sm);
  padding: 11px; font-weight: 600; letter-spacing: 0.2px;
}
.login-card button[type="submit"]:hover { background: var(--accent-2); }
.error { color: var(--bad); font-size: 13px; min-height: 18px; margin: 0; }

/* ── Topbar ────────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px; background: var(--panel); border-bottom: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  /* Above the drawer scrim (25) so the gutter toggles stay live while a pop-out
     is open (switch sides / re-toggle), but below the drawers (30) so an open
     pop-out still slides over the bar. */
  position: sticky; top: 0; z-index: 26; box-shadow: var(--shadow-sm);
}
.topbar-left { display: flex; align-items: center; gap: 24px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 13px; }
.ghost {
  background: transparent; color: var(--text); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); padding: 7px 12px;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }

.topbar-center { flex: 1 1 auto; display: flex; justify-content: center; min-width: 0; }
.page-title {
  font-family: var(--font-serif); font-size: 16px; font-weight: 600; color: var(--text);
  letter-spacing: 0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Gutter / icon buttons (drawer toggles, refresh, close) ──────────────────
   A square icon button used for the left/right panel "gutter" toggles and the
   in-drawer close/refresh affordances. The toggles light up while their panel
   is open. */
.gutter-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0; flex: 0 0 auto;
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: var(--r-sm);
  font-size: 16px; line-height: 1;
}
.gutter-btn svg { display: block; }
.gutter-btn:hover { color: var(--accent); background: var(--panel-2); border-color: var(--border-strong); }
.gutter-btn.active { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }

/* ── Monitoring ───────────────────────────────────────────────────────────── */
.monitoring-meta { margin: 0 0 14px; }
.monitoring-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 16px; }
.widget {
  margin: 0; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r); padding: 12px; overflow: hidden; box-shadow: var(--shadow-sm);
}
.widget-title { color: var(--muted); font-size: 12px; font-weight: 600; margin-bottom: 8px; }
.widget-img { width: 100%; height: auto; display: block; border-radius: 6px; background: #fff; }
.widget-err { color: var(--muted); font-size: 13px; padding: 28px 12px; text-align: center; }

.content { max-width: 1200px; margin: 0 auto; padding: 24px 22px 40px; }

/* ── Summary cards ─────────────────────────────────────────────────────────── */
.summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-bottom: 22px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r); padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.card .num { font-family: var(--font-serif); font-size: 30px; font-weight: 600; line-height: 1.1; }
.card .lbl { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; margin-top: 4px; }
.card.accent { border-color: var(--accent); border-top: 3px solid var(--accent); }
.card.accent .num { color: var(--accent); }

/* ── Toolbar ───────────────────────────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar h2 { font-family: var(--font-serif); margin: 0; font-size: 21px; font-weight: 600; letter-spacing: 0.2px; }
.toolbar-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filter { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
select, .search {
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 8px 10px;
  color: var(--text); font-size: 13px;
}
.search { flex: 1 1 240px; min-width: 0; }
select:focus, .search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ── Table ─────────────────────────────────────────────────────────────────── */
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--r); overflow: auto; box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted);
  padding: 12px 14px; border-bottom: 1px solid var(--border-strong); white-space: nowrap; background: var(--panel-2);
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
.mono { font-family: var(--font-mono); font-size: 12px; }
.email-cell { display: flex; align-items: center; gap: 6px; }
.email-link { color: var(--accent); text-decoration: none; font-size: 12px; word-break: break-all; }
.email-link:hover { text-decoration: underline; }
.copy-btn { background: transparent; border: 1px solid var(--border-strong); color: var(--muted); border-radius: 6px; padding: 1px 6px; font-size: 12px; line-height: 1.4; }
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.name { font-weight: 600; }
.name-link { color: var(--text); text-decoration: none; }
.name-link:hover { color: var(--accent); text-decoration: underline; }
.sub { color: var(--muted); font-size: 11px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.row-clickable { cursor: pointer; }
.uptime { font-variant-numeric: tabular-nums; color: var(--muted); }
.uptime.live { color: var(--ok); font-weight: 600; }

/* ── Status badge ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap;
  letter-spacing: 0.3px;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-ACTIVE { color: var(--ok); background: rgba(63, 122, 63, 0.12); }
.st-PENDING, .st-PROVISIONING, .st-TERMINATING { color: var(--run); background: rgba(47, 106, 138, 0.12); }
.st-STOPPED { color: var(--warn); background: rgba(154, 106, 20, 0.13); }
.st-FAILED { color: var(--bad); background: rgba(168, 57, 43, 0.12); }
.st-DELETED { color: var(--idle); background: rgba(138, 125, 109, 0.14); }

.user-badge {
  display: inline-block; margin-left: 8px; font-size: 10px; font-weight: 600;
  padding: 1px 7px; border-radius: 999px; letter-spacing: 0.4px; text-transform: uppercase;
  color: var(--run); background: rgba(47, 106, 138, 0.12); vertical-align: middle;
}

/* ── Bulk select ───────────────────────────────────────────────────────────── */
.col-check { width: 1%; white-space: nowrap; text-align: center; padding-right: 0; }
.col-check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }
.col-check input:disabled { cursor: not-allowed; opacity: 0.4; }
.bulk-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 12px; padding: 10px 14px;
  background: var(--accent-soft); border: 1px solid var(--border-strong); border-radius: var(--r);
}
.bulk-count { font-weight: 600; font-size: 13px; color: var(--accent); }
.bulk-actions { display: flex; gap: 8px; align-items: center; }

/* ── Row actions ───────────────────────────────────────────────────────────── */
.actions { display: flex; gap: 6px; white-space: nowrap; }
.btn {
  border: 1px solid var(--border-strong); background: var(--panel); color: var(--text);
  border-radius: var(--r-sm); padding: 5px 9px; font-size: 12px;
}
.btn:hover { border-color: var(--accent); color: var(--accent); background: var(--panel-2); }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; border: none; border-radius: var(--r-sm); padding: 9px 14px; font-weight: 600; font-size: 13px; letter-spacing: 0.2px; }
.btn-primary:hover { background: var(--accent-2); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Create modal ──────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
  background: rgba(44, 38, 34, 0.45); padding: 20px; overflow-y: auto;
}
.modal-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 26px;
  width: 400px; max-width: 100%; max-height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow);
  border-top: 3px solid var(--accent);
}
.modal-card h3 { font-family: var(--font-serif); margin: 0; font-size: 20px; font-weight: 600; }
.modal-sub { margin: -6px 0 4px; color: var(--muted); font-size: 12px; }
.modal-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.modal-card .opt { color: var(--idle); font-weight: 400; }
.modal-card input {
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 10px 12px;
  color: var(--text); font-size: 14px;
}
.modal-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

/* ── Session detail ────────────────────────────────────────────────────────── */
.detail-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.back-link { color: var(--muted); text-decoration: none; font-size: 13px; display: inline-block; margin-bottom: 8px; }
.back-link:hover { color: var(--accent); }
.detail-title { display: flex; align-items: center; gap: 12px; }
.detail-title h2 { font-family: var(--font-serif); margin: 0; font-size: 21px; font-weight: 600; letter-spacing: 0.2px; }

/* At-a-glance summary strip above the detail cards: status & health + access
   endpoints, surfaced so an operator doesn't have to scroll the cards. */
.detail-summary {
  display: flex; flex-wrap: wrap; gap: 10px 28px; align-items: flex-start;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r);
  padding: 14px 18px; margin-bottom: 14px; box-shadow: var(--shadow-sm);
}
.summary-stat { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.summary-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
.summary-value { font-size: 13px; word-break: break-word; }
.summary-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.summary-link { color: var(--accent); text-decoration: none; font-weight: 500; font-size: 13px; }
.summary-link:hover { text-decoration: underline; }

.detail-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 14px; margin-bottom: 14px; }
.detail-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r); padding: 16px 18px; margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.detail-cards .detail-card { margin-bottom: 0; }
.detail-card-title { margin: 0 0 14px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
/* Card header with a title on the left and an action button on the right. */
.card-head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.modal-card select.cfg-input { width: 100%; }

.field-grid { display: flex; flex-direction: column; gap: 12px; }
.field-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 3px; }
.field-value { font-size: 13px; word-break: break-word; }

/* Agent config form */
.cfg-label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.cfg-input {
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 9px 11px;
  color: var(--text); font-size: 13px; font-family: inherit; resize: vertical;
}
.cfg-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cfg-input:disabled { opacity: 0.6; cursor: not-allowed; }
.cfg-row { display: flex; gap: 14px; flex-wrap: wrap; }
.cfg-row .cfg-label { flex: 1; min-width: 180px; }
.cfg-poll-label { max-width: 160px; }
/* Separator between per-channel blocks in the multi-channel Communications card. */
.cfg-divider { border: 0; border-top: 1px solid var(--border); margin: 6px 0 16px; }

/* Harness-tuning proposals card */
.proposal-generate { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 0 14px; }
.proposal-list { display: flex; flex-direction: column; gap: 14px; }
.proposal-advanced { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.proposal-advanced > summary { cursor: pointer; font-size: 12px; color: var(--accent); }
.proposal-advanced > summary:hover { text-decoration: underline; }
.proposal-cmd { position: relative; }
.proposal-cmd .copy-btn { position: absolute; top: 8px; right: 8px; }
.proposal-cmd .proposal-file-body { margin: 6px 0; }
.proposal {
  border: 1px solid var(--border); border-radius: var(--r-sm); padding: 12px 14px;
  background: var(--bg);
}
.proposal-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.proposal-id { font-size: 12px; }
.proposal-when { color: var(--muted); font-size: 12px; }
.proposal-meta { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
.proposal-sub { font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); margin: 10px 0 6px; }
.proposal-suggestion {
  border: 1px solid var(--border); border-radius: var(--r-sm); padding: 10px 12px;
  background: var(--panel); margin-bottom: 10px;
}
.proposal-suggestion .proposal-sub { margin-top: 0; }
.proposal-field { margin-bottom: 8px; }
.proposal-field:last-child { margin-bottom: 0; }
.proposal-field-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 2px; display: block; }
.proposal-field-value { font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.proposal-actions { margin-bottom: 10px; }
.proposal-files { display: flex; flex-direction: column; gap: 6px; }
.proposal-file { font-size: 12px; }
.proposal-file-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.proposal-file-name { word-break: break-all; }
.proposal-file-size { color: var(--muted); font-size: 11px; white-space: nowrap; }
.proposal-file-toggle {
  background: none; border: none; color: var(--accent); cursor: pointer; padding: 2px 0;
  font: inherit; font-size: 12px; text-align: left; word-break: break-all;
}
.proposal-file-toggle:hover { text-decoration: underline; }
.proposal-file-body {
  margin: 6px 0 2px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--r-sm); font-size: 12px; line-height: 1.45; max-height: 360px; overflow: auto;
  white-space: pre-wrap; word-break: break-word;
}
/* Sub-section heading inside a card (e.g. "Add Telegram" in Communications). */
.cfg-subhead { font-size: 13px; font-weight: 600; color: var(--text); margin: 0 0 8px; }
/* The additive create-form channel checkboxes. */
.cs-channels { border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 10px 12px; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.cs-channels legend { font-size: 12px; color: var(--muted); padding: 0 4px; }

/* Checkbox lists — group members & session group attachment. */
.check-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 220px; overflow: auto;
  background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); padding: 8px 11px;
}
.check-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; }
.check-row input { flex: none; }
.check-row .sub { margin-left: auto; }
/* A check-row inside a modal must stay a horizontal row — .modal-card label
   otherwise forces flex-direction: column, stacking the checkbox over its label. */
.modal-card label.check-row { flex-direction: row; align-items: center; }
.contacts-intro { max-width: 70ch; margin: 4px 0 16px; }

/* ── Drawer (workflow) ─────────────────────────────────────────────────────── */
.scrim { position: fixed; inset: 0; background: rgba(44, 38, 34, 0.42); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 460px; max-width: 100%;
  background: var(--panel); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  z-index: 21; display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { font-family: var(--font-serif); margin: 0; font-size: 18px; font-weight: 600; }
.drawer-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.drawer-body { padding: 18px 20px; overflow: auto; }

/* ── Workflow timeline ─────────────────────────────────────────────────────── */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 18px 28px; }
.timeline li::before {
  content: ""; position: absolute; left: 7px; top: 18px; bottom: -4px; width: 2px; background: var(--border-strong);
}
.timeline li:last-child::before { display: none; }
.dot {
  position: absolute; left: 0; top: 2px; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border-strong); background: var(--panel);
}
.step-name { font-weight: 600; font-size: 13px; }
.step-meta { color: var(--muted); font-size: 11px; margin-top: 2px; }
.s-succeeded .dot { background: var(--ok); border-color: var(--ok); }
.s-failed .dot { background: var(--bad); border-color: var(--bad); }
.s-running .dot { background: var(--run); border-color: var(--run); animation: pulse 1.2s ease-in-out infinite; }
.s-pending .dot { background: var(--panel); border-color: var(--pending); }
.s-pending .step-name { color: var(--muted); }
.s-compensation .step-name::after { content: " · rollback"; color: var(--warn); font-weight: 400; font-size: 11px; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(47, 106, 138, 0.5); } 50% { box-shadow: 0 0 0 5px rgba(47, 106, 138, 0); } }

.exec-status { display: inline-block; margin-bottom: 14px; }
.fail-detail {
  margin-top: 14px; padding: 12px; background: rgba(168, 57, 43, 0.08); border: 1px solid rgba(168, 57, 43, 0.28);
  border-radius: var(--r-sm); font-size: 12px; color: #8a2f24; white-space: pre-wrap; word-break: break-word;
}
.note { color: var(--muted); font-size: 13px; }

details.raw { margin-top: 18px; }
details.raw summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.raw pre { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 12px; overflow: auto; font-size: 11px; max-height: 260px; }

/* ── Side drawers (left nav + right docs) ────────────────────────────────────
   Two full-height pop-outs that slide in from opposite gutters: the primary
   navigation on the left, the contextual docs on the right. Both share one
   dimming scrim. They live above the topbar and span the entire page height;
   `body.nav-open` / `body.docs-open` drive the slide-in (toggled in app.js). */
.side-drawer {
  position: fixed; top: 0; bottom: 0; z-index: 30;
  display: flex; flex-direction: column;
  background: var(--panel); box-shadow: var(--shadow);
  transition: transform 0.22s ease;
}
.nav-drawer {
  left: 0; width: 274px; max-width: 86vw;
  border-right: 1px solid var(--border); border-top: 3px solid var(--accent);
  transform: translateX(-100%);
}
.docs-panel {
  right: 0; width: 440px; max-width: 92vw;
  border-left: 1px solid var(--border); border-top: 3px solid var(--accent);
  transform: translateX(100%);
}
body.nav-open .nav-drawer { transform: none; }
body.docs-open .docs-panel { transform: none; }

.drawer-scrim {
  position: fixed; inset: 0; z-index: 25; background: rgba(44, 38, 34, 0.42);
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
body.nav-open .drawer-scrim, body.docs-open .drawer-scrim { opacity: 1; pointer-events: auto; }

@media (prefers-reduced-motion: reduce) {
  .side-drawer, .drawer-scrim, .content { transition: none; }
}

/* Wide screens: the two pop-outs dock as side-by-side sidebars below the
   topbar — both can stay open at once, with no scrim, and the page content
   reflows into the space between them. (Narrow screens keep the full-height
   overlay sheets + scrim defined above, where there's no room to dock both.) */
@media (min-width: 980px) {
  .side-drawer { top: var(--topbar-h); box-shadow: var(--shadow-sm); }
  .content { transition: padding 0.2s ease; }
  body.nav-open .content { padding-left: 274px; }
  body.docs-open .content { padding-right: 440px; }
  body.nav-open .drawer-scrim, body.docs-open .drawer-scrim { opacity: 0; pointer-events: none; }
}

/* Shared drawer header (brand/title on the left, a close gutter on the right). */
.side-drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.side-drawer-head h3 { font-family: var(--font-serif); margin: 0; font-size: 18px; font-weight: 600; }

/* ── Left nav drawer ─────────────────────────────────────────────────────────*/
.nav-list { display: flex; flex-direction: column; gap: 3px; padding: 12px 10px; flex: 1 1 auto; overflow: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: var(--r-sm);
  padding: 10px 12px; font-size: 14px; font-weight: 600; color: var(--muted);
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.nav-ico { width: 19px; height: 19px; flex: 0 0 auto; color: currentColor; opacity: 0.85; }
.nav-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 16px; border-top: 1px solid var(--border); flex: 0 0 auto;
}
.nav-foot .who { font-size: 12px; color: var(--muted); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Right docs drawer ───────────────────────────────────────────────────────*/
.docs-panel-sub { color: var(--muted); font-size: 12px; margin: 3px 0 0; }
.docs-panel-body { padding: 16px 18px 28px; overflow: auto; flex: 1 1 auto; }
.docs-panel-body a { color: var(--accent); }

@media (max-width: 640px) {
  .docs-panel { width: 92vw; }
  .nav-drawer { width: min(274px, 84vw); }
  .page-title { display: none; }
}

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 40;
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--r);
  padding: 11px 16px; box-shadow: var(--shadow); font-size: 13px; max-width: 90%;
}
.toast.ok { border-color: var(--ok); }
.toast.bad { border-color: var(--bad); }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile / narrow viewports ───────────────────────────────────────────────
   Keep everything within the viewport width so the page never scrolls
   horizontally and controls (e.g. "New session") stay on-screen. */
@media (max-width: 640px) {
  .content { padding: 18px 14px 32px; }
  .topbar { padding: 10px 12px; gap: 8px; }
  .topbar-left { gap: 10px; }
  /* Keep the wordmark on one line. */
  .brand { white-space: nowrap; }
  /* Stack the toolbar heading above its controls and let the controls fill
     the row, so the search field and "New session" button wrap cleanly. */
  .toolbar-controls { width: 100%; }
  #new-session-btn { flex: 1 1 100%; }
  .search { flex: 1 1 100%; }

  /* Tables marked `.stacking` (contacts, groups) collapse to one card per row
     on narrow viewports. A 4-column grid squeezes the email so hard it wraps
     one character per line; here each cell becomes a label/value row instead. */
  table.stacking { width: 100%; }
  table.stacking thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.stacking tbody tr { display: block; padding: 6px 4px; border-bottom: 1px solid var(--border); }
  table.stacking tbody tr:last-child { border-bottom: none; }
  table.stacking tbody tr:hover { background: transparent; }
  table.stacking tbody td {
    display: grid; grid-template-columns: 96px minmax(0, 1fr); align-items: baseline; gap: 10px;
    padding: 6px 10px; border-bottom: none;
    /* A long unbreakable value (a session name/id with no spaces or hyphens, a
       numeric Telegram ID) must wrap instead of forcing the value column — and
       with it the whole table — wider than the card. `minmax(0, 1fr)` lets the
       column shrink below the token's intrinsic width; `overflow-wrap: anywhere`
       lets the token itself break. Without both, the table-wrap scrolls
       sideways and content disappears off the right edge. */
    overflow-wrap: anywhere;
  }
  table.stacking tbody td::before {
    content: attr(data-label);
    font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted);
    /* Keep the label itself on one line; only the value should wrap. */
    overflow-wrap: normal;
  }
  /* Email no longer competes for column width — let it wrap on word boundaries. */
  table.stacking .email-link { word-break: break-word; }
  table.stacking .actions { flex-wrap: wrap; }

  /* The sessions table also stacks. Its per-row bulk-select checkbox (and the
     select-all in the now-hidden thead) is a desktop power-feature — hide it so
     each session reads as a clean card; the per-card Delete button remains. */
  #sessions-table tbody td.col-check { display: none; }

  /* iOS Safari auto-zooms (and never zooms back out) whenever a focused text
     control has a font-size below 16px — so the desktop 13–14px inputs left the
     site stuck "zoomed in a little" after the login field, search, or any modal
     input took focus on load. Pin every text-entry control to 16px on mobile to
     suppress that zoom; the desktop sizing above is unaffected. */
  .login-card input,
  .modal-card input,
  .ob-panel input,
  select, .search, .cfg-input { font-size: 16px; }
}

/* ── Onboarding invites (admin) ─────────────────────────────────────────────── */
.invites-intro { margin: -6px 0 14px; max-width: 60ch; }
.invite-result {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--r-md, 12px);
  padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow-sm);
}
.invite-result-inner { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.invite-qr {
  flex: 0 0 auto; width: 160px; height: 160px; padding: 8px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--r-sm);
}
.invite-qr svg { width: 100%; height: 100%; display: block; }
.invite-share { flex: 1 1 280px; min-width: 240px; }
.invite-share h3 { font-family: var(--font-serif); margin: 0 0 4px; font-size: 18px; font-weight: 600; }
.invite-url-row { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.invite-url {
  flex: 1 1 auto; min-width: 0; background: var(--bg); border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); padding: 9px 11px; font-size: 12px; color: var(--text);
}
.invite-result-actions { display: flex; gap: 10px; }
.invite-mini-link { color: var(--accent); cursor: pointer; }

/* ── Onboarding page (onboard.html) ─────────────────────────────────────────── */
.onboard-card { width: min(440px, 92vw); }
.ob-steps {
  display: flex; gap: 6px; list-style: none; padding: 0; margin: 4px 0 14px;
  counter-reset: ob; font-size: 11px;
}
.ob-steps li {
  flex: 1 1 0; text-align: center; color: var(--muted); padding: 6px 4px;
  border-bottom: 2px solid var(--border); text-transform: uppercase; letter-spacing: 0.5px;
}
.ob-steps li.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.ob-steps li.done { color: var(--ok); border-bottom-color: var(--ok); }
.ob-panel { display: flex; flex-direction: column; gap: 12px; }
.ob-panel label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.ob-panel input {
  background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  padding: 10px 12px; font-size: 14px; color: var(--text);
}
.ob-panel input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ob-block-btn { width: 100%; padding: 11px; font-size: 14px; }
.ob-link-btn { display: inline-block; text-align: center; text-decoration: none; }
.ob-size-note { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 8px 10px; }
.ob-check {
  width: 48px; height: 48px; margin: 4px auto 0; border-radius: 50%;
  background: var(--ok); color: #fff; font-size: 26px; line-height: 48px; text-align: center;
}
.ob-done-title { font-family: var(--font-serif); text-align: center; margin: 4px 0; font-size: 20px; font-weight: 600; }
.onboard-view #ob-done { text-align: center; align-items: center; }
/* "Where's my app" access box on the onboarding done screen. */
.ob-access {
  width: 100%; box-sizing: border-box; text-align: left;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
}
.ob-access-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.ob-access-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 14px; }
.ob-access-label { color: var(--muted); font-size: 12px; }
.ob-access-row a { color: var(--accent); text-decoration: none; font-weight: 500; }
.ob-access-row a:hover { text-decoration: underline; }
/* Invite status badges (own labels, reuse the dot-badge look). */
.inv-PENDING { color: var(--run); background: rgba(47, 106, 138, 0.12); }
.inv-REDEEMED { color: var(--ok); background: rgba(63, 122, 63, 0.12); }
.inv-REVOKED { color: var(--bad); background: rgba(168, 57, 43, 0.12); }
.inv-EXPIRED { color: var(--muted); background: rgba(120, 120, 120, 0.12); }
/* Soft hint after the expiry timestamp (e.g. "in 3 days" / "expired"). */
.expiry-hint { color: var(--muted); font-size: 12px; }
.expiry-hint.is-past { color: var(--bad); }
