:root {
  --bg: #f4f6f5; --card: #ffffff; --ink: #16302b; --muted: #5f7470; --line: #e3e9e7;
  --pri: #0f766e; --pri-dark: #0a4f4a; --pri-soft: #e1f1ef;
  --amb: #b45309; --amb-soft: #fdf0dc;
  --red: #b42318; --red-soft: #fde8e6;
  --r: 16px; --font: 'Tajawal', 'Segoe UI', Tahoma, Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.6; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.boot { display: grid; place-items: center; height: 60vh; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--pri); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px calc(40px + env(safe-area-inset-bottom)); }

/* الرأس */
.top { background: var(--pri); color: #fff; padding: calc(14px + env(safe-area-inset-top)) 0 54px; }
.top .wrap { padding-bottom: 0; display: flex; align-items: center; gap: 12px; }
.mark { width: 42px; height: 42px; border-radius: 12px; background: rgba(255,255,255,.16); display: grid; place-items: center; flex: none; }
.mark svg { width: 24px; height: 24px; }
.brand { flex: 1; min-width: 0; }
.brand b { display: block; font-size: 17px; font-weight: 700; line-height: 1.3; }
.brand span { font-size: 13px; opacity: .85; }
.iconbtn { width: 42px; height: 42px; border: 0; border-radius: 12px; background: rgba(255,255,255,.16); color: #fff; display: grid; place-items: center; flex: none; }
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn.on { background: #fff; color: var(--pri); }

.sheet { margin-top: -34px; position: relative; }
.seg { display: flex; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 10px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--pri-soft); color: var(--pri-dark); font-weight: 700; }
.terms { margin-bottom: 10px; }
.nav { margin-bottom: 16px; }

/* البطاقات */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 18px; margin-bottom: 14px; }
.card h2 { margin: 0 0 4px; font-size: 18px; font-weight: 700; }
.card h3 { margin: 0 0 10px; font-size: 16px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.stack > * + * { margin-top: 12px; }

select, input[type=text], input[type=password], input[type=date], input[type=tel] {
  width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; min-height: 46px; outline: none;
}
select:focus, input:focus { border-color: var(--pri); box-shadow: 0 0 0 3px var(--pri-soft); }

.btn { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 14px; min-height: 44px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn svg { width: 19px; height: 19px; flex: none; }
.btn:active { transform: scale(.98); }
.btn.pri { background: var(--pri); border-color: var(--pri); color: #fff; font-weight: 700; }
.btn.soft { background: var(--pri-soft); border-color: transparent; color: var(--pri-dark); }
.btn.danger { color: var(--red); }
.btn.block { width: 100%; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1; min-width: 120px; }

/* بطاقة المعلم */
.me-head { display: flex; align-items: center; gap: 14px; margin: 16px 0 6px; }
.avatar { width: 54px; height: 54px; border-radius: 50%; background: var(--pri-soft); color: var(--pri-dark); display: grid; place-items: center; font-size: 22px; font-weight: 700; flex: none; }
.me-head b { font-size: 19px; display: block; line-height: 1.35; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 4px; }
.chip { padding: 4px 12px; border-radius: 999px; background: var(--pri-soft); color: var(--pri-dark); font-size: 13.5px; font-weight: 500; }
.chip.amb { background: var(--amb-soft); color: var(--amb); }
.chip.red { background: var(--red-soft); color: var(--red); }

.duty { display: flex; align-items: center; gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.duty:first-child { border-top: 0; }
.duty .when { width: 96px; flex: none; }
.duty .when b { display: block; font-size: 17px; }
.duty .what { flex: 1; min-width: 0; }
.duty .what small { display: block; color: var(--muted); font-size: 12.5px; }
.duty .what span { font-weight: 500; }
.badge { min-width: 76px; text-align: center; padding: 8px 12px; border-radius: 14px; background: var(--pri-soft); color: var(--pri-dark); font-weight: 700; font-size: 21px; line-height: 1.2; }
.badge.res { background: var(--amb-soft); color: var(--amb); font-size: 17px; }

.empty { text-align: center; padding: 34px 12px; color: var(--muted); }
.empty svg { width: 46px; height: 46px; color: var(--pri); opacity: .6; margin-bottom: 8px; }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

/* اليوم */
.days { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.days::-webkit-scrollbar { display: none; }
.dchip { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 8px 14px; text-align: center; min-width: 84px; }
.dchip b { display: block; font-size: 14.5px; }
.dchip small { color: var(--muted); font-size: 12.5px; }
.dchip.on { background: var(--pri); border-color: var(--pri); color: #fff; }
.dchip.on small { color: rgba(255,255,255,.85); }
.dayhead { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.dayhead b { font-size: 19px; }
.slots { display: grid; grid-template-columns: 1fr; gap: 0; }
.slot { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-top: 1px solid var(--line); width: 100%; background: transparent; border-inline: 0; border-bottom: 0; text-align: start; }
.slot:first-child { border-top: 0; }
.slot .cls { width: 60px; font-weight: 700; color: var(--pri-dark); font-size: 17px; flex: none; }
.slot .nm { flex: 1; min-width: 0; }
.slot.me { background: var(--pri-soft); border-radius: 12px; padding-inline: 10px; }
.slot.res .cls { color: var(--amb); font-size: 14.5px; width: 60px; }
.slot .edit { color: var(--muted); width: 18px; height: 18px; flex: none; }
.slot .flag { font-size: 12px; background: var(--red-soft); color: var(--red); border-radius: 8px; padding: 1px 8px; }
.pin { width: 15px; height: 15px; color: var(--pri); vertical-align: -2px; margin-inline-start: 4px; }
.sechead { font-size: 13px; color: var(--muted); font-weight: 500; margin: 14px 0 2px; }

/* الجدول الكامل */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
table.m { border-collapse: collapse; min-width: 640px; width: 100%; font-size: 13.5px; }
table.m th, table.m td { padding: 9px 8px; text-align: center; border-bottom: 1px solid var(--line); border-inline-start: 1px solid var(--line); }
table.m th { background: var(--pri-soft); color: var(--pri-dark); font-weight: 700; position: sticky; top: 0; }
table.m th small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
table.m td:first-child, table.m th:first-child { position: sticky; inset-inline-start: 0; background: #fff; font-weight: 700; border-inline-start: 0; z-index: 1; }
table.m th:first-child { background: var(--pri-soft); }
table.m tr.rs td { background: #fffaf2; }
table.m tr.rs td:first-child { background: #fffaf2; color: var(--amb); }
table.m td.me { background: var(--pri-soft); font-weight: 700; color: var(--pri-dark); }
table.m td.bad { background: var(--red-soft); color: var(--red); }
table.m td button { all: unset; cursor: pointer; display: block; width: 100%; }

/* الإدارة */
.step { display: flex; gap: 12px; }
.step > i { flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--pri); color: #fff; display: grid; place-items: center; font-style: normal; font-weight: 700; font-size: 14px; margin-top: 2px; }
.step > div { flex: 1; min-width: 0; }
.drow { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; align-items: center; margin-top: 12px; }
.drow b { font-size: 14px; grid-column: 1 / -1; margin-bottom: -2px; }
.drow input[type=date] { font-size: 14px; padding-inline: 8px; }
.drow select { padding-inline: 8px; }
.status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #98a8a4; }
.dot.ok { background: #1a9d6b; } .dot.warn { background: #d98a1f; }
.loads { width: 100%; border-collapse: collapse; font-size: 14px; }
.loads td, .loads th { padding: 7px 4px; border-top: 1px solid var(--line); text-align: center; }
.loads td:first-child, .loads th:first-child { text-align: start; }
details > summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary svg { transform: rotate(180deg); }
summary svg { width: 18px; height: 18px; color: var(--muted); }
.issues { margin: 8px 0 0; padding: 0; list-style: none; font-size: 14px; }
.issues li { padding: 4px 0; color: var(--red); }

/* النوافذ */
.overlay { position: fixed; inset: 0; background: rgba(10, 30, 27, .5); display: flex; align-items: flex-end; justify-content: center; z-index: 50; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.modal { background: #fff; width: 100%; max-width: 520px; max-height: 88vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); animation: up .2s ease; }
@keyframes up { from { transform: translateY(24px); opacity: .6; } }
@media (min-width: 640px) { .overlay { align-items: center; } .modal { border-radius: 22px; } }
.modal h3 { margin: 0 0 4px; font-size: 18px; }
.pinbox { text-align: center; padding: 6px 0 2px; }
.pinbox .avatar { margin: 0 auto 10px; width: 62px; height: 62px; }
.pinbox input { text-align: center; font-size: 26px; letter-spacing: 10px; direction: ltr; margin-top: 14px; min-height: 56px; }
.err { color: var(--red); font-size: 14px; min-height: 22px; margin-top: 8px; text-align: center; }
.pick { max-height: 52vh; overflow: auto; margin: 10px -6px 0; }
.pickrow { display: flex; align-items: center; gap: 10px; width: 100%; background: transparent; border: 0; border-top: 1px solid var(--line); padding: 10px 6px; text-align: start; }
.pickrow:first-child { border-top: 0; }
.pickrow:disabled { opacity: .45; }
.pickrow .nm { flex: 1; min-width: 0; }
.pickrow small { display: block; color: var(--muted); font-size: 12.5px; }
.pickrow .tag { font-size: 12px; border-radius: 8px; padding: 1px 8px; background: var(--amb-soft); color: var(--amb); white-space: nowrap; }
.pickrow .tag.red { background: var(--red-soft); color: var(--red); }
.pickrow.cur { background: var(--pri-soft); border-radius: 12px; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 14.5px; }
.check input { width: 20px; height: 20px; accent-color: var(--pri); }
.preview img { width: 100%; border-radius: 14px; border: 1px solid var(--line); display: block; }
.toast { position: fixed; bottom: calc(22px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 14px; font-size: 15px; z-index: 80; max-width: 90vw; text-align: center; animation: fade .2s ease; }
.banner { background: var(--amb-soft); color: var(--amb); border-radius: 12px; padding: 8px 12px; font-size: 14px; margin-bottom: 12px; }
.banner.red { background: var(--red-soft); color: var(--red); }
.foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: 22px; }
.foot button { background: none; border: 0; color: var(--pri); font-weight: 500; text-decoration: underline; }

@media print { .top, .seg, .terms, .nav, .row, .foot, .overlay, .toast { display: none !important; } body { background: #fff; } }
