/* YOID Alert — self-contained, no external fonts or assets. Light and dark.

   Visual language extends the Partners portal's real brand system (checked directly:
   /root/p_sandbox/www/css/escen.css + media/yoid-logo.svg) rather than inventing a new
   one: Inter, the #E8EFF3 cool-canvas / white-panel surface, the violet-to-orange
   gradient used there for primary actions and the logo mark, and that same
   radius/shadow scale. This is an internal ops console, not the customer-facing product,
   so the gradient is used deliberately in exactly two places rather than smeared
   everywhere: the wordmark, and the UNASSIGNED flag — the one flag that's fundamentally
   a question of ownership/identity rather than a sensor reading, so it's the one place
   "brand" and "data" legitimately overlap. Every other flag stays a plain traffic-light
   color so severity still reads instantly.

   --brand-b is deepened from the partner site's raw #FC4408 to #C73500 -- the original
   fails WCAG AA (3.5:1) as white-on-button text or as gradient-text against a light
   background; #C73500 clears 4.5:1 in both directions while staying unmistakably the
   same violet-to-orange identity. --brand-a/--brand-b stay fixed across color schemes
   (they're always paired with white text on a filled shape), but the gradient-as-TEXT
   treatment (wordmark only) needs lighter stops in dark mode -- see --brand-text-gradient. */

:root {
  --canvas: #e8eff3;
  --panel: #ffffff;
  --ink: #12151b;
  --muted: #5b6b7a;
  --line: #dce3ea;

  --accent: #a110e0;
  --brand-a: #a110e0;
  --brand-b: #c73500;
  --brand-gradient: linear-gradient(to right, var(--brand-a), var(--brand-b));
  --brand-text-gradient: var(--brand-gradient);

  --ok: #086b4b;
  --ok-bg: #e3f7ef;
  --warn: #94420a;
  --warn-bg: #fbf0de;
  --danger: #a3241d;
  --danger-bg: #fbe9e7;
  --faulty: #7c3aed;
  --faulty-bg: #f1e9fd;

  --radius-sm: 0.25rem;
  --radius-md: 0.4rem;
  --radius-lg: 0.65rem;

  --shadow-xs: 0 1px 2px rgb(18 21 27 / 0.06);
  --shadow-sm: 0 1px 3px rgb(18 21 27 / 0.08), 0 1px 2px rgb(18 21 27 / 0.06);
  --shadow-md: 0 4px 10px rgb(18 21 27 / 0.08), 0 2px 4px rgb(18 21 27 / 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #12151b;
    --panel: #1b1f27;
    --ink: #eef1f5;
    --muted: #93a1b0;
    --line: #2c323c;

    /* Lighter than --brand-a/--brand-b so gradient TEXT stays legible directly on a dark
       page background. Not used for buttons/badges: those keep the fixed --brand-a/b
       (white text needs the darker, more saturated stops regardless of page theme). */
    --accent: #cf7af2;
    --brand-text-gradient: linear-gradient(to right, #cf7af2, #ff8a5c);

    --ok: #34d399;
    --ok-bg: #103326;
    --warn: #f2b155;
    --warn-bg: #34260f;
    --danger: #f87171;
    --danger-bg: #391b19;
    --faulty: #c4b5fd;
    --faulty-bg: #251c3d;

    --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.3);
    --shadow-sm: 0 1px 3px rgb(0 0 0 / 0.35), 0 1px 2px rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 10px rgb(0 0 0 / 0.4), 0 2px 4px rgb(0 0 0 / 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .92em;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex; align-items: center; gap: 28px;
  padding: 0 22px; height: 58px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand {
  font-weight: 800; font-size: 18px; letter-spacing: -.3px;
  background-image: var(--brand-text-gradient);
  background-clip: text; -webkit-background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
}
.topbar nav { display: flex; gap: 20px; margin-right: auto; }
.topbar nav a {
  color: var(--muted); padding: 4px 1px; border-bottom: 2px solid transparent;
  font-weight: 500; transition: color .15s, border-color .15s;
}
.topbar nav a:hover { text-decoration: none; color: var(--ink); }
.topbar nav a.active { color: var(--ink); border-image: var(--brand-gradient) 1; border-bottom-width: 2px; }
.topbar-right { display: flex; align-items: center; gap: 14px; min-width: 0; flex-wrap: wrap; }
.logout { color: var(--muted); font-size: 13px; }
.logout:hover { color: var(--ink); }

main { max-width: 1440px; margin: 0 auto; padding: 26px 22px 64px; }

h1 { font-size: 23px; font-weight: 700; margin: 0 0 18px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; letter-spacing: -.3px; }
h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .6px; font-weight: 700;
  color: var(--muted); margin: 34px 0 12px;
  display: flex; align-items: baseline; gap: 10px;
}
section:first-of-type h2 { margin-top: 26px; }

.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 12.5px; }
.empty {
  color: var(--muted); padding: 22px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.crumb { margin: 0 0 12px; font-size: 13px; }
.crumb a { color: var(--muted); font-weight: 500; }
.crumb a:hover { color: var(--accent); }

/* ---------- banners & pills ---------- */

.banner { padding: 13px 15px; border-radius: var(--radius-md); margin: 0 0 18px; border: 1px solid transparent; font-size: 14px; }
.banner code { opacity: .85; word-break: break-word; }
.banner .error-detail { display: block; margin-top: 6px; }
.banner-danger { background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }
.banner-warn { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--warn); }
.banner-ok { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 35%, transparent); color: var(--ok); }

