/* ── עיצוב הדשבורד: RTL, בהיר/כהה, ללא תלויות חיצוניות ─────────────────── */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e3e6ea;
  /* --border-strong תוחם רכיבי ממשק (שדות, כפתורים) ולכן חייב 3:1 לפי WCAG 1.4.11 */
  --border-strong: #8793a2;
  --text: #14181f;
  --muted: #667085;
  /* --faint הוא היררכיה שלישית, אבל הוא נושא מידע (שם שולח, הקשר) ולכן חייב 4.5:1.
     ההבחנה מ---muted נעשית בגודל ובמשקל, לא בבהירות. */
  --faint: #5d6b80;

  --brand: #4338ca;
  --brand-soft: #eef2ff;
  --alert: #b42318;
  --alert-soft: #fef3f2;
  --warn: #b54708;
  --warn-soft: #fffaeb;
  --ok: #027a48;
  --ok-soft: #ecfdf3;
  --info: #175cd3;
  --info-soft: #eff8ff;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .10);
  --sidebar: 232px;
}

:root[data-theme="dark"], html[data-theme="dark"] {
  --bg: #0c0f14;
  --surface: #141922;
  --surface-2: #1a2029;
  --border: #242c38;
  --border-strong: #5a6b87;
  --text: #e6ebf2;
  --muted: #93a0b4;
  --faint: #838f9f;

  --brand: #818cf8;
  --brand-soft: #1e2130;
  --alert: #f97066;
  --alert-soft: #2a1615;
  --warn: #fdb022;
  --warn-soft: #2a2013;
  --ok: #47cd89;
  --ok-soft: #10241b;
  --info: #53b1fd;
  --info-soft: #10202f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

/* מיקוד נראה בכל רכיב אינטראקטיבי — ניווט מקלדת חייב להיות עקיב */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 3px;
}

.skip-link {
  position: absolute;
  inset-inline-start: -9999px;
  top: 0;
  z-index: 100;
  background: var(--brand);
  color: #fff;
  padding: 10px 18px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-weight: 600;
}
.skip-link:focus { inset-inline-start: 0; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  direction: rtl;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Assistant", "Rubik", "Noto Sans Hebrew", system-ui, -apple-system, Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* חייב לכלול :link ו-:visited במפורש. `a` לבדו הוא סלקטור מסוג בלבד, ולדפדפן
   יש כלל פנימי על `a:-webkit-any-link` בעל ספציפיות גבוהה יותר — כך שקישורים
   קיבלו את צבע ברירת המחדל (כחול/סגול), שעל רקע כהה כמעט בלתי קריא. */
a, a:link, a:visited, a:hover, a:active { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 21px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

/* ── שלד ──────────────────────────────────────────────────────────────── */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: var(--surface);
  border-inline-start: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 9px; padding: 0 6px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), #7c3aed);
  display: grid; place-items: center; color: #fff; font-size: 15px; flex-shrink: 0;
}
.brand-text { line-height: 1.2; }
.brand-text strong { display: block; font-size: 13.5px; }
.brand-text span { font-size: 11px; color: var(--faint); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--faint); padding: 12px 8px 4px;
}
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--muted); font-size: 13.5px; font-weight: 500;
  transition: background .12s, color .12s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 620; }
