:root {
  --navy: #1b2f5e;
  --navy-soft: #3a4f80;
  --brown: #5a3b2c;
  --mocha: #a67b5b;
  --mocha-pale: #efe2d6;
  --sky: #bfe4f0;
  --sky-pale: #eaf5f9;
  --white: #ffffff;
  --line: #c9dbe3;
  --warn: #c2410c;
  --warn-bg: #ffe9dc;
  --ok: #1d6b4f;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Heebo', Arial, 'Segoe UI', sans-serif;
  background: var(--sky-pale);
  color: var(--navy);
  line-height: 1.5;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--mocha); outline-offset: 2px; }

/* ---------- מעטפת ---------- */
.topbar {
  background: var(--navy);
  color: var(--white);
  border-bottom: 5px solid var(--brown);
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
}
.brand { font-weight: 800; font-size: 1.35rem; text-decoration: none; color: var(--white); }
.topbar .spacer { flex: 1; }
.topbar a.nav { color: var(--sky); text-decoration: none; font-weight: 600; }
.topbar a.nav:hover { text-decoration: underline; }
.edit-badge { background: var(--mocha); color: var(--white); padding: 2px 12px; border-radius: 999px; font-size: .85rem; font-weight: 600; }
main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 80px; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
.page-title { font-size: 1.7rem; color: var(--brown); margin-bottom: 4px; }
.page-sub { color: var(--navy-soft); margin: 0 0 20px; }

/* ---------- כפתורים ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 2px solid var(--navy); background: var(--navy); color: var(--white);
  padding: 8px 18px; border-radius: 8px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--navy-soft); border-color: var(--navy-soft); }
.btn.brown { background: var(--brown); border-color: var(--brown); }
.btn.brown:hover { background: #7a5441; border-color: #7a5441; }
.btn.ghost { background: transparent; color: var(--navy); }
.btn.ghost:hover { background: var(--sky); }
.btn.mini { padding: 2px 10px; font-size: .85rem; border-radius: 6px; }
.btn.danger { background: transparent; color: var(--warn); border-color: var(--warn); }
.btn.danger:hover { background: var(--warn-bg); }
.btn[disabled] { opacity: .5; cursor: default; }

/* ---------- דף פתיחה ---------- */
.welcome { min-height: calc(100vh - 140px); display: grid; place-items: center; }
.welcome-card {
  background: var(--white); border: 3px solid var(--brown); border-radius: 18px;
  padding: 48px 56px; text-align: center; max-width: 560px; width: 100%;
  box-shadow: 10px 10px 0 var(--sky);
}
.welcome-card h1 { font-size: 3rem; color: var(--brown); }
.welcome-card p { font-size: 1.15rem; margin: 0 0 28px; }
.welcome-card .btn { font-size: 1.15rem; padding: 12px 40px; }

/* ---------- תפריט ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.tile {
  background: var(--white); border: 2px solid var(--line); border-top: 8px solid var(--mocha);
  border-radius: 12px; padding: 24px 22px; text-decoration: none; display: block; min-height: 140px;
}
.tile:hover { border-color: var(--navy); border-top-color: var(--navy); }
.tile strong { display: block; font-size: 1.3rem; color: var(--brown); margin-bottom: 6px; }
.tile span { color: var(--navy-soft); }
.tile.entry { border-top-color: var(--navy); background: var(--sky); }

/* ---------- רשימות בחירה ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px; }
.search { flex: 1; min-width: 200px; max-width: 360px; padding: 8px 12px; border: 2px solid var(--line); border-radius: 8px; background: var(--white); }
.grade-row { margin-bottom: 16px; }
.grade-row h3 { color: var(--mocha); font-size: 1.05rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-link {
  background: var(--white); border: 2px solid var(--line); border-radius: 8px; padding: 6px 14px;
  text-decoration: none; font-weight: 600;
}
.chip-link:hover { border-color: var(--navy); background: var(--sky); }
.empty { padding: 30px; background: var(--white); border: 2px dashed var(--line); border-radius: 12px; color: var(--navy-soft); text-align: center; }

/* ---------- מערכת ---------- */
.doc { background: var(--white); border: 2px solid var(--brown); border-radius: 12px; padding: 22px 24px 26px; margin-bottom: 24px; }
.doc-school { font-size: .95rem; color: var(--mocha); font-weight: 600; text-align: center; }
.doc-title { text-align: center; font-size: 2rem; color: var(--navy); margin: 2px 0 0; }
.doc-sub { text-align: center; color: var(--navy-soft); margin-bottom: 16px; }
.tbl-wrap { overflow-x: auto; }
table.sched { border-collapse: collapse; width: 100%; min-width: 760px; table-layout: fixed; }
table.sched th, table.sched td { border: 1px solid var(--line); padding: 8px 10px; text-align: center; vertical-align: middle; }
table.sched thead th { background: var(--brown); color: var(--white); font-weight: 600; border-color: var(--brown); }
table.sched th.corner { width: 92px; background: var(--brown); }
table.sched th.lesson { background: var(--mocha); color: var(--white); width: 92px; font-weight: 600; border-color: var(--mocha); }
table.sched td { height: 62px; }
table.sched td.has { background: var(--sky); }
table.sched td.conflict { background: var(--warn-bg); box-shadow: inset 0 0 0 3px var(--warn); }
.ln { padding: 1px 0; }
.ln + .ln { border-top: 1px dashed rgba(27,47,94,.3); margin-top: 4px; padding-top: 4px; }
.note { font-size: .82em; color: var(--navy-soft); }
.doc-details { margin-top: 18px; padding-top: 12px; border-top: 2px solid var(--line); }
.doc-details h3 { font-size: 1.05rem; color: var(--brown); }
.doc-details ul { margin: 0; padding: 0 20px 0 0; }
.doc-details li { margin-bottom: 4px; }

