/* Palette from the school logo: cream, ink, gold, crimson. */
:root {
  --bg: #f7f4ee;
  --card: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --border: #e7e2da;
  --ink: #1c1917;
  --gold: #f2b705;
  --gold-soft: #fdf3d1;
  --gold-text: #7a5a00;
  --red: #c62828;
  --red-soft: #fdecea;
  --green: #2e7d32;
  --green-soft: #e8f5e9;
  --input: #fdfcfa;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.04), 0 6px 20px rgba(28, 25, 23, 0.06);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12100e;
    --card: #1c1a17;
    --text: #f2efe9;
    --muted: #a8a29e;
    --border: #2f2b27;
    --ink: #f2efe9;
    --gold-soft: #2e2510;
    --gold-text: #f2c94c;
    --red: #ef5350;
    --red-soft: #2c1615;
    --green: #66bb6a;
    --green-soft: #142417;
    --input: #171512;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

input, select {
  font: inherit;
  color: var(--text);
  background: var(--input);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus { border-color: var(--ink); }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }

.btn {
  font: inherit;
  font-weight: 650;
  border-radius: 10px;
  padding: 10px 16px;
  border: 1.5px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: opacity 0.15s, background 0.15s;
}
.btn:hover { opacity: 0.9; }
.btn.primary { background: var(--ink); color: var(--card); }
.btn.danger { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--bg); opacity: 1; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; padding: 12px; }
.btn.icon-only { padding: 8px; }
.btn:disabled { opacity: 0.6; cursor: default; }

.alert {
  background: var(--red-soft);
  color: var(--red);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0;
  font-size: 14px;
}

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  gap: 24px;
}
.login-brand { text-align: center; }
.login-brand img { border-radius: 22px; box-shadow: var(--shadow); }
.login-brand h1 { font-size: 22px; margin-top: 14px; }
.login-brand .city { margin: 4px 0 0; letter-spacing: 0.2em; font-weight: 700; font-size: 13px; color: var(--muted); }
.login-card { width: 100%; max-width: 400px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.login-card h2 { font-size: 20px; }
.login-card p { margin: 4px 0 0; }
.input-with-btn { position: relative; display: block; }
.input-with-btn input { padding-right: 44px; }
.input-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--muted); cursor: pointer; padding: 6px; display: flex;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1240px; margin: 0 auto; padding: 10px 24px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand img { border-radius: 10px; }
.brand span { display: flex; flex-direction: column; line-height: 1.2; }
.brand strong { font-size: 15px; }
.brand small { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 4px; margin-left: auto; background: var(--bg); padding: 4px; border-radius: 12px; }
.tab {
  font: inherit; font-weight: 650; background: none; border: none; color: var(--muted);
  padding: 8px 14px; border-radius: 9px; cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.account { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--gold-soft); color: var(--gold-text); font-weight: 800; font-size: 13px; flex: none;
}
.account-name { font-weight: 600; font-size: 14px; }

