/* KMI HR System — app.css
   Vanilla CSS, tanpa build step. Token warna di :root, dark mode mengikuti
   preferensi sistem. Mobile-first: absensi dipakai di lapangan lewat HP. */

:root {
  --navy: #1f3864;
  --navy-600: #2b4a80;
  --navy-100: #e8edf7;
  --accent: #0f8a5f;
  --accent-100: #e3f5ec;
  --danger: #c0392b;
  --danger-100: #fdecea;
  --warn: #b7791f;
  --warn-100: #fdf4e3;
  --info: #1d6fa5;

  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface-2: #fafbfd;
  --border: #dfe3ec;
  --text: #1b2230;
  --text-soft: #5b6577;
  --text-faint: #8a93a5;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --topbar-h: 56px;
  --sidebar-w: 232px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --navy: #6b93d6;
    --navy-600: #7ea4e0;
    --navy-100: #1b2740;
    --accent: #4ac490;
    --accent-100: #14301f;
    --danger: #f07a6d;
    --danger-100: #34191a;
    --warn: #e0b054;
    --warn-100: #33280f;
    --info: #6fb4e0;
    --bg: #11151c;
    --surface: #171c25;
    --surface-2: #1c222c;
    --border: #2a323f;
    --text: #e6e9ef;
    --text-soft: #a3acbd;
    --text-faint: #737d90;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 12px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .98rem; }
p { margin: 0 0 .75rem; }
a { color: var(--navy); }
[hidden] { display: none !important; }

/* ---------- Boot ---------- */
.boot {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--bg); z-index: 200;
}
.boot-card { text-align: center; }
.boot-card p { color: var(--text-soft); margin-top: 1rem; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 64px; height: 64px; border-radius: 16px;
  background: var(--navy); color: #fff; font-weight: 800; letter-spacing: .5px;
  margin-bottom: 1.25rem;
}
.brand-mark.small { width: 30px; height: 30px; border-radius: 8px; font-size: .72rem; margin: 0; }
.spinner {
  width: 26px; height: 26px; margin: 0 auto;
  border: 3px solid var(--border); border-top-color: var(--navy);
  border-radius: 50%; animation: spin .7s linear infinite;
}
.spinner.sm { width: 15px; height: 15px; border-width: 2px; display: inline-block; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 .9rem;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; }
.brand-text { font-size: .98rem; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .7rem; }
.server-clock { font-family: var(--mono); font-size: .78rem; color: var(--text-faint); }
.user-chip { display: flex; align-items: center; gap: .5rem; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--navy-100); color: var(--navy);
  display: grid; place-items: center; font-weight: 700; font-size: .78rem;
  overflow: hidden; flex: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-name { font-size: .82rem; font-weight: 600; }
.user-role { font-size: .68rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .4px; }
.menu-toggle { display: none; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: .8rem .55rem; display: flex; flex-direction: column;
  position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; flex: 1; }
.sidebar li + li { margin-top: 2px; }
.sidebar a {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .65rem; border-radius: var(--radius-sm);
  color: var(--text-soft); text-decoration: none; font-size: .89rem; font-weight: 500;
}
.sidebar a:hover { background: var(--surface-2); color: var(--text); }
.sidebar a.active { background: var(--navy-100); color: var(--navy); font-weight: 650; }
.sidebar a svg { flex: none; opacity: .85; }
.nav-group-title {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-faint); padding: .9rem .65rem .3rem; font-weight: 700;
}
.sidebar-footer { padding: .6rem .65rem 0; border-top: 1px solid var(--border); margin-top: .6rem; }
.version { font-size: .68rem; color: var(--text-faint); font-family: var(--mono); }
.scrim { display: none; }
.content { flex: 1; padding: 1.1rem 1.25rem 3rem; min-width: 0; outline: none; }

