/* ============================================================
   Tahfidz v2 — design system
   Warm paper, satu aksen hijau pinus, tipografi editorial.
   ============================================================ */

@font-face {
  font-family: 'Manrope';
  src: url('../fonts/manrope-var.woff2') format('woff2');
  font-weight: 200 800;
  font-display: swap;
}
@font-face {
  font-family: 'Instrument Serif';
  src: url('../fonts/instrument-serif-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Instrument Serif';
  src: url('../fonts/instrument-serif-400-italic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'Amiri';
  src: url('../fonts/amiri-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}

:root {
  --bone: #f4f1e9;
  --paper: #fffdf8;
  --ink: #1a1b18;
  --ink-2: #55524a;
  --ink-3: #8b877b;
  --line: #e2dcce;
  --line-2: #ece7db;
  --pine: #1e4536;
  --pine-2: #2c5d49;
  --pine-soft: #e6eee8;
  --brass: #a87e32;
  --brass-soft: #f4ead3;
  --danger: #9b2c2c;
  --danger-soft: #f7e5e3;
  --radius: 10px;
  --sans: 'Manrope', 'Segoe UI', system-ui, sans-serif;
  --serif: 'Instrument Serif', Georgia, 'Times New Roman', serif;
  --shadow: 0 1px 2px rgba(26, 27, 24, 0.04);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bone);
  color: var(--ink);
  font: 13px/1.55 var(--sans);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 400; }
p { margin: 0; }
a { color: var(--pine); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
  padding: 0 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand .mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--pine);
  border-radius: 8px;
  color: var(--pine);
  flex: none;
}
.brand .mark svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.6; }
.brand h1 {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.brand .sub {
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* ---------- tab bar ---------- */
.tabs {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  gap: 4px;
  padding: 0 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px 13px;
  border: 0;
  background: none;
  color: var(--ink-3);
  font: inherit;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.15s ease;
}
.tab svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.6; }
.tab:hover { color: var(--ink); }
.tab:focus-visible { outline: 2px solid var(--brass); outline-offset: -2px; }
.tab[aria-selected='true'] { color: var(--ink); }
.tab[aria-selected='true']::after {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 2px;
  background: var(--pine);
}

/* ---------- layout ---------- */
.wrap {
  max-width: 1480px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}
.panel { display: none; }
.panel.active { display: block; animation: rise 0.25s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h2 {
  font-family: var(--serif);
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: -0.015em;
}
.page-head .lede { margin-top: 4px; color: var(--ink-2); max-width: 62ch; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 1100px) {
  .grid-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
}

/* ---------- card ---------- */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.card-head h3 {
  font-family: var(--serif);
  font-size: 19px;
  letter-spacing: -0.01em;
}
.card-head .hint { margin: 0; }
.card-body { padding: 18px; }
.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: #fcfaf4;
  flex-wrap: wrap;
}

/* ---------- forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px 14px;
}
.form-grid.tight { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label,
label.cap {
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}
input, select, textarea {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  min-height: 34px;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea { resize: vertical; line-height: 1.5; }
input:hover, select:hover, textarea:hover { border-color: #cfc7b5; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--pine);
  box-shadow: 0 0 0 3px rgba(30, 69, 54, 0.1);
}
input:disabled, select:disabled { background: #f6f3ec; color: var(--ink-3); cursor: not-allowed; }
input[type='date'] { min-width: 0; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 14px) 15px, calc(100% - 9px) 15px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 26px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--pine);
  border-radius: 6px;
  background: var(--pine);
  color: #fff;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease, color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--pine-2); border-color: var(--pine-2); }
.btn:active { transform: scale(0.985); }
.btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.btn:disabled { background: #d8d3c6; border-color: #d8d3c6; color: #fff; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.7; }

.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: #f7f4ec; border-color: #cfc7b5; }
.btn-ghost:disabled { background: transparent; border-color: var(--line); color: var(--ink-3); }

.btn-quiet { background: none; border-color: transparent; color: var(--ink-2); font-weight: 500; }
.btn-quiet:hover { background: #f2eee4; color: var(--ink); border-color: transparent; }

.btn-danger { background: transparent; border-color: transparent; color: var(--danger); font-weight: 500; }
.btn-danger:hover { background: var(--danger-soft); border-color: transparent; }

.btn-sm { min-height: 28px; padding: 0 10px; font-size: 11.5px; }

/* ---------- table ---------- */
.table-wrap {
  width: 100%;
  overflow: auto;
  max-height: 68vh;
  border-top: 1px solid var(--line-2);
}
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
}
thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f9f6ee;
  color: var(--ink-3);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  text-align: left;
  padding: 8px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line-2);
  vertical-align: middle;
}
tbody tr:hover td { background: #fbf8f1; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
th.num { text-align: right; }
.table-wrap table td.num input { text-align: right; }
.sticky-col { position: sticky; left: 0; background: var(--paper); z-index: 1; }
tbody tr:hover .sticky-col { background: #fbf8f1; }
thead th.sticky-col { background: #f9f6ee; z-index: 3; }
.sticky-col2 { position: sticky; left: 48px; background: var(--paper); z-index: 1; box-shadow: 4px 0 6px -4px rgba(26, 27, 24, 0.12); }
tbody tr:hover .sticky-col2 { background: #fbf8f1; }
thead th.sticky-col2 { background: #f9f6ee; z-index: 3; }
table .abs-col { width: 48px; min-width: 48px; max-width: 48px; }

/* input di dalam tabel */
td input, td select, td textarea {
  min-height: 28px;
  padding: 3px 7px;
  font-size: 12.5px;
  border-radius: 5px;
  border-color: #e8e2d4;
  background: #fff;
}
td input:hover, td select:hover, td textarea:hover { border-color: #cfc7b5; }
td input:focus, td select:focus, td textarea:focus { border-color: var(--pine); }
td input:disabled, td select:disabled {
  background: repeating-linear-gradient(135deg, #f6f3ea 0 6px, #f1ede2 6px 12px);
  color: #b4ae9f;
  border-color: #ece7db;
}
td input.warn { color: var(--brass); font-weight: 700; }
td input[type='number'] { width: 100%; }
/* spinner tidak perlu di grid padat */
td input[type='number']::-webkit-outer-spin-button,
td input[type='number']::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
td input[type='number'] { appearance: textfield; -moz-appearance: textfield; }
td select { background-image: none; padding-right: 6px; }

#tblSiswa table { table-layout: fixed; }
#tblSiswa td:nth-child(2) input { max-width: 620px; }
#tblSiswa th:nth-child(1), #tblSiswa td:nth-child(1) { width: 64px; }
#tblSiswa th:nth-child(3), #tblSiswa td:nth-child(3) { width: 120px; }
#tblSiswa th:nth-child(4), #tblSiswa td:nth-child(4) { width: 120px; }
#tblSiswa th:nth-child(5), #tblSiswa td:nth-child(5) { width: 160px; }
#tblSiswa th:nth-child(6), #tblSiswa td:nth-child(6) { width: 80px; }

/* nama siswa: titik kelengkapan + dua baris */
td .nama { display: flex; align-items: flex-start; gap: 8px; line-height: 1.35; }
td .nama .dot { margin-top: 5px; flex: none; }

/* ---------- misc ---------- */
.hint { color: var(--ink-3); font-size: 11.5px; }
.mono { font-variant-numeric: tabular-nums; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f0ece0;
  color: var(--ink-2);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}
.pill-pine { background: var(--pine-soft); color: #1c4132; }
.pill-brass { background: var(--brass-soft); color: #7a5a1f; }
.pill-danger { background: var(--danger-soft); color: #7f2323; }
.pill svg { width: 11px; height: 11px; stroke: currentColor; fill: none; stroke-width: 2; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 11.5px;
  color: var(--ink-2);
}
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.dot.on { background: var(--pine); }

.empty {
  padding: 28px 18px;
  text-align: center;
  color: var(--ink-3);
}

/* detail row (rapor) */
tr.detail > td { background: #fcfaf3; padding: 0; }
tr.detail .detail-inner {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
}
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.detail-block { border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 12px; background: #fff; }
.detail-block h4 {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 8px;
}
.inline { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 90;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  max-width: min(560px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: #fdfbf5;
  font-size: 12.5px;
  box-shadow: 0 10px 30px rgba(26, 27, 24, 0.18);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
#toast.tampil { opacity: 1; transform: translate(-50%, 0); }
#toast.gagal { background: #6f1f1f; }

/* dialog */
dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  padding: 0;
  width: min(520px, calc(100vw - 32px));
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(26, 27, 24, 0.2);
}
dialog::backdrop { background: rgba(26, 27, 24, 0.35); }
dialog .card-head { border-bottom: 1px solid var(--line); }
dialog .card-body { padding: 16px 18px; }
dialog .card-foot { display: flex; justify-content: flex-end; gap: 8px; }

/* scrollbar */
.table-wrap::-webkit-scrollbar { height: 10px; width: 10px; }
.table-wrap::-webkit-scrollbar-thumb { background: #d9d3c4; border-radius: 999px; border: 2px solid var(--paper); }
.table-wrap::-webkit-scrollbar-track { background: transparent; }

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  .form-grid, .form-grid.tight { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .topbar { height: 54px; padding: 0 14px; gap: 10px; }
  .brand .sub { display: none; }
  .brand h1 { font-size: 19px; }
  .brand .mark { width: 30px; height: 30px; }
  .chip { font-size: 10.5px; padding: 4px 8px; white-space: nowrap; }
  .tabs { padding: 0 8px; }
  .tab { padding: 12px 9px 11px; font-size: 12px; }
  .wrap { padding: 16px 12px 48px; }
  .page-head h2 { font-size: 24px; }
  .page-head { margin-bottom: 14px; }
  .card-body { padding: 14px; }
  .card-head { padding: 12px 14px; }
  .table-wrap { max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}

@media print {
  .topbar, .tabs, .page-head .actions, .card-foot { display: none; }
  body { background: #fff; }
  .card { border: 0; box-shadow: none; }
}
