/* Bandito panel. One stylesheet, no external resources: the server's CSP allows only 'self'. */

:root {
  color-scheme: light dark;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 8px;
  --rail-width: 360px;

  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --sunken: #eceef2;
  --border: #d9dde4;
  --border-strong: #b4bcc8;
  --text: #1b1f27;
  --text-muted: #566070;
  --text-faint: #7d8696;
  --input-bg: #ffffff;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --focus: #2f5bd3;
  --switch-off: #c9ced8;
  --danger: #c62828;
  --danger-text: #ffffff;
  --danger-bg: #fdeaea;
  --shadow: 0 8px 28px rgb(15 20 30 / 0.18);
  --backdrop: rgb(15 20 30 / 0.45);

  --observed: #5b7ba6;
  --observed-bg: #e8eef7;
  --observed-fg: #2b4a75;
  --ignored: #98a0ad;
  --ignored-bg: #eef0f2;
  --ignored-fg: #4b5260;
  --sent: #2f8f5b;
  --sent-bg: #e1f3e8;
  --sent-fg: #1b603b;
  --waiting: #c98a16;
  --waiting-bg: #fbf0d9;
  --waiting-fg: #74500a;
  --failed: #cf3b3b;
  --failed-bg: #fbe5e5;
  --failed-fg: #962020;
  --info: #2a8a8a;
  --info-bg: #def1f0;
  --info-fg: #1a5f5f;
  --switch: #7b5cc4;
  --switch-bg: #efe9fb;
  --switch-fg: #51389a;
  --neutral: #7d8696;
  --neutral-bg: #eceef2;
  --neutral-fg: #3d4553;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101317;
    --surface: #181c22;
    --surface-2: #14181d;
    --sunken: #0c0f13;
    --border: #2a3039;
    --border-strong: #404855;
    --text: #e3e6eb;
    --text-muted: #9ca5b3;
    --text-faint: #737c8b;
    --input-bg: #0f1216;
    --accent: #7aa2ff;
    --accent-text: #0b1020;
    --focus: #8fb1ff;
    --switch-off: #3a414c;
    --danger: #e5484d;
    --danger-text: #ffffff;
    --danger-bg: #3a1719;
    --shadow: 0 8px 28px rgb(0 0 0 / 0.55);
    --backdrop: rgb(0 0 0 / 0.6);

    --observed: #7f9cc9;
    --observed-bg: #1c2533;
    --observed-fg: #adc4e8;
    --ignored: #737b89;
    --ignored-bg: #20242b;
    --ignored-fg: #adb4bf;
    --sent: #4cbb7f;
    --sent-bg: #142a1e;
    --sent-fg: #8fdcb0;
    --waiting: #e0a634;
    --waiting-bg: #2e2412;
    --waiting-fg: #f0c977;
    --failed: #ef6464;
    --failed-bg: #351a1b;
    --failed-fg: #f5a6a6;
    --info: #4fb3b0;
    --info-bg: #132a2a;
    --info-fg: #91d7d4;
    --switch: #a48ae6;
    --switch-bg: #251f38;
    --switch-fg: #cbbaf6;
    --neutral: #737c8b;
    --neutral-bg: #20242b;
    --neutral-fg: #c3c9d2;
  }
}