/* ---------- Cards & surfaces ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem; margin-bottom: 1rem;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; margin-bottom: .85rem; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; }
.card-sub { color: var(--text-soft); font-size: .84rem; margin: -.4rem 0 .85rem; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head .sub { color: var(--text-soft); font-size: .88rem; margin: 0; }

.grid { display: grid; gap: 1rem; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) {
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

/* ---------- Stat tiles ---------- */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .85rem .95rem;
}
.stat .label { font-size: .74rem; color: var(--text-faint); text-transform: uppercase; letter-spacing: .5px; font-weight: 650; }
.stat .value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; margin-top: .25rem; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: .76rem; color: var(--text-soft); margin-top: .2rem; }
.stat.accent .value { color: var(--accent); }
.stat.warn .value { color: var(--warn); }
.stat.danger .value { color: var(--danger); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .5rem .9rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--navy); color: #fff;
  font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--navy-600); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-soft); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-danger:hover:not(:disabled) { filter: brightness(.92); background: var(--danger); }
.btn-success { background: var(--accent); }
.btn-success:hover:not(:disabled) { filter: brightness(.94); background: var(--accent); }
.btn-sm { padding: .32rem .6rem; font-size: .8rem; }
.btn-lg { padding: .8rem 1.4rem; font-size: 1rem; }
.btn-block { width: 100%; }
.icon-btn {
  background: transparent; border: none; color: var(--text-soft);
  padding: .35rem; border-radius: var(--radius-sm); cursor: pointer; display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.field { margin-bottom: .85rem; }
.field label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: .28rem; color: var(--text-soft); }
.field .req { color: var(--danger); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], input[type=tel], select, textarea {
  width: 100%; padding: .52rem .65rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: .9rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--navy); outline-offset: -1px; border-color: var(--navy);
}
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-faint); }
textarea { resize: vertical; min-height: 72px; }
.field .hint { font-size: .74rem; color: var(--text-faint); margin-top: .22rem; }
.field .err { font-size: .76rem; color: var(--danger); margin-top: .22rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; font-size: .88rem; }
.checkbox input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; margin: 0 0 1rem; }
legend { font-size: .8rem; font-weight: 700; color: var(--text-soft); padding: 0 .4rem; text-transform: uppercase; letter-spacing: .5px; }

.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: .9rem; }
.toolbar .field { margin: 0; min-width: 140px; }
.toolbar .grow { flex: 1; min-width: 200px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
thead th {
  text-align: left; padding: .6rem .7rem; background: var(--surface-2);
  border-bottom: 1px solid var(--border); font-size: .74rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px; color: var(--text-soft); white-space: nowrap;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
tbody td { padding: .55rem .7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.nowrap { white-space: nowrap; }
.cell-main { font-weight: 600; }
.cell-sub { font-size: .76rem; color: var(--text-faint); }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-top: .8rem; flex-wrap: wrap; }
.pagination .info { font-size: .8rem; color: var(--text-soft); }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: .12rem .45rem; border-radius: 999px;
  font-size: .7rem; font-weight: 700; letter-spacing: .3px;
  background: var(--surface-2); color: var(--text-soft); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.ok { background: var(--accent-100); color: var(--accent); border-color: transparent; }
.badge.warn { background: var(--warn-100); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-100); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--navy-100); color: var(--navy); border-color: transparent; }
.badge-list { display: flex; flex-wrap: wrap; gap: .25rem; }