.nav .icon { width: 17px; text-align: center; font-size: 14px; flex-shrink: 0; }
.nav .count {
  margin-inline-start: auto; font-size: 11px; font-weight: 700;
  background: var(--border); color: var(--muted);
  padding: 1px 7px; border-radius: 20px; min-width: 20px; text-align: center;
}
.nav a.active .count { background: var(--brand); color: #fff; }
.nav .count.alert { background: var(--alert); color: #fff; }
.nav .count.warn { background: var(--warn); color: #fff; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 4px; }
.user-chip { font-size: 12px; color: var(--faint); display: flex; align-items: center; gap: 6px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ── שורת הבריאות ─────────────────────────────────────────────────────── */
.health {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 24px; font-size: 12.5px;
  background: var(--ok-soft); color: var(--ok);
  border-bottom: 1px solid var(--border);
}
.health.bad { background: var(--alert-soft); color: var(--alert); }
.health .dot {
  width: 7px; height: 7px; border-radius: 50%; background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent);
}
.health .sep { color: var(--faint); opacity: .5; }
.health .quiet {
  margin-inline-start: auto; background: var(--info-soft); color: var(--info);
  padding: 2px 10px; border-radius: 20px; font-weight: 600;
}

/* ── כותרת עמוד ───────────────────────────────────────────────────────── */
.page-head {
  padding: 22px 24px 0;
  display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap;
}
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; }

.content { padding: 18px 24px 40px; display: flex; flex-direction: column; gap: 18px; }

/* ── כרטיסי מדד ───────────────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat .value { font-size: 27px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.stat .foot { font-size: 11.5px; color: var(--faint); margin-top: 2px; }
.stat.alert { border-color: color-mix(in srgb, var(--alert) 35%, var(--border)); background: var(--alert-soft); }
.stat.alert .value { color: var(--alert); }
.stat.warn { border-color: color-mix(in srgb, var(--warn) 35%, var(--border)); background: var(--warn-soft); }
.stat.warn .value { color: var(--warn); }
.stat.ok .value { color: var(--ok); }

/* ── כרטיס ────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.card-head {
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; background: var(--surface-2);
}
.card-head .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.card-head .actions { margin-inline-start: auto; display: flex; gap: 8px; }
.card-body { padding: 16px; }

/* ── טבלה ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: right; font-size: 11.5px; font-weight: 650; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 9px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface-2); white-space: nowrap; position: sticky; top: 0;
}
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(--surface-2); }
tbody tr.row-alert { box-shadow: inset 3px 0 0 var(--alert); }
tbody tr.row-warn { box-shadow: inset 3px 0 0 var(--warn); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

.chat-name { font-weight: 600; }
.snippet {
  color: var(--muted); font-size: 12.5px;
  max-width: 460px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sender { font-size: 12px; color: var(--faint); }

/* ── שעון ההמתנה ──────────────────────────────────────────────────────── */
.clock { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }
.clock.alert { color: var(--alert); }
.clock.warn { color: var(--warn); }
.clock.ok { color: var(--muted); }
.clock-sub { font-size: 11px; color: var(--faint); font-weight: 400; }
.paused { font-size: 11px; color: var(--faint); }

/* ── תגיות ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 620; padding: 2px 9px; border-radius: 20px;
  background: var(--border); color: var(--muted); white-space: nowrap;
}
.badge.alert { background: var(--alert-soft); color: var(--alert); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.client { background: var(--brand-soft); color: var(--brand); }

/* ── כפתורים ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: 12.5px; font-weight: 570; font-family: inherit;
  cursor: pointer; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 4px 9px; font-size: 11.5px; }
.btn-group { display: flex; gap: 5px; }

input[type="text"], input[type="password"], input[type="number"], input[type="time"],
input[type="date"], select, textarea {
  font-family: inherit; font-size: 13.5px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 7px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 1px;
  border-color: var(--brand);
}
label { font-size: 12.5px; font-weight: 570; color: var(--muted); display: block; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.check { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.check input { width: auto; }

/* ── מצב ריק ──────────────────────────────────────────────────────────── */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .mark { font-size: 34px; margin-bottom: 8px; }
.empty h3 { color: var(--text); margin-bottom: 4px; }
.empty p { margin: 0; font-size: 13px; }

/* ── כניסה ────────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login {
  width: 100%; max-width: 340px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 28px; box-shadow: var(--shadow-lg);
}
.login .brand { justify-content: center; margin-bottom: 18px; }
.login .err {
  background: var(--alert-soft); color: var(--alert); font-size: 12.5px;
  padding: 8px 12px; border-radius: var(--radius-sm); margin-bottom: 14px;
}

/* ── היסטוגרמה ────────────────────────────────────────────────────────── */
.hist { display: flex; flex-direction: column; gap: 9px; }
.hist-row { display: grid; grid-template-columns: 92px 1fr 46px; align-items: center; gap: 10px; }
.hist-label { font-size: 12.5px; color: var(--muted); text-align: left; }
.hist-track { background: var(--surface-2); border-radius: 5px; height: 22px; overflow: hidden; border: 1px solid var(--border); }
.hist-bar { height: 100%; background: var(--brand); border-radius: 4px; min-width: 2px; transition: width .3s; }
.hist-val { font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ── ציר שיחה ─────────────────────────────────────────────────────────── */
.thread { display: flex; flex-direction: column; gap: 10px; max-height: 620px; overflow-y: auto; padding: 4px; }
.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg .bubble {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; max-width: 74%;
}
.msg.team { flex-direction: row-reverse; }
.msg.team .bubble { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 22%, var(--border)); }
.msg.observer .bubble { background: transparent; border-style: dashed; }
.msg .who { font-size: 11.5px; font-weight: 650; margin-bottom: 2px; }
.msg .txt { font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.msg .at { font-size: 10.5px; color: var(--faint); margin-top: 3px; }

.help { font-size: 12.5px; color: var(--muted); }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar form { display: flex; gap: 8px; align-items: center; }
.filter-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-pills a {
  font-size: 12px; padding: 4px 11px; border-radius: 20px;
  border: 1px solid var(--border-strong); color: var(--muted);
}
.filter-pills a.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: row;
             flex-wrap: wrap; align-items: center; border-inline-start: none;
             border-bottom: 1px solid var(--border); }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-label, .sidebar-foot { display: none; }
  .content, .page-head { padding-inline: 14px; }
}