/* ---------- Bot tab ---------- */

/* Edit-in-place rows: inputs and their button on one line, wrapping on a narrow screen
   rather than overflowing the card. */
.inline-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0; }
.inline-form input { min-width: 0; }
.pill-warn { background: var(--warn-bg); color: var(--warn); }

.bot-search { display: flex; gap: 10px; align-items: center; margin: 0 0 10px; }
.bot-search input {
  flex: 1; max-width: 460px; padding: 9px 12px; font-size: 15px;
}

/* ---------- bands: the Alerts page's collapsible sections ----------

   The Bot and Alerts pages merged into one, so the page needed a way to hold five sections
   without becoming a scroll. Split by what you do with them: Partners and Chats are worked, and
   stay open; transitions, orphaned numbers and the reference notes are consulted, and collapse.

   `<details>` rather than the `:target` the partner editors use, and the difference is the point:
   bands toggle INDEPENDENTLY (open two at once), while exactly one partner editor may be open —
   `:target` enforces that for free, and would fight it here. The default marker is removed and
   replaced with a chevron on the right, so the control is the whole header rather than a small
   triangle. */
.band {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-xs);
  margin: 14px 0 0;
}
.band-head {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  padding: 13px 18px; cursor: pointer; list-style: none;
  border-radius: var(--radius-lg);
}
.band-head::-webkit-details-marker { display: none; }
.band-head:hover { background: var(--canvas); }
.band-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* Reuses the portal's existing section-label vocabulary, so a band header and an ordinary <h2>
   read as the same kind of thing whether the band is open or shut. */