/* ---------- Content ---------- */
.content { max-width: 1240px; margin: 0 auto; padding: 28px 24px 64px; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 20px; }
.page-head h1 { font-size: 26px; }
.page-head p { margin: 4px 0 0; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat {
  font: inherit; color: inherit; text-align: left;
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
button.stat { cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
button.stat:hover { transform: translateY(-1px); }
.stat.selected { border-color: currentColor; }
.stat-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.stat-icon .icon { width: 22px; height: 22px; }
.stat-value { display: block; font-size: 28px; font-weight: 800; line-height: 1.1; color: var(--text); }
.stat-label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.stat.red { color: var(--red); } .stat.red .stat-icon { background: var(--red-soft); }
.stat.green { color: var(--green); } .stat.green .stat-icon { background: var(--green-soft); }
.stat.total { color: var(--gold-text); } .stat.total .stat-icon { background: var(--gold-soft); }
.stat.neutral .stat-icon { background: var(--bg); color: var(--muted); }

/* Filters */
.filters { display: flex; gap: 10px; flex-wrap: wrap; padding: 10px; margin-bottom: 18px; align-items: center; }
.filters select { width: auto; min-width: 150px; }
.search { position: relative; flex: 1; min-width: 220px; display: block; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 38px; }
.segmented { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; }
.segmented button {
  font: inherit; font-weight: 650; border: none; background: none; color: var(--muted);
  padding: 7px 16px; cursor: pointer; border-radius: 8px;
}
.segmented button.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.segmented button[data-zone='red'].active { color: var(--red); }
.segmented button[data-zone='green'].active { color: var(--green); }
.active-filter { margin: -6px 0 16px; font-size: 14px; color: var(--muted); }
.active-filter button { font: inherit; color: var(--text); font-weight: 600; background: none; border: none; text-decoration: underline; cursor: pointer; padding: 0 0 0 6px; }

/* Report cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.report { overflow: hidden; display: flex; flex-direction: column; }
.report-photo { position: relative; aspect-ratio: 4 / 3; background: var(--bg); cursor: zoom-in; border: none; padding: 0; display: block; width: 100%; }
.report-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.zone-pill {
  position: absolute; top: 10px; left: 10px;
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 750; padding: 5px 10px; border-radius: 999px; color: #fff;
}
.zone-pill .icon { width: 14px; height: 14px; }
.zone-pill.red { background: #c62828; }
.zone-pill.green { background: #2e7d32; }
.report-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.report-head { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.student { font: inherit; font-weight: 750; font-size: 17px; color: var(--text); background: none; border: none; padding: 0; cursor: pointer; text-align: left; }
.student:hover { text-decoration: underline; }
.class-chip { font-size: 12px; font-weight: 700; background: var(--bg); color: var(--muted); padding: 4px 8px; border-radius: 6px; white-space: nowrap; }
.report-note { margin: 0; white-space: pre-wrap; line-height: 1.5; font-size: 14px; }
.voice { display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 10px; padding: 6px 6px 6px 10px; }
.voice .icon { color: var(--muted); }
.voice audio { flex: 1; height: 36px; min-width: 0; }
.report-meta {
  margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; color: var(--muted);
}
.report-meta strong { color: var(--text); font-weight: 600; }
.icon-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; display: flex; }
.icon-btn:hover { color: var(--red); background: var(--red-soft); }

.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 48px 16px; }
.empty .icon { width: 36px; height: 36px; color: var(--muted); margin-bottom: 6px; }
.center { text-align: center; margin-top: 24px; }

/* Teachers */
.add-teacher { padding: 20px; margin-bottom: 18px; }
.add-teacher h2 { font-size: 17px; display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.add-teacher .alert { margin-bottom: 12px; }
.row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.row label { flex: 1; min-width: 190px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 14px 18px; border-bottom: 1px solid var(--border); font-size: 14px; }
tr:last-child td { border-bottom: none; }
th { color: var(--muted); font-weight: 650; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.person { display: flex; align-items: center; gap: 12px; }
.person > span:not(.avatar) { display: flex; flex-direction: column; }
.person small { color: var(--muted); }
.counts { display: flex; gap: 6px; }
.count { font-size: 12px; font-weight: 750; padding: 3px 9px; border-radius: 999px; }
.count.red { background: var(--red-soft); color: var(--red); }
.count.green { background: var(--green-soft); color: var(--green); }
.status { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.status.on { background: var(--green-soft); color: var(--green); }
.status.off { background: var(--bg); color: var(--muted); }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn { margin-left: 6px; }
tr.inactive .person { opacity: 0.55; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; background: rgba(12, 10, 9, 0.9);
  display: grid; place-items: center; z-index: 30; cursor: zoom-out; padding: 24px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; }
.lightbox-close { position: absolute; top: 16px; right: 16px; background: rgba(255,255,255,0.12); color: #fff; border: none; border-radius: 50%; padding: 10px; cursor: pointer; display: flex; }

/* Dialog */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 24px;
  width: min(420px, calc(100vw - 32px)); background: var(--card); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(12, 10, 9, 0.5); }
dialog h3 { font-size: 18px; }
dialog p { margin: 8px 0 16px; line-height: 1.5; }
dialog input { margin-bottom: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--card); padding: 12px 18px; border-radius: 12px;
  font-weight: 600; font-size: 14px; z-index: 40; box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  max-width: calc(100vw - 32px);
}
.toast.error { background: var(--red); color: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .account-name { display: none; }
}
@media (max-width: 640px) {
  .topbar-inner { padding: 10px 16px; flex-wrap: wrap; gap: 10px; }
  .brand strong { font-size: 14px; }
  .tabs { order: 3; width: 100%; margin-left: 0; }
  .tab { flex: 1; justify-content: center; }
  .account { margin-left: auto; }
  .content { padding: 20px 16px 48px; }
  .page-head h1 { font-size: 22px; }
  .stat { padding: 12px; gap: 10px; }
  .stat-icon { width: 36px; height: 36px; }
  .stat-value { font-size: 22px; }
  .search { flex-basis: 100%; }
  .filters select { flex: 1; min-width: 0; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  th, td { padding: 12px; }
}
