:root {
  --bg: #eef1f5;
  --card: #ffffff;
  --ink: #1c2530;
  --muted: #667180;
  --line: #e2e7ee;
  --brand: #1e5aa8;
  --brand-dark: #16467f;
  --brand-soft: #eaf1fa;
  --green: #1a7f4b; --green-soft: #e6f3ec;
  --amber: #b45309; --amber-soft: #fbf0e2;
  --red: #b91c1c;   --red-soft: #fbeaea;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c; --card: #182029; --ink: #e6ebf1; --muted: #93a0b0; --line: #26313d;
    --brand: #4f8fd6; --brand-dark: #3d78ba; --brand-soft: #182a3d;
    --green: #4ec288; --green-soft: #14261d; --amber: #e0a45c; --amber-soft: #2a2013;
    --red: #e8807c; --red-soft: #2b1717;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 16px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --bg: #10151c; --card: #182029; --ink: #e6ebf1; --muted: #93a0b0; --line: #26313d;
  --brand: #4f8fd6; --brand-dark: #3d78ba; --brand-soft: #182a3d;
  --green: #4ec288; --green-soft: #14261d; --amber: #e0a45c; --amber-soft: #2a2013;
  --red: #e8807c; --red-soft: #2b1717;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 16px rgba(0,0,0,.3);
}
:root[data-theme="light"] {
  --bg: #eef1f5; --card: #fff; --ink: #1c2530; --muted: #667180; --line: #e2e7ee;
  --brand: #1e5aa8; --brand-dark: #16467f; --brand-soft: #eaf1fa;
  --green: #1a7f4b; --green-soft: #e6f3ec; --amber: #b45309; --amber-soft: #fbf0e2;
  --red: #b91c1c; --red-soft: #fbeaea;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}
/* Kontrol form & tombol memakai warna teks tema (perbaikan kontras mode gelap). */
input, select, textarea, button { color: var(--ink); font-family: inherit; }
input, select, textarea { background: var(--card); }
input::placeholder, textarea::placeholder { color: var(--muted); }

header {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
header .head-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
header .kicker { font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; opacity: 0.8; }
header .title { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.2px; margin-top: 2px; }
header .head-user {
  display: flex; flex-direction: column; align-items: flex-end; gap: 3px;
  background: rgba(255,255,255,0.14); border: none; color: #fff; cursor: pointer;
  padding: 7px 12px; border-radius: 10px; font-family: inherit; font-size: 0.82rem; font-weight: 600;
}
header .head-user:hover { background: rgba(255,255,255,0.24); }
.role-pill {
  font-size: 0.62rem; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 700;
  background: rgba(255,255,255,0.22); padding: 2px 7px; border-radius: 999px;
}

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow); padding: 26px 22px; width: 100%; max-width: 380px;
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand .kicker { font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.login-brand h1 { margin: 6px 0 4px; font-size: 1.6rem; color: var(--brand); }
.login-brand p { margin: 0; font-size: 0.82rem; color: var(--muted); }
.form-error { background: var(--red-soft, #fdecec); color: var(--red); font-size: 0.82rem; padding: 9px 12px; border-radius: 8px; margin-bottom: 10px; }

nav.tabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
nav.tabs button {
  flex: 1;
  padding: 12px 8px;
  border: none;
  background: none;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  cursor: pointer;
}
nav.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

main { max-width: 760px; margin: 0 auto; padding: 14px; }
.hidden { display: none !important; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 10px; font-size: 0.95rem; }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field input, .field select, .field textarea, #cItemSearch {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.92rem;
  font-family: inherit;
  background: var(--card);
  color: var(--ink);
}
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.item-list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.item:hover { border-color: var(--brand); }
.item.sel { border-color: var(--brand); background: var(--brand-soft); }
.item .no { color: var(--muted); font-size: 0.8rem; min-width: 22px; }
.item .teks { flex: 1; font-size: 0.9rem; }
.badge-poin {
  font-weight: 700;
  font-size: 0.85rem;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.p-lo { background: var(--green-soft); color: var(--green); }
.p-mid { background: var(--amber-soft); color: var(--amber); }
.p-hi { background: var(--red-soft); color: var(--red); }

button.primary {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.status-box {
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
}
.status-box .total { font-size: 1.8rem; font-weight: 800; line-height: 1; }
.status-box .lbl { font-size: 0.78rem; color: var(--muted); }
.tingkat-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}
.t-ringan { background: var(--green-soft); color: var(--green); }
.t-sedang { background: var(--amber-soft); color: var(--amber); }
.t-berat { background: var(--red-soft); color: var(--red); }
.t-none { background: var(--line); color: var(--muted); }
.tindak { font-size: 0.82rem; color: var(--muted); margin-top: 6px; }

table.rekap { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.rekap th, table.rekap td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
table.rekap th { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; }
table.rekap tr { cursor: pointer; }
table.rekap td.num { text-align: right; font-weight: 700; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.d-ringan { background: var(--green); }
.d-sedang { background: var(--amber); }
.d-berat { background: var(--red); }
.d-none { background: #cbd2da; }

.entry {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.entry .meta { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }
.entry .poin-tag { font-weight: 700; white-space: nowrap; }
.entry .poin-plus { color: var(--red); }
.entry .poin-minus { color: var(--green); }
.entry .del { color: var(--muted); background: none; border: none; cursor: pointer; font-size: 0.9rem; }

.empty { text-align: center; color: var(--muted); padding: 24px 12px; font-size: 0.9rem; }

/* Modal */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}
.modal {
  background: var(--card);
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 16px;
}
.modal .close-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal h3 { margin: 0; font-size: 1rem; }

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--card);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 40;
  box-shadow: var(--shadow);
}

.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; }

@media (min-width: 640px) {
  .modal { border-radius: 16px; align-self: center; }
  .overlay { align-items: center; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Toolbar & tabel manajemen */
.toolbar { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .field { margin: 0; flex: 1; min-width: 130px; }
.mng-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.mng-table th, .mng-table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.mng-table th { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.mng-table td.act { text-align: right; white-space: nowrap; }
.mng-table .icon-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 8px; padding: 5px 9px; font-size: 0.78rem; font-weight: 600; cursor: pointer; margin-left: 5px; font-family: inherit;
}
.mng-table .icon-btn:hover { border-color: var(--brand); color: var(--brand); }
.mng-table .icon-btn.danger:hover { border-color: var(--red); color: var(--red); }
.tag {
  display: inline-block; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand);
}
.tag.off { background: var(--line); color: var(--muted); }
.tag.admin { background: var(--red-soft); color: var(--red); }
.tag.operator { background: var(--amber-soft); color: var(--amber); }
.tag.guru { background: var(--green-soft); color: var(--green); }
.subhead { font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; margin: 4px 0 10px; }
.row-inline { display: flex; gap: 8px; align-items: center; }
.muted-sm { font-size: 0.78rem; color: var(--muted); }
.table-scroll { overflow-x: auto; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 0.86rem; color: var(--muted); margin-bottom: 10px; }
.check-row input { width: auto; }

/* Logo sekolah */
.brand-logo { width: 34px; height: 34px; flex: 0 0 auto; display: block; }
header .head-top .brand-left { display: flex; align-items: center; gap: 10px; }
.login-brand .brand-logo { width: 56px; height: 56px; margin: 0 auto 8px; }

/* Pencarian (autocomplete) */
.search-wrap { position: relative; }
.search-results {
  position: absolute; z-index: 8; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 260px; overflow-y: auto;
}
.search-results button {
  display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left;
  padding: 9px 12px; border: none; border-bottom: 1px solid var(--line); background: none;
  cursor: pointer; font-family: inherit; font-size: 0.88rem; color: var(--ink);
}
.search-results button:last-child { border-bottom: none; }
.search-results button:hover { background: var(--brand-soft); }
.search-results .sr-meta { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.chosen {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--brand); background: var(--brand-soft); border-radius: 10px;
}
.chosen .nm { font-weight: 700; }
.chosen .x { border: none; background: none; color: var(--brand); font-weight: 700; cursor: pointer; font-size: 0.82rem; font-family: inherit; }
.stu-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.stu-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--brand-soft); color: var(--ink); border: 1px solid var(--brand); border-radius: 999px; padding: 5px 5px 5px 11px; font-size: 0.82rem; font-weight: 600; }
.stu-chip button { border: none; background: none; color: var(--brand); cursor: pointer; font-weight: 700; font-size: 1.05rem; line-height: 1; padding: 0 4px; }

/* Dashboard */
.period-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.period-bar select { width: auto; min-width: 150px; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat .v { font-size: 1.5rem; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 0.74rem; color: var(--muted); font-weight: 600; margin-top: 2px; }
.stat.accent .v { color: var(--red); }
.stat.good .v { color: var(--green); }
.dash-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 720px) { .dash-grid.two { grid-template-columns: 1fr 1fr; } .stat-grid { grid-template-columns: repeat(4, 1fr); } }

/* Bar chart */
.chart { display: flex; flex-direction: column; gap: 9px; }
.cbar-row { display: grid; grid-template-columns: 96px 1fr auto; gap: 9px; align-items: center; }
.cbar-label { font-size: 0.8rem; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cbar-track { background: var(--line); border-radius: 999px; height: 12px; overflow: hidden; }
.cbar-fill { height: 100%; border-radius: 999px; background: var(--brand); }
.cbar-fill.sikap { background: var(--brand); }
.cbar-fill.kerajinan { background: var(--amber); }
.cbar-fill.kerapian { background: var(--green); }
.cbar-val { font-size: 0.8rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 30px; text-align: right; }

/* Day-of-week columns */
.dow { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 110px; }
.dow .col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.dow .bar { width: 70%; background: var(--brand); border-radius: 5px 5px 0 0; min-height: 3px; }
.dow .bar.peak { background: var(--red); }
.dow .lbl { font-size: 0.68rem; color: var(--muted); }
.dow .n { font-size: 0.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Follow-up queue */
.queue-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.queue-item:last-child { border-bottom: none; }
.queue-item .qn { font-weight: 700; }
.queue-item .qmeta { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }
.queue-item .qpts { font-weight: 800; font-variant-numeric: tabular-nums; }
.mini-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.76rem; color: var(--muted); margin-top: 8px; }
.mini-legend span { display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