.band-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .6px; font-weight: 700;
  color: var(--ink);
}
.band-hint { color: var(--muted); font-size: 12.5px; }
/* The chevron carries open/closed. On the right, where the eye ends up after the header text. */
.band-head::after {
  content: "⌄"; margin-left: auto; color: var(--muted);
  font-size: 16px; line-height: 1; transition: transform .15s;
}
.band[open] > .band-head::after { transform: rotate(180deg); }
.band[open] > .band-head { border-bottom: 1px solid var(--line); border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.band-body { padding: 14px 18px 18px; }
.band-intro { margin-top: 0; }
/* The bands own the surface now, so the tables inside them lose their own frame — two nested
   panels with two borders read as a box in a box. */
.band-body .table-scroll { border: none; border-radius: 0; box-shadow: none; background: none; }

/* A revoked chat stays legible: it is still a record, and greying it out entirely made it look
   broken rather than switched off. */
.row-revoked > td { opacity: .62; }
.chats-table code { font-size: 11.5px; }

@media (prefers-reduced-motion: reduce) {
  .band-head::after { transition: none; }
}

/* ---------- Bot tab: one dense table, rows open a sheet ----------

   Organised to match /telegram at the owner's request: summary tiles, then a real table with
   headers. It replaced a <details> disclosure (a small triangle to hit, and expanding one row
   pushed the rest of the roster off screen) and then a card list, which read as a pile of
   equal-weight boxes with nothing to scan down.

   The gain from a table is a scannable column: "Delivery" is derived from two independent facts
   — on the alert list, and has a chat — because only together do they answer whether a partner
   is actually being told anything. That question used to require opening every row.

   No new palette or typeface here: the page uses the existing tokens and Inter, and the brand
   gradient stays in the two places it already lives (the wordmark and the UNASSIGNED flag). */
.bot-table { width: 100%; }
.bot-table .pr-open {
  font-weight: 500; color: var(--ink);
  /* The name IS the control — the owner's ask was to click the name and get a panel. */
}
.bot-table .pr-open:hover { color: var(--accent); }
.bot-table tbody tr:hover { background: var(--canvas); }
/* Ids and counts line up as columns, so they get figures that do too. */
.bot-table .num, .bot-table td[data-label="Numbers"], .bot-table td[data-label="Chats"] {
  font-variant-numeric: tabular-nums;
}
.row-action { text-align: right; white-space: nowrap; }
.manage-link {
  font-size: 12.5px; font-weight: 500; color: var(--muted);
  padding: 6px 10px; border-radius: var(--radius-md); border: 1px solid var(--line);
}
.manage-link:hover {
  text-decoration: none; color: var(--ink); border-color: var(--accent); background: var(--panel);
}

/* One tile carries a state rather than a count: "on the alert list but nothing delivered" is
   the condition that reads as working and isn't. Tinted only when it is non-zero, so a healthy
   fleet does not show a permanent warning. */
.card-alert { border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.card-alert .tile-value { color: var(--danger); }
/* The denominator in "3 / 12" is context, not data — it should not read as loud as the count. */
.tile-of { font-size: 15px; font-weight: 500; color: var(--muted); margin-left: 4px; }

.bot-search { display: flex; gap: 10px; align-items: center; margin: 0 0 12px; }
.bot-search input { flex: 1; max-width: 460px; padding: 9px 12px; font-size: 15px; }

/* ---------- the inline editor ----------

   Owner's request, 2026-08-12: clicking Manage should expand the editor *there*, and opening
   another should collapse the first. It replaced a modal overlay, which hid the roster behind it
   and gave no sense of which row you were editing.

   🔴 Driven by `:target`, and that is what makes "one at a time" free: a document has exactly one
   target, so opening another row closes the previous with no state tracked anywhere and no
   script. It is also the only thing that survives a form POST — see _bot_redirect. */
.detail-row { display: none; }
.detail-row:target { display: table-row; }
.detail-row > td { padding: 0 !important; background: var(--canvas); }

/* The row being edited stays visually attached to its panel: same tint, and the border between
   them removed so they read as one object rather than two stacked ones. */
.bot-table tbody tr:has(+ .detail-row:target) > td {
  background: var(--canvas); border-bottom-color: transparent;
}
.bot-table tbody tr:has(+ .detail-row:target) .pr-open { color: var(--accent); }

.editor {
  padding: 16px 18px 18px;
  /* A stripe in the delivery-state colour. Structural, not decorative: it repeats the one fact
     the row's Delivery column carries, so an open panel still answers "is this partner actually
     being told anything" without looking back up at the row. */
  border-left: 3px solid var(--line);
}
.editor-live { border-left-color: var(--ok); }
.editor-silent { border-left-color: var(--danger); }
.editor-off { border-left-color: var(--line); }

.editor-head {
  display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap;
  padding-bottom: 12px; margin-bottom: 14px; border-bottom: 1px solid var(--line);
}
.editor-head strong { font-size: 15px; }
.editor-id { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.editor-id > strong + .badge { align-self: flex-start; }

/* The row's three numbers, kept inside the editor so it answers its own questions without the
   row above it being on screen. A <dl> because these are label/value pairs, not a table. */
.editor-facts {
  display: flex; gap: 18px; margin: 0 0 0 auto; align-items: baseline;
}
.editor-facts > div { display: flex; flex-direction: column; gap: 1px; }
.editor-facts dt {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted);
}
.editor-facts dd {
  margin: 0; font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums;
}
/* A note, not body text: it is a consequence of the switch above it, and as a muted paragraph it
   read as small print and got skipped. Tinted only when something is actually wrong. */
.editor-note {
  margin: 0; padding: 8px 10px; border-radius: var(--radius-md);
  font-size: 12.5px; line-height: 1.45;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
}
.editor-note b { color: var(--ink); }
.editor-note-bad {
  background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 30%, transparent);
  color: var(--danger);
}
.editor-note-bad b { color: var(--danger); }
.editor-note-bad .muted { color: inherit; opacity: .8; }
.editor-note-ok {
  background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 25%, transparent);
  color: var(--ok);
}
.editor-close {
  margin-left: auto; font-size: 12.5px; font-weight: 500; color: var(--muted);
  padding: 5px 12px; border-radius: var(--radius-md); border: 1px solid var(--line);
  background: var(--panel);
}
.editor-close:hover { text-decoration: none; color: var(--ink); border-color: var(--accent); }

