/* Smart Private School — layout shell + reusable components (RTL). */

/* ============================ APP SHELL ============================ */
.app { display: flex; min-height: 100vh; }

/* Force the shell into a mirrored layout when the document language is Arabic.
   Some browsers/extensions handle logical properties inconsistently, so these
   physical-side fallbacks keep the app unmistakably RTL. */
html[dir="rtl"] .app { direction: rtl; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--navy-900);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset-block: 0;
  inset-inline-end: 0;            /* RTL: sidebar on the right */
  z-index: 40;
  border-inline-start: 1px solid var(--navy-800);
}
html[dir="rtl"] .sidebar {
  right: 0;
  left: auto;
  border-right: 1px solid var(--navy-800);
  border-left: none;
}
.sidebar__brand {
  padding: var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  border-bottom: 1px solid var(--navy-800);
}
/* The real school crest, not a lettermark placeholder. */
.sidebar__logo { width: 42px; height: 42px; object-fit: contain; flex-shrink: 0; }
.sidebar__title { font-size: var(--fs-sm); font-weight: 800; color: var(--gold-500); }
.sidebar__subtitle { font-size: 0.62rem; color: #9fb0c4; }

.sidebar__nav { flex: 1; padding: var(--sp-3) var(--sp-2); display: flex;
  flex-direction: column; gap: 1px; overflow-y: auto; }

/* Grouped navigation: 15 flat links is a wall. Sections give the operator a
   mental map (people → money → configuration → system). */
.nav-group { margin-top: var(--sp-4); }
.nav-group:first-child { margin-top: 0; }
.nav-group__label {
  font-size: 0.6rem; font-weight: 800; letter-spacing: .1em;
  color: #6b7f96; padding: 0 0.85rem var(--sp-2); text-transform: uppercase;
}
.nav-link {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 0.5rem 0.85rem; border-radius: var(--r-sm);
  color: #c7d2df; font-size: var(--fs-sm); font-weight: 600;
  border-inline-end: 2px solid transparent; transition: background .12s, color .12s;
}
html[dir="rtl"] .nav-link {
  border-right: 2px solid transparent;
  border-left: none;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-link.is-active { background: var(--navy-800); color: #fff;
  border-inline-end-color: var(--gold-500); }
html[dir="rtl"] .nav-link.is-active { border-right-color: var(--gold-500); }
.nav-link .ic { color: #7d90a8; width: 18px; flex-shrink: 0; }
.nav-link.is-active .ic { color: var(--gold-500); }

.sidebar__footer {
  padding: var(--sp-4); border-top: 1px solid var(--navy-800);
  background: var(--navy-950); font-size: var(--fs-xs); color: #9fb0c4;
}
.session-dot { width: 9px; height: 9px; border-radius: var(--r-full); background: var(--success-500); display: inline-block; }

/* Main column */
.main { flex: 1; margin-inline-end: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }
html[dir="rtl"] .main {
  margin-right: var(--sidebar-w);
  margin-left: 0;
}

.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--sp-6); position: sticky; top: 0; z-index: 30;
}
.breadcrumb { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-faint); }
.breadcrumb b { color: var(--navy-800); font-weight: 700; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--gold-700); }
.topbar__right { display: flex; align-items: center; gap: var(--sp-4); }
.back-btn { flex-shrink: 0; }

/* Global search — the counter clerk's fastest route to a student or receipt.
   Sits in the header on every page so "find someone" is never a navigation task. */
.global-search {
  display: flex; align-items: center; gap: var(--sp-2); margin: 0;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); padding: 0 var(--sp-3); height: 34px;
  min-width: 260px; transition: border-color .12s, box-shadow .12s, background .12s;
}
.global-search:focus-within {
  background: var(--surface); border-color: var(--gold-500); box-shadow: var(--focus-ring);
}
.global-search svg { color: var(--text-faint); flex-shrink: 0; }
.global-search input {
  border: 0; background: transparent; outline: none; width: 100%;
  font-family: inherit; font-size: var(--fs-sm); color: var(--text);
}
.global-search input::placeholder { color: var(--text-faint); }
.global-search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.global-search__hint {
  flex-shrink: 0; font-family: inherit; font-size: 0.65rem; font-weight: 700;
  color: var(--text-faint); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 1px 6px; line-height: 1.4;
}
.global-search:focus-within .global-search__hint { visibility: hidden; }
@media (max-width: 1100px) { .global-search { min-width: 0; width: 160px; } }
@media (max-width: 820px) { .global-search__hint { display: none; } }