/* ---------- הזנת נתונים ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; border-bottom: 3px solid var(--brown); }
.tab { background: var(--white); border: 2px solid var(--line); border-bottom: none; border-radius: 10px 10px 0 0; padding: 8px 20px; font-weight: 600; cursor: pointer; }
.tab[aria-selected="true"] { background: var(--brown); border-color: var(--brown); color: var(--white); }
.card { background: var(--white); border: 2px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 20px; }
.card h3 { color: var(--brown); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px 16px; align-items: end; }
.form-grid label.lbl { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 3px; }
.form-grid input[type=text], .form-grid select, .field {
  width: 100%; padding: 8px 10px; border: 2px solid var(--line); border-radius: 8px; background: var(--white);
}
.form-grid input:focus, .form-grid select:focus, .field:focus { border-color: var(--navy); }
.radio-row { display: flex; gap: 16px; padding: 8px 0; }
.radio-row label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.combo { position: relative; }
.combo-list {
  position: absolute; top: 100%; right: 0; left: 0; z-index: 20; background: var(--white);
  border: 2px solid var(--navy); border-radius: 8px; max-height: 240px; overflow-y: auto; margin-top: 2px;
  box-shadow: 0 6px 16px rgba(27,47,94,.2);
}
.combo-item { padding: 7px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.combo-item:hover, .combo-item.active { background: var(--sky); }
.combo-item small { color: var(--navy-soft); }
.combo-empty { padding: 8px 12px; color: var(--navy-soft); }
table.data { border-collapse: collapse; width: 100%; background: var(--white); }
table.data th, table.data td { border-bottom: 1px solid var(--line); padding: 7px 10px; text-align: right; vertical-align: middle; }
table.data thead th { background: var(--sky); font-weight: 600; position: sticky; top: 0; }
table.data tr.row-conflict td { background: var(--warn-bg); }
.badge { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.badge.warn { background: var(--warn); color: var(--white); }
.badge.ok { background: var(--ok); color: var(--white); }
.table-scroll { overflow-x: auto; border: 2px solid var(--line); border-radius: 10px; max-height: 560px; overflow-y: auto; }
.member-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.member-chip { background: var(--sky); border-radius: 999px; padding: 3px 6px 3px 12px; display: inline-flex; gap: 6px; align-items: center; }
.member-chip button { border: none; background: var(--navy); color: var(--white); width: 20px; height: 20px; border-radius: 50%; cursor: pointer; line-height: 1; }
.hint { color: var(--navy-soft); font-size: .9rem; margin: 6px 0 0; }

/* ---------- הודעות ---------- */
#toasts { position: fixed; bottom: 16px; left: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 10px 16px; border-radius: 10px; font-weight: 600; box-shadow: 0 6px 16px rgba(0,0,0,.25); background: var(--navy); color: var(--white); border-right: 6px solid var(--sky); }
.toast.warn { background: var(--warn); border-right-color: #ffd0b5; }
.toast.err { background: #7a1d1d; border-right-color: #ffb3b3; }

/* ---------- חלון שאלה ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(27,47,94,.55); display: grid; place-items: center; z-index: 200; padding: 16px; }
.modal { background: var(--white); border: 3px solid var(--brown); border-radius: 14px; padding: 22px 24px; max-width: 480px; width: 100%; }
.modal h3 { color: var(--brown); }
.modal .actions { justify-content: flex-start; }

/* ---------- הדפסה ---------- */
#printArea { display: none; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body.print-mode { background: #fff; }
  body.print-mode > *:not(#printArea) { display: none !important; }
  body.print-mode #printArea { display: block; }
  body.print-mode .doc { border: none; padding: 0; margin: 0; page-break-after: always; break-after: page; }
  body.print-mode .doc:last-child { page-break-after: auto; break-after: auto; }
  body.print-mode * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body.print-mode table.sched { min-width: 0; }
  body.print-mode .tbl-wrap { overflow: visible; }
}
@media (max-width: 640px) {
  main { padding: 16px 12px 60px; }
  .welcome-card { padding: 32px 22px; }
  .doc { padding: 16px 10px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
