:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --ink: #16202e;
  --muted: #6b7a8d;
  --line: #dde4ed;
  --brand: #0b3a82;      /* dark blue */
  --brand-2: #1e6fd9;    /* blue */
  --light: #8cc8ff;      /* light blue */
  --tint: #eaf3ff;       /* very light blue background */
  --accent: #0b6bcb;
  --danger: #c0392b;
  --warn: #b7791f;
  --ok: #1d7a45;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 2px 8px rgba(16,24,40,.06);
  --shadow-sm: 0 1px 2px rgba(16,24,40,.05);
  --tap: 42px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ---------- Layout ---------- */
.topbar {
  background: var(--brand);
  background: linear-gradient(120deg, #1558c0, #0b2e6b);
  color: #fff;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: .2px; }
.topbar > div { display: flex; align-items: center; gap: 10px; }
.topbar .who { font-size: 13px; opacity: .9; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
  background: linear-gradient(135deg, #bfe0ff, #5aa9f0);
  color: #0b2e6b; font-size: 12.5px; font-weight: 800;
  box-shadow: 0 0 0 2px rgba(255,255,255,.35);
}

.tabs {
  display: flex;
  gap: 2px;
  background: #0a2a5e;
  padding: 0 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  position: sticky;
  top: 49px;
  z-index: 19;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.tabs::-webkit-scrollbar { height: 4px; }
.tabs::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 4px; }
.tabs button {
  background: transparent;
  border: 0;
  color: #cfe2fa;
  padding: 12px 15px;
  cursor: pointer;
  font-size: 13.5px;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s, background .15s;
  border-radius: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: auto;
  box-shadow: none;
}
.tabs button:hover { color: #fff; background: rgba(255,255,255,.06); }
.tabs button.active { color: #fff; border-bottom-color: #8cc8ff; font-weight: 600; }
.tab-icon { display: inline-flex; flex: 0 0 auto; }
.tab-icon svg { width: 17px; height: 17px; display: block; }
.tab-label { display: inline-block; }
.tab-label.short { display: none; }

.wrap { max-width: 1150px; margin: 18px auto; padding: 0 14px 40px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card h3 { margin: 16px 0 8px; font-size: 14px; color: var(--muted); }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 160px; min-width: 0; }
.row .narrow { flex: 0 0 auto; }

/* ---------- Forms ---------- */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; letter-spacing: .2px; }
input, select, textarea {
  width: 100%;
  padding: 10px 11px;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: none; box-shadow: 0 0 0 3px rgba(11,107,203,.15); border-color: var(--accent); }

button {
  padding: 10px 16px;
  min-height: var(--tap);
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .12s, transform .08s, box-shadow .12s;
  box-shadow: var(--shadow-sm);
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
button.green { background: var(--brand-2); }
#btnAllP { background: var(--ok); }   /* "Mark All Present" keeps the present-green */
button.red { background: var(--danger); }
button.grey { background: #5b6b7d; }
button.warn { background: var(--warn); }
button.sm { padding: 7px 12px; font-size: 12px; min-height: 34px; }

/* ---------- Table ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 480px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; }
th { background: #f5f8fb; font-size: 11.5px; text-transform: uppercase; color: var(--muted); letter-spacing: .4px; position: sticky; top: 0; }
tbody tr:hover { background: #f8fbff; }
tbody tr:last-child td { border-bottom: 0; }

/* ---------- Bits ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 26px; color: var(--brand-2); }
.stat span { font-size: 12px; color: var(--muted); }

.badge { padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; display: inline-block; }
.badge.active { background: #d8f3e2; color: #14532d; }
.badge.pending { background: #fdf0d2; color: #8a5a00; }
.badge.blocked { background: #fbdcd8; color: #8c2118; }

.msg { padding: 11px 14px; border-radius: 8px; margin: 10px 0; font-size: 14px; display: none; box-shadow: var(--shadow-sm); }
.msg.show { display: block; }
.msg.ok { background: #d8f3e2; color: #14532d; }
.msg.err { background: #fbdcd8; color: #8c2118; }
.muted { color: var(--muted); font-size: 13px; }
.right { text-align: right; }
.mt { margin-top: 12px; }

/* ---------- Attendance marking ---------- */
.att-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 6px; border-bottom: 1px solid var(--line); }
.att-row.att-head {
  background: #f5f8fb; font-size: 11px; text-transform: uppercase; color: var(--muted);
  letter-spacing: .3px; font-weight: 700; border-radius: 8px 8px 0 0;
}
.att-cell.sr { width: 30px; flex: 0 0 auto; color: var(--muted); font-size: 13px; }
.att-cell.id { width: 90px; flex: 0 0 auto; font-size: 13px; font-weight: 600; color: var(--brand-2); }
.att-cell.name { flex: 1 1 160px; min-width: 0; }
.att-cell.name b { display: block; font-size: 14px; }
.att-cell.name span { font-size: 12px; color: var(--muted); }
.pick-head { flex: 0 0 auto; width: 124px; }
.pick { display: flex; gap: 5px; flex: 0 0 auto; }
.att-cell.nr { flex: 1 1 210px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.att-cell.nr .att-cell.name { flex: 1 1 100px; }
.att-head .att-cell.name { flex: 1 1 210px; }
.remark-in { flex: 1 1 100px; min-width: 0; margin: 0; padding: 8px 9px; font-size: 13px; }
@media (max-width: 640px) {
  .att-row { gap: 8px; padding: 9px 4px; }
  .att-cell.sr { width: 22px; }
  .att-cell.id { width: 42px; font-size: 12px; }
  .att-head .pick-head { display: none; }   /* P/A/L sit under the name on phones */
}
.pick button {
  width: 40px; height: 38px; min-height: 38px; padding: 0; background: #eef2f7; color: #55657a; font-weight: 700;
}
.pick button.on.P { background: var(--ok); color: #fff; }
.pick button.on.A { background: var(--danger); color: #fff; }
.pick button.on.L { background: var(--warn); color: #fff; }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 18px;
  background: linear-gradient(140deg, #1558c0, #0b2e6b);
}
.login-box { width: 100%; max-width: 420px; background: #fff; border-radius: 16px; padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-box h1 { font-size: 20px; margin: 0 0 4px; text-align: center; }
.login-box p.sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.switcher { display: flex; margin-bottom: 18px; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.switcher button { flex: 1; background: #f3f6fa; color: var(--muted); border-radius: 0; box-shadow: none; }
.switcher button.active { background: var(--brand); color: #fff; font-weight: 600; }
.login-box .field { margin-bottom: 12px; }
.login-box button.main { width: 100%; padding: 12px; background: var(--brand-2); font-size: 15px; }

/* ---------- School registration: service agreement ---------- */
.terms-box { background: #f6f9fd; border: 1px solid #cfe0f5; border-radius: 10px; padding: 12px 14px; margin: 4px 0 14px; }
.terms-box h4 { margin: 0 0 6px; font-size: 13.5px; color: var(--brand); }
.terms-box p { margin: 0 0 10px; font-size: 12.5px; line-height: 1.55; color: var(--ink); text-align: justify; }
.terms-check { display: flex !important; align-items: flex-start; gap: 8px; margin: 0; cursor: pointer; font-size: 13px; font-weight: 700; color: var(--ink); letter-spacing: 0; }
.terms-check input { width: 18px; height: 18px; min-height: 0; margin: 1px 0 0; flex: 0 0 auto; accent-color: var(--brand-2); }

/* ---------- Print ---------- */
@media print {
  .topbar, .tabs, .no-print, button { display: none !important; }
  body { background: #fff; }
  .card { border: 0; padding: 0; box-shadow: none; }
  .wrap { margin: 0; max-width: none; }
  th { background: #eee !important; -webkit-print-color-adjust: exact; }
}

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .wrap { margin: 14px auto; padding: 0 10px 32px; }
  .card { padding: 14px; }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .topbar h1 { font-size: 15px; }
  .row > * { flex: 1 1 100%; }
  .share-row button { flex: 1 1 100%; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .row > *:not(.narrow) button { width: 100%; }
  .mt.right { text-align: stretch; }
  .mt.right button#btnSave { width: 100%; }

  /* App-style bottom navigation bar instead of a top tab strip */
  .wrap { padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
  .tabs {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    justify-content: space-around;
    overflow-x: visible;
    padding: 3px 2px calc(3px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -3px 14px rgba(0,0,0,.22);
    z-index: 30;
  }
  .tabs button {
    flex: 1 1 0;
    flex-direction: column;
    gap: 2px;
    padding: 7px 2px;
    font-size: 10px;
    border-bottom: none;
    border-top: 3px solid transparent;
    min-width: 0;
  }
  .tabs button.active { border-bottom-color: transparent; border-top-color: #8cc8ff; background: rgba(255,255,255,.07); }
  .tab-icon svg { width: 20px; height: 20px; }
  .tab-label.full { display: none; }
  .tab-label.short {
    display: block; font-size: 10px; line-height: 1.1; max-width: 100%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
}@media (max-width: 400px) {
  .topbar .who { max-width: 30vw; }
  .stats { grid-template-columns: 1fr 1fr; }
  .card h2 { font-size: 15px; }
}

/* ---------- Diary sub-tabs (teacher) ---------- */
.sub-tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.sub-tabs button {
  background: transparent; border: 0; color: var(--muted); padding: 9px 14px;
  cursor: pointer; font-size: 13px; border-bottom: 2px solid transparent; box-shadow: none; min-height: auto;
  font-weight: 600; white-space: nowrap;
}
.sub-tabs button.sub-active { color: var(--brand-2); border-bottom-color: var(--brand-2); }
.class-chip {
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--brand-2);
  border-radius: 9px; padding: 12px 13px; cursor: pointer; transition: .12s; box-shadow: var(--shadow-sm);
}
.class-chip:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow); }
.class-chip:active { transform: translateY(0); }
.class-chip.on { background: var(--tint); border-left-color: var(--accent); box-shadow: 0 0 0 2px #bcd8ff; }
.class-chip b { display: block; font-size: 15px; }
.class-chip span { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.class-chip span.ok { color: var(--ok); }
.class-chip span.warn { color: var(--warn); }

/* ---------- Share / success panel (teacher) ---------- */
.done-panel {
  border: 2px solid var(--ok); background: #f2fbf6; border-radius: var(--radius);
  padding: 16px; margin-top: 14px;
}
.done-panel h3 { color: var(--ok); margin: 0 0 8px; font-size: 16px; }
.share-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.share-row button { flex: 1 1 130px; }
button.wa { background: #25d366; color: #063; font-weight: 700; }
.preview-img {
  max-width: 100%; border: 1px solid var(--line); border-radius: 8px; margin-top: 12px;
  display: block;
}
.portal-closed {
  background: #fdf0d2; border: 1px solid #e3c98a; color: #7a5600;
  padding: 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 14px; box-shadow: var(--shadow-sm);
}

/* ---------- Monthly master sheet ---------- */
table.master { min-width: 0; width: 100%; font-size: 12px; border-collapse: collapse; border: 1px solid #333; }
table.master th, table.master td { padding: 4px 2px; text-align: center; border: 1px solid #333; background: #fff; color: #000; }
table.master th { position: static; font-size: 11px; font-weight: 700; background: #ffc000; color: #000; text-transform: none; letter-spacing: 0; }
table.master .c-sr { width: 34px; }
table.master .c-id { white-space: nowrap; }
table.master .c-name, table.master .c-fname { text-align: left; white-space: nowrap; padding: 4px 6px; }
table.master td.day { min-width: 24px; width: 24px; font-weight: 700; background: #e7e7e7; }
table.master th.sunday, table.master td.sunday { background: #ffc000; }
table.master td.sunday { padding: 0; vertical-align: middle; }
table.master td.sunday span {
  display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg);
  font-style: italic; font-weight: 700; font-size: 12px; letter-spacing: .5px;
}
table.master .tot { min-width: 28px; font-weight: 700; }
table.master .tp { background: #ccffe6; } table.master th.tp { background: #7df2b5; }
table.master .ta { background: #ff6a4a; }
table.master .tl { background: #ffe08a; }
table.master .pct { min-width: 56px; white-space: nowrap; background: #5b9bd5; }
.mk.P { color: var(--ok); }
table.master td.mk.A { color: var(--danger); background: #fdd5d0; }
table.master td.mk.L { color: #8a5a00; background: #fdeab5; }
@media print {
  table.master { font-size: 8px; }
  table.master th, table.master td { padding: 2px 1px; }
  table.master .c-name, table.master .c-fname { padding: 2px 4px; }
  table.master, table.master th, table.master td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}


/* ---- Assign Class / Diary tab ---- */
.pick-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 6px 0; border-bottom: 1px dashed #e3e9f0; }
.pick-row:last-child { border-bottom: 0; }
.pick-row > b { min-width: 64px; }
label.ck { display: inline-flex; align-items: center; gap: 6px; margin: 0; padding: 6px 10px; border: 1px solid #d5dde6;
  border-radius: 8px; background: #fff; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text, #16202e); }
label.ck input { width: auto; margin: 0; }
label.ck.on { background: var(--tint); border-color: #7fb2ea; }
label.ck small { font-weight: 500; color: #8a5a00; }
.as-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; margin: 3px 6px 3px 0;
  border: 1px solid #b8d3f0; border-radius: 20px; background: var(--tint); font-size: 13px; }
.as-chip button { border: 0; background: transparent; color: #c0392b; font-size: 15px; line-height: 1; cursor: pointer; padding: 0 2px; width: auto; }
.as-links { font-size: 12px; margin: 4px 0 8px; }
.as-links a { color: #0a66c2; cursor: pointer; margin-right: 12px; }


/* ---------- Student search (attendance by ID / name) ---------- */
.ss-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 4px; border-bottom: 1px solid #e3e9f0;
}
.ss-row:last-child { border-bottom: 0; }
.ss-info { flex: 1 1 220px; min-width: 0; max-width: 460px; }
.ss-row { justify-content: flex-start; column-gap: 28px; }
.ss-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ss-id { background: var(--tint); color: var(--brand); font-weight: 700; font-size: 12px; padding: 2px 8px; border-radius: 10px; }
.ss-name { font-size: 15px; }
.ss-sub { font-size: 13px; color: var(--muted, #5a6b7d); margin-top: 2px; }
.ss-act { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.ss-saved { font-size: 12px; min-width: 52px; color: var(--muted, #5a6b7d); }
.ss-saved.ok { color: var(--ok); font-weight: 700; }
@media (max-width: 640px) {
  .ss-act { width: 100%; }
}


/* ---------- Reports & Print (advanced) ---------- */
.rtiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-top: 12px; }
.rtile { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; padding: 11px 13px;
  background: #fff; color: var(--text, #16202e); border: 1px solid #d5dde6; border-radius: 10px; box-shadow: none; min-height: 0; height: auto; }
.rtile b { font-size: 14px; }
.rtile span { font-size: 12px; font-weight: 500; color: var(--muted, #5a6b7d); }
.rtile:hover { border-color: #7fb2ea; }
.rtile.on { background: var(--tint, #eaf2fc); border-color: var(--brand, #1558c0); box-shadow: inset 0 0 0 1px var(--brand, #1558c0); }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chip { width: auto; min-height: 0; height: auto; padding: 5px 12px; border-radius: 20px; font-size: 13px; font-weight: 600;
  background: #fff; color: var(--brand, #1558c0); border: 1px solid #b8d3f0; box-shadow: none; }
.chip:hover { background: var(--tint, #eaf2fc); }
.dayshift { display: flex; gap: 4px; align-items: center; }
.dayshift input { flex: 1; min-width: 0; }
.dayshift button { width: 34px; padding: 0; font-size: 18px; line-height: 1; }
.rstats { margin: 10px 0 12px; }
.rsearch { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.rsearch input { max-width: 340px; margin: 0; }
.rtable th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.rtable th.sortable:hover { background: #e3edf9; }
.rtable tr.trow td { font-weight: 700; background: #f3f7fb; border-top: 2px solid #0b3a82; }
.pct-pill, .st-pill { display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.pct-pill.good, .st-pill.P { background: #dcf3e5; color: #1d7a45; }
.pct-pill.mid,  .st-pill.L { background: #fdeab5; color: #8a5a00; }
.pct-pill.low,  .st-pill.A { background: #fdd5d0; color: #b02a1c; }
.barcell { position: relative; min-width: 120px; height: 20px; background: #eef2f7; border-radius: 10px; overflow: hidden; }
.barcell i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 10px; }
.barcell i.good { background: #9fdcb7; } .barcell i.mid { background: #f6d77e; } .barcell i.low { background: #f4a99d; }
.barcell span { position: relative; display: block; text-align: center; font-size: 12px; font-weight: 700; line-height: 20px; }
.print-only { display: none; }
@media print {
  .print-only { display: block; text-align: center; margin-bottom: 8px; }
  .print-only h1 { font-size: 18px; margin: 0; }
  .print-only h2 { font-size: 15px; margin: 2px 0; }
  .print-only p { font-size: 11px; margin: 0; color: #444; }
  #reportBox > h2, #reportBox > p.muted:first-of-type { display: none; }
  .rstats { display: flex !important; flex-wrap: wrap; gap: 6px; }
  .rstats .stat { padding: 4px 10px; }
  .pct-pill, .st-pill, .barcell i, .rtable tr.trow td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rtable { font-size: 11px; }
  .rtable th, .rtable td { padding: 3px 5px; }
  .table-scroll { overflow: visible !important; }
}


/* ================================================================== */
/*  Class grid (Diary / Classes): auto columns on desktop, 2 on phones */
/* ================================================================== */
.chip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.class-chip { min-width: 0; }
.class-chip b, .class-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ================================================================== */
/*  MOBILE POLISH (phones)                                             */
/* ================================================================== */
@media (max-width: 640px) {
  :root { --tap: 40px; --radius: 14px; }
  body { font-size: 14px; }

  /* ---- Top bar: compact, not sticky (the bottom nav is the main navigation) ---- */
  .topbar {
    position: static; padding: 10px 12px; gap: 8px; flex-wrap: nowrap; align-items: center;
  }
  .topbar h1 {
    flex: 1 1 auto; min-width: 0; font-size: 14.5px; line-height: 1.25;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  .topbar > div { flex: 0 0 auto; gap: 8px; }
  .topbar .who { display: none; }
  .topbar .avatar { width: 32px; height: 32px; }
  .topbar button.sm { padding: 6px 12px; min-height: 32px; font-size: 12.5px; }

  /* ---- Bottom navigation: scrolls sideways instead of squeezing 9 tabs ---- */
  .tabs {
    justify-content: flex-start; overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
    padding: 2px 4px calc(2px + env(safe-area-inset-bottom, 0px)); gap: 0;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 1 0 62px; padding: 6px 4px; min-width: 62px; min-height: 52px; justify-content: center; }
  .tab-label.short { overflow: visible; text-overflow: clip; font-size: 10.5px; }
  .tab-icon svg { width: 20px; height: 20px; }
  .wrap { padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)); margin-top: 10px; }

  /* ---- Cards / text ---- */
  .wrap { padding-left: 10px; padding-right: 10px; }
  .card { padding: 13px; margin-bottom: 12px; border-radius: var(--radius); }
  .card h2 { font-size: 16px; margin-bottom: 8px; }
  .card h3 { font-size: 13px; margin: 12px 0 6px; }
  .muted { font-size: 12.5px; }

  /* ---- Forms: tighter, lighter buttons ---- */
  .row { gap: 8px; }
  .row > * { flex: 1 1 100%; }
  .row > .narrow { flex: 1 1 100%; }
  label { font-size: 11.5px; margin-bottom: 3px; }
  label.ghost { display: none; }
  input, select, textarea { min-height: 40px; padding: 8px 10px; font-size: 15px; border-radius: 10px; }
  input[type=date], input[type=month] { width: 100%; min-width: 0; }
  button { min-height: 40px; padding: 8px 14px; font-size: 13.5px; border-radius: 10px; }
  button.sm { min-height: 32px; padding: 5px 11px; font-size: 12.5px; }
  .row > *:not(.narrow) button, .row > .narrow > button { width: 100%; }
  .mt { margin-top: 10px; }

  /* ---- Class chips: 2 per row ---- */
  .chip-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .class-chip { padding: 9px 10px; border-radius: 10px; }
  .class-chip b { font-size: 14px; }
  .class-chip span { font-size: 11px; }

  /* ---- Stats ---- */
  .stats { gap: 8px; }
  .stat { padding: 10px 12px; border-radius: 12px; }
  .stat b { font-size: 21px; }
  .stat span { font-size: 11.5px; }

  /* ---- Tables ---- */
  table { font-size: 13px; min-width: 420px; }
  th, td { padding: 8px 9px; }

  /* ---- Reports & Print ---- */
  .rtiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
  .rtile { padding: 8px 10px; border-radius: 10px; gap: 1px; min-height: 0; }
  .rtile b { font-size: 12.5px; line-height: 1.25; }
  .rtile span { font-size: 10.5px; line-height: 1.25; }
  .chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-left: -2px; padding: 2px; gap: 6px; }
  .chips::-webkit-scrollbar { display: none; }
  .chips > span.muted { display: none; }
  .chip { flex: 0 0 auto; padding: 5px 11px; font-size: 12.5px; min-height: 0; white-space: nowrap; }

  .dayshift { gap: 6px; width: 100%; }
  .dayshift input { flex: 1 1 auto; width: auto; min-width: 0; }
  .row > * .dayshift button, .dayshift button { flex: 0 0 40px; width: 40px; min-height: 40px; padding: 0; font-size: 20px; }

  #rActions { gap: 8px; }
  #rActions > .narrow { flex: 1 1 calc(50% - 8px); min-width: 0; }
  #rActions button, #rActions select { width: 100%; min-height: 38px; font-size: 13px; padding: 6px 8px; }
  #btnReport { min-height: 42px; }

  .rstats { grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 8px 0 10px; }
  .rsearch { flex-wrap: wrap; gap: 6px; }
  .rsearch input { max-width: none; width: 100%; }
  .pct-pill, .st-pill { font-size: 11px; padding: 2px 8px; }

  .share-row { gap: 8px; }
  .share-row button { flex: 1 1 calc(50% - 8px); min-height: 38px; font-size: 13px; padding: 6px 8px; }

  /* ---- Attendance rows: a bit tighter ---- */
  .att-row { padding: 8px 2px; gap: 8px; }
  .pick button { width: 38px; height: 36px; min-height: 36px; }
  .sub-tabs button { padding: 8px 12px; min-height: 0; }
  .msg { font-size: 13px; padding: 9px 12px; }
}

/* Very small phones */
@media (max-width: 360px) {
  .topbar h1 { font-size: 13.5px; }
  .tabs button { flex-basis: 58px; min-width: 58px; }
  .rtile b { font-size: 12px; }
  .stat b { font-size: 19px; }
}

@media (max-width: 640px) {
  /* small action buttons (e.g. Mark All Present / Absent) sit side by side */
  .row > .narrow:has(> button.sm) { flex: 1 1 calc(50% - 8px); }
  .row > .narrow:has(> button.sm) > button { min-height: 38px; font-size: 13px; }
}

@media (max-width: 640px) {
  /* Attendance roster on phones: one tidy card per student
       1  S11  Student name / Father
       [  P  ][  A  ][  L  ]
       Reason (only for A / L)                                    */
  .att-row.att-head { display: none; }
  .att-row:not(.att-head) {
    display: grid; grid-template-columns: 22px 54px minmax(0, 1fr); column-gap: 8px; row-gap: 6px;
    align-items: center; padding: 9px 2px;
  }
  .att-row .att-cell.nr { display: contents; }
  .att-row .att-cell.sr { grid-column: 1; grid-row: 1; width: auto; }
  .att-row .att-cell.id { grid-column: 2; grid-row: 1; width: auto; }
  .att-row .att-cell.nr .att-cell.name { grid-column: 3; grid-row: 1; min-width: 0; }
  .att-row .att-cell.name b { font-size: 14px; }
  .att-row .pick { grid-column: 1 / -1; grid-row: 2; gap: 6px; }
  .att-row .pick button { flex: 1 1 0; width: auto; height: 38px; min-height: 38px; }
  .att-row .remark-in { grid-column: 1 / -1; grid-row: 3; width: 100%; min-height: 36px; font-size: 14px; }
}

/* Message parents (WhatsApp) */
.pm-row{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:8px 0;border-bottom:1px solid var(--line)}
.pm-row:last-child{border-bottom:0}
.pm-row button{flex:0 0 auto;width:auto}
.pm-class{margin:14px 0 4px;font-size:16px}
.pm-row .pm-name{min-width:0}
.pm-row .pm-btns{display:flex;gap:6px;align-items:center;flex:0 0 auto}

/* Payments cards */
.pay-card{border:1px solid var(--line);border-radius:12px;padding:12px;margin-bottom:10px;background:#fff}
.pay-head{display:flex;justify-content:space-between;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:8px}
.pay-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(110px,1fr));gap:10px;font-size:14px}
.pay-grid input{width:100%;max-width:140px}
.pay-actions{display:flex;gap:8px;flex-wrap:wrap;margin-top:10px}
.pay-actions button{width:auto}
.pay-form{margin-top:10px;padding-top:10px;border-top:1px dashed var(--line)}


/* ================= Mobile bottom navigation: raised centre button + notch ================= */
.bn-bar, .bn-arrow { display: none; }
@media (max-width: 640px) {
  body.has-bn .wrap { padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px)); }

  /* the dark bar itself, with a round notch cut out of its top edge, centred */
  .bn-bar {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 29; pointer-events: none;
    height: calc(58px + env(safe-area-inset-bottom, 0px));
    filter: drop-shadow(0 -3px 7px rgba(10, 30, 70, .22));
  }
  .bn-bar-in {
    width: 100%; height: 100%; background: #0a2a5e;
    border-radius: 18px 18px 0 0;
    -webkit-mask: radial-gradient(circle 36px at 50% 0, transparent 35px, #000 36px);
            mask: radial-gradient(circle 36px at 50% 0, transparent 35px, #000 36px);
  }

  /* the scroller is transparent and taller than the bar, so the raised circle has head-room */
  body.has-bn .tabs {
    height: calc(86px + env(safe-area-inset-bottom, 0px));
    padding: 28px 0 env(safe-area-inset-bottom, 0px);
    background: transparent; box-shadow: none; gap: 0;
    justify-content: flex-start; align-items: stretch;
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
    pointer-events: none; z-index: 30;
  }
  body.has-bn .tabs::-webkit-scrollbar { display: none; }
  /* spacers let even the first / last tab reach the centre */
  body.has-bn .tabs::before, body.has-bn .tabs::after { content: ''; flex: 0 0 calc(50% - 33px); }

  body.has-bn .tabs button {
    pointer-events: auto; position: relative;
    flex: 0 0 66px; min-width: 66px; width: 66px; height: 58px; min-height: 0; padding: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    background: transparent; border: 0; border-radius: 0; box-shadow: none;
    color: #a9c3e8; font-size: 10.5px; -webkit-tap-highlight-color: transparent;
  }
  body.has-bn .tabs button:hover { background: transparent; color: #dbe8fb; }
  body.has-bn .tabs button .tab-icon svg { width: 21px; height: 21px; }
  body.has-bn .tabs button .tab-label.short { font-size: 10.5px; line-height: 1.1; }

  /* selected: raised white circle in the notch, slightly larger icon, label underneath */
  body.has-bn .tabs button.active {
    background: transparent; border: 0; color: #fff; font-weight: 700;
    justify-content: flex-end; padding-bottom: 6px;
  }
  body.has-bn .tabs button.active .tab-icon {
    position: absolute; top: -24px; left: 50%; margin-left: -26px;
    width: 52px; height: 52px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: #fff; color: var(--brand);
    box-shadow: 0 5px 12px rgba(10, 30, 70, .35);
    animation: bnPop .28s cubic-bezier(.3, 1.5, .5, 1);
  }
  body.has-bn .tabs button.active .tab-icon svg { width: 26px; height: 26px; }
  @keyframes bnPop { from { transform: scale(.65); } to { transform: scale(1); } }

  /* arrows: more tabs are hidden on that side */
  .bn-arrow {
    position: fixed; z-index: 31; bottom: calc(15px + env(safe-area-inset-bottom, 0px));
    width: 26px; height: 30px; padding: 0; min-height: 0; border: 0; border-radius: 8px;
    display: none; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .16); color: #fff; box-shadow: none; cursor: pointer;
  }
  .bn-arrow.show { display: flex; }
  .bn-arrow.left { left: 4px; } .bn-arrow.right { right: 4px; }
  .bn-arrow svg { width: 16px; height: 16px; }
}
@media print { .bn-bar, .bn-arrow { display: none !important; } }


/* Date fields: dd/mm/yyyy label drawn over the native input (see enhanceDateInputs in app.js) */
.dtw { position: relative; }
.dtw input[type=date] { color: transparent; }
.dt-fmt .dtw input[type=date]::-webkit-datetime-edit { opacity: 0; }
.dt-fmt .dtw input[type=date]::-webkit-date-and-time-value { opacity: 0; }
.dtw-text {
  position: absolute; left: 11px; right: 44px; top: 0; bottom: 0;
  display: flex; align-items: center; pointer-events: none;
  font-size: 14px; color: var(--ink); white-space: nowrap; overflow: hidden;
}
.dtw-text.empty { color: var(--muted); }
@media (max-width: 640px) { .dtw-text { left: 10px; font-size: 15px; } }

.dayshift .dtw { flex: 1 1 auto; min-width: 0; }
.dayshift .dtw input { flex: none; width: 100%; }


/* ---------- Super Admin: school list as cards on phones, tidy table on PC ---------- */
.sa-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.sa-btns button { margin: 0; }
@media (min-width: 761px) {
  body.sa-page .wrap { max-width: 1500px; }
  .sa-table { min-width: 960px; }
  .sa-table td { vertical-align: middle; }
  .sa-btns { flex-wrap: nowrap; }          /* all action buttons on ONE straight row */
  .sa-btns button { white-space: nowrap; min-width: 64px; }
  .sa-table td.sa-actions { width: 1%; white-space: nowrap; }
}
@media (max-width: 760px) {
  .sa-table { min-width: 0; display: block; }
  .sa-table thead { display: none; }
  .sa-table tbody { display: block; }
  .sa-table tr {
    display: block; background: #fff; border: 1px solid var(--line); border-radius: 12px;
    padding: 10px 12px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(15,35,60,.06);
  }
  .sa-table tbody tr:hover { background: #fff; }
  .sa-table td { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border: 0; padding: 6px 0; text-align: right; }
  .sa-table td::before { content: attr(data-label); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); text-align: left; flex: 0 0 auto; }
  .sa-table td.sa-name { display: block; text-align: left; font-size: 16px; padding-bottom: 8px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
  .sa-table td.sa-name::before { content: none; }
  .sa-table td.sa-actions { display: flex; flex-wrap: wrap; justify-content: flex-start; padding-top: 10px; margin-top: 4px; border-top: 1px solid var(--line); }
  .sa-table td.sa-actions::before { content: none; }
}

.chk-footer { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; cursor: pointer; min-height: 40px; white-space: nowrap; }
.chk-footer input { width: auto; margin: 0; }

/* ---------- Admin: Mark Attendance class cards ---------- */
.mk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.mk-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left;
  background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; box-shadow: 0 1px 3px rgba(15,35,60,.06); cursor: pointer; font-weight: 400;
}
.mk-card:hover { border-color: var(--brand-2); box-shadow: 0 3px 10px rgba(15,35,60,.12); }
.mk-card b { font-size: 16px; color: var(--brand-2); }
.mk-card span { font-size: 12.5px; }
.mk-card.done { border-left: 4px solid var(--ok); }
.mk-badge { padding: 2px 9px; border-radius: 99px; font-weight: 600; font-size: 12px !important; margin-top: 4px; }
.mk-badge.ok { background: #dff5e6; color: #14703a; }
.mk-badge.no { background: #fdeaea; color: #b3261e; }
.mk-nums { font-weight: 600; }
@media (max-width: 520px) { .mk-grid { grid-template-columns: 1fr 1fr; gap: 10px; } }

/* ---------- Period table ---------- */
.pt-times { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.pt-times label { font-size: 12px; margin: 0 0 2px; }
.pt-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.pt-table th, .pt-table td { border: 1px solid #2b3440; padding: 6px 8px; text-align: center; vertical-align: middle; }
.pt-table th { background: #e3e8ef; font-weight: 700; }
.pt-table th small { display: block; font-weight: 500; font-size: 11px; color: #374151; }
.pt-table td.l, .pt-table th.l { text-align: left; }
.pt-table td.pt-band { background: #d9d2b6; width: 28px; padding: 2px; font-weight: 700; }
.pt-table td.pt-band span { writing-mode: vertical-rl; white-space: nowrap; }
.pt-table tr.pt-break td { background: #d9d2b6; font-weight: 700; }
.pt-table td.pt-sub { font-size: 12px; }
.pt-table td.pt-sub i { display: block; font-style: normal; color: #4b5563; font-size: 11px; }
.pt-chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.as-chip .per { color: #0b3a82; font-weight: 700; }
.as-chip .edit { color: #0b3a82 !important; font-size: 13px !important; }
@media print {
  #ptBox .table-scroll { overflow: visible !important; }
  .pt-table { font-size: 11px; }
  .pt-table td.pt-band, .pt-table tr.pt-break td, .pt-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- Teacher: My Periods cards (phone first) ---------- */
.mp-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin-bottom: 8px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.mp-p { flex: 0 0 76px; text-align: center; }
.mp-p b { display: block; font-size: 15px; color: var(--brand-2); }
.mp-p small { display: block; font-size: 11px; color: var(--muted); line-height: 1.25; word-break: break-word; }
.mp-body { flex: 1; min-width: 0; overflow-wrap: anywhere; line-height: 1.35; }
.mp-state { flex: 0 0 34px; display: flex; justify-content: flex-end; }
.mp-tick { width: 28px; height: 28px; border-radius: 50%; background: #1f9d55; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px; }
.mp-badge { background: #0b5ed7; color: #fff; border-radius: 99px; padding: 3px 10px; font-size: 12px; font-weight: 600; }
.mp-row.today { background: #f5f9ff; }
.mp-row.done { background: #f1faf4; border-color: #bfe5cd; }
.mp-row.done .mp-body { color: #4b6b58; }
.mp-row.now { background: #eaf3ff; border-color: #0b5ed7; box-shadow: 0 0 0 2px rgba(11,94,215,.15); }
.mp-row.free { opacity: .6; border-style: dashed; background: #fff; }
.mp-break { text-align: center; background: #d9d2b6; border-radius: 8px; padding: 5px; font-weight: 600; font-size: 13px; margin: 0 0 8px; }
@media (max-width: 400px) { .mp-row { gap: 8px; padding: 9px 8px; } .mp-p { flex-basis: 66px; } .mp-state { flex-basis: 30px; } }

.pt-table tr.pt-foot td { background: #eef6ff; font-weight: 600; }
.pt-table td.pt-freecol { background: #f3faf5; color: #14532d; font-weight: 600; text-align: left; min-width: 110px; }

.mp-free { background: #dff5e6; color: #14703a; border-radius: 99px; padding: 2px 10px; font-weight: 600; font-size: 13px; }
.mp-row.freeperiod { border-color: #bfe5cd; background: #f7fcf9; }

/* ---------- Free Teachers tab ---------- */
.ft-row { display: flex; gap: 12px; padding: 10px 12px; margin-bottom: 8px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.ft-p { flex: 0 0 84px; text-align: center; }
.ft-p b { display: block; font-size: 15px; color: var(--brand-2); }
.ft-p small { display: block; font-size: 11px; color: var(--muted); line-height: 1.25; }
.ft-body { flex: 1; min-width: 0; }
.ft-body > div { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 3px 0; }
.ft-label { flex: 0 0 82px; font-size: 12px; font-weight: 600; color: var(--muted); }
.ft-chip { padding: 3px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; }
.ft-chip.a { background: #dff5e6; color: #14703a; }
.ft-chip.b { background: #eef1f6; color: #3b4756; }
@media (max-width: 520px) { .ft-row { flex-direction: column; gap: 6px; } .ft-p { flex-basis: auto; text-align: left; display: flex; gap: 8px; align-items: baseline; } .ft-label { flex-basis: 100%; } }


/* ---------- Desktop / tablet: tab bar fits on one screen, icon on top, name below ---------- */
@media (min-width: 641px) {
  .tabs { gap: 0; padding: 0 6px; }
  .tabs button {
    flex: 1 0 64px; min-width: 64px;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: 9px 3px 7px; font-size: 11.5px; line-height: 1.2;
    white-space: normal; text-align: center;
  }
  .tabs button .tab-icon svg { width: 20px; height: 20px; }
}

/* ---------- Teacher attendance (admin) ---------- */
.ta-row { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line); }
.ta-row:last-child { border-bottom: 0; }
.ta-name { flex: 1 1 180px; font-weight: 600; min-width: 0; }
.ta-seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: 0 0 auto; }
.ta-b { border: 0; border-radius: 0; background: #fff; color: var(--muted); padding: 8px 14px; min-height: 38px; font-size: 13px; font-weight: 600; box-shadow: none; cursor: pointer; }
.ta-b + .ta-b { border-left: 1px solid var(--line); }
.ta-b.P.on { background: #d8f3e2; color: #14532d; }
.ta-b.A.on { background: #fbdcd8; color: #8c2118; }
.ta-b.L.on { background: #fdf0d2; color: #8a5a00; }
.ta-b.S.on { background: #e3dcf7; color: #43308a; }
.ta-after { flex: 0 1 170px; min-width: 130px; }
table.master .ts { background: #d9cff5; } table.master th.ts { background: #b9a8ee; }
table.master td.mk.S { color: #43308a; background: #e3dcf7; }
.ta-rem { flex: 1 1 160px; min-width: 0; }
.ta-abs { border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px 8px; margin-bottom: 12px; background: #fbfdff; }
.ta-abs h3 { margin: 10px 0 6px; }
.ta-slot { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 8px 0; border-top: 1px dashed var(--line); }
.ta-slot-info { flex: 1 1 220px; min-width: 0; }
.ta-slot select { flex: 0 1 240px; min-width: 150px; }
.ta-nofree { font-size: 12px; color: var(--danger); }
@media (max-width: 640px) {
  .ta-seg { width: 100%; }
  .ta-b { flex: 1; padding: 10px 4px; min-height: 42px; }
  .ta-rem, .ta-after { flex-basis: 100%; }
  .ta-slot select { flex: 1 1 100%; }
}

/* ---------- Dashboard: needs attention ---------- */
.attn-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.attn-part { border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px 12px; background: #fbfdff; min-width: 0; }
.attn-part h3 { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin: 10px 0 8px; }
.attn-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.attn-chip { padding: 4px 10px; border-radius: 20px; font-size: 12.5px; font-weight: 600; background: #fdf0d2; color: #8a5a00; }
.attn-ok { color: var(--ok); font-weight: 600; margin: 6px 0; }
.attn-warn, .attn-warn-inline { color: var(--danger); font-weight: 600; }
.attn-warn { margin: 6px 0; }
.attn-line { margin: 6px 0; font-size: 13.5px; line-height: 1.45; }

/* ---------- Phones: every table becomes a stack of cards (no sideways scrolling) ---------- */
@media screen and (max-width: 640px) {
  table.cardable { display: block; min-width: 0; width: 100%; border: 0; }
  table.cardable thead { display: none; }
  table.cardable tbody { display: block; }
  table.cardable tbody tr, table.cardable tr {
    display: block; background: #fff; border: 1px solid var(--line); border-radius: 12px;
    margin: 0 0 10px; padding: 4px 12px; box-shadow: var(--shadow-sm);
  }
  table.cardable tbody tr:hover { background: #fff; }
  table.cardable td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 8px 0; border: 0; border-bottom: 1px dashed var(--line);
    text-align: right; word-break: break-word;
  }
  table.cardable td:last-child { border-bottom: 0; }
  table.cardable td[data-label]::before {
    content: attr(data-label); flex: 0 0 36%; max-width: 40%; text-align: left;
    color: var(--muted); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px;
  }
  table.cardable td.card-hide { display: none; }
  table.cardable td.card-wide { display: block; text-align: left; }
  table.cardable td button, table.cardable td .btn-row { max-width: 100%; }
  .table-scroll:has(> table.cardable) { overflow: visible; }
}

/* ---------- My Periods: a replacement period (an absent teacher's class) ---------- */
.mp-row.sub, .mp-row.sub.today, .mp-row.sub.now, .mp-row.sub.done { background: #fdecea; border-color: #e8a29b; border-left: 4px solid #c0392b; }
.mp-row.sub .mp-body, .mp-row.sub.done .mp-body { color: #7a1f16; }
.mp-subtag { background: #c0392b; color: #fff; border-radius: 99px; padding: 2px 10px; font-weight: 700; font-size: 12px; }
.mp-subline { margin-bottom: 3px; }
.mp-subline small { color: #8c2118; }

/* table cells with several lines of content stay readable as cards (label on top, content below) */
@media screen and (max-width: 640px) {
  table.cardable td.card-stack { display: block; text-align: left; }
  table.cardable td.card-stack[data-label]::before { display: block; max-width: 100%; margin-bottom: 4px; }
}
