/* SIAKAD v2 — gaya aplikasi */
:root {
  --sidebar-w: 240px;
  --navy: #1a237e;
  --navy2: #283593;
  --navy-soft: #c5cae9;
  --navy-pale: #e8eaf6;
  --accent: #2e7d32;
  --bg: #f4f6f8;
  --card: #ffffff;
  --line: #dfe3e8;
  --text: #263238;
  --muted: #546e7a;
  --fs: 1; /* pengali ukuran font (menu Tampilan) */
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", Arial, sans-serif; background: var(--bg); color: var(--text); font-size: calc(16px * var(--fs)); }

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar kiri ---------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  color: #fff;
  position: fixed; top: 0; bottom: 0; left: 0;
  display: flex; flex-direction: column;
  transition: margin-left .25s ease;
  z-index: 100;
}
.brand { padding: 18px 16px; font-size: calc(22px * var(--fs)); font-weight: 700; border-bottom: 1px solid rgba(255,255,255,.15); text-align: center; }
.brand-logo { display: block; margin: 0 auto 8px; height: 64px; max-height: 64px; width: auto; background: #fff; border-radius: 8px; padding: 5px; box-sizing: border-box; }
.brand span { display: block; font-size: calc(12px * var(--fs)); font-weight: 400; color: var(--navy-soft); margin-top: 2px; }
.sidebar nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.sidebar nav a {
  display: block; padding: 11px 18px; color: #e8eaf6; text-decoration: none; font-size: calc(14px * var(--fs));
  border-left: 4px solid transparent;
}
.sidebar nav a:hover { background: rgba(255,255,255,.08); }
.sidebar nav a.active { background: rgba(255,255,255,.14); border-left-color: #fff; font-weight: 600; }
.side-foot { padding: 14px 16px; font-size: calc(11px * var(--fs)); color: var(--navy-soft); border-top: 1px solid rgba(255,255,255,.15); }
.side-logout { display: block; padding: 11px 18px; color: #ffcdd2; text-decoration: none; font-size: calc(14px * var(--fs)); font-weight: 600; border-top: 1px solid rgba(255,255,255,.15); }
.side-logout:hover { background: rgba(255,255,255,.08); }

/* mode collapse: sidebar disembunyikan */
body.sidebar-collapsed .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
body.sidebar-collapsed .main { margin-left: 0; }

.main { flex: 1; margin-left: var(--sidebar-w); transition: margin-left .25s ease; min-width: 0; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 18px; position: sticky; top: 0; z-index: 50;
}
.hamburger {
  font-size: calc(20px * var(--fs)); background: none; border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 10px; cursor: pointer; color: var(--navy);
}
.hamburger:hover { background: #eef1f5; }
.page-title { font-size: calc(17px * var(--fs)); font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: calc(13px * var(--fs)); flex-shrink: 0; }
.userbox .uname { font-weight: 600; }
.userbox .urole { background: var(--navy-pale); color: var(--navy); border-radius: 12px; padding: 2px 10px; font-size: calc(12px * var(--fs)); }
.userbox .logout { color: #c62828; text-decoration: none; font-weight: 600; }
.usermenu { position: relative; }
button.uname { background: none; border: 0; padding: 2px 0; font: inherit; color: inherit; cursor: pointer; display: flex; align-items: center; }
button.uname .uname-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usermenu-list { display: none; position: absolute; top: calc(100% + 8px); right: 0; min-width: 190px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.16); padding: 6px; z-index: 200; }
.usermenu.open .usermenu-list { display: block; }
.usermenu-list a { display: block; padding: 9px 12px; border-radius: 8px; color: inherit; text-decoration: none; font-weight: 500; }
.usermenu-list a:hover { background: var(--navy-pale); }
.usermenu-list a.usermenu-danger { color: #c62828; }

.content { padding: 20px; max-width: 1200px; }

/* ---------- Komponen ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 18px; margin-bottom: 18px; }
.card h3 { margin: 0 0 12px; font-size: calc(16px * var(--fs)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.stat .num { font-size: calc(26px * var(--fs)); font-weight: 700; color: var(--navy); }
.stat .lbl { font-size: calc(12px * var(--fs)); color: var(--muted); }

table.tbl { width: 100%; border-collapse: collapse; font-size: calc(13px * var(--fs)); background: #fff; }
table.tbl th, table.tbl td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
table.tbl th { background: #eef1f5; }
table.tbl tr:nth-child(even) td { background: #fafbfc; }
/* Pita sesi khusus (0/S1/S2/S3): kegiatan di luar jam pelajaran */
table.tbl tr.khusus td { background: #fff8e1; }
table.tbl td.ctr, table.tbl th.ctr { text-align: center; }
.muted { color: var(--muted); }

.btn {
  display: inline-block; background: var(--navy2); color: #fff; border: none;
  padding: 9px 18px; border-radius: 6px; cursor: pointer; font-size: calc(14px * var(--fs)); text-decoration: none;
}
.btn:hover { background: var(--navy); }
.btn.green { background: var(--accent); }
.btn.gray { background: #546e7a; }
.piket-hari-ini { font-size: calc(13px * var(--fs)); margin-top: 10px; }
.btn.red { background: #c62828; }
.btn.small { padding: 5px 10px; font-size: calc(12px * var(--fs)); }
a.btn { color: #fff; }
.btn-link { background: none; border: none; color: #c62828; cursor: pointer; font-size: calc(13px * var(--fs)); padding: 0; text-decoration: underline; }

.form-grid { display: grid; grid-template-columns: 180px 1fr; gap: 10px 14px; align-items: center; max-width: 720px; }
.form-grid label { font-weight: 600; font-size: calc(13px * var(--fs)); }
.form-inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.form-inline label { font-size: calc(13px * var(--fs)); font-weight: 600; display: flex; flex-direction: column; gap: 4px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], select, textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: calc(14px * var(--fs));
  font-family: inherit; background: #fff;
}
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }
textarea { min-height: 70px; resize: vertical; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: calc(13px * var(--fs)); }
.checks label { font-weight: 400; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: calc(14px * var(--fs)); }
.flash.ok { background: #e8f5e9; border: 1px solid #a5d6a7; color: #2e7d32; }
.flash.err { background: #ffebee; border: 1px solid #ef9a9a; color: #c62828; }
.preview-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: calc(14px * var(--fs)); background: #fff8e1; border: 1px solid #ffe082; color: #6d4c00; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; border-bottom: 2px solid var(--line); }
.tabs a { padding: 9px 18px; text-decoration: none; color: var(--navy); font-weight: 600; font-size: calc(14px * var(--fs)); border: 1px solid var(--line); border-bottom: none; border-radius: 8px 8px 0 0; background: var(--navy-pale); margin-bottom: -2px; }
.tabs a.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 10px; font-size: calc(11px * var(--fs)); background: #e0e0e0; }
.badge.good { background: #c8e6c9; color: #1b5e20; }
.badge.warn { background: #fff9c4; color: #6d4c00; }
.badge.bad { background: #ffcdd2; color: #b71c1c; }
.badge.info { background: #bbdefb; color: #0d47a1; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; background: var(--navy); padding: 16px; }
.login-logo { width: 100%; max-width: 360px; height: auto; background: #fff; border-radius: 10px; padding: 10px 14px; box-sizing: border-box; }
.login-box { background: #fff; border-radius: 10px; padding: 30px; width: 100%; max-width: 380px; }
.login-box h1 { margin: 0 0 4px; color: var(--navy); font-size: calc(24px * var(--fs)); }
.login-box p { margin: 0 0 18px; color: var(--muted); font-size: calc(13px * var(--fs)); }
.login-box input { width: 100%; margin-bottom: 10px; }
.login-box .btn { width: 100%; margin-top: 8px; }
.login-err { background: #ffebee; color: #c62828; padding: 9px 12px; border-radius: 6px; margin-bottom: 12px; font-size: calc(13px * var(--fs)); }

/* ---------- Kop & TTD cetak ---------- */
.kop-cetak { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.kop-logo { height: 70px; width: auto; flex: 0 0 auto; }
.kop-teks { flex: 1; text-align: center; }
.kop-sekolah { font-size: 17px; font-weight: 700; }
.kop-judul { font-size: 15px; font-weight: 700; text-decoration: underline; margin-top: 6px; }
.kop-sub { font-size: 12px; margin-top: 4px; }
.print-h { margin: 18px 0 8px; font-size: 15px; }
.ttd-print { display: flex; justify-content: space-between; margin-top: 26px; font-size: 13px; }
.ttd-print .ctr { text-align: center; }

/* ---------- Absensi ---------- */
.absensi-grid label { display: inline-flex; align-items: center; gap: 3px; margin-right: 10px; font-size: calc(13px * var(--fs)); }

/* ---------- Tampilan (preferensi user) ---------- */
.swatch-grid { display: flex; flex-wrap: wrap; gap: 14px; margin: 6px 0 4px; }
.swatch { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; font-size: calc(12px * var(--fs)); width: 76px; text-align: center; }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch .dot { width: 42px; height: 42px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.swatch input:checked + .dot { box-shadow: 0 0 0 3px var(--text); }
.swatch input:focus-visible + .dot { box-shadow: 0 0 0 3px var(--muted); }

/* ---------- Aksesibilitas ---------- */
/* Cincin fokus yang jelas untuk navigasi keyboard (pengguna mouse tidak terpengaruh). */
:focus-visible { outline: 3px solid #3949ab; outline-offset: 1px; }
.sidebar a:focus-visible, .sidebar button:focus-visible { outline-color: #c5cae9; }
input:focus, select:focus, textarea:focus { border-color: var(--navy2); }

/* Hormati preferensi gerak minimum dari sistem operasi pengguna. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- Responsif ---------- */
@media (max-width: 900px) {
  .sidebar { margin-left: calc(-1 * var(--sidebar-w)); box-shadow: 2px 0 8px rgba(0,0,0,.3); }
  body.sidebar-open .sidebar { margin-left: 0; }
  .main { margin-left: 0; }
  .content { padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .userbox .uname { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .userbox button.uname { max-width: 40vw; }
  table.tbl { font-size: calc(12px * var(--fs)); }
  /* Target sentuh lebih tinggi di layar kecil (tampilan desktop tidak berubah). */
  .btn.small { padding: 11px 12px; }
  .hamburger { padding: 8px 12px; }
}

/* ---------- Cetak ---------- */
@media print {
  :root { --fs: 1 !important; }
  .sidebar, .topbar, .no-print, .flash, .tabs { display: none !important; }
  .kop-logo { height: 70px; width: auto; }
  body { background: #fff; }
  .main { margin-left: 0; }
  .content { padding: 0; margin: 0; background: #fff; max-width: none; }
  .card { border: none; padding: 0; }
  table.tbl th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { size: A4 portrait; margin: 12mm; }
}

/* ---------- Lonceng pesan (header) & halaman Pesan ---------- */
.bell { position: relative; font-size: 20px; line-height: 1; text-decoration: none; flex-shrink: 0; }
.bell-num { position: absolute; top: -8px; right: -10px; background: #c62828; color: #fff; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 9px; padding: 0 4px; box-sizing: border-box; }
.pesan-riwayat { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.pesan-item { max-width: 78%; padding: 8px 12px; border-radius: 12px; background: var(--navy-pale); align-self: flex-start; overflow-wrap: break-word; }
.pesan-item.saya { background: #e3f2fd; align-self: flex-end; }

/* ---------- Tema "Biru Lengkung" (pilihan di menu Tampilan) ---------- */
/* Sudut membulat besar, bayangan lembut, dan palet biru cerah seperti */
/* aplikasi kepegawaian. Hanya aktif bila <body> membawa kelas tema-biru. */
body.tema-biru {
  --navy: #1565c0;
  --navy2: #1e88e5;
  --navy-soft: #bbdefb;
  --navy-pale: #e3f2fd;
  --bg: #edf3fb;
  --line: #d3e1f2;
}
body.tema-biru .sidebar {
  background: linear-gradient(180deg, #0d47a1 0%, #1565c0 55%, #1e88e5 100%);
}
body.tema-biru .card,
body.tema-biru .stat {
  border-radius: 20px;
  box-shadow: 0 6px 18px rgba(21, 101, 192, .10);
}
body.tema-biru .btn { border-radius: 12px; }
body.tema-biru input[type=text],
body.tema-biru input[type=password],
body.tema-biru input[type=number],
body.tema-biru input[type=date],
body.tema-biru input[type=time],
body.tema-biru select,
body.tema-biru textarea { border-radius: 12px; }
body.tema-biru .flash,
body.tema-biru .preview-banner { border-radius: 12px; }
body.tema-biru .tabs a { border-radius: 12px 12px 0 0; }
body.tema-biru .hamburger { border-radius: 10px; }
body.tema-biru .preview-box { border-radius: 20px; }
body.tema-biru table.tbl th { background: #e3f2fd; }
@media print {
  body.tema-biru .card,
  body.tema-biru .stat { box-shadow: none; }
}
