/* style.css — Styling kustom mobile-first Sistem Pelaporan Pekerjaan Tim ASN */

:root {
  --primary: #0f4c81;
  --primary-600: #0c3d68;
  --primary-50: #e8f1fa;
  --accent: #f5c400;
  --ok: #16a34a;
  --ok-50: #dcfce7;
  --warn: #d97706;
  --warn-50: #fef3c7;
  --err: #dc2626;
  --err-50: #fee2e2;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .06);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[x-cloak] { display: none !important; }

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(80px + var(--safe-bottom));
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: .35rem 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
a { color: var(--primary); }
img { max-width: 100%; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.text-err { color: var(--err); }
.line-clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.noscript { padding: 2rem; text-align: center; }

/* ---------- Layout ---------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-head h2, .card-title { font-size: 1rem; font-weight: 700; }
.section-title { font-size: 1.05rem; margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.section-title small { font-weight: 400; font-size: .8rem; }

.grid-2, .grid-3 { display: grid; grid-template-columns: 1fr; gap: 10px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 16px;
  border: 1px solid transparent; border-radius: 10px;
  font: inherit; font-weight: 600; cursor: pointer;
  background: #e2e8f0; color: var(--text);
  transition: background .15s, transform .05s, opacity .15s;
  text-decoration: none; user-select: none;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-600); }
.btn-outline { background: #fff; color: var(--primary); border-color: #cbd5e1; }
.btn-outline:hover:not(:disabled) { background: var(--primary-50); }
.btn-danger-outline { background: #fff; color: var(--err); border-color: #fca5a5; }
.btn-danger-outline:hover:not(:disabled) { background: var(--err-50); }
.btn-light { background: #fff; color: var(--primary); }
.btn-block { width: 100%; }
.btn-lg { min-height: 50px; font-size: 1rem; }
.btn-sm { min-height: 34px; padding: 4px 12px; font-size: .85rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row .btn { flex: 1 1 auto; }
.btn-col { display: flex; flex-direction: column; gap: 8px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px; border: 0;
  background: transparent; font-size: 1.15rem; cursor: pointer; color: inherit;
}
.icon-btn:hover:not(:disabled) { background: rgba(15, 23, 42, .08); }
.icon-btn:disabled { opacity: .4; }
.icon-btn.sm { width: 30px; height: 30px; font-size: .9rem; flex: none; }

/* ---------- Chips, badges, alerts ---------- */
.chip {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: var(--primary-50); color: var(--primary); font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: .72rem; font-weight: 700;
  white-space: nowrap; text-transform: uppercase; letter-spacing: .02em;
}
.st-menunggu { background: var(--warn-50); color: var(--warn); }
.st-mengirim { background: var(--primary-50); color: var(--primary); }
.st-selesai  { background: var(--ok-50); color: var(--ok); }
.st-gagal    { background: var(--err-50); color: var(--err); }

.role-chip { margin-left: 4px; padding: 0 6px; border-radius: 4px; background: var(--accent); color: #3b2f00; font-size: .68rem; font-weight: 700; }

.alert { padding: 10px 12px; border-radius: 10px; font-size: .87rem; display: flex; flex-direction: column; gap: 8px; margin: 0; }
.alert-err { background: var(--err-50); color: #991b1b; }
.alert-warn { background: var(--warn-50); color: #92400e; }

.net-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 700;
}
.net-badge i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.net-badge.on { background: var(--ok-50); color: var(--ok); }
.net-badge.on i { background: var(--ok); box-shadow: 0 0 0 3px rgba(22, 163, 74, .2); }
.net-badge.off { background: var(--err-50); color: var(--err); }
.net-badge.off i { background: var(--err); }

/* ---------- Spinner ---------- */
.spinner {
  display: inline-block; width: 14px; height: 14px; vertical-align: -2px;
  border: 2px solid rgba(15, 76, 129, .25); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .8s linear infinite;
}
.spinner.light { border-color: rgba(255, 255, 255, .35); border-top-color: #fff; }
.spin { display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 18px 24px;
  background: radial-gradient(circle at 20% 0%, #1c6bb0 0%, var(--primary) 45%, #082a48 100%);
}
.login-card {
  width: 100%; max-width: 400px; background: #fff; border-radius: 20px;
  padding: 28px 22px; text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.login-logo { width: 88px; height: 88px; border-radius: 22px; margin-bottom: 6px; }
.login-card h1 { font-size: 1.4rem; color: var(--primary); }
.login-instansi { font-weight: 600; margin: 0; }
.login-actions { width: 100%; display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.gsi-wrap { display: flex; justify-content: center; min-height: 44px; }
.demo-box { background: var(--primary-50); border-radius: 12px; padding: 12px; font-size: .85rem; text-align: left; display: flex; flex-direction: column; gap: 10px; }
.login-foot { color: rgba(255, 255, 255, .75); margin-top: 16px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--primary); color: #fff;
  padding-top: var(--safe-top);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 10px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.topbar .icon-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .15); }
.topbar .net-badge.on { background: rgba(255, 255, 255, .15); color: #bbf7d0; }
.topbar .net-badge.off { background: rgba(220, 38, 38, .9); color: #fff; }
.topbar .net-badge.off i { background: #fff; }
.topbar-actions { display: flex; align-items: center; gap: 2px; }
.topbar-title { display: flex; align-items: center; gap: 6px; font-size: 1.05rem; }
.profile { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  flex: none; width: 44px; height: 44px; border-radius: 50%; overflow: hidden;
  background: var(--accent); color: #3b2f00; font-weight: 800;
  display: flex; align-items: center; justify-content: center; border: 2px solid rgba(255, 255, 255, .6);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.profile-text b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-text small { opacity: .85; font-size: .74rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.update-banner {
  position: sticky; top: 0; z-index: 30; background: var(--accent); color: #3b2f00;
  padding: 8px 14px; display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 600; font-size: .88rem;
}

/* ---------- Sync widget ---------- */
.sync-card { border-left: 4px solid var(--primary); }
.sync-card.is-running { border-left-color: var(--accent); }
.sync-empty { margin: 0; }
.progress { height: 12px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.progress.thin { height: 6px; }
.progress-bar {
  height: 100%; background: linear-gradient(90deg, var(--primary), #2b8ad8);
  border-radius: 999px; transition: width .4s ease;
}
.is-running .progress-bar {
  background-image: linear-gradient(45deg, rgba(255,255,255,.2) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.2) 50%, rgba(255,255,255,.2) 75%, transparent 75%), linear-gradient(90deg, var(--primary), #2b8ad8);
  background-size: 20px 20px, 100% 100%;
  animation: stripes 1s linear infinite;
}
@keyframes stripes { to { background-position: 20px 0, 0 0; } }
.progress-meta { display: flex; justify-content: space-between; font-size: .82rem; color: var(--muted); margin-top: 4px; }
.queue-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow: auto; }
.queue-item { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.queue-row { display: flex; align-items: center; gap: 8px; }
.queue-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; }
.mini-progress { height: 4px; background: #e2e8f0; border-radius: 4px; overflow: hidden; margin: 6px 0 4px; }
.mini-progress div { height: 100%; background: var(--primary); transition: width .4s; }
.queue-meta { display: flex; justify-content: space-between; gap: 8px; font-size: .75rem; color: var(--muted); }
.queue-meta span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-meta span:last-child { white-space: nowrap; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 8px; text-align: center; display: flex; flex-direction: column; border-top: 3px solid var(--primary);
}
.stat.ok { border-top-color: var(--ok); }
.stat.warn { border-top-color: var(--warn); }
.stat-num { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.stat-lbl { font-size: .72rem; color: var(--muted); font-weight: 600; }
.stats-caption { margin: -6px 0 0; text-align: center; }

/* ---------- Tabs & filters ---------- */
.tabs { display: flex; background: var(--bg); border-radius: 10px; padding: 4px; gap: 4px; }
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px;
  font: inherit; font-weight: 600; color: var(--muted); cursor: pointer;
}
.tabs button.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }
.filters { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.filters input[type="search"] { grid-column: 1 / -1; grid-row: 2; }

/* ---------- Report list ---------- */
.empty { text-align: center; padding: 24px 8px; color: var(--muted); }
.report-cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.report-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 3px; }
.report-top, .report-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.report-date { font-size: .8rem; color: var(--muted); font-weight: 600; }
.report-title { font-size: .98rem; }
.link { font-size: .82rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
.table-wrap { display: none; overflow-x: auto; }
.report-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.report-table th, .report-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.report-table th { font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f8fafc; position: sticky; top: 0; }
.report-table tbody tr:hover { background: #f8fafc; }

/* ---------- Form ---------- */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: .82rem; font-weight: 600; color: #334155; }
input[type="text"], input[type="email"], input[type="number"], input[type="date"], input[type="month"],
input[type="search"], select, textarea {
  width: 100%; font: inherit; color: var(--text);
  padding: 10px 12px; min-height: 44px;
  border: 1px solid #cbd5e1; border-radius: 10px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none; appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 76, 129, .15); }
input[readonly] { background: #f8fafc; color: var(--muted); }
.field .err { color: var(--err); font-size: .78rem; min-height: 0; }
.field .err:empty { display: none; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--err); background: #fffafa; }

.gps-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 10px; padding: 10px 12px;
}
.gps-coords { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.gps-coords > div { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.gps-acc { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.acc-baik { background: var(--ok-50); color: var(--ok); }
.acc-sedang { background: var(--warn-50); color: var(--warn); }
.acc-buruk { background: var(--err-50); color: var(--err); }

.upload-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.upload-actions .btn, label.btn { cursor: pointer; }
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb { position: relative; margin: 0; border-radius: 10px; overflow: hidden; background: #e2e8f0; aspect-ratio: 1; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb figcaption {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 2px 6px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .7)); color: #fff; font-size: .7rem; font-weight: 600;
}
.thumb-del {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%;
  border: 0; background: rgba(0, 0, 0, .6); color: #fff; cursor: pointer; font-size: .8rem;
}
.doc-meter { display: flex; flex-direction: column; gap: 4px; }
.doc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.doc-list li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; }
.doc-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .88rem; }

.form-actions {
  position: sticky; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: 1fr 2fr; gap: 10px;
  margin: 0 -14px; padding: 12px 14px calc(12px + var(--safe-bottom));
  background: rgba(241, 245, 249, .95); backdrop-filter: blur(6px);
  border-top: 1px solid var(--border);
}
#view-form form { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Settings ---------- */
.radio-list { display: flex; flex-direction: column; gap: 8px; }
.radio, .switch-row {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
}
.radio:has(input:checked) { border-color: var(--primary); background: var(--primary-50); }
.radio.disabled { opacity: .7; cursor: not-allowed; }
.radio input { margin-top: 4px; accent-color: var(--primary); width: 18px; height: 18px; flex: none; }
.radio span, .switch-row span { display: flex; flex-direction: column; }
.radio small, .switch-row small { color: var(--muted); font-size: .78rem; }
.switch-row { justify-content: space-between; align-items: center; }
.switch {
  -webkit-appearance: none; appearance: none; flex: none;
  width: 46px; height: 26px; border-radius: 999px; background: #cbd5e1; position: relative; cursor: pointer; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch:checked { background: var(--primary); }
.switch:checked::after { transform: translateX(20px); }

.pegawai-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.pegawai-list li { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.pegawai-list li.inactive { background: #fafafa; opacity: .75; }
.pegawai-info { display: flex; flex-direction: column; min-width: 0; }
.pegawai-info small { overflow: hidden; text-overflow: ellipsis; }
.pegawai-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pegawai-form { border-top: 1px dashed var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- Toast ---------- */
.toasts {
  position: fixed; left: 50%; bottom: calc(16px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none;
}
.toast {
  padding: 10px 14px; border-radius: 10px; color: #fff; background: #1e293b; font-size: .88rem; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); animation: toast-in .25s ease;
}
.toast-ok { background: #15803d; }
.toast-warn { background: #b45309; }
.toast-err { background: #b91c1c; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* Offline: garis merah tipis di atas layar */
body.is-offline::before {
  content: ""; position: fixed; top: 0; left: 0; right: 0; height: 3px; background: var(--err); z-index: 50;
}

/* ---------- Tablet & desktop ---------- */
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
  .thumbs { grid-template-columns: repeat(5, 1fr); }
  .filters { grid-template-columns: 200px 1fr auto; }
  .filters input[type="search"] { grid-column: auto; grid-row: auto; }
  .pegawai-list li { flex-direction: row; align-items: center; justify-content: space-between; }
  .btn-col { flex-direction: row; flex-wrap: wrap; }
  .form-actions { grid-template-columns: 200px 1fr; margin: 0; border-radius: var(--radius); border: 1px solid var(--border); }
}

@media (min-width: 900px) {
  body { font-size: 15.5px; }
  .container { padding: 20px; }
  .report-cards { display: none !important; }
  .table-wrap { display: block; }
  .stat-num { font-size: 2rem; }
}

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