/* =====================================================================
   PPSC Prep — Admin Dashboard styles
   Brand: deep green (#0B6B3A family) · white cards · soft shadows
   Responsive: sidebar on desktop → top bar + bottom nav on mobile
   ===================================================================== */

:root {
  --green-900: #06331b;
  --green-800: #084c27;
  --green-700: #0b6b3a;
  --green-600: #0e8147;
  --green-500: #12a35c;
  --green-100: #dcf2e5;
  --green-50:  #eef8f2;
  --amber: #f5a623;
  --red: #d64541;
  --red-50: #fdf0ef;
  --ink: #17281f;
  --muted: #6b7d72;
  --line: #e3ece6;
  --bg: #f4f7f4;
  --card: #ffffff;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(11, 60, 35, .07), 0 8px 24px -12px rgba(11, 60, 35, .12);
  --shadow-lg: 0 24px 60px -18px rgba(6, 51, 27, .35);
  --sidebar-w: 248px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--green-700); }
[hidden] { display: none !important; }

/* ---------------- Login ---------------- */

.login-wrap {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: linear-gradient(150deg, var(--green-900) 0%, var(--green-700) 58%, var(--green-500) 130%);
}
.login-card {
  background: var(--card);
  width: 100%; max-width: 392px;
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px 30px;
  text-align: center;
}
.login-logo {
  width: 68px; height: 68px; margin: 0 auto 14px;
  border-radius: 18px;
  background: var(--green-50);
  border: 1px solid var(--green-100);
  display: flex; align-items: center; justify-content: center;
  font-size: 34px;
}
.login-card h1 { font-size: 23px; font-weight: 800; letter-spacing: -.2px; }
.login-card .sub { color: var(--muted); font-size: 13.5px; margin: 4px 0 22px; }
.login-card form { text-align: left; }
.login-error {
  background: var(--red-50); color: var(--red);
  border: 1px solid #f3cfcd;
  border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 13.5px; margin-bottom: 14px;
}
.demo-hint {
  margin-top: 16px; font-size: 12.5px; color: var(--muted);
  background: var(--green-50); border: 1px dashed var(--green-100);
  border-radius: var(--radius-sm); padding: 8px 10px;
}

/* ---------------- PIN entry (login + change PIN) ---------------- */

.pin-boxes { display: flex; gap: 8px; justify-content: center; }
.pin-boxes.pin-left { justify-content: flex-start; }
.pin-box {
  width: 46px; height: 54px; flex: 0 1 46px; min-width: 0;
  text-align: center;
  font-size: 22px; font-weight: 700;
  color: var(--ink); background: #fff;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  caret-color: var(--green-700);
  transition: border-color .15s, box-shadow .15s;
}
.pin-box:focus {
  outline: none; border-color: var(--green-600);
  box-shadow: 0 0 0 3px var(--green-100);
}
.pin-boxes.shake { animation: pin-shake .4s ease; }
@keyframes pin-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:disabled:active { transform: none; }

/* ---------------- App shell ---------------- */

.shell { display: flex; min-height: 100dvh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: linear-gradient(178deg, var(--green-900), var(--green-800) 70%);
  color: #dcefe3;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100dvh;
  padding: 20px 14px 16px;
  z-index: 40;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 2px 8px 18px; }
