/* Tulip International College — same identity as the School Timetable System. */

/* ============ Tokens ============ */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #2b2a45;
  --muted: #6f6e8a;
  --primary: #2b9fd8;
  --primary-2: #3fb0e6;
  --primary-dark: #4b3b85;
  --violet: #7a63ad;
  --accent: #7ecbef;
  --border: #e4e7f2;
  --input-border: #d5d9e8;
  --th: #eef4fb;
  --th2: #ece8f6;
  --ok: #1f9d6a;
  --ok-soft: #e4f7ee;
  --warn: #c47a1a;
  --warn-soft: #fff4e0;
  --danger: #d64560;
  --danger-soft: #fde8ec;
  --brand-gradient: linear-gradient(110deg, #3f2f78 0%, #5a4a99 45%, #2b9fd8 100%);
  --brand-gradient-diag: linear-gradient(135deg, #3f2f78 0%, #5a4a99 50%, #2b9fd8 100%);
  --active-gradient: linear-gradient(120deg, var(--primary-dark), var(--violet));
  --shadow: 0 4px 18px rgba(75, 59, 133, .08);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, .35);
  --radius: 14px;
  color-scheme: light;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; overflow-x: clip; }
body {
  font-family: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 15px; line-height: 1.5;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
img, canvas, svg { max-width: 100%; }
.ic { width: 18px; height: 18px; flex: none; }
.container { max-width: 1240px; margin: 0 auto; padding: 0 26px; }
[hidden] { display: none !important; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 18px;
  border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 700; font-size: 14px;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: filter .15s, transform .15s, background .15s, box-shadow .15s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn .ic { width: 16px; height: 16px; }
.btn-primary {
  background: linear-gradient(120deg, var(--primary), var(--primary-2));
  border-color: var(--primary); color: #fff;
  box-shadow: 0 2px 8px rgba(43, 159, 216, .25);
}
.btn-soft { background: var(--th2); color: var(--primary-dark); }
.btn-ghost { background: #fff; color: var(--primary-dark); border-color: #cfd3e6; }
.btn-danger { background: linear-gradient(120deg, #d64560, #e25d76); border-color: var(--danger); color: #fff; }
@media (hover: hover) {
  .btn-primary:hover, .btn-danger:hover { filter: brightness(1.06); transform: translateY(-1px); }
  .btn-ghost:hover { background: var(--th); }
  .btn-soft:hover { background: #e2dcf2; }
}
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; min-height: 46px; font-size: 15px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 9px;
  border: 1px solid transparent; background: transparent; color: var(--muted);
  cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn .ic { width: 17px; height: 17px; }
@media (hover: hover) {
  .icon-btn:hover { background: var(--th); color: var(--primary-dark); }
  .icon-btn.danger:hover { background: #fff1f4; color: var(--danger); }
}

/* Pill buttons on the gradient header (like the timetable's language / sign-out buttons) */
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 13px; font-weight: 700;
  height: 36px; padding: 0 16px; border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, .6); background: rgba(255, 255, 255, .14); color: #fff;
  cursor: pointer; transition: background .15s;
}
.pill-btn .ic { width: 16px; height: 16px; }
@media (hover: hover) { .pill-btn:hover { background: rgba(255, 255, 255, .3); } }

/* ============ Forms ============ */
.field { display: block; margin-bottom: 14px; text-align: start; }
.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
/* 16px inputs stop iOS Safari from zooming when a field is focused. */
.input, .field input, .field select, select.input {
  width: 100%; min-height: 44px; padding: 0 12px;
  font: inherit; font-size: 16px; color: var(--text);
  background: #fff; border: 1px solid var(--input-border); border-radius: 10px;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}
.field select, select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236f6e8a' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-inline-end: 38px;
}
[dir="rtl"] .field select, [dir="rtl"] select.input { background-position: left 12px center; }
.input:focus, .field input:focus, .field select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(43, 159, 216, .18);
}
.field-hint { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.hint { font-size: 12.5px; color: var(--muted); margin: -4px 0 14px; }
.form-error {
  display: flex; gap: 8px; align-items: center; text-align: start;
  font-size: 14px; font-weight: 600; color: #8f1e34; background: var(--danger-soft);
  padding: 10px 14px; border-radius: 10px; margin: 0 0 14px;
}

/* ============ Language switch (pill select) ============ */
.lang-switch {
  position: relative; display: inline-flex; align-items: center;
  height: 36px; border-radius: 20px;
  border: 1px solid var(--input-border); background: #fff; color: var(--primary-dark);
}
.lang-switch .ic { position: absolute; top: 50%; transform: translateY(-50%); inset-inline-start: 11px; width: 16px; height: 16px; pointer-events: none; }
.lang-switch select {
  appearance: none; border: 0; background: transparent; color: inherit;
  font: inherit; font-size: 13px; font-weight: 700;
  height: 100%; padding-inline: 33px 16px; cursor: pointer; border-radius: 20px;
}
.lang-switch select:focus-visible { outline: 2px solid var(--accent); }
.lang-switch option { color: var(--text); background: #fff; }
.on-brand .lang-switch { border-color: rgba(255, 255, 255, .6); background: rgba(255, 255, 255, .14); color: #fff; }

/* ============ App header (gradient bar with logo) ============ */
.app-header { background: var(--brand-gradient); color: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, .15); }
.hdr { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-block: 14px; }
.brand { display: flex; align-items: center; gap: 14px; color: #fff; min-width: 0; }
.brand img {
  width: 58px; height: 58px; flex: none; border-radius: 50%;
  background: #fff; padding: 3px; object-fit: contain; box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
.brand h1 { font-size: 21px; font-weight: 800; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { display: block; opacity: .85; font-size: 13px; }
.brand > div { min-width: 0; }
.hdr-side { display: flex; align-items: center; gap: 10px; flex: none; }

/* White tab bar under the header (like the timetable's nav) */
.app-nav {
  position: sticky; top: 0; z-index: 20;
  background: #fff; border-bottom: 1px solid var(--border); box-shadow: 0 1px 6px rgba(0, 0, 0, .04);
}
.app-nav .container { display: flex; gap: 4px; padding-block: 8px; overflow-x: auto; scrollbar-width: none; }
.app-nav .container::-webkit-scrollbar { display: none; }
.app-nav a {
  flex: none; display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px;
  color: var(--muted); font-weight: 600; transition: .15s;
}
.app-nav a .count { font-size: 12px; background: var(--th2); color: var(--primary-dark); padding: 0 8px; border-radius: 10px; }
@media (hover: hover) { .app-nav a:hover { background: var(--th); color: var(--primary-dark); } }
.app-nav a.on { background: var(--active-gradient); color: #fff; box-shadow: 0 3px 10px rgba(75, 59, 133, .3); }
.app-nav a.on .count { background: rgba(255, 255, 255, .22); color: #fff; }

/* ============ Cards / tables / badges ============ */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 18px 22px 0;
}
.card-head h2 {
  display: flex; align-items: center; gap: 8px;
  font-size: 17px; font-weight: 800; color: var(--primary-dark);
}
.card-head h2::before {
  content: ""; width: 5px; height: 20px; border-radius: 3px; flex: none;
  background: linear-gradient(var(--primary), var(--violet));
}
.card-head p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.card-head + .table-wrap { margin-top: 14px; }
.card-body { padding: 18px 22px 22px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 20px;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: #136945; }
.badge.warn { background: var(--warn-soft); color: #8a4f0e; }
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: start; font-size: 13px; font-weight: 700; color: var(--primary-dark);
  padding: 10px 22px; background: var(--th2);
}
.table td { padding: 12px 22px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
@media (hover: hover) { .table tbody tr:hover td { background: #fafbff; } }
.table .actions { display: flex; gap: 4px; justify-content: flex-end; }
.table .num { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.cell-main { display: flex; align-items: center; gap: 12px; font-weight: 700; color: var(--text); }
.cell-sub { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
.dot-tile {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; flex: none;
  color: #fff; font-weight: 800; font-size: 15px;
}
.empty-state {
  text-align: center; padding: 34px 20px; color: var(--muted);
  border: 1px dashed var(--input-border); border-radius: 12px; margin: 14px 22px 22px;
}
.empty-state .ic { width: 36px; height: 36px; margin-bottom: 6px; opacity: .6; }
.books-empty { margin: 0; background: #fff; }

/* ============ Toasts ============ */
.toasts {
  position: fixed; inset-block-end: 20px; left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: max-content; max-width: calc(100% - 32px);
}
.toast {
  display: flex; gap: 10px; align-items: center;
  background: var(--primary-dark); color: #fff;
  padding: 11px 18px; border-radius: 12px; box-shadow: 0 10px 30px rgba(43, 42, 69, .35);
  font-size: 14px; font-weight: 700;
  animation: toast-in .2s ease-out; transition: opacity .3s, transform .3s;
}
.toast.ok .ic { color: #7ee2b8; }
.toast.err { background: #8f1e34; }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(43, 42, 69, .5); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 16px;
  opacity: 0; transition: opacity .15s;
}
.modal-backdrop.show { opacity: 1; }
.modal {
  width: 100%; max-width: 460px;
  background: #fff; border-radius: 16px; padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  max-height: calc(100dvh - 32px); overflow-y: auto;
  transform: scale(.97); transition: transform .15s;
}
.modal-backdrop.show .modal { transform: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.modal-head h3 { font-size: 18px; font-weight: 800; color: var(--primary-dark); }
.modal-text { color: var(--muted); margin: -2px 0 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ============ Login (full gradient + centered card, like the timetable) ============ */
.login-page {
  position: relative; min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 72px 16px 28px; background: var(--brand-gradient-diag);
}
.login-lang { position: absolute; top: 16px; inset-inline-end: 16px; }
.login-card {
  width: 100%; max-width: 410px; text-align: center;
  background: #fff; border-radius: 20px; padding: 34px 30px 28px;
  box-shadow: var(--shadow-lg); animation: fade .3s;
}
.login-card .logo {
  width: 150px; height: 150px; border-radius: 50%; object-fit: contain;
  background: #fff; margin: -8px 0 4px;
}
.login-card h2 { font-size: 20px; font-weight: 800; color: var(--primary-dark); margin: 4px 0 2px; }
.login-card .sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px;
  background: var(--th); border-radius: 12px; margin-bottom: 18px;
}
.segmented button {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; border: 0; border-radius: 9px; background: transparent;
  font: inherit; font-weight: 700; font-size: 14px; color: var(--muted); cursor: pointer;
}
.segmented button.on { background: var(--active-gradient); color: #fff; box-shadow: 0 3px 10px rgba(75, 59, 133, .3); }
.segmented .ic { width: 16px; height: 16px; }
.login-foot { margin-top: 20px; color: rgba(255, 255, 255, .8); font-size: 12.5px; text-align: center; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ============ Library ============ */
.lib-top { background: var(--brand-gradient); color: #fff; padding-bottom: 64px; }
.lib-top .app-header { background: none; box-shadow: none; border-bottom: 1px solid rgba(255, 255, 255, .15); }
.lib-hero { padding-top: 26px; }
.lib-hero .eyebrow { opacity: .85; font-weight: 600; }
.lib-hero h2 { font-size: 30px; font-weight: 800; }
.search { position: relative; margin-top: 18px; max-width: 540px; }
.search .ic { position: absolute; inset-inline-start: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input {
  width: 100%; height: 50px; border: 0; border-radius: 14px;
  padding-inline: 46px 16px; font: inherit; font-size: 16px;
  background: #fff; color: var(--text); box-shadow: 0 10px 30px rgba(43, 42, 69, .25);
}
.search input:focus { outline: 3px solid rgba(126, 203, 239, .7); }
.lib-main { margin-top: -40px; padding-bottom: 60px; }
.section-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 18px; font-weight: 800; color: var(--primary-dark); margin: 26px 0 14px;
}
.section-title::before { content: ""; width: 5px; height: 20px; border-radius: 3px; background: linear-gradient(var(--primary), var(--violet)); }
.section-title:empty { display: none; }
.subject-tabs { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 8px; scrollbar-width: thin; }
.subject-tab {
  flex: none; display: flex; align-items: center; gap: 12px;
  min-width: 180px; padding: 12px 16px; text-align: start;
  background: #fff; color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); cursor: pointer; font: inherit;
  transition: transform .15s, box-shadow .15s;
}
@media (hover: hover) { .subject-tab:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(75, 59, 133, .14); } }
.subject-tab .name { font-weight: 800; display: block; }
.subject-tab .count { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.subject-tab.on { background: var(--active-gradient); color: #fff; border-color: transparent; box-shadow: 0 6px 18px rgba(75, 59, 133, .35); }
.subject-tab.on .count { color: rgba(255, 255, 255, .85); }
.subject-tab.on .dot-tile { background: rgba(255, 255, 255, .22) !important; }

.books-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.book-card {
  display: flex; flex-direction: column; min-width: 0;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); transition: transform .2s, box-shadow .2s;
}
@media (hover: hover) { .book-card:hover { transform: translateY(-4px); box-shadow: 0 12px 28px rgba(75, 59, 133, .16); } }
.cover {
  position: relative; aspect-ratio: 3 / 4; overflow: hidden;
  display: grid; place-items: center; color: #fff;
  background: var(--c, #4b3b85);
  background-image: linear-gradient(160deg, rgba(255, 255, 255, .2), rgba(0, 0, 0, .18));
}
.cover .cover-fallback { text-align: center; padding: 16px; }
.cover .cover-fallback .ic { width: 38px; height: 38px; opacity: .85; margin-bottom: 10px; }
.cover .cover-fallback div { font-weight: 800; font-size: 15px; line-height: 1.35; }
.cover canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #fff; }
.cover::after {
  content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 8px;
  background: linear-gradient(90deg, rgba(0, 0, 0, .18), transparent);
}
[dir="rtl"] .cover::after { background: linear-gradient(-90deg, rgba(0, 0, 0, .18), transparent); }
.book-body { padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.book-title { font-weight: 800; font-size: 15px; line-height: 1.4; overflow-wrap: anywhere; }
.book-meta { font-size: 12px; color: var(--muted); font-weight: 600; }
.book-subject { font-size: 12px; font-weight: 700; color: var(--violet); }
.book-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 0 14px 14px; }

/* Teacher grade switcher (in the library hero) */
.grade-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.grade-chip {
  font: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
  min-height: 38px; padding: 0 16px; border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, .6); background: rgba(255, 255, 255, .14); color: #fff;
  transition: background .15s;
}
@media (hover: hover) { .grade-chip:hover { background: rgba(255, 255, 255, .28); } }
.grade-chip.on { background: #fff; color: var(--primary-dark); border-color: #fff; }

/* Checkbox chips (like the timetable's .chip) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none;
  min-height: 38px; padding: 0 14px; border-radius: 20px;
  border: 1px solid var(--input-border); background: #fff; color: var(--muted);
  font-size: 14px; font-weight: 700; transition: .12s;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked) { background: var(--active-gradient); color: #fff; border-color: transparent; }
.chip:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
@media (hover: hover) { .chip:hover { border-color: var(--primary); } }
.chip.on { background: var(--active-gradient); color: #fff; border-color: transparent; }
button.chip { font: inherit; font-size: 14px; font-weight: 700; }
.chip-count { font-size: 12px; background: var(--th2); color: var(--primary-dark); padding: 0 8px; border-radius: 10px; }
.chip.on .chip-count { background: rgba(255, 255, 255, .22); color: #fff; }
.admin-body > .chips { margin-bottom: -4px; }
.tag.subj { background: var(--th); color: #1782b8; }
.tag { display: inline-block; background: var(--th2); color: var(--primary-dark); border-radius: 6px; padding: 1px 9px; font-size: 12px; font-weight: 700; margin: 2px; }

/* ============ Admin ============ */
.admin-main { padding: 22px 0 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; min-height: 40px; }
.page-head h1 { font-size: 22px; font-weight: 800; color: var(--primary-dark); }
.admin-body { display: grid; gap: 18px; }
.admin-body > * { min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow); min-width: 0;
}
.stat .stat-ic { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 12px; flex: none; }
.stat .stat-ic .ic { width: 22px; height: 22px; }
.stat .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 24px; font-weight: 800; color: var(--primary-dark); font-variant-numeric: tabular-nums; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2 > * { min-width: 0; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 22px; border-top: 1px solid var(--border); }
.card-head + .list-row { border-top: 0; margin-top: 10px; }
.list-row:last-child { padding-bottom: 16px; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar .input { width: auto; min-width: 190px; min-height: 40px; font-size: 16px; }
.dropzone {
  display: grid; place-items: center; text-align: center; gap: 4px;
  border: 2px dashed var(--input-border); border-radius: var(--radius);
  padding: 26px 16px; cursor: pointer; color: var(--muted);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--th); }
.dropzone .dz-ic { display: grid; place-items: center; width: 50px; height: 50px; border-radius: 14px; background: var(--th2); color: var(--primary-dark); margin-bottom: 4px; }
.dropzone .dz-ic .ic { width: 24px; height: 24px; }
.dropzone strong { color: var(--text); overflow-wrap: anywhere; }
.dropzone small { font-weight: 600; }
.dropzone.has-file { border-style: solid; border-color: var(--ok); background: var(--ok-soft); }
.progress { height: 8px; background: var(--th); border-radius: 20px; overflow: hidden; margin-top: 14px; }
.progress div { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary-dark), var(--primary)); transition: width .2s; }

/* ============ Reader ============ */
body.reader { background: #e9ebf3; }
.reader-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  min-height: 62px; padding: 8px 16px;
  background: var(--brand-gradient); color: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, .15);
}
.reader-bar .logo { width: 40px; height: 40px; border-radius: 50%; background: #fff; padding: 2px; object-fit: contain; flex: none; }
.reader-bar .title { flex: 1; min-width: 0; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-bar .status { font-size: 13px; opacity: .9; white-space: nowrap; font-weight: 600; font-variant-numeric: tabular-nums; }
.reader-bar .icon-btn { color: #fff; }
@media (hover: hover) { .reader-bar .icon-btn:hover { background: rgba(255, 255, 255, .2); color: #fff; } }
.zoom-group { display: flex; align-items: center; gap: 2px; background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .35); border-radius: 20px; padding: 1px 4px; }
.zoom-group span { min-width: 44px; text-align: center; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.zoom-group .icon-btn { width: 32px; height: 32px; border-radius: 50%; }
#pages { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 20px 10px 60px; }
.page-slot { width: 100%; display: flex; justify-content: center; }
.page-slot canvas { max-width: 100%; background: #fff; border-radius: 6px; box-shadow: 0 6px 24px rgba(43, 42, 69, .18); }
.page-ph { background: #fff; opacity: .6; border-radius: 6px; }
.reader-error { text-align: center; padding: 60px 20px; color: var(--muted); }
.reader-error .ic { width: 40px; height: 40px; color: var(--danger); }

/* User-entered text (titles, names) keeps its own direction inside any UI language. */
.school-name, .book-title, .list-row .title, .cell-main, .reader-bar .title, .cover-fallback div, #stageName, .subject-tab .name { unicode-bidi: plaintext; }

/* ============ Responsive ============ */
/* Touch screens (phones & tablets): bigger tap targets */
@media (pointer: coarse) {
  .icon-btn { width: 42px; height: 42px; }
  .btn-sm { min-height: 40px; }
  .pill-btn, .lang-switch { height: 40px; }
}

/* Laptop / small desktop */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* Tablet */
@media (max-width: 900px) {
  .container { padding: 0 18px; }
  .grid-2 { grid-template-columns: 1fr; }
  .books-grid { grid-template-columns: repeat(3, 1fr); }
  .brand img { width: 50px; height: 50px; }
  .brand h1 { font-size: 18px; }
}

/* Phones */
@media (max-width: 640px) {
  .container { padding: 0 14px; }
  .hdr { padding-block: 10px; gap: 8px; }
  .brand { gap: 10px; }
  .brand img { width: 42px; height: 42px; padding: 2px; }
  .brand h1 { font-size: 15px; white-space: normal; line-height: 1.25; }
  .brand small { font-size: 12px; }
  .hdr-side { gap: 6px; }
  .pill-btn span { display: none; }
  .pill-btn { width: 40px; padding: 0; justify-content: center; }
  .lib-top { padding-bottom: 56px; }
  .lib-hero { padding-top: 18px; }
  .lib-hero h2 { font-size: 22px; }
  .lib-main { margin-top: -36px; }
  .books-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .book-body { padding: 10px; }
  .book-title { font-size: 14px; }
  .book-actions { padding: 0 10px 10px; gap: 6px; }
  .subject-tab { min-width: 150px; padding: 10px 12px; }
  .app-nav a { padding: 9px 14px; }
  .admin-main { padding-top: 16px; }
  .page-head h1 { font-size: 19px; }
  #headAction .btn span { display: none; }
  #headAction .btn { width: 42px; padding: 0; }
  .card-head { padding: 14px 16px 0; }
  .card-body { padding: 14px 16px 16px; }
  .table th, .table td { padding: 10px 14px; }
  .list-row { padding: 12px 16px; }
  .empty-state { margin: 14px 16px 16px; }
  .stats { gap: 10px; }
  .stat { padding: 12px; gap: 10px; }
  .stat .stat-ic { width: 38px; height: 38px; }
  .stat .value { font-size: 19px; }
  .hide-sm { display: none; }
  .table .actions { gap: 0; }
  .table td:last-child { padding-inline: 4px 8px; }
  .login-card { padding: 26px 20px 22px; }
  .login-card .logo { width: 124px; height: 124px; }
  .modal { padding: 18px; }
  .modal-actions .btn { flex: 1; }
  .reader-bar { gap: 6px; padding: 8px 10px; }
  .reader-bar .logo, .reader-bar .title, .reader-bar .lang-switch, .zoom-group span { display: none; }
  .reader-bar .status { flex: 1; text-align: center; }
}
.show-sm { display: none; }
@media (max-width: 640px) { .show-sm { display: block; } }

/* Very small phones (≤360px) */
@media (max-width: 360px) {
  .segmented .ic { display: none; }
  .brand small { display: none; }
  .lang-switch select { padding-inline: 30px 8px; font-size: 12px; }
  .book-card .book-meta { display: none; }
}
