/* ===========================================================
   base.css — טוקנים, איפוס, פריסה, רכיבי ממשק בסיסיים
   =========================================================== */

:root {
  --accent-h: 213;
  --accent: hsl(var(--accent-h) 68% 48%);
  --accent-strong: hsl(var(--accent-h) 68% 40%);
  --accent-soft: hsl(var(--accent-h) 70% 96%);
  --accent-ring: hsl(var(--accent-h) 68% 48% / .28);

  --bg: #f4f6fa;
  --bg-elev: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e3e8ef;
  --border-strong: #cfd6e2;
  --text: #1d2939;
  --text-soft: #475467;
  --muted: #7b8698;
  --ok: #12866f;
  --ok-soft: #e6f6f1;
  --warn: #b7791f;
  --warn-soft: #fdf6e7;
  --danger: #c0392f;
  --danger-soft: #fdeceb;

  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-sm: 0 2px 8px rgba(16, 24, 40, .07);
  --shadow: 0 8px 24px rgba(16, 24, 40, .09);
  --shadow-lg: 0 20px 48px rgba(16, 24, 40, .18);

  --nav-w: 248px;
  --topbar-h: 60px;
  --speed: .18s;
  --ease: cubic-bezier(.33, 1, .68, 1);

  --font: "Rubik", "Heebo", "Assistant", "Segoe UI", "Arial Hebrew", Arial, system-ui, sans-serif;
}

html[data-theme="dark"] {
  --accent: hsl(var(--accent-h) 72% 62%);
  --accent-strong: hsl(var(--accent-h) 72% 70%);
  --accent-soft: hsl(var(--accent-h) 45% 18%);
  --accent-ring: hsl(var(--accent-h) 72% 62% / .3);

  --bg: #0f1623;
  --bg-elev: #0b111c;
  --surface: #18202e;
  --surface-2: #1d2634;
  --surface-3: #232d3d;
  --border: #2a3444;
  --border-strong: #3a465a;
  --text: #e8eef9;
  --text-soft: #b7c2d2;
  --muted: #8794a8;
  --ok: #45c5a3;
  --ok-soft: #102b26;
  --warn: #e0b35e;
  --warn-soft: #2d2415;
  --danger: #f08279;
  --danger-soft: #331a19;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .35);
  --shadow: 0 8px 24px rgba(0, 0, 0, .42);
  --shadow-lg: 0 22px 50px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.3; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.18rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .6em; }
a { color: var(--accent-strong); }