.brand-badge {
  width: 42px; height: 42px; border-radius: 12px; flex: 0 0 42px;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center; font-size: 21px;
}
.brand b { display: block; color: #fff; font-size: 16.5px; line-height: 1.15; }
.brand span { font-size: 11.5px; color: #9fd4b4; letter-spacing: .4px; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 11px;
  color: #cfe7d7; text-decoration: none; font-weight: 600; font-size: 14.5px;
  transition: background .15s, color .15s;
}
.nav a .ico { width: 21px; text-align: center; font-size: 16px; }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.active { background: #fff; color: var(--green-800); box-shadow: var(--shadow); }
.nav a .pill {
  margin-left: auto; background: var(--red); color: #fff;
  font-size: 11px; font-weight: 700; min-width: 20px; height: 20px;
  border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; padding: 0 6px;
}
.nav a.active .pill { background: var(--red); color: #fff; }

.sidebar-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.12); padding-top: 13px; }
.sidebar-foot .who { font-size: 12.5px; color: #9fd4b4; padding: 0 10px 9px; }
.btn-logout {
  width: 100%; background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.16);
  border-radius: 11px; padding: 9px 12px; font-weight: 600;
}
.btn-logout:hover { background: rgba(255,255,255,.16); }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(244,247,244,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 14px 26px;
  display: flex; align-items: center; gap: 14px;
}
.topbar h2 { font-size: 20px; font-weight: 800; letter-spacing: -.2px; }
.topbar .crumb { color: var(--muted); font-size: 13px; }
.topbar .spacer { flex: 1; }
.demo-chip {
  background: #fff7e8; color: #8a5a00; border: 1px solid #f3ddab;
  font-size: 12px; font-weight: 700; border-radius: 999px; padding: 4px 11px;
}

.content { padding: 24px 26px 90px; width: 100%; max-width: 1220px; margin: 0 auto; }

/* Bottom nav (mobile only) */
.bottomnav { display: none; }

/* ---------------- Generic UI ---------------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card h3 { font-size: 16px; font-weight: 750; margin-bottom: 4px; }
.card .card-sub { color: var(--muted); font-size: 13px; margin-bottom: 12px; }

.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 1.6fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.mt { margin-top: 16px; }

.kpi { position: relative; overflow: hidden; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.kpi .value { font-size: 31px; font-weight: 800; letter-spacing: -.5px; margin-top: 5px; line-height: 1.1; }
.kpi .delta { font-size: 12.5px; margin-top: 5px; color: var(--muted); }
.kpi .delta b { color: var(--green-600); }
.kpi .kico {
  position: absolute; right: 14px; top: 14px;
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--green-50); border: 1px solid var(--green-100);
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}

.pulse-dot {
  width: 9px; height: 9px; border-radius: 50%; background: #22c55e; display: inline-block; position: relative;
}
.pulse-dot::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid rgba(34,197,94,.5); animation: pulse 1.6s ease-out infinite;
}
@keyframes pulse { 0% { transform: scale(.55); opacity: 1; } 100% { transform: scale(1.15); opacity: 0; } }

.live-badge {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--red); color: #fff; font-weight: 800; font-size: 12px;
  letter-spacing: 1.2px; padding: 5px 12px; border-radius: 999px;
}
.live-badge .pulse-dot { background: #fff; }
.live-badge .pulse-dot::after { border-color: rgba(255,255,255,.6); }

.stat-row { display: flex; flex-wrap: wrap; gap: 10px; }
.stat-chip {
  flex: 1 1 130px; background: var(--green-50); border: 1px solid var(--green-100);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.stat-chip .n { font-size: 21px; font-weight: 800; }
.stat-chip .t { font-size: 12px; color: var(--muted); font-weight: 600; }

.chart-box { position: relative; height: 250px; }
.chart-box.tall { height: 290px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border-radius: 11px; border: 1px solid transparent;
  padding: 9px 16px; font-weight: 650; font-size: 14px;
  background: var(--green-700); color: #fff; transition: background .15s, transform .05s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--green-600); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: #fff; color: var(--green-800); border-color: var(--line); }
.btn.secondary:hover { background: var(--green-50); }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #b93632; }
.btn.ghost-danger { background: #fff; color: var(--red); border-color: #f0cfcd; }
.btn.ghost-danger:hover { background: var(--red-50); }
.btn.small { padding: 6px 11px; font-size: 13px; border-radius: 9px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn.block { width: 100%; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 650; margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.input, select.input, textarea.input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 11px;
  padding: 10px 12px; background: #fff; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--green-500); box-shadow: 0 0 0 3px var(--green-100); }
textarea.input { resize: vertical; min-height: 74px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar .grow { flex: 1 1 210px; }
.toolbar .spacer { flex: 1; }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 700; border-radius: 999px; padding: 3px 9px;
}
.badge.green { background: var(--green-100); color: var(--green-800); }
.badge.red { background: #fbe3e1; color: #a02c28; }
.badge.grey { background: #edf1ee; color: var(--muted); }
.badge.amber { background: #fdeecd; color: #8a5a00; }
.badge.diff-Easy { background: var(--green-100); color: var(--green-800); }
.badge.diff-Medium { background: #fdeecd; color: #8a5a00; }
.badge.diff-Hard { background: #fbe3e1; color: #a02c28; }

/* Subjects view — the subject's existing topics, clearly one labelled list */
.topics-box {
  background: var(--green-50);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 13px 0;
}
.topics-head { font-size: 13px; font-weight: 700; color: var(--green-800); margin-bottom: 8px; }
.topics-head span { font-weight: 500; color: var(--muted); }
.topics-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* Tables → card list on mobile */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line); background: #fbfdfb;
}
.tbl td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl .strong { font-weight: 650; }
.tbl .dim { color: var(--muted); font-size: 13px; }
.tbl .actions { display: flex; gap: 7px; flex-wrap: wrap; }

.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-top: 14px; font-size: 13.5px; color: var(--muted); }