.chip {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 0.35rem 0.7rem; border-radius: var(--r-md);
  font-size: var(--fs-xs); font-weight: 700;
}
.chip--gold { background: var(--gold-50); color: var(--gold-700); border: 1px solid var(--gold-100); }
.chip--success { background: var(--success-50); color: var(--success-700); border: 1px solid #bbf7d0; }

/* Notification bell */
.bell { position: relative; display: grid; place-items: center; width: 34px; height: 34px;
  border-radius: var(--r-full); color: var(--text-muted); }
.bell:hover { background: var(--surface-2); color: var(--navy-800); }
.bell__dot { position: absolute; top: -2px; inset-inline-end: -2px; min-width: 16px; height: 16px;
  padding: 0 4px; border-radius: var(--r-full); background: var(--danger-600); color: #fff;
  font-size: .6rem; font-weight: 800; display: grid; place-items: center; }
html[dir="rtl"] .bell__dot {
  right: -2px;
  left: auto;
}

/* Academic-year selector in the header */
.year-selector { display: inline-flex; align-items: center; gap: 6px; margin: 0;
  background: var(--gold-50); border: 1px solid var(--gold-100); color: var(--gold-700);
  padding: 0.25rem 0.6rem; border-radius: var(--r-md); }
.year-selector svg { color: var(--gold-600); }
.year-selector select { border: none; background: transparent; color: var(--gold-700);
  font-family: inherit; font-size: var(--fs-xs); font-weight: 700; cursor: pointer; padding: 2px; }
.year-selector select:focus { outline: none; }

.avatar {
  width: 34px; height: 34px; border-radius: var(--r-full);
  background: var(--navy-800); color: #fff; display: grid; place-items: center;
  font-size: var(--fs-xs); font-weight: 700; box-shadow: var(--shadow-sm);
}
.user-menu { display: flex; align-items: center; gap: var(--sp-2); }
.user-menu__name { font-size: var(--fs-xs); font-weight: 700; color: var(--text); line-height: 1.2; }
.user-menu__role { font-size: 0.62rem; color: var(--text-faint); }

.content { padding: var(--sp-6); flex: 1; }

/* ============================ PAGE HEADER ============================ */
/* The gold underline echoes the school's own printed form, where every section
   heading (اولا : بيانات الطالب) is set in gold. */
.page-head { display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--sp-4); margin-bottom: var(--sp-5); flex-wrap: wrap;
  padding-bottom: var(--sp-3); border-bottom: 1px solid var(--border); position: relative; }
.page-head::after { content: ""; position: absolute; bottom: -1px; inset-inline-start: 0;
  width: 56px; height: 2px; background: var(--gold-500); }
.page-head h1 { font-size: var(--fs-xl); letter-spacing: -.01em; }
.page-head p { color: var(--text-muted); font-size: var(--fs-xs); margin-top: 2px; }

/* ============================ CARDS ============================ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.card__head { padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.card__title { font-size: var(--fs-md); font-weight: 700; color: var(--navy-800); }
.card__body { padding: var(--sp-5); }
.card, .card__body, .card__head { min-width: 0; max-width: 100%; }

.grid { display: grid; gap: var(--sp-4); }
/* auto-fit keeps the metric row even at any count — no orphaned tile on row 2. */
.grid--kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 640px) { .grid--2 { grid-template-columns: 1fr; } }

/* Context strip — replaces the old gradient "hero".
   A school back-office needs orientation (which school, which year, is my till
   open), not a marketing header. Flat, dense, one line of chrome. */