button, input, select, textarea { font: inherit; color: inherit; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 3px solid var(--accent-ring); outline-offset: 2px; border-radius: 6px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- פריסה ---------- */
.app {
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "top top" "nav main";
  height: 100dvh;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}
.topbar-spacer { flex: 1; }

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { color: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 30px; height: 30px; stroke: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: .98rem; }
.brand-text small { color: var(--muted); font-size: .74rem; }

.sidenav {
  grid-area: nav;
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: auto;
  z-index: 25;
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  text-decoration: none;
  font-size: .92rem;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.nav-link:hover { background: var(--surface-3); color: var(--text); }
.nav-link.is-active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.nav-link svg { flex: none; }
.nav-footer { margin-top: auto; padding: 10px 12px; }
.nav-version { color: var(--muted); font-size: .74rem; }
.nav-toggle { display: none; }
.nav-scrim { display: none; }

.content {
  grid-area: main;
  overflow: auto;
  padding: 22px;
  scroll-behavior: smooth;
}
.content:focus { outline: none; }
.content.is-flush { padding: 0; overflow: hidden; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .nav-toggle { display: inline-grid; }
  .sidenav {
    position: fixed; inset-block: var(--topbar-h) 0; inset-inline-start: 0;
    width: min(84vw, var(--nav-w));
    transform: translateX(110%);
    transition: transform .22s var(--ease);
    box-shadow: var(--shadow-lg);
  }
  html[dir="rtl"] .sidenav { transform: translateX(110%); }
  .sidenav.is-open { transform: none; }
  .nav-scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0; background: rgba(15, 22, 35, .4); z-index: 24; }
  .nav-scrim[hidden] { display: none; }
  .content { padding: 14px; }
  .brand-text small { display: none; }
}

/* ---------- כפתורים ---------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px;
  min-height: 38px;
  border: 1px solid var(--btn-bd);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform var(--speed) var(--ease), box-shadow var(--speed) var(--ease), background var(--speed) var(--ease), border-color var(--speed) var(--ease), opacity var(--speed);
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary { --btn-bg: var(--accent); --btn-fg: #fff; --btn-bd: transparent; box-shadow: var(--shadow-xs); }
.btn-primary:hover { --btn-bg: var(--accent-strong); }
html[data-theme="dark"] .btn-primary { --btn-fg: #0d1420; }

.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-danger { --btn-bg: var(--danger-soft); --btn-fg: var(--danger); --btn-bd: transparent; }
.btn-danger:hover { --btn-bg: var(--danger); --btn-fg: #fff; }

.btn-soft { --btn-bg: var(--accent-soft); --btn-fg: var(--accent-strong); --btn-bd: transparent; }

.btn-sm { padding: 6px 10px; min-height: 32px; font-size: .84rem; }
.btn-lg { padding: 11px 20px; min-height: 44px; font-size: .98rem; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
  flex: none;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.is-on { background: var(--accent-soft); color: var(--accent-strong); }
.icon-btn[disabled] { opacity: .4; cursor: not-allowed; }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.sm svg { width: 17px; height: 17px; }

#themeToggle .ico-moon { display: none; }
html[data-theme="dark"] #themeToggle .ico-sun { display: none; }
html[data-theme="dark"] #themeToggle .ico-moon { display: block; }

/* ---------- טפסים ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: .86rem; font-weight: 500; color: var(--text-soft); }
.field .hint { font-size: .78rem; color: var(--muted); }
.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color var(--speed), box-shadow var(--speed);
  min-height: 40px;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.6; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: 14px 17px, 19px 17px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-inline-start: 34px; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row > .field { flex: 1 1 160px; margin-bottom: 14px; }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 42px; height: 24px; border-radius: 99px; background: var(--border-strong); position: relative; transition: background var(--speed); flex: none; }
.switch .track::after { content: ""; position: absolute; inset-block: 3px; inset-inline-start: 3px; width: 18px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-xs); transition: transform var(--speed) var(--ease); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(-18px); }
html[dir="ltr"] .switch input:checked + .track::after { transform: translateX(18px); }

/* ---------- כרטיסים ופריסות עזר ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
}
.card-pad { padding: 16px; }

.page { max-width: 1180px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .grow { flex: 1; min-width: 200px; }
.page-sub { color: var(--muted); font-size: .88rem; margin: 2px 0 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--surface-3);
  color: var(--text-soft);
  font-size: .78rem;
  white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); color: var(--accent-strong); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip svg { width: 14px; height: 14px; }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.empty svg { width: 46px; height: 46px; opacity: .55; margin-bottom: 10px; }
.empty h3 { color: var(--text); margin-bottom: 4px; }
.empty p { max-width: 460px; margin: 0 auto 14px; font-size: .9rem; }

/* ---------- כרטיסיות כיתה ---------- */
.class-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 14px;
}
.class-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-xs);
  transition: transform var(--speed) var(--ease), box-shadow var(--speed) var(--ease), border-color var(--speed);
  animation: rise .26s var(--ease) both;
}
.class-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.class-card .cc-top { display: flex; align-items: flex-start; gap: 10px; }
.class-card .cc-name { font-weight: 600; font-size: 1.05rem; }
.class-card .cc-grade { color: var(--muted); font-size: .82rem; }
.class-card .cc-stats { display: flex; gap: 6px; flex-wrap: wrap; }
.class-card .cc-notes { color: var(--text-soft); font-size: .85rem; background: var(--surface-2); border-radius: var(--radius-xs); padding: 8px 10px; white-space: pre-wrap; word-break: break-word; max-height: 70px; overflow: hidden; }
.class-card .cc-foot { display: flex; align-items: center; gap: 6px; margin-top: auto; padding-top: 4px; }
.class-card .cc-date { color: var(--muted); font-size: .74rem; }
.cc-avatar { width: 40px; height: 40px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-strong); display: grid; place-items: center; font-weight: 700; flex: none; }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- טבלה ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 500; font-size: .82rem; background: var(--surface-2); position: sticky; top: 0; z-index: 1; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); max-height: 100%; }

