/* The dashboard's stylesheet: RTL Hebrew, system fonts, no external resource. English terms (ASIN,
   order ids, run ids, paths) sit in .en / .mono spans that force LTR inside the RTL page.
   Colours live ONLY in the :root tokens below (design record 14, part A): every rule points at a token,
   so a palette change is a change of this block alone. The one exception is the MOCK banner at the end,
   which keeps its own orange on purpose: a rehearsal must stay loud whatever the theme. */

:root {
  --bg: #faf7f2;
  --panel: #ffffff;
  --ink: #23282f;
  --muted: #5f6670;
  --line: #e7e1d6;
  --line-strong: #cfc6b8;
  --accent: #0b7f76;
  --accent-strong: #096a62;
  --accent-ink: #ffffff;
  --accent-soft: #dff4f1;
  --accent-2: #f2735a;
  --accent-2-ink: #bf3f26;
  --ok: #1e7d45;
  --ok-soft: #e2f5e8;
  --ok-line: #b6dfc2;
  --warn: #8a5a00;
  --warn-soft: #fff3d6;
  --danger: #b42318;
  --danger-strong: #921e18;
  --danger-soft: #fde7e4;
  --danger-line: #efb5b0;
  --info-ink: #1d4f9c;
  --info-soft: #e4eefb;
  --chip: #f1ede6;
  --tile: #f6f3ee;
  --row-off: #fbf9f6;
  --code-bg: #1f2a33;
  --code-ink: #e8ecf5;
  --log-ink: #d8deea;
  --log-dim: #8a93a6;
  --log-error: #ff8a80;
  --log-warn: #ffd180;
  --log-stdout: #a5d6a7;
  --log-event: #82b1ff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(70, 55, 30, 0.05), 0 6px 18px rgba(70, 55, 30, 0.07);
  --focus: 0 0 0 3px rgba(11, 127, 118, 0.35);
  --font: system-ui, "Segoe UI", Arial, "Noto Sans Hebrew", sans-serif;
  --mono: Consolas, "Cascadia Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 0.5rem; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }
code, .mono, .en {
  direction: ltr;
  unicode-bidi: isolate;
  font-family: var(--mono);
  font-size: 0.92em;
}
.en { font-family: var(--font); }
code { background: var(--chip); padding: 0 0.3em; border-radius: 4px; }
pre code { background: none; padding: 0; color: inherit; font-size: inherit; }
pre { background: var(--code-bg); color: var(--code-ink); padding: 0.75rem; border-radius: var(--radius); overflow: auto; direction: ltr; text-align: left; font-family: var(--mono); font-size: 0.85rem; }
:focus-visible { outline: none; box-shadow: var(--focus); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header and status strip */
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0.75rem 1.25rem 0;
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.25rem; }
.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-icon { width: 30px; height: 30px; flex: none; }
.login-icon { display: block; width: 56px; height: 56px; margin: 0 auto 0.5rem; }
.brand small { color: var(--accent-2-ink); font-weight: 600; }
.status { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-inline-start: auto; font-size: 0.9rem; }
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.15rem 0.6rem; border-radius: 999px; font-weight: 600; font-size: 0.85rem;
  border: 1px solid transparent; white-space: nowrap;
}
.badge-live { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-line); }
.badge-dry { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.badge-neutral { background: var(--chip); color: var(--muted); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info-ink); }
.badge-busy::before { content: ""; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--accent-2); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: 0.35; } to { opacity: 1; } }

/* Tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.5rem; }
.tab {
  appearance: none; background: none; border: none; border-bottom: 3px solid transparent;
  padding: 0.55rem 0.9rem; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer;
  border-radius: 6px 6px 0 0;
}
.tab:hover { color: var(--ink); background: var(--accent-soft); }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tab small { font-weight: 400; color: var(--muted); margin-inline-start: 0.3rem; }

main { padding: 1.25rem; max-width: 1400px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.15rem; margin-bottom: 1rem; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin-bottom: 0.75rem; }
.panel-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-settings { display: grid; grid-template-columns: 3fr 2fr; gap: 1rem; align-items: start; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.notice { padding: 0.6rem 0.9rem; border-radius: 8px; margin-bottom: 0.75rem; }
.notice-info { background: var(--info-soft); }
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-danger { background: var(--danger-soft); color: var(--danger); }
.notice-ok { background: var(--ok-soft); color: var(--ok); }
.empty { color: var(--muted); padding: 1rem; text-align: center; }

/* Controls */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--panel); color: var(--ink); padding: 0.45rem 0.9rem; line-height: 1.3;
}
button:hover:not(:disabled) { background: var(--chip); }
button:disabled { cursor: not-allowed; opacity: 0.55; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-danger { background: var(--danger); color: var(--accent-ink); border-color: var(--danger); font-weight: 600; }
.btn-danger:hover:not(:disabled) { background: var(--danger-strong); }
.btn-small { padding: 0.25rem 0.6rem; font-size: 0.88rem; }
.btn-group { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.btn-group button { border: none; border-radius: 0; border-inline-start: 1px solid var(--line); }
.btn-group button:first-child { border-inline-start: none; }
.btn-group button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
input[type="text"], input[type="search"], input[type="number"], input[type="date"], input[type="email"], select, textarea {
  font: inherit; padding: 0.4rem 0.6rem; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel); color: var(--ink);
}
input[type="number"], input[type="date"] { direction: ltr; }
input:invalid, .field-error input, .field-error select { border-color: var(--danger); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin-bottom: 0.75rem; }
.toolbar .spacer { flex: 1; }
.mt-1 { margin-top: 1rem; }
.choice { display: inline-flex; gap: 0.3rem; align-items: center; margin-inline-end: 1rem; }
/* The login page (web/login.html): one card in the middle, the same tokens as the dashboard. */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { width: min(100%, 26rem); }
.login-card h1 { margin-bottom: 0.25rem; }
.login-card form { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 1rem; }
.login-card input[type="password"] { width: 100%; padding: 0.5rem 0.65rem; border: 1px solid var(--line-strong); border-radius: 8px; font: inherit; direction: ltr; }
.login-card input[type="password"]:focus { outline: none; box-shadow: var(--focus); }
.login-card .btn-primary { align-self: flex-start; }
.login-card .err { min-height: 1.4em; color: var(--danger); font-size: 0.92rem; }
.search { min-width: 18rem; }

/* Toggle switch */
.switch {
  appearance: none; width: 2.6rem; height: 1.45rem; border-radius: 999px; border: none; padding: 0;
  background: var(--line-strong); position: relative; cursor: pointer; vertical-align: middle; flex: none;
}
.switch::after {
  content: ""; position: absolute; top: 0.15rem; inset-inline-start: 0.15rem; width: 1.15rem; height: 1.15rem;
  border-radius: 50%; background: var(--panel); transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(-1.15rem); }
.switch:disabled { opacity: 0.5; cursor: wait; }

/* Tables */
table { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
th, td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
th { background: var(--chip); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
th button.sort { border: none; background: none; padding: 0; font: inherit; font-weight: 600; cursor: pointer; }
th button.sort[aria-sort="ascending"]::after { content: " \25B2"; font-size: 0.7em; }
th button.sort[aria-sort="descending"]::after { content: " \25BC"; font-size: 0.7em; }
tr.inactive td { color: var(--muted); background: var(--row-off); }
tr.inactive td .name-input { color: var(--muted); }
td.num, th.num { text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }
td.en, th.en { direction: ltr; text-align: left; }
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; }
.name-input { width: 100%; min-width: 18rem; border-color: transparent; background: transparent; }
td.name-cell { min-width: 20rem; }
.name-input:hover, .name-input:focus { border-color: var(--line-strong); background: var(--panel); }
.days-select { min-width: 9rem; }
.chip { display: inline-block; padding: 0.05rem 0.5rem; border-radius: 999px; background: var(--chip); font-size: 0.82rem; font-weight: 600; }
.chip-off { text-decoration: line-through; opacity: 0.6; }
.legend { margin-bottom: 0.75rem; }
.state-WOULD_SEND, .state-SENT { color: var(--ok); font-weight: 600; }
.state-NOT_AVAILABLE { color: var(--warn); }
.state-ERROR, .state-SENT_UNCONFIRMED { color: var(--danger); font-weight: 600; }
.state-SKIPPED_CANCELED, .state-SKIPPED_REPLACEMENT, .state-SKIPPED_REFUNDED, .state-SKIPPED_RETURNED, .state-SKIPPED_SOLICITED_ELSEWHERE, .state-EXPIRED, .state-NOT_PERMITTED, .state-OUT_OF_SCOPE { color: var(--muted); }

/* Charts */
.chart { width: 100%; height: auto; display: block; font-family: var(--font); }
.chart text { font-size: 11px; fill: var(--muted); }
.chart .axis { stroke: var(--line-strong); }
.chart .grid { stroke: var(--line); }
.chart .hover-line { stroke: var(--ink); stroke-dasharray: 3 3; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 0.35rem 0.9rem; margin-top: 0.5rem; font-size: 0.88rem; }
.chart-legend button { border: none; background: none; padding: 0.1rem 0.2rem; display: inline-flex; align-items: center; gap: 0.35rem; font: inherit; cursor: pointer; }
.chart-legend button[aria-pressed="false"] { opacity: 0.4; text-decoration: line-through; }
.swatch { width: 0.8rem; height: 0.8rem; border-radius: 3px; display: inline-block; flex: none; }
.chart-tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--accent-ink); padding: 0.35rem 0.6rem; border-radius: 6px; font-size: 0.82rem; white-space: nowrap; z-index: 3; }
.chart-box { position: relative; }
.donut-wrap { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }
.donut-wrap svg { width: 240px; height: 240px; flex: none; }
.donut-legend { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; flex: 1; min-width: 14rem; }
.donut-legend li { display: flex; align-items: center; gap: 0.5rem; padding: 0.15rem 0; }
.donut-legend .count { margin-inline-start: auto; font-variant-numeric: tabular-nums; }
.stat-tiles { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 0.75rem; }
.tile { background: var(--tile); border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.9rem; min-width: 8rem; }
.tile .v { font-size: 1.4rem; font-weight: 700; direction: ltr; }
.tile .k { font-size: 0.82rem; color: var(--muted); }

