:root {
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f4f6fb;
  --paper: #ffffff;
  --brand: #2f5bea;
  --brand-dark: #1e40d8;
  --brand-soft: #eef2ff;
  --ok: #0f9d58;
  --ok-soft: #e6f6ec;
  --warn: #b54708;
  --warn-soft: #fef4e6;
  --danger: #d92d20;
  --danger-soft: #fee4e2;
  --sidebar: #101a33;
  --radius: 14px;
  --shadow: 0 4px 18px rgba(15, 23, 42, .07);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  direction: rtl;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Assistant, Rubik, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- שלד ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 236px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: #cbd5e1;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.brand .logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #2f5bea, #7b3fe4);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 17px;
}
.brand .name { color: #fff; font-weight: 600; font-size: 16px; line-height: 1.2; }
.brand .sub { font-size: 12px; color: #7f8db0; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px;
  color: #b6c2dc; cursor: pointer; font-size: 15px; user-select: none;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: #1b2745; color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; font-weight: 600; }
.nav-item .ico { width: 20px; text-align: center; font-size: 16px; }
.nav-sep { height: 1px; background: #1e2a49; margin: 12px 4px; }
.sidebar-foot { margin-top: auto; font-size: 12px; color: #64748b; padding: 12px 8px 0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: 14px 26px;
  display: flex; align-items: center; gap: 14px;
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; }
.search {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  min-width: 240px; font-family: inherit; font-size: 14px; background: var(--bg);
}
.search:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); background: #fff; }

.content { padding: 24px 26px 60px; flex: 1; }

/* ---------- רכיבים ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 15px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--paper); color: var(--ink-2);
  font-family: inherit; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #f8fafc; border-color: #cbd5e1; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

.card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card h2 { font-size: 17px; margin: 0 0 14px; }
.card h3 { font-size: 15px; margin: 0 0 6px; }

.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 700; line-height: 1.25; margin-top: 4px; }
.stat .hint { font-size: 12px; color: var(--muted); }

table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 11px 12px; text-align: right; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data th { font-size: 13px; color: var(--muted); font-weight: 600; background: #fafbfd; position: sticky; top: 0; }
table.data tbody tr:hover { background: #fafbff; }
table.data td.actions { white-space: nowrap; text-align: left; }
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); background: var(--paper); box-shadow: var(--shadow); }

.badge { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--brand-soft); color: var(--brand); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.gray { background: #f1f5f9; color: var(--muted); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.spacer { flex: 1; }
.mt { margin-top: 16px; }
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty .big { font-size: 34px; margin-bottom: 8px; }

.chip {
  display: inline-block; padding: 3px 10px; border-radius: 8px;
  background: #f1f5f9; color: var(--ink-2); font-size: 12.5px; margin-inline-end: 5px;
}

.banner {
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--warn-soft); color: #7a3c00; border: 1px solid #f5d9b0;
}
.banner.info { background: var(--brand-soft); color: #1e3a8a; border-color: #c7d2fe; }

/* ---------- טפסים ---------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13.5px; color: var(--ink-2); margin-bottom: 5px; font-weight: 600; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=email],
input[type=tel], input[type=password], input[type=file], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-family: inherit; font-size: 14.5px; background: #fff; color: var(--ink);
}
textarea { min-height: 92px; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check input { width: 17px; height: 17px; }

.repeater { border: 1px dashed var(--line); border-radius: 12px; padding: 12px; background: #fbfcfe; }
.rep-row { display: grid; gap: 8px; align-items: start; margin-bottom: 8px; }
.rep-row .rm { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 18px; padding: 4px; }

/* ---------- מודאל ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 100; overflow-y: auto;
}
.modal {
  background: var(--paper); border-radius: 16px; width: 100%; max-width: 700px;
  box-shadow: 0 20px 60px rgba(2, 6, 23, .3); animation: pop .16s ease;
}
.modal.wide { max-width: 940px; }
@keyframes pop { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.modal header { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.modal header h2 { margin: 0; font-size: 18px; flex: 1; }
.modal .body { padding: 20px 22px; max-height: 68vh; overflow-y: auto; }
.modal footer { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-start; background: #fafbfd; border-radius: 0 0 16px 16px; }
.x { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

/* ---------- טוסט ---------- */
.toasts { position: fixed; bottom: 20px; left: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 8px 24px rgba(2, 6, 23, .35); animation: pop .15s ease;
  max-width: 380px;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- פרטי ישות ---------- */
.detail-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 18px; }
.detail-head h2 { margin: 0; font-size: 22px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.list-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: none; }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tab { padding: 8px 14px; cursor: pointer; border-radius: 10px 10px 0 0; font-size: 14.5px; color: var(--muted); }
.tab.active { background: var(--paper); color: var(--brand); font-weight: 600; border: 1px solid var(--line); border-bottom-color: var(--paper); margin-bottom: -1px; }

.slide-preview { background: #0b1020; color: #fff; border-radius: 10px; padding: 14px 16px; font-size: 13px; }
.slide-preview strong { display: block; margin-bottom: 4px; }

@media (max-width: 860px) {
  .sidebar { width: 68px; padding: 16px 8px; }
  .sidebar .label, .brand .name, .brand .sub, .sidebar-foot { display: none; }
  .nav-item { justify-content: center; padding: 11px 0; }
  .content { padding: 16px 12px 60px; }
  .topbar { padding: 12px 14px; }
  .search { min-width: 120px; }
  .field-row, .field-row.three { grid-template-columns: 1fr; }
}

/* ---------- יומן ---------- */
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.cal-title { font-size: 19px; font-weight: 600; min-width: 170px; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.cal-dow { background: #fafbfd; padding: 9px 6px; text-align: center; font-size: 13px; color: var(--muted); font-weight: 600; }
.cal-cell { background: var(--paper); min-height: 116px; padding: 7px 8px; cursor: pointer; transition: background .12s; }
.cal-cell:hover { background: #fafbff; }
.cal-cell.other { background: #fbfcfe; color: #b3bcc9; }
.cal-cell.today { background: #f2f6ff; box-shadow: inset 0 0 0 2px var(--brand); }
.cal-daynum { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.cal-cell.today .cal-daynum { color: var(--brand); }
.cal-ev { display: block; font-size: 12px; padding: 3px 7px; border-radius: 7px; margin-bottom: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none; }
.cal-ev.lecture { background: var(--brand); color: #fff; }
.cal-ev.lecture:hover { background: var(--brand-dark); text-decoration: none; }
.cal-ev.gcal { background: #eef1f6; color: var(--ink-2); border-inline-start: 3px solid #94a3b8; }
.cal-ev.gcal:hover { background: #e6eaf1; text-decoration: none; }
.cal-legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-top: 12px; flex-wrap: wrap; }
.cal-legend span::before { content: ''; display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-inline-end: 6px; }
.cal-legend .l-lecture::before { background: var(--brand); }
.cal-legend .l-gcal::before { background: #94a3b8; }
@media (max-width: 860px) {
  .cal-cell { min-height: 78px; padding: 4px; }
  .cal-ev { font-size: 10.5px; padding: 2px 4px; }
}
.cal-ev.ext { background: #f6f2ff; color: var(--ink-2); border-inline-start: 3px solid #7b3fe4; cursor: default; }
.cal-legend .l-src::before { background: var(--c, #7b3fe4); }
.ext-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ext-row:last-child { border-bottom: none; }
.ext-dot { width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0; }

/* מחולל סילבוסים: בחירה בלחיצה בלבד */
.pick-group { margin-bottom: 14px; }
.pick-group > label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 6px; color: var(--ink-2); }
.picks { display: flex; flex-wrap: wrap; gap: 6px; }
.pick {
  border: 1px solid var(--line); background: var(--paper); color: var(--ink-2);
  padding: 6px 12px; border-radius: 999px; font: inherit; font-size: 13px; cursor: pointer;
}
.pick:hover { border-color: var(--brand); }
.pick.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.pick .n { opacity: .6; font-size: 11.5px; margin-inline-start: 4px; }
.pick.add { border-style: dashed; color: var(--ink-2); }
.pick-del { margin-inline-start: 6px; opacity: .55; font-weight: 700; }
.pick-del:hover { opacity: 1; }
.pick-add { display: inline-flex; gap: 4px; align-items: center; }
.pick-input { width: 160px; padding: 5px 8px; font-size: 13px; }
.builder-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 18px; }
.builder-preview { border-inline-start: 1px solid var(--line); padding-inline-start: 18px; }
.builder-preview .mod { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.builder-preview .mod:last-child { border-bottom: 0; }
@media (max-width: 760px) {
  .builder-grid { grid-template-columns: 1fr; }
  .builder-preview { border: 0; padding: 0; }
}
