/* סטודיו אביגל — RTL, mobile-first for teacher screens */
:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1e2130;
  --muted: #6b7280;
  --border: #e3e6ef;
  --green: #16a34a;
  --orange: #ea8a0c;
  --red: #dc2626;
  --grey: #9ca3af;
  --blue: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 24, 50, .08), 0 1px 2px rgba(20, 24, 50, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Heebo", "Arial Hebrew", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; direction: rtl;
}
.loading { padding: 48px; text-align: center; color: var(--muted); }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 18px; margin: 18px 0 10px; }
h3 { font-size: 16px; margin: 12px 0 8px; }

/* layout */
.topbar {
  position: sticky; top: 0; z-index: 30; background: var(--primary); color: #fff;
  display: flex; align-items: center; gap: 4px; padding: 0 10px;
  overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch;
}
.topbar .brand { font-weight: 700; padding: 12px 8px; font-size: 17px; }
.topbar a.nav {
  color: #e0e0ff; padding: 13px 10px; display: inline-block; font-size: 14.5px;
  border-bottom: 3px solid transparent;
}
.topbar a.nav.active { color: #fff; border-bottom-color: #fff; font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; color: #d9dcff; padding-inline-end: 6px; }
.topbar a.logout { color: #d9dcff; font-size: 13px; padding: 13px 6px; }
main { padding: 16px; max-width: 1280px; margin: 0 auto; padding-bottom: 90px; }

/* teacher bottom tabs (mobile) */
.bottomnav {
  position: fixed; bottom: 0; right: 0; left: 0; z-index: 30;
  display: flex; background: var(--card); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; text-align: center; padding: 10px 0 8px; color: var(--muted); font-size: 13px;
}
.bottomnav a.active { color: var(--primary); font-weight: 700; }
.bottomnav a .ico { display: block; font-size: 22px; }

/* cards & tables */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 9px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #fafbff; color: var(--muted); font-weight: 600; font-size: 13px; user-select: none; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--primary); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f6f7ff; }

/* forms */
label.f { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  font: inherit; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text); width: 100%; direction: rtl;
}
input[type="date"], input[type="time"], input[type="month"] { direction: ltr; text-align: right; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7cbf7; border-color: var(--primary); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > div { flex: 1; min-width: 130px; }
.row > .grow0 { flex: 0; min-width: auto; }

/* buttons */
button, .btn {
  font: inherit; border: 0; border-radius: 9px; padding: 9px 16px; cursor: pointer;
  background: var(--primary); color: #fff; font-weight: 600; font-size: 14.5px;
}
button:hover { background: var(--primary-dark); }
button.sec { background: #eceef8; color: var(--text); }
button.sec:hover { background: #e0e3f2; }
button.danger { background: #fbe9e9; color: var(--red); }
button.small { padding: 5px 10px; font-size: 13px; }
button.icon { background: transparent; color: var(--muted); padding: 4px 8px; font-size: 16px; }
button:disabled { opacity: .5; cursor: default; }

/* chips & badges */
.chip {
  display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
  background: #eceef8; color: var(--text); cursor: pointer; border: 1px solid transparent; margin: 2px;
}
.chip.on { background: var(--primary); color: #fff; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.st-scheduled { background: #e5edff; color: var(--blue); }
.st-completed { background: #e3f6e9; color: var(--green); }
.st-cancelled_advance { background: #eef0f3; color: var(--muted); }
.st-cancelled_last_minute { background: #fdeedd; color: var(--orange); }
.st-no_show { background: #fde5e5; color: var(--red); }
.muted { color: var(--muted); font-size: 13.5px; }
.progress { background: #eceef8; border-radius: 99px; height: 8px; overflow: hidden; min-width: 70px; }
.progress > div { height: 100%; background: var(--green); border-radius: 99px; }

/* filter bar */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.filters > div { min-width: 120px; }
.filters label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }

/* modal */
.modal-back {
  position: fixed; inset: 0; background: rgba(20, 22, 40, .45); z-index: 90;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); border-radius: 16px 16px 0 0; width: 100%; max-width: 560px;
  max-height: 92vh; overflow-y: auto; padding: 20px; animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) {
  .modal-back { align-items: center; }
  .modal { border-radius: 16px; }
}
.modal h2 { margin-top: 0; }
.modal .actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-start; }

/* toast */
#toast-root { position: fixed; bottom: 76px; right: 0; left: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 120; pointer-events: none; }
.toast { background: #23263a; color: #fff; padding: 11px 20px; border-radius: 99px; font-size: 14.5px; box-shadow: var(--shadow); animation: up .18s ease-out; max-width: 90vw; }
.toast.err { background: var(--red); }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 32px 28px; width: 100%; max-width: 380px; text-align: center; }
.login-box h1 { font-size: 24px; }
.login-box .logo { font-size: 44px; }
.login-box input { text-align: center; font-size: 18px; margin: 14px 0; }
.login-box input.code { letter-spacing: 8px; font-size: 26px; direction: ltr; }
.login-box button { width: 100%; padding: 12px; font-size: 16px; }

/* teacher lesson cards */
.lesson-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 10px; }
.lesson-card .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.lesson-card .time { font-weight: 700; font-size: 17px; }
.lesson-card .name { font-size: 17px; font-weight: 600; }
.lesson-card .sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.lesson-card .acts { display: flex; gap: 10px; margin-top: 12px; }
.lesson-card .acts button { flex: 1; padding: 12px; font-size: 16px; }
.btn-done { background: var(--green); }
.btn-done:hover { background: #128a3e; }
.btn-miss { background: #fdeedd; color: var(--orange); }
.btn-miss:hover { background: #fbe2c4; }
.hint-last { background: #fff7e0; border: 1px solid #f5e2a0; border-radius: 8px; padding: 6px 10px; font-size: 13.5px; margin-top: 8px; }

/* summary tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; text-align: center; }
.tile .v { font-size: 26px; font-weight: 700; }
.tile .l { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* schedule board */
.board-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px; }
.board { display: flex; gap: 0; min-width: 900px; }
.board .timecol { width: 52px; flex: 0 0 52px; }
.board .timecol .slot-label { height: 26px; font-size: 11px; color: var(--muted); text-align: left; padding-left: 6px; transform: translateY(-7px); }
.board .daycol { flex: 1; border-inline-start: 1px solid var(--border); min-width: 110px; }
.board .dayhead { text-align: center; font-weight: 700; font-size: 13.5px; padding: 6px 2px; border-bottom: 2px solid var(--border); position: sticky; top: 0; background: var(--card); }
.board .dayhead .d { color: var(--muted); font-weight: 400; font-size: 12px; }
.board .rooms { display: flex; }
.board .roomcol { flex: 1; position: relative; border-inline-start: 1px dashed #eef0f6; }
.board .roomcol:first-child { border-inline-start: 0; }
.board .roomhead { text-align: center; font-size: 11px; color: var(--muted); border-bottom: 1px solid var(--border); padding: 2px 0; overflow: hidden; }
.board .grid-bg { position: relative; }
.board .slot-line { height: 26px; border-bottom: 1px solid #f2f3f9; }
.board .slot-line.hour { border-bottom-color: #e3e6ef; }
.board .blk {
  position: absolute; right: 1px; left: 1px; background: repeating-linear-gradient(45deg, #eef0f3, #eef0f3 6px, #e6e8ee 6px, #e6e8ee 12px);
  color: #8a90a3; font-size: 10.5px; border-radius: 4px; padding: 2px 4px; overflow: hidden; z-index: 1;
}
.board .les {
  position: absolute; right: 2px; left: 2px; border-radius: 6px; padding: 2px 5px; font-size: 11.5px;
  overflow: hidden; cursor: pointer; z-index: 2; border: 1px solid rgba(0,0,0,.06); line-height: 1.25;
}
.board .les .t { font-weight: 700; }
.board.compact .daycol { min-width: 92px; }
.board .daycol.today .dayhead { color: var(--primary); }
.board .les.st-scheduled { background: #e5edff; }
.board .les.st-completed { background: #e3f6e9; }
.board .les.st-cancelled_advance { background: #eef0f3; text-decoration: line-through; }
.board .les.st-cancelled_last_minute { background: #fdeedd; }
.board .les.st-no_show { background: #fde5e5; }

/* misc */
.head-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.head-row h1 { margin: 0; flex: 1; }
.pill-group { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 36px 10px; }
details.box { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; }
details.box > summary { padding: 14px 16px; cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
details.box > summary::-webkit-details-marker { display: none; }
details.box > .inner { padding: 0 16px 16px; }
.kv { font-size: 14px; }
.kv b { font-weight: 600; }
pre.diff { background: #f6f7fb; border-radius: 8px; padding: 8px; font-size: 11.5px; direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-all; max-width: 420px; max-height: 120px; overflow: auto; }
@media (max-width: 700px) {
  main { padding: 10px; }
  th, td { padding: 7px 6px; font-size: 13px; }
}

/* teachers zone */
.my-nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.note-line { color: #6d5a10; background: #fdf7e3; border-radius: 6px; padding: 4px 8px; margin-top: 4px; }
.warn-list { margin: 8px 0 4px; padding-inline-start: 20px; }
.warn-list li { margin-bottom: 6px; color: #a05a00; }
.breakdowns { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 14px 0; }
.breakdowns h3 { margin: 0 0 6px; }
@media (max-width: 700px) { .breakdowns { grid-template-columns: 1fr; } }

/* ---------- הרמס chat widget ---------- */
#chat-fab {
  position: fixed; bottom: 18px; left: 18px; z-index: 60;
  width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--primary); color: #fff; font-size: 26px; line-height: 1;
  box-shadow: 0 4px 14px rgba(79, 70, 229, .4);
}
#chat-fab:hover { background: var(--primary-dark); }
#chat-fab.with-nav { bottom: 76px; }
#chat-panel {
  position: fixed; bottom: 82px; left: 18px; z-index: 61;
  width: min(400px, calc(100vw - 36px)); height: min(560px, calc(100dvh - 140px));
  background: var(--card); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(20, 24, 50, .22);
  display: flex; flex-direction: column; overflow: hidden;
}
#chat-panel.with-nav { bottom: 140px; height: min(520px, calc(100dvh - 210px)); }
#chat-panel.hidden { display: none; }
.chat-head {
  background: var(--primary); color: #fff; padding: 10px 14px;
  display: flex; justify-content: space-between; align-items: center; font-weight: 600;
}
.chat-head-btns button {
  background: transparent; border: none; color: #d9dcff; font-size: 15px;
  cursor: pointer; padding: 4px 6px;
}
.chat-head-btns button:hover { color: #fff; }
#chat-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg {
  max-width: 85%; padding: 9px 13px; border-radius: 14px; font-size: 14.5px;
  line-height: 1.45; white-space: pre-wrap; word-break: break-word;
}
.chat-msg.user { align-self: flex-start; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.assistant { align-self: flex-end; background: #eef0f8; color: var(--text); border-bottom-left-radius: 4px; }
.chat-msg.typing span {
  display: inline-block; width: 7px; height: 7px; margin: 0 2px; border-radius: 50%;
  background: var(--muted); animation: chat-blink 1.2s infinite;
}
.chat-msg.typing span:nth-child(2) { animation-delay: .2s; }
.chat-msg.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chat-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.chat-card { border: 1.5px solid var(--primary); border-radius: 10px; padding: 10px 12px; background: #fff; }
.chat-card-title { font-size: 12.5px; font-weight: 700; color: var(--primary); margin-bottom: 6px; }
.chat-card-sum { font-size: 14.5px; font-weight: 600; }
.chat-card-prev { font-size: 13px; color: var(--muted); margin-top: 4px; }
.chat-card-btns { display: flex; gap: 8px; margin-top: 10px; }
.chat-card-btns .chat-ok { background: var(--green); }
.chat-card-state { margin-top: 8px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.chat-input-row { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-input-row textarea {
  flex: 1; resize: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; font: inherit; font-size: 14.5px; max-height: 90px;
}
#chat-send { padding: 0 18px; }