/* States */
.skeleton { border-radius: var(--radius); background: linear-gradient(100deg, #e8efe9 40%, #f4f8f4 50%, #e8efe9 60%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.empty {
  text-align: center; padding: 42px 18px; color: var(--muted);
  border: 1.5px dashed var(--line); border-radius: var(--radius); background: #fff;
}
.empty .big { font-size: 34px; margin-bottom: 8px; }
.empty b { color: var(--ink); display: block; font-size: 15.5px; margin-bottom: 3px; }
.error-box {
  background: var(--red-50); border: 1px solid #f3cfcd; color: #8c2b27;
  border-radius: var(--radius); padding: 16px 18px; font-size: 14px;
}

/* Live feed */
.feed { display: flex; flex-direction: column; }
.feed-item { display: flex; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.feed-item:last-child { border-bottom: none; }
.feed-item .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green-500); margin-top: 7px; flex: 0 0 9px; }
.feed-item .when { margin-left: auto; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.online-row { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.online-row:last-child { border-bottom: none; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 38px;
  background: var(--green-100); color: var(--green-800);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px;
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6, 40, 20, .5); z-index: 80;
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
}
.modal {
  background: #fff; width: 100%; max-width: 640px; max-height: 92dvh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 24px 24px 20px; box-shadow: var(--shadow-lg);
  animation: slideup .22s ease;
}
@keyframes slideup { from { transform: translateY(26px); opacity: .4; } to { transform: none; opacity: 1; } }
.modal h3 { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.modal .modal-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.opt-row { display: flex; gap: 9px; align-items: flex-start; margin-bottom: 10px; }
.opt-row .input { flex: 1; }
.radio-correct { margin-top: 12px; accent-color: var(--green-700); width: 17px; height: 17px; flex: 0 0 auto; }

/* Toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 120; display: flex; flex-direction: column; gap: 9px; max-width: min(360px, calc(100vw - 36px)); }
.toast {
  background: var(--green-900); color: #eaf6ee; border-radius: 13px; padding: 12px 15px;
  box-shadow: var(--shadow-lg); font-size: 14px; display: flex; gap: 9px; align-items: flex-start;
  animation: toastin .25s ease;
}
.toast.error { background: #7c1d19; }
@keyframes toastin { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

.notice {
  border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13.5px; margin-bottom: 16px;
  background: #fff8e8; border: 1px solid #f3ddab; color: #6d4c00;
}
.notice b { color: #543900; }

.subject-block { margin-bottom: 18px; }
.subject-block h4 { font-size: 15px; font-weight: 750; margin-bottom: 9px; display: flex; gap: 8px; align-items: center; }
.note-row { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.note-row:last-child { border-bottom: none; }
.note-row .meta { color: var(--muted); font-size: 12.5px; }

.switch { position: relative; width: 44px; height: 24px; flex: 0 0 44px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px; background: #cfdcd2; transition: .2s; cursor: pointer;
}
.switch .track::before {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--green-600); }
.switch input:checked + .track::before { transform: translateX(20px); }

/* ---------------- Responsive ---------------- */

@media (max-width: 1020px) {
  .grid-kpi { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}

@media (min-width: 721px) {
  .modal-backdrop { align-items: center; padding: 22px; }
  .modal { border-radius: 20px; }
}

@media (max-width: 720px) {
  .sidebar { display: none; }
  .content { padding: 17px 14px 96px; }
  .topbar { padding: 12px 15px; }
  .topbar h2 { font-size: 17.5px; }
  .topbar .crumb { display: none; }
  .grid-kpi { grid-template-columns: repeat(2, 1fr); gap: 11px; }
  .kpi .value { font-size: 24px; }
  .kpi .kico { display: none; }
  .card { padding: 15px; }
  .chart-box { height: 215px; }
  .chart-box.tall { height: 240px; }

  .bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: #fff; border-top: 1px solid var(--line);
    box-shadow: 0 -6px 20px -10px rgba(6,51,27,.25);
    padding: 6px 2px calc(6px + env(safe-area-inset-bottom));
    overflow-x: auto;
  }
  .bottomnav a {
    flex: 1 0 auto; min-width: 58px; text-align: center; text-decoration: none;
    color: var(--muted); font-size: 10.5px; font-weight: 650; padding: 4px 2px; border-radius: 9px;
  }
  .bottomnav a .ico { display: block; font-size: 19px; margin-bottom: 1px; }
  .bottomnav a.active { color: var(--green-700); background: var(--green-50); }
  .bottomnav a .pill {
    background: var(--red); color: #fff; border-radius: 999px; font-size: 9.5px; padding: 0 5px; margin-left: 3px;
  }
  .toasts { bottom: 84px; }

  /* table → cards */
  .table-wrap { border: none; box-shadow: none; background: transparent; overflow: visible; }
  table.tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl thead { display: none; }
  .tbl tr {
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 12px 15px; margin-bottom: 11px;
  }
  .tbl td { border: none; padding: 4px 0; display: flex; justify-content: space-between; gap: 14px; align-items: center; }
  .tbl td::before {
    content: attr(data-label); font-size: 11.5px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .4px; color: var(--muted); flex: 0 0 auto;
  }
  .tbl td:first-child { display: block; padding-bottom: 7px; }
  .tbl td:first-child::before { display: none; }
  .tbl td.actions { justify-content: flex-end; padding-top: 9px; }
  .tbl td.actions::before { display: none; }
}

/* Sign-out lives in the sidebar on desktop; topbar copy is for mobile */
@media (min-width: 721px) {
  #logoutBtnTop { display: none; }
}

@media (max-width: 420px) {
  .grid-kpi { grid-template-columns: 1fr 1fr; }
  .stat-chip { flex-basis: 100px; }
}