/* Log stream */
.log {
  background: var(--code-bg); color: var(--log-ink); font-family: var(--mono); font-size: 0.82rem; padding: 0.6rem;
  border-radius: 8px; max-height: 24rem; overflow: auto; direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-word;
}
.log .l-error { color: var(--log-error); }
.log .l-warn { color: var(--log-warn); }
.log .l-info { color: var(--log-ink); }
.log .l-debug { color: var(--log-dim); }
.log .l-stdout { color: var(--log-stdout); }
/* Hebrew notes (dir="auto") read right to left with their punctuation on the right; JSON lines stay LTR. */
.log [dir='auto'] { unicode-bidi: plaintext; text-align: start; }
.log .t { color: var(--log-dim); }
.log .ev { color: var(--log-event); font-weight: 600; }

/* Forms */
.form-grid { display: grid; grid-template-columns: minmax(12rem, 18rem) 1fr; gap: 0.6rem 1rem; align-items: start; }
.form-grid label.k { font-weight: 600; padding-top: 0.45rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field .row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.field .hint { font-size: 0.85rem; color: var(--muted); }
.field .err { font-size: 0.85rem; color: var(--danger); }
.source { font-size: 0.78rem; padding: 0.05rem 0.45rem; border-radius: 999px; background: var(--chip); color: var(--muted); }
.source-settings { background: var(--accent-soft); color: var(--accent-strong); }
.source-env { background: var(--info-soft); color: var(--info-ink); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 1rem; font-size: 0.92rem; }
.kv dt { font-weight: 600; margin: 0; }
.kv dd { margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.9rem; margin: 0; }
legend { font-weight: 600; padding: 0 0.3rem; }

/* Dialog */
dialog { border: none; border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); padding: 1.25rem; max-width: 34rem; width: calc(100% - 2rem); direction: rtl; font-family: var(--font); color: var(--ink); background: var(--panel); }
dialog::backdrop { background: rgba(40, 30, 20, 0.45); }
dialog .actions { display: flex; gap: 0.6rem; justify-content: flex-start; margin-top: 1rem; }
dialog .big { font-size: 1.5rem; font-weight: 700; }

/* Toasts */
.toasts { position: fixed; bottom: 1rem; inset-inline-start: 1rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 20; max-width: 28rem; }
.toast { padding: 0.6rem 0.9rem; border-radius: 8px; box-shadow: var(--shadow); background: var(--panel); border-inline-start: 4px solid var(--accent-2); }
.toast-error { border-inline-start-color: var(--danger); }
.toast-ok { border-inline-start-color: var(--ok); }

/* Help (rendered markdown) */
.help h1 { font-size: 1.3rem; margin-top: 1rem; }
.help h2 { font-size: 1.1rem; margin-top: 1.25rem; }
.help table { width: auto; }
.help pre { direction: ltr; }
.md { font-size: 0.93rem; }
.md pre { max-height: 20rem; }
.md table { width: auto; }
.md td, .md th { white-space: nowrap; }
.md-wrap { overflow: auto; }

@media (max-width: 1100px) {
  .grid-settings { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid label.k { padding-top: 0; }
  main { padding: 0.75rem; }
  .search { min-width: 0; width: 100%; }
}

/* MOCK mode: the general rehearsal. Loud on purpose, above every tab, on every screen width.
   The orange is a literal, not a token: it must not follow the theme. */
.mock-banner {
  position: sticky;
  top: 0;
  z-index: 40;
  background: #b45309;
  color: #fff;
  font-weight: 700;
  text-align: center;
  padding: 0.55rem 0.9rem;
  letter-spacing: 0.01em;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
body.is-mock .topbar { border-top: 3px solid #b45309; }
