:root {
  --bg: #f4f7f6;
  --card: #ffffff;
  --ink: #1b2a28;
  --muted: #64748b;
  --line: #e2e8e6;
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --brand-soft: #e6f6f4;
  --present: #16a34a;
  --late: #d97706;
  --absent: #dc2626;
  --excused: #6366f1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 40, 35, .06), 0 4px 14px rgba(15, 40, 35, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Top bar + tabs */
.topbar {
  background: linear-gradient(135deg, var(--brand), #115e59);
  color: #fff;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
}
.brand { display: flex; gap: 12px; align-items: center; max-width: 1000px; margin: 0 auto; }
.logo {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: rgba(255,255,255,.18); font-weight: 700; font-size: 20px;
}
.brand-name { font-weight: 700; font-size: 18px; }
.brand-sub { opacity: .85; font-size: 13px; }

.tabs {
  position: sticky; top: 0; z-index: 10;
  display: flex; gap: 4px; overflow-x: auto;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 6px 12px;
}
.tabs button {
  flex: 1 0 auto; border: 0; background: none; padding: 10px 14px; border-radius: 10px;
  font-weight: 600; color: var(--muted); white-space: nowrap;
}
.tabs button.active { background: var(--brand-soft); color: var(--brand); }

main { max-width: 1000px; margin: 0 auto; padding: 16px; }

/* Cards & forms */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card h2 { margin: 0 0 4px; font-size: 18px; }
.card h3 { margin: 0 0 10px; font-size: 16px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > .field { flex: 1 1 160px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  background: #fff; min-height: 42px;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; }

.btn {
  border: 0; border-radius: 10px; padding: 10px 14px; font-weight: 600;
  background: var(--brand); color: #fff; min-height: 42px;
}
.btn.ghost { background: var(--brand-soft); color: var(--brand); }
.btn.plain { background: #f1f5f4; color: var(--ink); }
.btn.danger { background: #fee2e2; color: var(--absent); }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Today: stats */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 12px 0 4px; }
.stat { background: #f8faf9; border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.p b { color: var(--present); } .stat.l b { color: var(--late); }
.stat.a b { color: var(--absent); } .stat.e b { color: var(--excused); }
.stat.r b { color: var(--brand); }

/* Student roll */
.roll { list-style: none; margin: 0; padding: 0; }
.student {
  display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.student:first-child { border-top: 0; }
.roll .group {
  list-style: none; margin: 14px 0 2px; padding: 6px 10px; border-radius: 8px;
  background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 12px;
  text-transform: uppercase; letter-spacing: .06em;
}
.roll .group:first-child { margin-top: 0; }
.roll .group span { opacity: .7; margin-left: 4px; }
.roll .group + .student { border-top: 0; }
tr.group td {
  background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 12px;
  text-transform: uppercase; letter-spacing: .06em; text-align: left;
}
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days button {
  min-width: 52px; height: 42px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; font-weight: 600; color: var(--muted);
}
.days button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.student-edit .sex-select { flex: 0 0 110px; width: 110px; }
.student.picked { background: #fff7d6; border-radius: 10px; padding-left: 8px; padding-right: 8px; }
.s-name { font-weight: 600; }
.s-num { color: var(--muted); font-weight: 500; margin-right: 6px; }
.s-meta { font-size: 12px; color: var(--muted); }
.status { display: flex; gap: 4px; }
.status button {
  width: 40px; height: 38px; border-radius: 9px; border: 1px solid var(--line);
  background: #fff; font-weight: 700; color: var(--muted);
}
.status button.on.P { background: var(--present); border-color: var(--present); color: #fff; }
.status button.on.L { background: var(--late); border-color: var(--late); color: #fff; }
.status button.on.A { background: var(--absent); border-color: var(--absent); color: #fff; }
.status button.on.E { background: var(--excused); border-color: var(--excused); color: #fff; }

.recite { grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.recite .plus {
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: var(--brand); color: #fff; font-size: 26px; font-weight: 600; line-height: 1;
  display: grid; place-items: center; padding: 0 0 2px;
  box-shadow: 0 2px 6px rgba(15, 118, 110, .35); transition: transform .08s;
}
.recite .plus:active { transform: scale(.9); }
.recite .plus:disabled { background: #cbd5d3; box-shadow: none; cursor: not-allowed; }
.rec-count { font-size: 13px; font-weight: 600; color: var(--brand); margin-right: 2px; }
.points button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip {
  border: 0; border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 600;
  background: #ecfdf5; color: var(--present);
}
.chip.low { background: #fef3c7; color: #92400e; }
.chip.note { background: #f1f5f9; color: var(--muted); font-weight: 500; }
.points { display: flex; gap: 6px; flex-wrap: wrap; }
.points button { width: 52px; height: 52px; border-radius: 12px; border: 1px solid var(--line); background: #fff; font-size: 18px; font-weight: 700; }
.points button:hover { background: var(--brand-soft); border-color: var(--brand-2); }

/* Records table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; background: #fff; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
th { background: #f8faf9; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); position: sticky; top: 0; }
td:first-child, th:first-child { text-align: left; position: sticky; left: 0; background: inherit; }
tbody tr:hover { background: #f8faf9; }
tbody tr { background: #fff; }
td.P { color: var(--present); font-weight: 700; } td.L { color: var(--late); font-weight: 700; }
td.A { color: var(--absent); font-weight: 700; } td.E { color: var(--excused); font-weight: 700; }
.pct { font-weight: 700; }
.pct.bad { color: var(--absent); } .pct.warn { color: var(--late); } .pct.good { color: var(--present); }
.link { background: none; border: 0; color: var(--brand); font-weight: 600; padding: 0; text-align: left; }
.seg { display: inline-flex; background: #f1f5f4; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 7px 12px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.seg button.on { background: #fff; color: var(--brand); box-shadow: var(--shadow); }

/* Classes list */
.class-item { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.class-item:first-of-type { border-top: 0; }
.tag { display: inline-block; background: var(--brand-soft); color: var(--brand); border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; }
.student-edit { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.student-edit input { flex: 1; }

.empty { text-align: center; padding: 30px 16px; color: var(--muted); }
.empty .big { font-size: 40px; }

/* Toast + modal */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #1b2a28; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50;
  box-shadow: var(--shadow); font-weight: 500; max-width: calc(100% - 32px);
}
.modal { position: fixed; inset: 0; background: rgba(15, 30, 28, .45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal-card { background: #fff; border-radius: 16px; padding: 18px; width: 100%; max-width: 440px; max-height: 90vh; overflow: auto; }
.modal-card h3 { margin: 0 0 6px; }
[hidden] { display: none !important; }

@media (max-width: 560px) {
  .stats { grid-template-columns: repeat(5, 1fr); gap: 5px; }
  .stat { padding: 8px 2px; }
  .stat b { font-size: 17px; }
  .status button { width: 36px; }
  .tabs button { padding: 9px 10px; font-size: 14px; }
}

@media print {
  .topbar, .tabs, .no-print, .toast { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; padding: 0; }
  main { padding: 0; }
  th { position: static; }
}