/* Two columns on a wide screen: the single decision (alerts on/off) beside the list it governs.
   `minmax(0, …)` on both tracks so a long number or explanation cannot widen the grid. */
.editor-grid {
  display: grid; grid-template-columns: minmax(0, 280px) minmax(0, 1fr); gap: 18px 24px;
  align-items: start;
}
.editor-block { min-width: 0; }
/* Three blocks now: the decision, who else it reaches, and the numbers. The first two are narrow
   controls and share the left column; the list of numbers takes the rest. */
.editor-grants { grid-column: 1; }
.editor-numbers { grid-column: 2; grid-row: 1 / span 2; }
.grant-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
/* Chips: a granted chat is a small removable thing, and a full-width list row made two of them
   look like a major section. */
.grant-list { flex-direction: row; flex-wrap: wrap; }
.grant-list li {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 4px 4px 11px; font-size: 12.5px;
}
.grant-list li form button {
  padding: 2px 8px; font-size: 11px; border-radius: 999px; min-height: 0;
}
.grant-list li > span { min-width: 0; overflow-wrap: anywhere; }
.grant-list form { margin: 0 0 0 auto; }
.grant-add { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 6px; }
.grant-add select { max-width: 100%; flex: 1; min-width: 0; }

/* Column captions for the number rows. The grid mirrors .phone-row so the words sit over the
   fields they describe rather than near them. */
.phone-caption {
  display: flex; align-items: baseline; gap: 6px;
  padding: 0 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
}
.phone-caption > span:first-child { width: 15ch; }
.phone-caption > span:nth-child(2) { width: 14ch; }
.phone-caption-state { margin-left: auto; }
.editor-block > form { margin: 0 0 8px; }
.editor-block p:last-child { margin-bottom: 0; }
.editor-label {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; font-weight: 700;
  color: var(--muted); margin: 0 0 8px;
}

