/* ============================================================================
   GuruSmartAI — Design System v1.0 (Unified Surface / MP-3 M-01)
   Token + komponen dasar. Theme-aware (terang/gelap), mobile-first, WCAG AA.
   Tanpa framework (ADR-001). Kosakata visual tenang & profesional.
   ============================================================================ */

:root {
  --bg: #f6f7f9;        --surface: #ffffff;    --surface-2: #f0f2f5;
  --text: #16181d;      --text-dim: #5b6472;   --border: #e3e6ea;
  --brand: #4f46e5;     --brand-2: #7c3aed;    --brand-soft: rgba(79,70,229,.08);
  --ok: #15803d;        --warn: #b45309;       --danger: #b91c1c;
  --radius: 12px;       --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --nav-w: 248px;
}
:root[data-theme="dark"] {
  --bg: #0f1115;        --surface: #171a21;    --surface-2: #1e222b;
  --text: #e9ecf1;      --text-dim: #9aa4b2;   --border: #2a2f3a;
  --brand: #8b85f0;     --brand-2: #a78bfa;    --brand-soft: rgba(139,133,240,.14);
  --ok: #4ade80;        --warn: #fbbf24;       --danger: #f87171;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
h1,h2,h3 { margin: 0 0 .4em; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
a { color: var(--brand); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }
.nav {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center; font-weight: 800;
}
.brand b { display: block; font-size: .95rem; }
.brand small { display: block; color: var(--text-dim); font-size: .75rem; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border: 0; border-radius: 10px; cursor: pointer;
  background: transparent; color: var(--text); font: inherit; text-align: left;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item[aria-current="page"] { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-ico { width: 20px; text-align: center; flex: none; }
.nav-spacer { flex: 1; }
.nav-foot { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.top .burger { display: none; }
.view { padding: 22px 20px 60px; max-width: 1040px; width: 100%; margin: 0 auto; flex: 1; }

/* ---------- Komponen ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0,1fr)); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 18px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-primary {
  border: 0; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2));
}
.btn-primary:hover { filter: brightness(1.07); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 7px 12px; font-size: .87rem; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 600; margin-bottom: 5px; font-size: .9rem; }
.input, .select, .textarea {
  width: 100%; padding: 11px 13px; border-radius: 10px; font: inherit;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.textarea { min-height: 96px; resize: vertical; }
.hint { color: var(--text-dim); font-size: .84rem; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  font-size: .82rem; color: var(--text-dim);
}
.chip b { color: var(--text); font-weight: 600; }
.chip-brand { background: var(--brand-soft); border-color: transparent; color: var(--brand); }

.status { font-size: .78rem; padding: 3px 10px; border-radius: 999px; font-weight: 600; }
.status-draf { background: var(--surface-2); color: var(--text-dim); }
.status-siap { background: rgba(21,128,61,.12); color: var(--ok); }

.doc-card {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  cursor: pointer; width: 100%; text-align: left; font: inherit; color: inherit;
}
.doc-card:hover { border-color: var(--brand); background: var(--brand-soft); }
.doc-card .t { font-weight: 600; }
.doc-card .m { color: var(--text-dim); font-size: .85rem; }

.stages { list-style: none; padding: 0; margin: 12px 0 0; }
.stages li { display: flex; align-items: center; gap: 10px; padding: 7px 0; color: var(--text-dim); }
.stages li .dot {
  width: 20px; height: 20px; border-radius: 50%; flex: none; display: grid; place-items: center;
  border: 2px solid var(--border); font-size: .7rem;
}
.stages li.done { color: var(--text); }
.stages li.done .dot { background: var(--ok); border-color: var(--ok); color: #fff; }
.stages li.active { color: var(--brand); font-weight: 600; }
.stages li.active .dot { border-color: var(--brand); border-top-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.alert { padding: 13px 15px; border-radius: var(--radius); border: 1px solid var(--border); }
.alert-warn { background: rgba(180,83,9,.09); border-color: rgba(180,83,9,.3); }
.alert-info { background: var(--brand-soft); border-color: transparent; }

.empty { text-align: center; padding: 40px 16px; color: var(--text-dim); }
.empty .big { font-size: 2rem; margin-bottom: 8px; }

.skel { background: var(--surface-2); border-radius: var(--radius); height: 74px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.doc-body {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
  background: var(--surface); min-height: 260px; line-height: 1.7;
}
.doc-body:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

/* ---------- Tabel dokumen (ATP, Prota, Promes, rubrik, kisi-kisi) ----------
   Dokumen pendidikan sangat bergantung pada tabel. Sanitizer membuang atribut
   `style` dari keluaran AI, jadi SELURUH garis berasal dari sini.
   `border-collapse: collapse` menyatukan garis antar sel sehingga tidak ada
   garis ganda maupun terputus pada perpotongan kolom dan baris. */
.doc-body table {
  width: 100%;
  border-collapse: collapse;      /* kunci: garis kolom & baris menyambung utuh */
  border-spacing: 0;
  margin: 14px 0;
  font-size: .94rem;
  table-layout: auto;
}
.doc-body th,
.doc-body td {
  border: 1px solid var(--text);  /* garis di SETIAP sisi setiap sel */
  padding: 8px 10px;
  vertical-align: top;
  text-align: left;
  word-break: break-word;
}
.doc-body thead th,
.doc-body th {
  background: var(--surface-2);
  font-weight: 650;
}
.doc-body caption {
  caption-side: top;
  font-weight: 650;
  padding: 6px 0;
  text-align: left;
}
/* Sel gabungan (colspan/rowspan) tetap mendapat garis penuh */
.doc-body td[colspan], .doc-body th[colspan],
.doc-body td[rowspan], .doc-body th[rowspan] { border: 1px solid var(--text); }
/* Tabel lebar tidak merusak tata letak: geser di dalam wadahnya sendiri */
.doc-body { overflow-x: auto; }
.cites { list-style: none; padding: 0; margin: 8px 0 0; font-size: .86rem; color: var(--text-dim); }
.cites li { padding: 3px 0; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--text-dim); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .nav {
    position: fixed; inset: 0 auto 0 0; width: 84vw; max-width: var(--nav-w);
    transform: translateX(-100%); transition: transform .2s ease; z-index: 30;
  }
  .nav.open { transform: none; }
  .top .burger { display: inline-flex; }
  .view { padding: 16px 14px 60px; }
  .grid.c2, .grid.c3 { grid-template-columns: 1fr; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Cetak: garis tabel WAJIB utuh di kertas ----------
   Peramban membuang warna latar & border saat mencetak bila tidak dipaksa.
   Tanpa aturan ini, garis kolom/baris tampak terputus atau hilang. */
@media print {
  .nav, .top, .toolbar, .scrim, #gsaToast { display: none !important; }
  .shell { display: block; }
  .view { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
  body, .doc-body {
    background: #fff !important; color: #000 !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .doc-body { border: 0; overflow: visible; }
  .doc-body table { border-collapse: collapse !important; width: 100%; }
  .doc-body th, .doc-body td {
    border: 1px solid #000 !important;          /* garis tegas di semua sisi */
    padding: 6px 8px;
  }
  .doc-body thead th { background: #eee !important; }
  /* Jaga baris tidak terpotong separuh antar halaman → garis tampak terputus */
  .doc-body tr, .doc-body img { page-break-inside: avoid; break-inside: avoid; }
  /* Ulangi header tabel di tiap halaman agar kolom tetap terbaca */
  .doc-body thead { display: table-header-group; }
  .doc-body tfoot { display: table-footer-group; }
  .doc-body h1, .doc-body h2, .doc-body h3 { page-break-after: avoid; break-after: avoid; }
  @page { margin: 1.6cm; }
}