/* Each tone is a stripe colour plus a pill background and text colour. */
[data-tone="observed"] { --tone: var(--observed); --tone-bg: var(--observed-bg); --tone-fg: var(--observed-fg); }
[data-tone="ignored"] { --tone: var(--ignored); --tone-bg: var(--ignored-bg); --tone-fg: var(--ignored-fg); }
[data-tone="sent"] { --tone: var(--sent); --tone-bg: var(--sent-bg); --tone-fg: var(--sent-fg); }
[data-tone="waiting"] { --tone: var(--waiting); --tone-bg: var(--waiting-bg); --tone-fg: var(--waiting-fg); }
[data-tone="failed"] { --tone: var(--failed); --tone-bg: var(--failed-bg); --tone-fg: var(--failed-fg); }
[data-tone="info"] { --tone: var(--info); --tone-bg: var(--info-bg); --tone-fg: var(--info-fg); }
[data-tone="switch"] { --tone: var(--switch); --tone-bg: var(--switch-bg); --tone-fg: var(--switch-fg); }
[data-tone="neutral"] { --tone: var(--neutral); --tone-bg: var(--neutral-bg); --tone-fg: var(--neutral-fg); }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
p { margin: 0; }
.mono { font-family: var(--mono); font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 5px 12px;
  font: inherit; font-weight: 500; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 6px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--text-muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { border-color: var(--accent); filter: brightness(1.08); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-quiet:hover:not(:disabled) { border-color: var(--border-strong); color: var(--text); }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%; min-height: 32px; padding: 5px 8px;
  font: inherit; color: var(--text);
  background: var(--input-bg); border: 1px solid var(--border-strong); border-radius: 6px;
}
textarea { resize: vertical; font-family: var(--mono); font-size: 13px; }
input:disabled, select:disabled, textarea:disabled { opacity: 0.6; cursor: not-allowed; }
input[type="radio"], input[type="checkbox"] { accent-color: var(--accent); margin: 0; }

.switch {
  appearance: none; -webkit-appearance: none;
  position: relative; flex: none;
  width: 40px; height: 22px; margin: 0;
  background: var(--switch-off); border: 1px solid var(--border-strong); border-radius: 999px;
  cursor: pointer; transition: background-color 0.15s, border-color 0.15s;
}
.switch::before {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #ffffff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.35);
  transition: transform 0.15s;
}
.switch:checked { background: var(--accent); border-color: var(--accent); }
.switch:checked::before { transform: translateX(18px); }
.switch:disabled { cursor: not-allowed; opacity: 0.5; }

.form-error { color: var(--failed-fg); font-size: 13px; }
.form-error:empty { display: none; }
.hint { color: var(--text-muted); font-size: 12.5px; }

/* Boot and login */
.boot { padding: 48px 16px; text-align: center; color: var(--text-muted); }
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%);
  display: grid; gap: 10px; padding: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.login-card .brand { font-size: 20px; margin-bottom: 6px; }
.login-card label { font-weight: 600; }
.brand { font-weight: 700; letter-spacing: 0.01em; }

/* App frame: the feed scrolls inside the main column, the rail scrolls on its own. */
.app { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100vh; height: 100dvh; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px;
  padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .brand { font-size: 16px; }
.status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px;
  flex: 1 1 0; min-width: 0; margin: 0; padding: 0; list-style: none;
  font-size: 12.5px;
}
.stat { display: inline-flex; align-items: baseline; gap: 5px; min-width: 0; }
.stat-k { color: var(--text-muted); }
.stat-v { font-weight: 600; }
.stat-v[data-state]::before {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 5px;
  border-radius: 50%; background: var(--neutral); vertical-align: 0.05em;
}
.stat-v[data-state="up"]::before { background: var(--sent); }
.stat-v[data-state="down"]::before { background: var(--failed); border-radius: 1px; }
.stat-v[data-state="pending"]::before { background: var(--waiting); }
.stat-error { max-width: 100%; }
.stat-error .stat-v { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 36ch; }
.stat-error .stat-v.has-error { color: var(--failed-fg); }
.stat-stopped {
  padding: 1px 10px; border-radius: 999px;
  background: var(--danger); color: var(--danger-text); font-weight: 700; letter-spacing: 0.02em;
}
.topbar-actions { display: flex; gap: 6px; margin-left: auto; }
.rail-toggle, .rail-close { display: none; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) var(--rail-width); min-height: 0; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.feed-area { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.feed-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 12px 16px 8px; }
.feed-head .muted { font-size: 12.5px; }
.filter { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; font-size: 12.5px; color: var(--text-muted); }
.filter select { width: auto; max-width: 16rem; min-height: 28px; padding: 2px 6px; font-size: 13px; }
.feed-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0 16px 16px; }
.empty { padding: 32px 8px; text-align: center; color: var(--text-muted); }

.later {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px;
  padding: 8px 16px 10px; border-top: 1px solid var(--border);
}
.later-area {
  padding: 8px 10px; font-size: 12.5px; color: var(--text-faint);
  background: var(--sunken); border: 1px dashed var(--border-strong); border-radius: 6px;
}
.later-area strong { color: var(--text-muted); }

