/* לוח המרכזנית — מערכת עיצוב
   רפרנט: מסוף מרכזנית (לוח שקעים כהה עם מנורות) + כרטיסיית לקוח בארון + מספרים כמו כותרת עיתון.
   חומרים: זכוכית שקופה למשטחי ניווט, נייר חם לרקע, דיו כהה לטקסט. */

:root {
  --paper: #f3efe8;
  --paper-deep: #e9e3d8;
  --ink: #1c1b18;
  --ink-2: #4a463f;
  --muted: #7a7469;
  --line: rgba(28, 27, 24, 0.09);
  --line-strong: rgba(28, 27, 24, 0.18);
  --glass: rgba(255, 255, 255, 0.62);
  --glass-edge: rgba(255, 255, 255, 0.75);
  --card: rgba(255, 255, 255, 0.78);
  --rail: rgba(22, 24, 27, 0.92);
  --rail-ink: #e8e4dc;
  --rail-muted: #9a958c;
  --accent: #0f5c5a;
  --accent-ink: #ffffff;
  --accent-soft: rgba(15, 92, 90, 0.1);
  --lamp: #e6a400;
  --lamp-glow: rgba(230, 164, 0, 0.45);
  --ok: #2a7d4f;
  --ok-soft: rgba(42, 125, 79, 0.12);
  --warn: #b8741a;
  --warn-soft: rgba(184, 116, 26, 0.13);
  --bad: #b3372e;
  --bad-soft: rgba(179, 55, 46, 0.12);
  --shadow-sm: 0 1px 1px rgba(28, 27, 24, 0.04), 0 2px 6px rgba(28, 27, 24, 0.06);
  --shadow-md: 0 2px 4px rgba(28, 27, 24, 0.05), 0 12px 32px -8px rgba(28, 27, 24, 0.18);
  --r: 14px;
  --r-sm: 9px;
  --display: "Frank Ruhl Libre", "Times New Roman", serif;
  --body: "Heebo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141311;
    --paper-deep: #0e0d0c;
    --ink: #f1ece3;
    --ink-2: #c9c3b8;
    --muted: #8f8a80;
    --line: rgba(241, 236, 227, 0.09);
    --line-strong: rgba(241, 236, 227, 0.2);
    --glass: rgba(34, 33, 30, 0.62);
    --glass-edge: rgba(255, 255, 255, 0.08);
    --card: rgba(36, 35, 32, 0.82);
    --rail: rgba(12, 12, 12, 0.9);
    --accent: #6fc9c2;
    --accent-ink: #0c1f1e;
    --accent-soft: rgba(111, 201, 194, 0.14);
    --ok: #6fc28f;
    --warn: #e0a54a;
    --bad: #e0716a;
    --shadow-sm: 0 1px 1px rgba(0, 0, 0, 0.3), 0 2px 6px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.3), 0 12px 32px -8px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100%;
  font-family: var(--body); font-size: 15px; line-height: 1.5; font-weight: 400;
  color: var(--ink); direction: rtl;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(15, 92, 90, 0.10), transparent 60%),
    radial-gradient(900px 500px at 0% 100%, rgba(230, 164, 0, 0.08), transparent 60%),
    var(--paper);
  background-attachment: fixed;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: var(--display); font-weight: 500; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 5vw, 3.2rem); line-height: 1.05; letter-spacing: -0.02em; }
