:root {
  --navy: #1c2b5a;
  --navy-dark: #121c3f;
  --navy-soft: #2a3b73;
  --gold: #c9a24b;
  --gold-light: #e6c97a;
  --red: #b8312f;
  --red-dark: #96262a;
  --silver: #d9dce3;
  --silver-light: #f1f2f6;
  --ink: #1b2033;
  --muted: #667089;
  --ok: #2e7d4f;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--silver-light); line-height: 1.45; }
h1, h2, h3 { margin: 0 0 .5rem; color: var(--navy); }
a { color: var(--red); }
.loading { text-align: center; margin-top: 4rem; color: var(--muted); }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(circle at 20% 10%, var(--navy-soft), var(--navy-dark) 70%); }
.auth-card { width: 100%; max-width: 440px; background: linear-gradient(var(--gold), var(--gold)) top / 100% 6px no-repeat, #fff; border-radius: 18px; padding: 1.9rem 1.5rem 1.75rem; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.auth-card.wide { max-width: 560px; }
.auth-logo { display: block; width: 120px; height: 120px; object-fit: contain; margin: 0 auto .5rem; }
.auth-card h1 { text-align: center; font-size: 1.4rem; }
.tagline { text-align: center; color: var(--muted); margin: 0 0 1.25rem; font-size: .9rem; }

/* Form */
label { display: block; font-weight: 600; font-size: .85rem; margin: .8rem 0 .25rem; color: var(--navy); }
input, select, textarea { width: 100%; padding: .65rem .75rem; border: 1px solid var(--silver); border-radius: 8px; font: inherit; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); border-color: var(--gold); }
textarea { min-height: 80px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.preview { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; border: 3px solid var(--gold); margin-top: .5rem; display: none; }
.error { background: #fdecec; color: var(--red-dark); border: 1px solid #f2c0bf; padding: .6rem .8rem; border-radius: 8px; margin-top: .8rem; font-size: .9rem; }
.success { background: #eaf6ee; color: var(--ok); border: 1px solid #bfe0cb; padding: .6rem .8rem; border-radius: 8px; margin-top: .8rem; font-size: .9rem; }

/* Buttons */
.btn { display: inline-block; border: 0; border-radius: 8px; padding: .6rem 1.1rem; font: inherit; font-weight: 600; cursor: pointer; background: var(--red); color: #fff; text-decoration: none; }
.btn:hover { background: var(--red-dark); }
.btn.block { width: 100%; margin-top: 1.2rem; padding: .8rem; }
.btn.gold { background: var(--gold); color: var(--navy-dark); }
.btn.gold:hover { background: var(--gold-light); }
.btn.ghost { background: transparent; color: var(--navy); border: 1px solid var(--silver); }
.btn.ghost:hover { background: var(--silver-light); }
.btn.small { padding: .3rem .65rem; font-size: .82rem; }
.btn.ok { background: var(--ok); }
.btn:disabled { opacity: .6; cursor: wait; }
.switch { text-align: center; margin-top: 1rem; font-size: .9rem; }

/* Layout */
.topbar { background: linear-gradient(95deg, var(--navy-dark), var(--navy) 60%, var(--navy-soft)); color: #fff; border-bottom: 3px solid var(--gold); }
.topbar-in, .nav-in { max-width: 1180px; margin: 0 auto; }
.topbar-in { display: flex; align-items: center; gap: .85rem; padding: .7rem 1.25rem; }
.topbar .logo { width: 52px; height: 52px; object-fit: contain; flex: none; filter: drop-shadow(0 0 0 1px var(--gold)) drop-shadow(0 2px 8px rgba(201,162,75,.45)); }
.topbar .brand { font-weight: 700; letter-spacing: .3px; line-height: 1.2; min-width: 0; }
.topbar .brand small { display: block; font-weight: 400; color: var(--gold-light); font-size: .74rem; letter-spacing: .6px; margin-top: .15rem; }
.topbar .spacer { flex: 1; }
.topbar .who { display: flex; align-items: center; gap: .6rem; text-align: right; font-size: .85rem; line-height: 1.2; }
.topbar .who .avatar { width: 36px; height: 36px; }
.topbar .who small { color: var(--silver); display: block; font-size: .75rem; }
.nav { background: var(--navy); border-bottom: 1px solid var(--navy-dark); position: sticky; top: 0; z-index: 20; box-shadow: 0 6px 16px -10px rgba(10,15,35,.6); }
.nav-in { display: flex; gap: .15rem; overflow-x: auto; padding: 0 .75rem; scrollbar-width: none; scroll-behavior: smooth; }
.nav-in::-webkit-scrollbar { display: none; }
.nav a { color: var(--silver); text-decoration: none; padding: .8rem 1rem; font-size: .92rem; white-space: nowrap; border-bottom: 3px solid transparent; flex: none; }
.nav a:hover { color: #fff; }
.nav a.active { color: var(--gold-light); border-bottom-color: var(--gold); font-weight: 600; }
main { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 3.5rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }

/* Cards & tables */
.card { background: #fff; border: 1px solid var(--silver); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--silver); border-left: 5px solid var(--gold); border-radius: var(--radius); padding: .8rem 1rem; }
.stat.red { border-left-color: var(--red); }
.stat.navy { border-left-color: var(--navy); }
.stat.silver { border-left-color: #9aa0b3; }
.stat .n { font-size: 1.6rem; font-weight: 700; color: var(--navy); }
.stat .l { font-size: .8rem; color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; background: var(--navy); color: #fff; padding: .55rem .7rem; font-weight: 600; white-space: nowrap; }
th:first-child { border-top-left-radius: 8px; } th:last-child { border-top-right-radius: 8px; }
td { padding: .55rem .7rem; border-bottom: 1px solid var(--silver-light); vertical-align: middle; }
tr:hover td { background: #fafbfd; }
.num { text-align: right; white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 1.5rem; }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.badge.lunas, .badge.hadir, .badge.masuk { background: #e3f3ea; color: var(--ok); }
.badge.menunggu, .badge.izin { background: #fbf1d8; color: #8a6a14; }
.badge.ditolak, .badge.alpha, .badge.keluar { background: #fbe4e3; color: var(--red-dark); }
.badge.sakit { background: #e6e9f5; color: var(--navy); }
.badge.role { background: var(--silver-light); color: var(--navy); border: 1px solid var(--silver); }

.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); background: var(--silver); flex: none; }
.avatar.lg { width: 96px; height: 96px; }
.person { display: flex; align-items: center; gap: .6rem; }
.person small { color: var(--muted); display: block; }
.initial { display: inline-grid; place-items: center; background: var(--navy); color: var(--gold-light); font-weight: 700; }

.member-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.member { background: #fff; border: 1px solid var(--silver); border-radius: var(--radius); padding: .9rem .5rem; text-align: center; cursor: pointer; }
.member:hover { border-color: var(--gold); box-shadow: 0 2px 10px rgba(28,43,90,.12); }
.member .avatar { width: 64px; height: 64px; margin: 0 auto .4rem; display: block; }
.member b { display: block; font-size: .88rem; color: var(--navy); }
.member small { color: var(--muted); }
.tabs { display: flex; gap: .4rem; margin-bottom: .75rem; flex-wrap: wrap; }
.tab { padding: .4rem .9rem; border-radius: 99px; border: 1px solid var(--silver); background: #fff; cursor: pointer; font: inherit; font-size: .88rem; }
.tab.active { background: var(--navy); color: var(--gold-light); border-color: var(--navy); }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; margin-bottom: .75rem; }
.toolbar > div { min-width: 140px; }
.toolbar label { margin-top: 0; }

/* Modal & toast */
.overlay { position: fixed; inset: 0; background: rgba(10,15,35,.6); display: grid; place-items: center; padding: 1rem; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; padding: 1.4rem 1.25rem 1.25rem; background: linear-gradient(var(--gold), var(--gold)) top / 100% 5px no-repeat, #fff; max-height: 92vh; overflow-y: auto; }
.modal h2 { margin-bottom: .25rem; }
.modal .actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.2rem; }
.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: var(--navy-dark); color: #fff; padding: .65rem 1.1rem; border-radius: 99px; border: 1px solid var(--gold); z-index: 100; font-size: .9rem; }
.toast.bad { background: var(--red-dark); }
.detail dl { display: grid; grid-template-columns: 120px 1fr; gap: .35rem .75rem; margin: .75rem 0 0; }
.detail dt { color: var(--muted); font-size: .85rem; }
.detail dd { margin: 0; }


/* Polish */
html { -webkit-text-size-adjust: 100%; }
img { max-width: 100%; }
button, input, select, textarea, a { touch-action: manipulation; }
body { min-height: 100vh; background: linear-gradient(180deg, #eceef4 0, var(--silver-light) 280px); }
h2 { font-size: clamp(1.15rem, 1rem + .8vw, 1.5rem); letter-spacing: .2px; }
.card, .stat, .member { box-shadow: 0 1px 2px rgba(18,28,63,.04), 0 10px 24px -16px rgba(18,28,63,.22); }
.num, .stat .n { font-variant-numeric: tabular-nums; }
.page-head h2::after { content: ""; display: block; width: 38px; height: 3px; border-radius: 3px; margin-top: .3rem; background: linear-gradient(90deg, var(--gold), var(--red)); }
.overlay { animation: fade .15s ease-out; }
.modal { animation: pop .18s ease-out; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.toast { max-width: calc(100vw - 2rem); text-align: center; bottom: calc(1.5rem + env(safe-area-inset-bottom)); }
.auth-logo { filter: drop-shadow(0 4px 14px rgba(18,28,63,.35)); }

/* Tablet */
@media (max-width: 900px) {
  main { padding: 1.25rem 1rem 3rem; }
  .topbar-in { padding: .6rem 1rem; }
}

/* Bar menu bawah (HP) */
.tabbar { display: none; }
.ico { width: 22px; height: 22px; flex: none; }
.menu-sheet { padding-bottom: .25rem; }
.menu-user { display: flex; align-items: center; gap: .8rem; margin-bottom: 1rem; }
.menu-user .avatar.lg { width: 56px; height: 56px; }
.menu-user b { display: block; color: var(--navy); font-size: 1.02rem; }
.menu-user small { color: var(--muted); }
.menu-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
.menu-tile { display: flex; align-items: center; gap: .7rem; padding: .85rem .9rem; border: 1px solid var(--silver); border-radius: 12px; color: var(--navy); text-decoration: none; font-weight: 600; font-size: .92rem; background: #fff; }
.menu-tile .ico { color: var(--gold); width: 24px; height: 24px; }
.menu-tile.active { background: var(--navy); color: var(--gold-light); border-color: var(--navy); }
.menu-tile.active .ico { color: var(--gold-light); }
.btn.ghost.menu-out { width: 100%; margin-top: .9rem; display: flex; align-items: center; justify-content: center; gap: .5rem; color: var(--red-dark); border-color: #efc6c5; padding: .75rem; }

@media (max-width: 700px) {
  .nav { display: none; }
  #logout { display: none; }
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: linear-gradient(180deg, var(--navy), var(--navy-dark)); border-top: 2px solid var(--gold); padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom)); box-shadow: 0 -8px 24px -12px rgba(10,15,35,.7); }
  .tabbar a, .tabbar button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem; padding: .45rem .1rem .35rem; min-height: 56px; background: none; border: 0; color: var(--silver); font: inherit; font-size: .68rem; font-weight: 500; text-decoration: none; cursor: pointer; border-radius: 10px; -webkit-tap-highlight-color: transparent; }
  .tabbar .active { color: var(--gold-light); font-weight: 700; }
  .tabbar .active::before { content: ""; position: absolute; top: -.3rem; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--gold); }
  .tabbar .active .ico { transform: translateY(-1px); }
  main { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)) !important; }
  .toast { bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
}

/* HP */
@media (max-width: 640px) {
  .row { grid-template-columns: 1fr; gap: 0; }

  .topbar-in { padding: .5rem .85rem; gap: .65rem; }
  .topbar .logo { width: 42px; height: 42px; }
  .topbar .brand { font-size: .8rem; flex: 1; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .topbar .brand small { display: none; }
  .topbar .spacer { display: none; }
  .topbar .who span { display: none; }
  .topbar .who .avatar { width: 34px; height: 34px; }
  .nav { position: sticky; }
  .nav::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 28px; background: linear-gradient(90deg, rgba(28,43,90,0), var(--navy)); pointer-events: none; }
  .nav-in { padding: 0 .4rem; padding-right: 28px; }
  .nav a { padding: .75rem .8rem; font-size: .9rem; }
  main { padding: 1rem .85rem 3rem; }

  .page-head { align-items: flex-start; }
  .page-head > .btn { width: 100%; text-align: center; }
  .page-head > input { max-width: none !important; width: 100%; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .stat { padding: .7rem .85rem; }
  .stat .n { font-size: 1.35rem; }
  .member-grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: .6rem; }
  .toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
  .toolbar > div { min-width: 0; }
  .toolbar > div:first-child:nth-last-child(3) { grid-column: 1 / -1; }
  .btn.small { min-height: 38px; padding: .4rem .8rem; }
  .tab { padding: .55rem 1rem; }

  /* Tabel berjudul menjadi kartu per baris */
  .table-wrap { overflow: visible; }
  .card:has(table.stack) { background: transparent; border: 0; box-shadow: none; padding: 0; }
  .card:has(table.stack) > h3, .card:has(table.stack) > .page-head { padding: 0 .15rem; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack thead { display: none; }
  table.stack tr { background: #fff; border: 1px solid var(--silver); border-radius: 12px; padding: .55rem .9rem; margin-bottom: .6rem; box-shadow: 0 1px 2px rgba(18,28,63,.04), 0 8px 18px -14px rgba(18,28,63,.3); }
  table.stack tr:hover td { background: none; }
  table.stack td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .4rem 0; border: 0; text-align: right; min-width: 0; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: .76rem; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; text-align: left; flex: none; }
  table.stack td:first-child { justify-content: flex-start; text-align: left; padding: .2rem 0 .55rem; margin-bottom: .25rem; border-bottom: 1px solid var(--silver-light); }
  table.stack td:first-child::before, table.stack td[data-label=""]::before { display: none; }
  table.stack td[data-label=""] { justify-content: flex-end; flex-wrap: wrap; padding-top: .55rem; }
  table.stack td.num { text-align: right; }
  table.stack td.empty { display: block; text-align: center; }
  table.stack td small { text-align: right; }

  /* Jendela dialog menjadi lembar dari bawah */
  .overlay { padding: 0; place-items: end center; }
  .modal { max-width: none; border-radius: 18px 18px 0 0; max-height: 92vh; padding: 1.1rem 1rem calc(1.1rem + env(safe-area-inset-bottom)); animation: sheet .22s ease-out; }
  .modal .actions { position: sticky; bottom: calc(-1.1rem - env(safe-area-inset-bottom)); background: #fff; padding-top: .6rem; }
  .modal .actions .btn { flex: 1; text-align: center; padding: .75rem; }
  .detail dl { grid-template-columns: 95px 1fr; }

  .auth { padding: 1rem .75rem; align-items: start; padding-top: 4vh; }
  .auth-card { padding: 1.4rem 1.1rem; border-radius: 16px; }
  .auth-logo { width: 104px; height: 104px; }
}
@keyframes sheet { from { transform: translateY(40px); opacity: .6; } }

@media (max-width: 360px) {
  .topbar .brand { font-size: .75rem; }
  .member-grid { grid-template-columns: 1fr 1fr; }
}

/* Profil */
.profile-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 1rem; align-items: start; }
.profile-photo { display: flex; align-items: center; gap: 1rem; margin: .5rem 0 .25rem; }
.profile-photo .avatar.lg { width: 88px; height: 88px; font-size: 2rem; }
.topbar .who { cursor: pointer; }
.topbar .who:hover { opacity: .85; }
@media (max-width: 800px) { .profile-grid { grid-template-columns: 1fr; } }

/* Kelola anggota */
.manage { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--silver-light); }
.manage .btn { flex: 1 1 auto; text-align: center; }
.btn.ghost.warn { color: var(--red-dark); border-color: #efc6c5; }
.btn.ghost.warn:hover { background: #fdecec; }
.btn.danger { background: var(--red-dark); }
.btn.danger:hover { background: #7d1f22; }
.warn-list { margin: .25rem 0 .75rem; padding-left: 1.2rem; }
label.check { display: flex; gap: .55rem; align-items: flex-start; font-weight: 500; color: var(--ink); margin-top: 1rem; cursor: pointer; }
input[type=checkbox] { width: auto; margin-top: .2rem; accent-color: var(--red); }
.member.inactive { opacity: .55; }
.member.inactive b { text-decoration: line-through; text-decoration-color: var(--muted); }

/* Ekspor */
.head-tools { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.export-bar { display: flex; gap: .4rem; }
.export-bar .btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; }
.export-bar .ico { width: 16px; height: 16px; }
@media (max-width: 640px) {
  .head-tools { width: 100%; }
  .head-tools input { max-width: none !important; width: 100%; }
  .head-tools > .btn { flex: 1; }
  .export-bar { flex: 1 1 100%; }
  .export-bar .btn { flex: 1; min-height: 40px; }
}