/* ---------- חיווי שמירה ---------- */
.save-indicator {
  display: flex; align-items: center; gap: 6px;
  font-size: .78rem; color: var(--muted);
  padding: 4px 10px; border-radius: 99px; background: var(--surface-3);
  transition: opacity var(--speed), color var(--speed);
}
.save-indicator .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.save-indicator.is-saving { color: var(--warn); }
.save-indicator.is-saving .dot { background: var(--warn); animation: pulse 1s infinite; }
.save-indicator.is-error { color: var(--danger); }
.save-indicator.is-error .dot { background: var(--danger); animation: none; }
@keyframes pulse { 50% { opacity: .25; } }
@media (max-width: 640px) { .save-indicator .save-text { display: none; } }

/* ---------- טוסטים ---------- */
.toast-stack {
  position: fixed; inset-block-end: 18px; inset-inline-start: 18px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 15px;
  min-width: 230px; max-width: min(90vw, 420px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-inline-start: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: .9rem;
  pointer-events: auto;
  animation: toastIn .22s var(--ease) both;
}
.toast.is-out { animation: toastOut .18s var(--ease) both; }
.toast.ok { border-inline-start-color: var(--ok); }
.toast.ok svg { color: var(--ok); }
.toast.error { border-inline-start-color: var(--danger); }
.toast.error svg { color: var(--danger); }
.toast.warn { border-inline-start-color: var(--warn); }
.toast.warn svg { color: var(--warn); }
.toast svg { flex: none; color: var(--accent); }
.toast .t-text { flex: 1; word-break: break-word; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(.97); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px) scale(.97); } }

/* ---------- מודאלים ---------- */
.modal-root:empty { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(15, 22, 35, .45);
  display: grid; place-items: center;
  padding: 18px;
  animation: fade .16s var(--ease) both;
  backdrop-filter: blur(2px);
}
.modal {
  width: min(560px, 100%);
  max-height: min(86dvh, 820px);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: pop .2s var(--ease) both;
}
.modal.wide { width: min(820px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 10px; }
.modal-head h2 { flex: 1; font-size: 1.1rem; }
.modal-body { padding: 4px 18px 8px; overflow: auto; }
.modal-foot { display: flex; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); background: var(--surface-2); }
.modal-foot .spacer { flex: 1; }
.modal-icon { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent-strong); }
.modal-icon.danger { background: var(--danger-soft); color: var(--danger); }
.modal-icon.warn { background: var(--warn-soft); color: var(--warn); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.97); } }

/* רשימת בחירה בתוך מודאל */
.pick-list { display: flex; flex-direction: column; gap: 4px; max-height: 46dvh; overflow: auto; margin: 2px -4px; padding: 0 4px; }
.pick-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: start;
  padding: 9px 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--speed), border-color var(--speed);
}
.pick-item:hover { background: var(--accent-soft); border-color: var(--accent); }
.pick-item .pi-name { flex: 1; }
.pick-item .pi-tag { font-size: .76rem; color: var(--muted); }
.pick-item.is-assigned { opacity: .72; }

.seg { display: inline-flex; background: var(--surface-3); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.seg button {
  border: none; background: transparent; color: var(--text-soft);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: .86rem;
  transition: background var(--speed), color var(--speed);
}
.seg button.is-on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-xs); }

.search-box { position: relative; flex: 1 1 200px; min-width: 150px; }
.search-box .input { padding-inline-start: 36px; }
.search-box svg { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; pointer-events: none; }

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------------------- פס עדכון גרסה (PWA) ---------------------- */

.pwa-update {
  position: fixed;
  inset-block-end: 18px;
  inset-inline-end: 18px;
  z-index: 210;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  max-width: min(92vw, 460px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-inline-start: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  animation: pwa-rise .22s ease-out;
}
.pwa-update-text { font-size: .9rem; color: var(--text); }

@keyframes pwa-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 560px) {
  .pwa-update {
    inset-inline: 12px;
    inset-block-end: 12px;
    justify-content: space-between;
  }
}

/* ------------------------ כרטיס התקנה ------------------------ */

.pwa-status { display: flex; flex-direction: column; gap: 6px; }
.pwa-row { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.pwa-row svg { width: 17px; height: 17px; flex: none; }
.pwa-row.ok { color: var(--ok); }
.pwa-row.off { color: var(--muted); }