.context-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-4); flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-top: var(--rule-gold);
  border-radius: var(--r-md); padding: var(--sp-4) var(--sp-5);
}
.context-bar__id { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.context-bar__crest { width: 40px; height: 40px; object-fit: contain; flex-shrink: 0; }
.context-bar__name { font-size: var(--fs-md); font-weight: 800; color: var(--navy-800); }
.context-bar__meta { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 1px; }
.context-bar__facts { display: flex; align-items: stretch; gap: 0; flex-wrap: wrap; }
.fact { padding: 0 var(--sp-5); border-inline-start: 1px solid var(--border); text-align: center; }
.fact:first-child { border-inline-start: none; }
html[dir="rtl"] .fact {
  border-right: 1px solid var(--border);
  border-left: none;
}
html[dir="rtl"] .fact:first-child { border-right: none; }
.fact__label { font-size: 0.66rem; color: var(--text-faint); font-weight: 700; }
.fact__value { font-size: var(--fs-md); font-weight: 800; color: var(--navy-800);
  font-variant-numeric: tabular-nums; }

/* Metric tile.
   No icon chip: seven identical icons in a row is noise, and the number *is*
   the content. State is carried by a severity rail on the leading edge. */
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-inline-start: 3px solid var(--navy-200);
  border-radius: var(--r-md); padding: var(--sp-4) var(--sp-5);
  display: flex; flex-direction: column; justify-content: center; min-height: 84px;
}
html[dir="rtl"] .kpi {
  border-right: 3px solid var(--navy-200);
  border-left: 1px solid var(--border);
}
.kpi__label { font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted); }
.kpi__value { font-size: var(--fs-2xl); font-weight: 800; color: var(--navy-800);
  line-height: 1.15; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi__unit { font-size: var(--fs-xs); font-weight: 700; color: var(--text-faint);
  margin-inline-start: 4px; }
.kpi__hint { font-size: 0.66rem; color: var(--text-faint); margin-top: 3px; }
.kpi--success { border-inline-start-color: var(--success-500); }
.kpi--success .kpi__value { color: var(--success-700); }
.kpi--danger  { border-inline-start-color: var(--danger-500); }
.kpi--danger .kpi__value { color: var(--danger-600); }
.kpi--warning { border-inline-start-color: var(--warning-500); }
.kpi--warning .kpi__value { color: var(--warning-700); }
.kpi--navy { border-inline-start-color: var(--navy-800); }
html[dir="rtl"] .kpi--success { border-right-color: var(--success-500); }
html[dir="rtl"] .kpi--danger { border-right-color: var(--danger-500); }
html[dir="rtl"] .kpi--warning { border-right-color: var(--warning-500); }
html[dir="rtl"] .kpi--navy { border-right-color: var(--navy-800); }

/* ============================ BUTTONS ============================ */
.btn {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 0.55rem 1rem; border-radius: var(--r-md);
  font-size: var(--fs-sm); font-weight: 700; border: 1px solid transparent;
  transition: background .15s, box-shadow .15s, color .15s; white-space: nowrap;
}
.btn--primary { background: var(--navy-800); color: #fff; }
.btn--primary:hover { background: var(--navy-900); color: #fff; }
.btn--gold { background: var(--gold-500); color: var(--navy-900); }
.btn--gold:hover { background: var(--gold-600); }
.btn--secondary { background: var(--surface); color: var(--navy-800); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--surface-2); }
.btn--success { background: var(--success-600); color: #fff; } .btn--success:hover { background: var(--success-700); }
.btn--danger { background: var(--danger-600); color: #fff; } .btn--danger:hover { background: var(--danger-700); }
.btn--warning { background: var(--warning-600); color: #fff; } .btn--warning:hover { background: var(--warning-700); }
.btn--block { width: 100%; justify-content: center; }
.btn--sm { padding: 0.35rem 0.7rem; font-size: var(--fs-xs); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ============================ BADGES ============================ */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 0.2rem 0.6rem; border-radius: var(--r-full); font-size: 0.68rem; font-weight: 700; }
.badge--success { background: var(--success-50); color: var(--success-700); }
.badge--danger  { background: var(--danger-50);  color: var(--danger-700); }
.badge--warning { background: var(--warning-50); color: var(--warning-700); }
.badge--info    { background: var(--info-50);    color: var(--info-600); }
.badge--neutral { background: var(--navy-50);    color: var(--navy-700); }
.badge--gold    { background: var(--gold-50);    color: var(--gold-700); }
.muted { color: var(--text-faint); font-size: var(--fs-xs); }

/* ============================ TABLES ============================ */
.table-wrap { overflow-x: auto; }
.table-wrap { -webkit-overflow-scrolling: touch; max-width: 100%; }
.table-meta {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  margin: 0 0 .55rem;
  padding: .28rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 800;
}
.table-meta b {
  color: var(--navy-800);
  font-size: var(--fs-sm);
}
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table thead th {
  background: var(--surface-2); color: var(--text-muted); font-weight: 700;
  text-align: right; padding: 0.6rem 1rem; white-space: nowrap;
  border-bottom: 1px solid var(--border-strong);
  font-size: var(--fs-xs); letter-spacing: .02em;
}
.table tbody td { padding: 0.62rem 1rem; border-bottom: 1px solid var(--border); color: var(--text); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
/* Zebra striping earns its keep on long financial registers. */
.table tbody tr:nth-child(even) { background: rgba(127,140,160,.035); }
.table tbody tr:nth-child(even):hover { background: var(--surface-2); }
.table--compact tbody td, .table--compact thead th { padding: 0.42rem 1rem; }
.table__serial {
  width: 4.6rem;
  min-width: 4.6rem;
  text-align: center !important;
  color: var(--text-muted);
  font-weight: 800;
  white-space: nowrap;
}
.table__serial--head {
  color: var(--navy-800) !important;
}
[aria-live="polite"].is-searching { opacity: .55; pointer-events: none; transition: opacity .15s; }

/* The "start a payment" lane: gold edge marks it as the page's primary act,
   distinct from the filter box directly beneath it. */
.start-payment { border-inline-start: 3px solid var(--gold-500); }

/* Dashboard worklist rows that lead somewhere — the whole row reads as clickable. */
.worklist-row:hover { background: var(--gold-50); }
.worklist-row a { color: var(--navy-700); font-weight: 700; }
.worklist-row:hover a { color: var(--gold-700); }

/* ============================ FORMS ============================ */
.field { margin-bottom: var(--sp-4); }
.field__label { display: block; font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted); margin-bottom: 6px; }
.field__label .req { color: var(--danger-600); }
.field__input, .field select, textarea.field__input {
  width: 100%; min-width: 0; max-width: 100%; padding: 0.6rem 0.8rem; font-family: inherit; font-size: var(--fs-sm);
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border-strong); border-radius: var(--r-md); transition: border-color .15s, box-shadow .15s;
}
.field__input:focus, .field select:focus { border-color: var(--gold-500); box-shadow: var(--focus-ring); background: var(--surface); }
/* Typing a phone/ID/email in an RTL form: the value is left-to-right, but the
   field stays right-aligned like every other field on the page. Without this the
   caret jumps and a leading "+" lands on the wrong end of the number. */
.field__input[dir="ltr"] { direction: ltr; text-align: right; }
.field__input[dir="ltr"]::placeholder { text-align: right; }
.field__error { color: var(--danger-600); font-size: var(--fs-xs); margin-top: 5px; }
.field__hint { color: var(--text-faint); font-size: var(--fs-xs); margin-top: 5px; }
.field ul { list-style: none; margin: 0; padding: 0; }
.field ul:has(input[type="checkbox"]) {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.35rem 0.75rem; padding: 0.65rem;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); max-height: 320px; overflow: auto;
}
.field li label { display: flex; align-items: center; gap: 0.45rem; font-size: var(--fs-xs); }
.role-picker {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.55rem; padding: 0.7rem;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
}
.role-picker > div { margin: 0; }
.role-picker label {
  min-height: 44px; display: flex; align-items: center; gap: 0.5rem;
  padding: 0.55rem 0.7rem; border: 1px solid var(--border);
  border-radius: var(--r-sm); background: var(--surface);
  font-size: var(--fs-xs); font-weight: 800; color: var(--navy-800);
}
.role-picker input { accent-color: var(--gold-600); }
.role-access-list {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.65rem; margin-top: 0.75rem;
}
.role-access-card {
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 0.75rem; background: var(--surface);
}
.role-access-card__title { color: var(--navy-800); font-size: var(--fs-xs); font-weight: 800; }
.role-access-card p { margin-top: 0.35rem; color: var(--text-muted); font-size: var(--fs-xs); line-height: 1.7; }
.input-money { position: relative; }
.input-money .suffix { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%); color: var(--text-faint); font-size: var(--fs-xs); }
html[dir="rtl"] .input-money .suffix {
  right: 10px;
  left: auto;
}

/* ============================ ALERTS ============================ */
.alerts { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.alert { display: flex; align-items: flex-start; gap: var(--sp-3); padding: 0.7rem 1rem; border-radius: var(--r-md); font-size: var(--fs-sm); border: 1px solid transparent; }
.alert--success { background: var(--success-50); color: var(--success-700); border-color: #bbf7d0; }
.alert--danger  { background: var(--danger-50);  color: var(--danger-700); border-color: #fecaca; }
.alert--warning { background: var(--warning-50); color: var(--warning-700); border-color: #fde68a; }
.alert--info    { background: var(--info-50);    color: var(--info-600);   border-color: #bfdbfe; }
.alert__close { margin-inline-start: auto; background: none; border: none; color: inherit; opacity: .6; font-size: 1rem; }
.alert__close:hover { opacity: 1; }

/* ============================ EMPTY STATE ============================ */
.empty { text-align: center; padding: var(--sp-10) var(--sp-6); color: var(--text-muted); }
.empty__icon { width: 56px; height: 56px; margin: 0 auto var(--sp-3); border-radius: var(--r-full); background: var(--navy-50); display: grid; place-items: center; color: var(--navy-200); }

/* ============================ PAGINATION ============================ */
.pager { display: flex; gap: var(--sp-2); justify-content: center; margin-top: var(--sp-5); }
.pager a, .pager span { padding: 0.35rem 0.7rem; border-radius: var(--r-md); font-size: var(--fs-xs); font-weight: 700; border: 1px solid var(--border); color: var(--navy-800); }
.pager .is-current { background: var(--navy-800); color: #fff; border-color: var(--navy-800); }

/* ============================ AUTH ============================ */
/* Flat navy ground — no gradient wash. The crest supplies the identity. */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--sp-6);
  background: var(--navy-900); }
.auth__card { width: 100%; max-width: 380px; background: var(--surface);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg); overflow: hidden;
  border-top: 3px solid var(--gold-500); }
.auth__head { padding: var(--sp-8) var(--sp-6) var(--sp-5); text-align: center;
  border-bottom: 1px solid var(--border); }
.auth__logo { width: 72px; height: 72px; margin: 0 auto var(--sp-3); object-fit: contain; }
.auth__head h1 { color: var(--navy-800); font-size: var(--fs-md); line-height: 1.5; }
.auth__head p { color: var(--text-muted); font-size: var(--fs-xs); margin-top: 4px; }
.auth__body { padding: var(--sp-6); }

/* ============================ TABS ============================ */
/* Without JS every panel is visible (progressive enhancement). The JS adds
   .js-tabs, which switches to one-panel-at-a-time. */
.tabs__nav { display: flex; gap: var(--sp-2); flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: var(--sp-5); }
.tab { padding: 0.55rem 0.9rem; font-size: var(--fs-sm); font-weight: 700; color: var(--text-muted);
  border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--navy-800); }
.tab.is-active { color: var(--navy-800); border-bottom-color: var(--gold-500); }
.tabpanel { margin-bottom: var(--sp-6); }
.tabs.js-tabs .tabpanel { display: none; margin-bottom: 0; }
.tabs.js-tabs .tabpanel.is-active { display: block; }

/* ============================ FILTER BAR ============================ */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-3); align-items: end; }

/* ============================ MISC ============================ */
.stack { display: flex; flex-direction: column; gap: var(--sp-5); }
.row { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.sidebar-toggle { display: none; background: none; border: none; color: var(--navy-800); font-size: 1.3rem; }

/* ============================ RESPONSIVE ============================ */
@media (max-width: 900px) {
  .sidebar { width: min(var(--sidebar-w), 86vw); transform: translateX(100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .app.nav-open .sidebar { transform: translateX(0); }
  .main { margin-inline-end: 0; }
  html[dir="rtl"] .main {
    margin-right: 0;
    margin-left: 0;
  }
  .sidebar-toggle { display: inline-block; }
}

/* The topbar packs a search box, year selector, bell, user menu, profile and
   logout buttons into one row with no wrap. On a phone that is more content
   than fits next to a back button and breadcrumb, so it is trimmed in stages
   rather than left to overflow the page sideways — dropping the least useful
   text first, in order, rather than hiding anything a control depends on to
   stay reachable. */
@media (max-width: 640px) {
  .topbar {
    height: auto;
    min-height: var(--header-h);
    align-items: stretch;
    flex-wrap: wrap;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
  }
  .topbar > .row {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
    flex-wrap: nowrap;
  }
  .topbar__right {
    width: 100%;
    gap: var(--sp-2);
  }
  .global-search {
    flex: 1 1 11rem;
    width: auto;
    min-width: 0;
  }
  .year-selector {
    max-width: 11rem;
    min-width: 0;
  }
  .year-selector select {
    min-width: 0;
    max-width: 100%;
  }
  .content {
    padding: var(--sp-4) var(--sp-3);
  }
  .row {
    flex-wrap: wrap;
  }
  .row > * {
    min-width: 0;
  }
  .btn {
    max-width: 100%;
    min-height: 38px;
    justify-content: center;
  }
  .card__body {
    padding: var(--sp-4);
  }
  .card[style*="max-width"] {
    max-width: 100% !important;
  }
  .tabs__nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .tab {
    white-space: nowrap;
    flex: 0 0 auto;
  }
  form .row,
  form.row {
    align-items: stretch;
  }
  form .row .field__input,
  form.row .field__input {
    flex: 1 1 12rem;
  }
  .page-head {
    align-items: stretch;
  }
  .page-head > div:first-child {
    min-width: 0;
  }
  .page-head h1,
  .card__title,
  .breadcrumb b {
    overflow-wrap: anywhere;
  }
  .page-head > .row,
  .card__head {
    flex-wrap: wrap;
  }
  .page-head .btn,
  .card__head .btn {
    flex: 1 1 auto;
  }
  .filters {
    grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  }
  .filters .field {
    min-width: 0 !important;
  }
  .kpi {
    padding: var(--sp-3) var(--sp-4);
  }
  .kpi__value {
    font-size: var(--fs-xl);
    overflow-wrap: anywhere;
  }
  .table {
    min-width: max-content;
  }
  .table thead th,
  .table tbody td {
    padding-inline: .65rem;
  }
  .search-dropdown {
    max-width: calc(100vw - 1.5rem);
  }
  .search-dropdown__item {
    align-items: flex-start;
    flex-direction: column;
    gap: 1px;
  }
  .search-dropdown__subtitle {
    white-space: normal;
  }
  .workspace-actions {
    flex-wrap: wrap;
    padding: var(--sp-2) var(--sp-3);
  }
  .workspace-actions .btn {
    min-width: min(10rem, 100%);
  }
  .breadcrumb__home, .breadcrumb__sep { display: none; }
  .user-menu__text { display: none; }
  .logout-btn .btn__label { display: none; }
}

/* Emergency valve: if a page still does not fit (a very long report title, an
   unusually wide inline control), this group scrolls within itself instead of
   the whole page gaining a horizontal scrollbar. */
@media (max-width: 480px) {
  .topbar__right { overflow-x: auto; padding-bottom: 1px; }
  .global-search {
    order: 1;
    flex-basis: 100%;
  }
  .year-selector {
    max-width: none;
    flex: 1 1 9rem;
  }
  .avatar {
    width: 30px;
    height: 30px;
  }
  .btn--sm {
    padding-inline: .55rem;
  }
  .filters {
    grid-template-columns: 1fr;
  }
  .page-head .btn,
  .card__head .btn,
  .workspace-actions .btn {
    width: 100%;
  }
  .photo-upload {
    flex-direction: column;
    align-items: flex-start;
  }
  .merge-student[open] .merge-bar {
    position: static;
    width: 100%;
    margin-top: .4rem;
  }
  .chat-msg {
    max-width: 92%;
  }
}

/* Report menu links */
.report-links { display: flex; flex-direction: column; gap: 2px; }
.report-links a { padding: 0.6rem 0.75rem; border-radius: var(--r-md); font-size: var(--fs-sm);
  font-weight: 600; color: var(--navy-800); border: 1px solid transparent; }
.report-links a:hover { background: var(--navy-50); border-color: var(--border); color: var(--gold-700); }

/* ============================ PROFILE PHOTO UPLOAD ============================ */
.photo-upload {
  display: flex; align-items: center; gap: var(--sp-5);
  padding: var(--sp-4) 0 var(--sp-5); margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border);
}

/* Circular preview container */
.photo-upload__preview-wrap {
  position: relative; flex-shrink: 0;
  width: 96px; height: 96px;
}

/* The <img> itself — fills the circle */
.photo-upload__preview {
  width: 96px; height: 96px;
  border-radius: var(--r-full);
  object-fit: cover;
  border: 3px solid var(--border-strong);
  background: var(--surface-2);
  display: block;
}
/* Hide the <img> when no photo is set (placeholder SVG shows instead) */
.photo-upload__preview--empty { opacity: 0; position: absolute; inset: 0; }

/* Silhouette placeholder shown when no photo */
.photo-upload__placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  width: 96px; height: 96px;
  border-radius: var(--r-full);
  background: var(--navy-50);
  border: 3px solid var(--border-strong);
  color: var(--navy-200);
}

/* Gold camera badge — click opens file picker */
.photo-upload__badge {
  position: absolute;
  bottom: 0; inset-inline-end: 0;
  width: 28px; height: 28px;
  border-radius: var(--r-full);
  background: var(--gold-500);
  color: var(--navy-900);
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
  cursor: pointer;
  transition: background .15s, transform .15s;
}
html[dir="rtl"] .photo-upload__badge { right: 0; left: auto; }
.photo-upload__badge:hover { background: var(--gold-600); transform: scale(1.08); }

/* Right-side text + button */
.photo-upload__info { display: flex; flex-direction: column; gap: var(--sp-2); }
.photo-upload__label { font-size: var(--fs-sm); font-weight: 700; color: var(--text); }
.photo-upload__hint { font-size: var(--fs-xs); color: var(--text-faint); }

/* ============================ STUDENT WORKSPACE ============================ */
.student-workspace { padding-bottom: 78px; }
.workspace-steps {
  position: sticky; top: 62px; z-index: 20;
  display: flex; gap: var(--sp-2); flex-wrap: wrap;
  margin-bottom: var(--sp-4); padding: var(--sp-3);
  background: rgba(255, 255, 255, .96); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-sm);
}
.workspace-steps a {
  padding: .35rem .7rem; border-radius: var(--r-md);
  color: var(--navy-700); background: var(--surface-2);
  font-size: var(--fs-xs); font-weight: 700;
}
.workspace-steps a:hover { color: var(--gold-700); background: var(--gold-50); }
.workspace-section { scroll-margin-top: 126px; overflow: hidden; }
.workspace-section__number {
  display: inline-grid; place-items: center; width: 26px; height: 26px;
  margin-inline-end: var(--sp-2); border-radius: var(--r-full);
  color: #fff; background: var(--navy-800); font-size: var(--fs-xs); font-weight: 800;
}
.workspace-section__hint {
  color: var(--text-muted); font-size: var(--fs-xs); margin-bottom: var(--sp-4);
}
.workspace-fields {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 var(--sp-5);
}
.workspace-fields > .alert,
.workspace-fields > input[type="hidden"],
.workspace-field--wide { grid-column: 1 / -1; }
.workspace-actions {
  position: fixed; bottom: 0; inset-inline-start: 0; inset-inline-end: var(--sidebar-w);
  z-index: 30; display: flex; align-items: center; justify-content: center;
  gap: var(--sp-3); padding: var(--sp-3) var(--sp-6);
  background: rgba(255, 255, 255, .97); border-top: 1px solid var(--border-strong);
  box-shadow: 0 -4px 18px rgba(11, 34, 64, .08);
}
html[dir="rtl"] .workspace-actions { right: 0; left: var(--sidebar-w); }
@media (max-width: 900px) {
  .workspace-actions, html[dir="rtl"] .workspace-actions { right: 0; left: 0; }
  .workspace-steps { top: 54px; }
}
@media (max-width: 640px) {
  .workspace-fields { grid-template-columns: 1fr; }
  .workspace-field--wide { grid-column: auto; }
  .workspace-steps { position: static; }
  .workspace-actions { justify-content: stretch; }
  .workspace-actions .btn { flex: 1; justify-content: center; }
}
.registration-print-callout {
  align-items: center; justify-content: space-between; flex-wrap: wrap;
  margin-bottom: var(--sp-5); border-inline-start: 4px solid var(--success-500);
}
.installment-editor > summary { cursor: pointer; list-style: none; }
.installment-editor > summary::-webkit-details-marker { display: none; }
.future-installment-row {
  display: grid; grid-template-columns: auto minmax(180px, 1fr) minmax(220px, 2fr);
  align-items: start; gap: var(--sp-3); padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border);
}
.future-installment-row:last-of-type { border-bottom: 0; }
.future-installment-row .field { margin: 0; }
@media (max-width: 640px) {
  .future-installment-row { grid-template-columns: 1fr; }
}

/* ============================ SEARCH SUGGESTIONS DROPDOWN ============================ */
/* Floats over every `data-live-search` box: positioned in JS from the input's
   own bounding box (not a CSS-relative ancestor), so it needs no cooperation
   from whatever markup happens to wrap the input on a given page. */
.search-dropdown {
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  max-height: 320px;
  overflow-y: auto;
}
.search-dropdown__item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.search-dropdown__item:last-child { border-bottom: 0; }
.search-dropdown__item:hover,
.search-dropdown__item.is-active { background: var(--gold-50); }
.search-dropdown__label { font-weight: 700; color: var(--text); }
.search-dropdown__subtitle {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  white-space: nowrap;
  flex-shrink: 0;
}

/* The row a chosen suggestion scrolls to, when it has no link to follow —
   a brief flash rather than a permanent style, so it reads as "here it is"
   and not as a new, lasting selection state. */
@keyframes searchRowFlash {
  0%, 100% { background: transparent; }
  20%, 80% { background: var(--gold-100); }
}
.table tbody tr.is-highlighted { animation: searchRowFlash 1.6s ease; }

/* Cash/POS breakdown inside an installment row — the office's own tuition
   spreadsheet keeps a per-installment amount+date for each payment method;
   this is the same information surfaced from the payment ledger instead of
   hand-copied. Each row is one method actually used for that installment;
   an installment with no payments yet shows nothing (the empty "—" state). */
.pay-breakdown { display: flex; flex-direction: column; gap: 2px; }
.pay-breakdown__row { display: flex; align-items: baseline; gap: var(--sp-2); white-space: nowrap; }
.pay-breakdown__label { font-size: var(--fs-xs); font-weight: 700; color: var(--text-faint); flex-shrink: 0; }
.pay-breakdown__dates { font-size: 0.66rem; color: var(--text-faint); }

/* Weekly timetable grids */
.timetable .tt-cell { text-align: center; vertical-align: top; min-width: 6.5rem; }
.timetable .tt-break { background: var(--navy-50); color: var(--text-muted); font-size: var(--fs-xs);
  text-align: center; width: 2.25rem; min-width: 2.25rem; padding-inline: .2rem; writing-mode: vertical-rl; }
.timetable td.tt-locked { background: var(--gold-50, #fff8e6); }
.timetable td.tt-moving { outline: 2px dashed var(--gold-500); outline-offset: -3px; }
.tt-page + .tt-page { margin-top: 1.5rem; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  .tt-page { break-after: page; margin: 0 !important; }
  .tt-page:last-child { break-after: auto; }
  .tt-print { font-size: 11px; width: 100%; }
  .tt-print th, .tt-print td { border: 1px solid #000 !important; padding: 4px !important; }
}
.tt-chip { border-radius: 6px; padding: .3rem .35rem; border-inline-start: 3px solid var(--c, #8a94a6);
  background: var(--bg, #f4f6f9); display: flex; flex-direction: column; gap: 1px; text-align: center; }
.tt-chip small { color: var(--text-muted); font-size: var(--fs-xs); }
.tt-chip[data-slot] { cursor: grab; }
.tt-chip[data-slot]:active { cursor: grabbing; }
.timetable td.tt-over { outline: 2px solid var(--gold-500); outline-offset: -3px; background: var(--gold-50); }
.timetable td.tt-blocked { background: #fdecec; }
.timetable td.tt-drag-source { opacity: .45; }
.tone-0  { --c:#2f6fb3; --bg:#e8f1fb; } .tone-1  { --c:#2e8b57; --bg:#e7f5ec; }
.tone-2  { --c:#c77d1a; --bg:#fcf1e1; } .tone-3  { --c:#8e44ad; --bg:#f3e9f8; }
.tone-4  { --c:#c0392b; --bg:#fbe9e7; } .tone-5  { --c:#138d90; --bg:#e2f4f4; }
.tone-6  { --c:#6d7b1f; --bg:#f1f4df; } .tone-7  { --c:#b0457a; --bg:#fae8f1; }
.tone-8  { --c:#3b4cc0; --bg:#eaecfb; } .tone-9  { --c:#9a6b3d; --bg:#f5ede4; }
.tone-10 { --c:#1f7a3f; --bg:#e3f2e8; } .tone-11 { --c:#5a6270; --bg:#eef0f3; }
.tt-actions { display: flex; gap: .2rem; justify-content: center; margin-top: .3rem; flex-wrap: wrap; }
.tt-actions .btn--sm { padding: .1rem .4rem; min-width: 1.7rem; }

/* Timetable centre */
.tt-steps .tab { font-size: var(--fs-base, 1rem); padding: .7rem 1rem; }
.tt-step-n { display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%;
  background: var(--navy-50); color: var(--navy-800); font-weight: 800; margin-inline-end: .35rem; }
.tt-steps .tab.is-active .tt-step-n { background: var(--gold-500); color: var(--navy-900); }
.tt-daychips { display: flex; flex-wrap: wrap; gap: .4rem; }
.tt-daychip input { position: absolute; opacity: 0; pointer-events: none; }
.tt-daychip span { display: inline-block; padding: .45rem .9rem; border-radius: 999px; border: 1.5px solid var(--border);
  cursor: pointer; font-weight: 700; color: var(--text-muted); user-select: none; }
.tt-daychip input:checked + span { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
.tt-daychip input:focus-visible + span { outline: 2px solid var(--gold-500); outline-offset: 2px; }
.tt-savebar { position: sticky; bottom: 0; z-index: 5; display: flex; gap: .5rem; flex-wrap: wrap; padding: .75rem 0;
  background: linear-gradient(to top, var(--bg, #f7f8fa) 70%, transparent); }
.tt-matrix-wrap { max-height: 70vh; overflow: auto; }
.tt-matrix { font-size: var(--fs-sm); }
.tt-matrix th, .tt-matrix td { padding: .25rem .3rem; white-space: nowrap; }
.tt-matrix thead th { position: sticky; top: 0; background: var(--surface, #fff); z-index: 3; text-align: center; }
.tt-matrix tfoot th { position: sticky; bottom: 0; background: var(--navy-50); z-index: 3; text-align: center; }
.tt-matrix .tt-sticky { position: sticky; right: 0; background: var(--surface, #fff); z-index: 2; min-width: 11rem; }
.tt-matrix .tt-sticky2 { position: sticky; right: 11.6rem; background: var(--surface, #fff); z-index: 2; min-width: 9rem; }
.tt-matrix thead .tt-sticky, .tt-matrix thead .tt-sticky2, .tt-matrix tfoot .tt-sticky, .tt-matrix tfoot .tt-sticky2 { z-index: 4; }
.tt-matrix select.field__input { padding: .25rem .35rem; font-size: var(--fs-sm); }
.tt-num { width: 3.1rem; text-align: center; padding: .3rem .1rem; border: 1px solid var(--border); border-radius: 6px; font-weight: 700; }
.tt-num:not(:placeholder-shown):not([value=""]) { background: var(--gold-50); }
.tt-coltotal.is-over { background: #fdecec !important; color: var(--danger-600); }
.tt-coltotal.is-full { background: var(--success-50) !important; color: var(--success-700); }
.tt-newrow td { background: #fbfcfe; }
.tt-picker { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
@media (max-width: 640px) { .tt-matrix .tt-sticky, .tt-matrix .tt-sticky2 { position: static; } }

/* سجل الحركات */
.audit-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: .6rem; }
.audit-diff { font-size: var(--fs-xs); border-collapse: collapse; margin-top: .35rem; }
.audit-diff th { text-align: start; color: var(--text-muted); padding: 2px 8px 2px 0; font-weight: 700; white-space: nowrap; vertical-align: top; }
.audit-diff td { padding: 2px 0; word-break: break-word; }
.audit-old { color: var(--danger-600); text-decoration: line-through; }
.audit-new { color: var(--success-700); font-weight: 700; }
.audit-table details summary { cursor: pointer; color: var(--navy-800); font-weight: 700; }
@media (max-width: 720px) {
  .audit-table thead { display: none; }
  .audit-table tr { display: block; border-bottom: 1px solid var(--border); padding: .5rem 0; }
  .audit-table td { display: flex; gap: .5rem; border: 0 !important; padding: .15rem .75rem !important; }
  .audit-table td::before { content: attr(data-label); min-width: 5.5rem; color: var(--text-muted); font-size: var(--fs-xs); font-weight: 700; }
}

/* Timetable on phones */
.tt-daylist { display: none; }
@media (max-width: 760px) {
  .tt-gridwrap { display: none; }
  .tt-daylist { display: grid; gap: .75rem; padding: .5rem; }
  .tt-day { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface, #fff); }
  .tt-day__head { background: var(--navy-800); color: #fff; font-weight: 800; padding: .5rem .75rem; }
  .tt-day__break { background: var(--gold-50); color: #8a6d2b; font-size: var(--fs-xs); font-weight: 700; text-align: center; padding: .25rem; }
  .tt-day__row { display: grid; grid-template-columns: 3.2rem 1fr; gap: .5rem; align-items: center; padding: .45rem .6rem; border-top: 1px solid var(--border); }
  .tt-day__row .tt-actions { grid-column: 1 / -1; justify-content: flex-start; margin-top: 0; }
  .tt-day__time { font-weight: 800; color: var(--navy-800); text-align: center; line-height: 1.1; }
  .tt-day__time small { display: block; font-size: .65rem; color: var(--text-muted); font-weight: 600; }
  .tt-day__row.tt-locked { background: var(--gold-50); }
  .tt-steps { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .tt-steps .tab { white-space: nowrap; padding: .55rem .6rem; font-size: var(--fs-sm); }
  .tt-center .grid--2 { grid-template-columns: 1fr; }
  .tt-center .card__head { flex-wrap: wrap; }
  .tt-savebar { padding-inline: .25rem; }
  .tt-savebar .btn { flex: 1 1 auto; justify-content: center; }
  .tt-matrix-wrap { max-height: none; }
  .tt-center .page-head .row, .page-head .row { flex-wrap: wrap; }
  .tt-picker .btn--sm { flex: 0 0 auto; }
  .tt-picker { flex-wrap: nowrap; overflow-x: auto; padding-bottom: .25rem; }
  .tt-picker select { max-width: 100% !important; }
  .tt-center input[type=time] { min-width: 6.5rem; }
}
.merge-bar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; padding: .6rem .9rem;
  border-top: 1px dashed var(--border); background: var(--gold-50); }
.merge-bar .field__input { flex: 1 1 14rem; max-width: 26rem; }
.merge-student { position: relative; }
.merge-student > summary { list-style: none; cursor: pointer; }
.merge-student > summary::-webkit-details-marker { display: none; }
.merge-student[open] .merge-bar { position: absolute; inset-inline-end: 0; top: calc(100% + .35rem); z-index: 20;
  width: min(28rem, 90vw); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.12); }
.progress { display: inline-block; width: 5rem; height: .45rem; border-radius: 999px; background: var(--navy-50);
  overflow: hidden; vertical-align: middle; margin-inline-end: .35rem; }
.progress > span { display: block; height: 100%; background: var(--success-600); }

/* App chat inbox */
.nav-badge { margin-inline-start: auto; background: var(--gold-500); color: var(--navy-900); border-radius: 999px;
  font-size: .7rem; font-weight: 800; padding: 0 .45rem; min-width: 1.3rem; text-align: center; }
.chat-layout { display: grid; grid-template-columns: 1fr 18rem; gap: 1rem; align-items: start; }
@media (max-width: 860px) { .chat-layout { grid-template-columns: 1fr; } }
.chat-card { display: flex; flex-direction: column; }
.chat-log { height: min(60vh, 34rem); overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .6rem;
  background: var(--navy-50); }
.chat-msg { max-width: 75%; padding: .55rem .75rem; border-radius: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.chat-msg--user { align-self: flex-start; background: #fff; border-start-start-radius: 4px; }
.chat-msg--staff { align-self: flex-end; background: #dcefe3; border-start-end-radius: 4px; }
.chat-msg__tag { font-size: var(--fs-xs); color: var(--navy-800); font-weight: 700; margin-bottom: .2rem; }
.chat-msg__body { white-space: pre-wrap; word-break: break-word; }
.chat-msg__img { max-width: 14rem; max-height: 14rem; border-radius: 8px; margin-top: .3rem; display: block; }
.chat-msg__meta { font-size: .68rem; color: var(--text-muted); margin-top: .25rem; }
.chat-reply { display: grid; gap: .5rem; padding: .75rem; border-top: 1px solid var(--border); }

/* Shown only on paper (e.g. the printed-at line of a report). */
.only-print { display: none; }
@media print { .only-print { display: inline; } }

/* D-157: «اليوم» / «أمس» under a money date */
.quick-date { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 5px; }
.quick-date__btn { font: inherit; font-size: var(--fs-xs); padding: 2px 10px; border-radius: var(--r-full); cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--navy-800); }
.quick-date__btn:hover { background: var(--gold-50); border-color: var(--gold-500); }
.quick-date__note { font-size: var(--fs-xs); font-weight: 700; color: var(--warning-700); }