/* Feed entries: a tone stripe on the left whose style also differs by state, plus a pill with words. */
.feed, .cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cards { margin-bottom: 10px; }
.entry, .card {
  background: var(--surface);
  border: 1px solid var(--border); border-left: 4px solid var(--tone, var(--neutral));
  border-radius: 6px;
  padding: 8px 12px;
  min-width: 0;
}
.entry[data-tone="observed"] { border-left-width: 3px; }
.entry[data-tone="ignored"] { border-left-style: dotted; border-left-width: 4px; }
.entry[data-tone="waiting"], .card { border-left-style: dashed; }
.entry[data-tone="failed"] { border-left-style: double; border-left-width: 6px; }
.entry[data-kind="switch"], .entry[data-kind="status"] { background: var(--surface-2); }

.entry-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; min-width: 0; }
.entry-head time { margin-left: auto; color: var(--text-faint); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0 8px; border-radius: 999px;
  background: var(--tone-bg, var(--neutral-bg)); color: var(--tone-fg, var(--neutral-fg));
  font-size: 12px; font-weight: 600; line-height: 20px; white-space: nowrap;
}
.pill[data-tone="sent"]::before { content: "✓"; }
.pill[data-tone="failed"]::before { content: "✕"; }
.pill[data-tone="waiting"]::before { content: "◷"; }
.who { font-weight: 600; overflow-wrap: anywhere; }
.where { color: var(--text-muted); font-size: 12.5px; overflow-wrap: anywhere; }
.tag {
  padding: 0 6px; border: 1px solid var(--border); border-radius: 4px;
  color: var(--text-muted); font-size: 12px; line-height: 18px; white-space: nowrap;
}
.tag-strong { border-color: var(--text-muted); color: var(--text); font-weight: 600; }
.entry-text { margin-top: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.entry-text.is-empty { color: var(--text-faint); font-style: italic; }
.entry-meta {
  display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 4px;
  color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums;
}
.entry-meta span { overflow-wrap: anywhere; }
.changes { margin: 4px 0 0; padding: 0; list-style: none; font-size: 13px; }
.changes li { overflow-wrap: anywhere; }
.changes code, .extras dd { font-family: var(--mono); font-size: 12px; }
.draft { display: grid; gap: 4px; margin-top: 6px; padding-left: 10px; border-left: 2px solid var(--border-strong); }
.bubble { white-space: pre-wrap; overflow-wrap: anywhere; }
.label-view { margin-top: 6px; font-size: 12.5px; overflow-wrap: anywhere; }
.label-view strong { color: var(--accent); }

details > summary { cursor: pointer; width: fit-content; color: var(--text-muted); font-size: 12.5px; }
details > summary:hover { color: var(--text); }
.entry-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 6px; }
.entry-foot:empty { display: none; }
.entry-foot > details[open] { flex-basis: 100%; }
.extras dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 12px; margin: 6px 0 0; font-size: 12px; }
.extras dt { color: var(--text-muted); }
.extras dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.labeler > summary {
  display: inline-block; padding: 1px 10px;
  border: 1px solid var(--border-strong); border-radius: 999px; font-weight: 500;
}
.labeler[open] > summary { color: var(--text); }
.label-form { display: grid; gap: 8px; margin-top: 8px; padding: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; }
.label-form fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.label-form legend { padding: 0; margin-bottom: 4px; font-size: 12.5px; font-weight: 600; }
.label-form .field { display: grid; gap: 3px; font-size: 12.5px; font-weight: 600; }
.label-form select { width: auto; min-width: 10rem; justify-self: start; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface); font-size: 13px; cursor: pointer;
}
.chip:has(input:checked) { border-color: var(--accent); background: var(--observed-bg); }
.label-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* Rail */
.rail {
  min-height: 0; overflow-y: auto;
  padding: 12px; background: var(--surface-2); border-left: 1px solid var(--border);
}
.rail-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.block {
  display: grid; gap: 8px;
  margin: 0 0 10px; padding: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.block[aria-busy="true"] { border-color: var(--accent); }
.block-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.block-head h3 { flex: 1 1 auto; min-width: 0; }
.block-actions { display: flex; gap: 6px; }
.later-tag {
  display: none; padding: 0 6px; border-radius: 4px;
  background: var(--sunken); color: var(--text-faint); font-size: 11.5px; line-height: 18px; white-space: nowrap;
}
.block.unavailable { background: var(--sunken); }
.block.unavailable h3, .block.unavailable .hint, .block.unavailable .field { color: var(--text-faint); }
.block.unavailable .later-tag { display: inline-block; border: 1px dashed var(--border-strong); }
.count {
  padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 20px;
  background: var(--waiting-bg); color: var(--waiting-fg);
}

.field { display: grid; gap: 4px; min-width: 0; margin: 0; padding: 0; border: 0; font-size: 13px; font-weight: 500; }
.field > legend { padding: 0; margin-bottom: 4px; font-weight: 500; }
.field .hint { font-weight: 400; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.choice { display: inline-flex; align-items: center; gap: 6px; margin-right: 14px; font-weight: 400; cursor: pointer; }

.days { gap: 4px; }
.day { display: grid; grid-template-columns: 4.5rem minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 6px; }
.day > span { color: var(--text-muted); font-size: 12px; }
.day input[type="text"] { font-family: var(--mono); text-align: center; }

.segmented { display: flex; flex-wrap: wrap; gap: 0; margin: 0; padding: 0; border: 0; min-width: 0; }
.segmented label {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--border-strong); margin-left: -1px;
  background: var(--surface); font-size: 13px; cursor: pointer;
}
.segmented label:first-of-type { border-radius: 6px 0 0 6px; margin-left: 0; }
.segmented label:last-of-type { border-radius: 0 6px 6px 0; }
.segmented label:has(input:checked) { background: var(--observed-bg); border-color: var(--accent); position: relative; font-weight: 600; }
.segmented label:has(input:disabled) { cursor: not-allowed; }

.block-stop { gap: 10px; }
.stop-title { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.btn-stop {
  width: 100%; min-height: 48px;
  font-size: 17px; font-weight: 700; letter-spacing: 0.02em;
  background: var(--danger); border-color: var(--danger); color: var(--danger-text);
}
.btn-stop:hover:not(:disabled) { border-color: var(--danger); filter: brightness(1.08); }
.block-stop.is-stopped { background: var(--danger-bg); border-color: var(--danger); }
.block-stop.is-stopped .stop-title { color: var(--failed-fg); font-weight: 700; }
.block-stop.is-stopped .btn-stop { background: var(--surface); border: 2px solid var(--danger); color: var(--text); }

.forced { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.forced li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.backdrop { position: fixed; inset: 0; z-index: 19; background: var(--backdrop); }

.notice {
  position: fixed; left: 50%; bottom: 16px; z-index: 30;
  transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 8px 14px;
  background: var(--text); color: var(--bg); border-radius: 6px; box-shadow: var(--shadow);
  font-weight: 500;
}
.notice:empty { display: none; }
.notice[data-tone="error"] { background: var(--danger); color: var(--danger-text); }

/* Below 760 px the rail is a drawer opened from the top bar. */
@media (max-width: 759.98px) {
  .topbar { padding: 8px 12px; }
  .topbar-actions { order: 2; }
  .status { order: 3; flex-basis: 100%; }
  .stat-optional { display: none; }
  .stat-error .stat-v { white-space: normal; max-width: none; overflow-wrap: anywhere; }
  .rail-toggle, .rail-close { display: inline-flex; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .feed-head { padding: 10px 12px 6px; }
  .feed-scroll { padding: 0 12px 12px; }
  .filter { margin-left: 0; }
  .later { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; padding: 6px 12px 8px; }
  .later-area { padding: 4px 8px; font-size: 12px; }
  .rail {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 20;
    width: min(400px, 100%);
    border-left: 1px solid var(--border); box-shadow: var(--shadow);
    transform: translateX(100%); visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  body.rail-open .rail { transform: none; visibility: visible; transition: transform 0.2s ease; }
}

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