/* ---------- Alerts ---------- */
.alert {
  padding: .7rem .85rem; border-radius: var(--radius-sm);
  border-left: 3px solid var(--info); background: var(--surface-2);
  font-size: .86rem; margin-bottom: .9rem;
}
.alert.warn { border-left-color: var(--warn); background: var(--warn-100); color: var(--warn); }
.alert.danger { border-left-color: var(--danger); background: var(--danger-100); color: var(--danger); }
.alert.ok { border-left-color: var(--accent); background: var(--accent-100); color: var(--accent); }
.alert strong { display: block; margin-bottom: .15rem; }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--text-faint); }
.empty .big { font-size: 2rem; margin-bottom: .4rem; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 300; display: flex; flex-direction: column; gap: .5rem; max-width: min(380px, calc(100vw - 2rem)); }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--navy);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  padding: .65rem .8rem; font-size: .85rem; animation: slideIn .18s ease;
}
.toast.ok { border-left-color: var(--accent); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast .t-title { font-weight: 700; margin-bottom: .1rem; }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(12, 16, 24, .55);
  display: grid; place-items: center; z-index: 250; padding: 1rem;
}
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: min(660px, 100%); max-height: 90vh; overflow: auto;
}
.modal.wide { width: min(980px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: .9rem 1rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 1rem; }
.modal-foot { padding: .8rem 1rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; position: sticky; bottom: 0; background: var(--surface); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; background: var(--bg); }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 1.75rem 1.5rem; }
.login-card .brand-mark { display: block; margin: 0 auto 1rem; }
.login-card h1 { text-align: center; font-size: 1.2rem; }
.login-card .tagline { text-align: center; color: var(--text-soft); font-size: .85rem; margin-bottom: 1.4rem; }
.divider { display: flex; align-items: center; gap: .7rem; color: var(--text-faint); font-size: .75rem; margin: 1.1rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
#googleBtnHolder { display: flex; justify-content: center; min-height: 44px; }

/* ---------- Attendance ---------- */
.attend-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 860px) { .attend-grid { grid-template-columns: 1fr; } }
.camera-frame {
  position: relative; background: #0b0e14; border-radius: var(--radius);
  overflow: hidden; aspect-ratio: 3 / 4; display: grid; place-items: center;
}
.camera-frame video, .camera-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-frame video { transform: scaleX(-1); }
.camera-placeholder { color: #7c869a; text-align: center; padding: 1.5rem; font-size: .86rem; }
.camera-overlay {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: .55rem .7rem; background: linear-gradient(transparent, rgba(0, 0, 0, .75));
  color: #fff; font-size: .75rem; font-family: var(--mono);
}
.gps-row { display: flex; align-items: center; gap: .5rem; font-size: .82rem; margin-bottom: .6rem; }
.gps-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-faint); flex: none; }
.gps-dot.ok { background: var(--accent); }
.gps-dot.warn { background: var(--warn); }
.gps-dot.err { background: var(--danger); }
.kv { display: grid; grid-template-columns: minmax(110px, 34%) 1fr; gap: .3rem .7rem; font-size: .85rem; }
.kv dt { color: var(--text-soft); }
.kv dd { margin: 0; font-weight: 550; word-break: break-word; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: .7rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: none; }
.timeline .t-time { font-family: var(--mono); font-size: .84rem; font-weight: 700; min-width: 52px; }

/* ---------- Detail page ---------- */
.detail-head { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.detail-photo {
  width: 88px; height: 88px; border-radius: 12px; object-fit: cover;
  background: var(--navy-100); color: var(--navy);
  display: grid; place-items: center; font-size: 1.6rem; font-weight: 700; flex: none;
}
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .75rem; }
.doc-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .7rem; background: var(--surface-2); }
.doc-card .doc-cat { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--text-soft); }
.doc-card .doc-name { font-size: .78rem; word-break: break-all; color: var(--text-faint); margin: .25rem 0 .5rem; }
.preview-box { max-height: 70vh; overflow: auto; text-align: center; background: var(--surface-2); border-radius: var(--radius-sm); }
.preview-box img { max-width: 100%; }
.preview-box iframe { width: 100%; height: 70vh; border: 0; }

/* ---------- Progress ---------- */
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--navy); transition: width .25s; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .menu-toggle { display: inline-grid; }
  .sidebar {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0; z-index: 60;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0; background: rgba(0, 0, 0, .35); z-index: 55; }
  .content { padding: .9rem .8rem 3rem; }
  .user-meta { display: none; }
  .server-clock { display: none; }
}
@media (max-width: 480px) {
  .brand-text { display: none; }
  .toolbar .field { min-width: 100%; }
}

/* ---------- Print ---------- */
@media print {
  .topbar, .sidebar, .toasts, .btn, .toolbar { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