h2 { font-size: 1.55rem; line-height: 1.15; }
h3 { font-size: 1.12rem; line-height: 1.25; }
p { margin: 0; }
a { color: var(--accent); }
.skip { position: absolute; top: -40px; right: 8px; background: var(--accent); color: var(--accent-ink); padding: 6px 10px; border-radius: 8px; z-index: 100; }
.skip:focus { top: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- controls ---------- */
.btn, button {
  font: inherit; font-weight: 500; color: var(--ink); cursor: pointer;
  background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  padding: 7px 13px; line-height: 1.3;
  transition: transform 120ms var(--ease-out), background 160ms, border-color 160ms, box-shadow 160ms;
  box-shadow: inset 0 1px 0 var(--glass-edge);
}
button:hover, .btn:hover { border-color: var(--accent); }
button:active, .btn:active { transform: scale(0.96); transition-duration: 60ms; }
button:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary, button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: none; }
.btn.primary:hover { filter: brightness(1.08); }
button.ok { background: var(--ok); color: #fff; border-color: transparent; }
button.warn { background: var(--warn); color: #fff; border-color: transparent; }
button.bad { background: var(--bad); color: #fff; border-color: transparent; }
button.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--accent); }
button.small { padding: 4px 10px; font-size: 13px; }
.wide { width: 100%; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line-strong);
  border-radius: var(--r-sm); padding: 7px 11px; min-width: 0; max-width: 100%;
  transition: border-color 140ms, box-shadow 140ms;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { width: 100%; min-height: 72px; resize: vertical; }
label.field, .field { display: block; margin-bottom: 10px; }
.field > span, .field > label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; letter-spacing: 0.01em; }
.field input, .field select { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 160px; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
.num { font-family: var(--display); font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- glass ---------- */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(160%); backdrop-filter: blur(22px) saturate(160%);
  border: 1px solid var(--glass-edge);
  box-shadow: var(--shadow-md);
}
@media (prefers-reduced-transparency: reduce) { .glass, .rail, .topbar { backdrop-filter: none; background: var(--paper); } }

/* ---------- login ---------- */
#login { min-height: 100vh; display: grid; place-content: center; gap: 28px; padding: 24px; text-align: center; }
.masthead-kicker { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.masthead p { color: var(--ink-2); margin-top: 8px; }
.login-card { width: min(380px, 92vw); padding: 26px 24px 18px; border-radius: 18px; text-align: right; margin: 0 auto; }
.form-error { color: var(--bad); font-size: 14px; min-height: 22px; margin-top: 8px; }

/* ---------- shell ---------- */
#app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh; padding: 20px 14px 16px;
  background: var(--rail); color: var(--rail-ink);
  -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px);
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  display: flex; flex-direction: column; gap: 6px;
}
.rail-brand { display: flex; gap: 12px; align-items: center; padding: 6px 8px 18px; }
.brand-name { font-family: var(--display); font-size: 19px; font-weight: 500; color: #fff; letter-spacing: -0.01em; }
.brand-sub { font-size: 12.5px; color: var(--rail-muted); margin-top: 2px; }
.lamp {
  width: 12px; height: 12px; border-radius: 50%; flex: none;
  background: #3a3d42; box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.15);
  transition: background 300ms, box-shadow 300ms;
}
.lamp.on { background: var(--lamp); box-shadow: 0 0 0 3px var(--lamp-glow), 0 0 14px var(--lamp); animation: lamp 1.6s ease-in-out infinite; }
@keyframes lamp { 50% { box-shadow: 0 0 0 2px var(--lamp-glow), 0 0 6px var(--lamp); } }
nav#menu { display: flex; flex-direction: column; gap: 2px; }
nav#menu button {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; text-align: right;
  background: transparent; border: 0; box-shadow: none; color: var(--rail-ink); padding: 9px 12px; border-radius: 10px; font-weight: 400;
}
nav#menu button:hover { background: rgba(255, 255, 255, 0.07); }
nav#menu button[aria-current="page"] { background: rgba(255, 255, 255, 0.13); color: #fff; font-weight: 500; }
nav#menu .badge { font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--lamp); color: #1c1b18; font-weight: 600; }
.rail-logout { margin-top: auto; background: transparent; border-color: rgba(255, 255, 255, 0.14); color: var(--rail-muted); box-shadow: none; }
.rail-logout:hover { color: #fff; border-color: rgba(255, 255, 255, 0.4); }

main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 28px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; box-shadow: none;
  -webkit-mask-image: none;
}
.topbar-side { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stage { padding: 22px 28px 60px; display: grid; gap: 16px; align-content: start; }

/* ---------- cards / panels ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); padding: 16px 18px; min-width: 0; }
.panel > h3 { margin-bottom: 12px; }
.panel .sub { margin-top: -8px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px 12px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.kpi::after { content: ""; position: absolute; inset: auto 0 0 0; height: 3px; background: var(--kpi-color, var(--accent)); opacity: 0.85; }
.kpi .v { font-family: var(--display); font-size: 2.1rem; line-height: 1; letter-spacing: -0.02em; font-weight: 500; }
.kpi .l { color: var(--muted); font-size: 12.5px; margin-top: 8px; }
.kpi.warn { --kpi-color: var(--warn); }
.kpi.ok { --kpi-color: var(--ok); }
.kpi.bad { --kpi-color: var(--bad); }
.kpi.lamp-c { --kpi-color: var(--lamp); }

/* ---------- index card (כרטיסיית לקוח) ---------- */
.index-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-md); position: relative; }
.index-card .tab {
  display: inline-flex; align-items: center; gap: 8px; margin: -1px 18px 0 0; padding: 6px 14px;
  background: var(--accent); color: var(--accent-ink); border-radius: 0 0 10px 10px; font-size: 13px; font-weight: 500;
}
.index-card .head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; padding: 12px 18px 6px; flex-wrap: wrap; }
.index-card .head h3 { font-size: 1.5rem; }
.index-card .phone { font-family: var(--display); color: var(--ink-2); font-size: 1.1rem; }
.index-card .body { padding: 6px 18px 16px; display: grid; gap: 18px; }
.index-card .cols-3 { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.ruled { border-top: 1px solid var(--line); padding-top: 12px; }
.ruled > h3 { margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.ruled > h3 .count { font-family: var(--body); font-size: 12px; color: var(--muted); font-weight: 400; }

/* ---------- tables ---------- */
.overflow { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
table:has(th:nth-child(7)) { min-width: 820px; }
table:has(th:nth-child(9)) { min-width: 980px; }
th, td { text-align: right; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12.5px; letter-spacing: 0.01em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; transition: background 120ms; }
tr.click:hover, tr.click:focus-within { background: var(--accent-soft); }
tr.click:active { background: var(--paper-deep); }
tr.selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
td select, td input { padding: 4px 8px; font-size: 13px; }
.empty { color: var(--muted); padding: 22px 10px; text-align: center; font-size: 14px; }
.empty b { display: block; font-family: var(--display); font-size: 1.15rem; color: var(--ink-2); font-weight: 500; margin-bottom: 4px; }

/* ---------- tags / lamps ---------- */
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.muted { background: var(--line); color: var(--muted); }
.tag.lamp-t { background: rgba(230, 164, 0, 0.16); color: #8a6100; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.dot.live { background: var(--lamp); box-shadow: 0 0 0 3px var(--lamp-glow); animation: lamp 1.6s ease-in-out infinite; }

/* ---------- live calls board ---------- */
.board { display: grid; gap: 10px; }
.line {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  cursor: pointer; transition: transform 160ms var(--spring), box-shadow 160ms, border-color 160ms; text-align: right; width: 100%;
}
.line:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.line:active { transform: scale(0.985); }
.line.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.line .lamp { width: 14px; height: 14px; }
.line .who { font-weight: 500; }
.line .meta { color: var(--muted); font-size: 13px; }
.line .step { font-size: 12.5px; color: var(--accent); white-space: nowrap; }

/* ---------- lists ---------- */
.list { margin: 0; padding: 0; list-style: none; }
.list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li .grow { flex: 1; }
.timeline { margin: 0; padding: 0 12px 0 0; list-style: none; border-right: 2px solid var(--line); }
.timeline li { position: relative; padding: 2px 14px 12px 0; }
.timeline li::before { content: ""; position: absolute; right: -19px; top: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--paper); }
audio { width: 100%; min-width: 210px; max-width: 320px; height: 34px; }
.date { white-space: nowrap; }
bdi.num { unicode-bidi: isolate; }

/* ---------- toast (HUD) ---------- */
#toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(520px, 92vw); pointer-events: none; }
.toast { pointer-events: auto; padding: 11px 16px; border-radius: 14px; background: var(--rail); color: #fff; box-shadow: var(--shadow-md); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); font-weight: 500; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* ---------- motion ---------- */
.enter { animation: enter 460ms var(--spring) both; }
@keyframes enter { from { opacity: 0; transform: translateY(10px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  .enter { animation: none; }
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .cols-3, .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; }
  .rail {
    position: fixed; inset: auto 0 0 0; height: auto; flex-direction: row; align-items: center; gap: 4px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); border-left: 0; border-top: 1px solid rgba(255, 255, 255, 0.08); z-index: 20;
  }
  .rail-brand, .rail-logout { display: none; }
  nav#menu { flex-direction: row; overflow-x: auto; width: 100%; gap: 2px; scrollbar-width: none; }
  nav#menu::-webkit-scrollbar { display: none; }
  nav#menu button { flex: 0 0 auto; padding: 8px 11px; font-size: 13.5px; white-space: nowrap; }
  main { padding-bottom: 72px; }
  .topbar { padding: 12px 16px; }
  .stage { padding: 14px 14px 80px; }
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
  .index-card .head h3 { font-size: 1.3rem; }
  h2 { font-size: 1.3rem; }
  .kpi .v { font-size: 1.7rem; }
}