.phone-rows { display: flex; flex-direction: column; gap: 8px; margin: 0 0 14px; }
.phone-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 6px 0; border-bottom: 1px solid var(--line);
}
.phone-row:last-child { border-bottom: none; }
.phone-edit { display: flex; align-items: center; gap: 6px; margin: 0; flex: 1; min-width: 0; }
.phone-meta { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.phone-toggle { margin: 0; }
/* A disabled number stays legible — it is still a record, and greying it out entirely made it
   look broken rather than switched off. */
.phone-row.row-off .phone-input, .phone-row.row-off .name-input { opacity: .6; }
.phone-flags { display: flex; gap: 6px; flex-wrap: wrap; }
/* A flagless row renders an empty span, which as a flex item still claims the group's gap and
   nudged its switch out of line with the rest. */
.phone-flags:empty { display: none; }

/* Wide enough for +<cc> and a full national number without the text scrolling as you edit —
   the reason numbers were hard to correct before. */
.phone-input { width: 15ch; font-variant-numeric: tabular-nums; }
.name-input { width: 14ch; }

.add-phone {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 0; padding: 12px; border-radius: var(--radius-md);
  /* A panel on the editor's tinted ground, so "add" reads as a separate affordance rather than
     dissolving into the list above it — the canvas tint it used to carry was the same colour as
     the editor itself. */
  background: var(--panel); border: 1px solid var(--line);
}

/* On/off switch, sitting beside the name it belongs to. Shows STATE; the action is in the
   tooltip and the aria-label, so "On" never reads as "click to turn on". */
.toggle {
  display: inline-flex; align-items: center; gap: 6px;
  min-width: 5.5em; justify-content: center;
  font-weight: 500;
}
.toggle-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.toggle-on { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.toggle-off { background: var(--canvas); color: var(--muted); border-color: transparent; }

/* Save is hidden until a field changes (see bot.html). Marking the row makes it obvious which
   one has work pending when several are open. */
.phone-edit.is-dirty .phone-input, .phone-edit.is-dirty .name-input {
  border-color: var(--accent);
}

/* ---------- phone: the sheet becomes a bottom sheet ----------

   Anchored to the bottom because that is where a thumb is, and full-bleed because 320px of
   width does not survive being inset. Inputs go full width and stack: two 15ch fields plus a
   toggle on one line is what made this unusable on a phone. */
@media (max-width: 640px) {
  /* 🔴 The table becomes stacked cards rather than scrolling sideways.

     A five-column table at 375px either overflows horizontally or crushes every column to
     unreadable. Same markup either way — each cell announces itself with the `data-label` the
     template already carries, so there is one source of truth and the phone layout cannot drift
     from the desktop one. */
  .table-scroll:has(.bot-table) { border: none; background: none; box-shadow: none; overflow: visible; }
  .bot-table thead { display: none; }
  /* 🔴 `:not(.detail-row)` is load-bearing. `.bot-table tr` (0,1,1) outranks `.detail-row`
     (0,1,0), so blanket-blocking every tr re-showed every collapsed editor at once — the whole
     page unrolled on a phone while looking correct on desktop. */
  .bot-table, .bot-table tbody, .bot-table td { display: block; width: auto; }
  .bot-table tr:not(.detail-row) { display: block; width: auto; }
  .bot-table tr {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius-md); margin-bottom: 8px; padding: 12px;
  }
  .bot-table td { border: none; padding: 0; }
  /* The name gets the whole card width as a tap target, since tapping it is the primary action. */
  .bot-table td[data-label="Partner"] { margin-bottom: 8px; }
  /* The name is the primary control, so it gets a full-width, thumb-sized target rather than
     just the height of its own text (24px measured — well under the 44px minimum). */
  .bot-table .pr-open {
    display: flex; align-items: center;
    font-size: 16px; min-height: 44px; margin: -10px -12px 0; padding: 0 12px;
  }
  /* Counts and state sit on one line, each prefixed by what it is. */
  .bot-table td[data-label="Numbers"],
  .bot-table td[data-label="Chats"],
  .bot-table td[data-label="Delivery"] {
    display: inline-flex; align-items: baseline; gap: 5px;
    margin-right: 14px; text-align: left; font-size: 13px;
  }
  .bot-table td[data-label]::before {
    content: attr(data-label) ":"; color: var(--muted); font-size: 12px;
  }
  .bot-table td[data-label="Partner"]::before { content: none; }
  /* Redundant on a phone: the whole name is already the target. */
  .bot-table .row-action { display: none; }

  /* The editor stacks: one column, and the panel spans the card it belongs to. */
  .detail-row:target { display: block; }

  /* The hint is orienting context for someone scanning a wide page; on a phone it pushes the
     chevron onto its own line and costs more than it explains. */
  .band-hint { display: none; }
  .band-head { padding: 12px 14px; }
  .band-body { padding: 12px 14px 14px; }
  .band-intro { font-size: 12.5px; }
  .editor { padding: 12px 14px 14px; border-left-width: 3px; }
  .editor-grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  /* Undo the desktop column/row spans, or the blocks land on top of each other. */
  .editor-grants, .editor-numbers { grid-column: auto; grid-row: auto; }
  .editor-head { margin-bottom: 10px; }
  .editor-close { min-height: 36px; display: inline-flex; align-items: center; }

  /* The rows stack, so column captions no longer sit above anything. */
  .phone-caption { display: none; }
  .editor-facts { margin-left: 0; gap: 14px; }
  .editor-facts dd { font-size: 15px; }
  .phone-row { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 0; }
  .phone-edit { flex-direction: column; align-items: stretch; gap: 8px; }
  .phone-meta { margin-left: 0; justify-content: space-between; }
  .phone-input, .name-input { width: 100%; }
  /* 16px stops iOS Safari zooming the viewport when a field takes focus. */
  .phone-input, .name-input, .bot-search input { font-size: 16px; }
  .add-phone { flex-direction: column; align-items: stretch; }
  .add-phone button, .editor-block > form button { width: 100%; min-height: 44px; }
  .toggle { min-height: 44px; }
}

[hidden] { display: none !important; }

.pill {
  font-size: 12px; font-weight: 500; padding: 4px 10px; border-radius: 999px;
  white-space: nowrap;
  /* The neutral default. Unset, it rendered as bare text beside its filled siblings and did
     not read as a state at all. */
  background: var(--canvas); color: var(--muted);
}
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-danger { background: var(--danger-bg); color: var(--danger); }

/* ---------- tiles ---------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(136px, 1fr)); gap: 12px; margin-bottom: 8px; }
.tile {
  position: relative;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 17px 18px; color: var(--ink);
  box-shadow: var(--shadow-xs);
  transition: box-shadow .15s, transform .15s, border-color .15s;
}
.tile::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--line);
}
.tile:hover { text-decoration: none; box-shadow: var(--shadow-md); transform: translateY(-1px); }
.tile-value { font-size: 29px; font-weight: 750; letter-spacing: -.6px; font-variant-numeric: tabular-nums; }
.tile-label { font-size: 12.5px; color: var(--muted); margin-top: 2px; font-weight: 500; }
.tile-offline::before    { background: var(--danger); }
.tile-faulty::before     { background: var(--faulty); }
.tile-unassigned::before { background: var(--brand-gradient); }
.tile-full::before       { background: var(--warn); }
.tile-low_stock::before  { background: var(--warn); }
.tile-ok::before         { background: var(--ok); }

/* ---------- tables ---------- */

.table-scroll { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.sort-link {
  color: inherit; display: inline-flex; align-items: center; gap: 3px;
  text-transform: inherit; letter-spacing: inherit; font-weight: inherit;
}
.sort-link:hover { color: var(--ink); }
.sort-link.sort-active { color: var(--accent); }
.sort-arrow { font-size: 9px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color .1s; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.addr { max-width: 320px; }
td.warn, dd.warn { color: var(--warn); font-weight: 600; }

/* ---------- badges ---------- */

.badge { display: inline-block; font-size: 11.5px; font-weight: 650; padding: 3px 9px; border-radius: var(--radius-sm); white-space: nowrap; }
.badge-ok         { background: var(--ok-bg); color: var(--ok); }
.badge-offline    { background: var(--danger-bg); color: var(--danger); }
.badge-low_stock  { background: var(--warn-bg); color: var(--warn); }
.badge-full       { background: var(--warn-bg); color: var(--warn); }
.badge-faulty     { background: var(--faulty-bg); color: var(--faulty); }
.badge-unassigned { background-image: var(--brand-gradient); color: #fff; }

.count { font-weight: 650; }
.count-offline { color: var(--danger); }
.count-low_stock, .count-full { color: var(--warn); }
.count-faulty { color: var(--faulty); }
.count-unassigned { color: var(--accent); }
.count-ok { color: var(--ok); }

/* ---------- filters ---------- */

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.filters input[type=search] { flex: 1 1 260px; min-width: 200px; }
input, select, button {
  font: inherit; padding: 8px 11px; border-radius: var(--radius-md);
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
button {
  background-image: var(--brand-gradient); color: #fff; border-color: transparent;
  font-weight: 650; cursor: pointer; padding: 9px 18px;
  transition: filter .15s, box-shadow .15s;
}
button:hover { filter: brightness(1.06); box-shadow: var(--shadow-sm); }
.clear { font-size: 13px; color: var(--muted); align-self: center; }
.clear:hover { color: var(--ink); }
.export-link {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 600; color: var(--ink); align-self: center;
  margin-left: auto; padding: 8px 14px; border: 1px solid var(--line); border-radius: var(--radius-md);
  background: var(--panel); box-shadow: var(--shadow-xs);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.export-link svg { color: var(--muted); transition: color .15s; }
.export-link:hover { text-decoration: none; border-color: var(--accent); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.export-link:hover svg { color: var(--accent); }

/* ---------- cards ---------- */

/* 220px, not 280: the merged Alerts page shows four tiles, and at 280 the fourth wrapped to
   its own row on a 1200px screen — one lonely tile under three. */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow-xs); }
.card h2 { margin: 0 0 12px; }
dl { margin: 0; display: grid; grid-template-columns: minmax(90px, 34%) 1fr; gap: 8px 14px; }
dt { color: var(--muted); font-size: 13px; }
dd { margin: 0; font-size: 14px; word-break: break-word; }

.rules ul { margin: 0 0 10px; padding-left: 20px; color: var(--muted); font-size: 14px; }
.rules li { margin-bottom: 3px; }
.rules strong { color: var(--ink); }

/* ---------- click-to-copy ---------- */

.copy-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 7px; height: 7px; margin-left: 4px; padding: 0; vertical-align: middle;
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color .15s, background-color .15s;
}
.copy-btn svg { width: 100%; height: 100%; display: block; }
/* Hit area stays finger/mouse-friendly even though the visible glyph is tiny. */
.copy-btn::before { content: ""; position: absolute; inset: -6px; }
.copy-btn:hover { color: var(--accent); }
.copy-btn.copied { color: var(--ok); }

/* ---------- login ---------- */

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(120% 90% at 50% -10%, color-mix(in srgb, var(--accent) 7%, var(--canvas)), var(--canvas) 60%);
}
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 34px 32px; width: 100%; max-width: 368px;
  box-shadow: var(--shadow-md);
}
.login-card h1 {
  font-size: 26px; font-weight: 800; margin: 0; display: block; letter-spacing: -.4px;
  background-image: var(--brand-text-gradient);
  background-clip: text; -webkit-background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
  width: fit-content;
}
.login-card p.muted { margin: 4px 0 24px; font-size: 14px; }
.login-card label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 5px; }
.login-card input { width: 100%; margin-bottom: 16px; }
.login-card button { width: 100%; padding: 11px; font-size: 14.5px; }

/* ---------- offline report ---------- */

.report-actionbar { display: flex; gap: 10px; justify-content: flex-end; margin-bottom: 20px; }
.report-actionbar button { display: inline-flex; align-items: center; gap: 7px; }
.report-actionbar button.copied { color: var(--ok); border-color: var(--ok); }
.report-actionbar svg { width: 14px; height: 14px; }

.report-letterhead {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  border-bottom: 2px solid var(--line); padding-bottom: 18px; margin-bottom: 4px;
}
.report-title { font-size: 25px; font-weight: 750; letter-spacing: -.4px; margin: 6px 0 0; }
.report-meta { text-align: right; }
.report-count { font-size: 29px; font-weight: 800; color: var(--danger); font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.report-count-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.report-stamp { font-size: 12px; color: var(--muted); margin-top: 6px; }

.partner-card {
  position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-xs);
  margin-top: 18px; padding: 16px 18px 16px 20px; overflow: hidden;
  break-inside: avoid; page-break-inside: avoid;
}
.partner-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--danger); }
.partner-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.partner-name { font-size: 15.5px; font-weight: 700; }
.partner-sub { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.partner-copy {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px; font: inherit; font-size: 12px; font-weight: 600;
  padding: 3px 7px; border-radius: var(--radius-sm); transition: color .15s, background-color .15s;
}
.partner-copy svg { width: 11px; height: 11px; }
.partner-copy:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.partner-copy.copied { color: var(--ok); }

.station-list { margin: 12px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
/* Two columns: cabinet id, then venue with the address beneath it. A third column held
   the downtime duration until 2026-07-30, when it was dropped from the partner-facing
   report -- see app/main.py::_report_station_line. */
.station-row { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; align-items: baseline; }
.station-row + .station-row { border-top: 1px dashed var(--line); padding-top: 10px; }
.station-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; font-weight: 700; background: var(--danger-bg); color: var(--danger);
  padding: 2px 7px; border-radius: var(--radius-sm); white-space: nowrap;
}
.station-venue { font-weight: 600; }
.station-addr { grid-column: 2; font-size: 12.5px; color: var(--muted); }

.report-footer { margin-top: 26px; font-size: 11.5px; color: var(--muted); text-align: center; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- telegram subscribers ----------
   Revoking is destructive and sits in a dense table, so it gets a quiet outline rather
   than the brand gradient every other button uses -- a row of gradient buttons reads as
   the primary action on the page, which this is emphatically not. */

.btn-danger {
  background-image: none; background: var(--panel); color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  font-size: 12px; font-weight: 600; padding: 5px 12px;
}
.btn-danger:hover { background: var(--danger-bg); box-shadow: none; filter: none; }

/* The stat cards on /telegram reuse .card, but their value needs the tile treatment. */
.card .tile-label { color: var(--muted); font-size: 13px; }
.card .tile-value { font-size: 26px; font-weight: 700; line-height: 1.2; margin: 2px 0 6px; }
.card p.small:last-child { margin-bottom: 0; }

@media (max-width: 640px) {
  .topbar { height: auto; padding: 10px 14px; gap: 12px; }
  .topbar nav { order: 3; width: 100%; margin-right: 0; }

  /* 🔴 This was making EVERY page scroll sideways on a phone, not just the Bot tab.
     `.pill` is `white-space: nowrap`, and the health pill can say "Partner mapping stale
     (20677d 12h old)" — 249px of unbreakable text that pushed the document to 434px against a
     375px viewport. Everything then sat 59px too wide, including a `position: fixed` overlay,
     whose containing block follows the document rather than the visual viewport here.

     Fixed at the source (let the text wrap) rather than with `overflow-x: hidden` on <html>,
     which would have hidden the symptom and left the layout genuinely too wide. */
  .topbar-right { width: 100%; order: 2; }
  .topbar-right .pill { white-space: normal; }
  .topbar nav { order: 4; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  main { padding: 18px 14px 48px; }
  dl { grid-template-columns: 1fr; gap: 2px; }
  dt { margin-top: 8px; }
  .report-letterhead { align-items: flex-start; }
  .report-meta { text-align: left; }

  /* Summary tiles become a compact stat strip.

     At full size each tile runs a screen tall, so three of them buried the partner list under
     three screens of explanation — and that explanation is desktop context, not something you
     re-read on a phone. The label and the number are what you glance at; those stay.

     🔴 These live in THIS media block, not the earlier one, because the base `.cards` rule sits
     between the two — from the earlier block they lost the cascade to its auto-fit columns at
     equal specificity. Applies to /telegram's tiles too, which share the shape and the problem. */
  /* Two columns, not three: the merged Alerts page has four tiles, and three across left one
     stranded on its own row. */
  .cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .card { padding: 10px 11px; }
  .card p.small { display: none; }
  .card .tile-label { font-size: 11.5px; line-height: 1.25; }
  .card .tile-value { font-size: 21px; margin: 4px 0 0; }
  .tile-of { font-size: 12px; }
}

/* Always paper, regardless of the viewer's light/dark preference. */
@media print {
  .topbar, .report-actionbar, .crumb { display: none !important; }
  body { background: #fff; color: #12151b; }
  main { max-width: none; padding: 0; }
  .partner-card { box-shadow: none; border: 1px solid #dce3ea; }
}
