:root {
  --primary: #1a6070;
  --primary-dark: #134a57;
  --accent: #00b2c8;
  --green: #0d9f6e;
  --orange: #f97316;
  --red: #e53935;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --radius: 14px;
  --shadow: 0 2px 8px rgba(0,0,0,.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45;
}

/* ===== Buttons (thumb-friendly) ===== */
.btn {
  border: none; border-radius: var(--radius); padding: 14px 18px; font-size: 16px;
  font-weight: 600; cursor: pointer; transition: filter .15s, transform .05s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 14px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-outline { background: #fff; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-ghost { background: transparent; color: var(--muted); }

/* ===== Inputs ===== */
.input {
  width: 100%; padding: 13px 14px; font-size: 16px; border: 1.5px solid var(--border);
  border-radius: 10px; background: #fff; color: var(--text); margin-bottom: 0;
}
.input:focus { outline: none; border-color: var(--accent); }
textarea.input { resize: vertical; }
select.input { appearance: none; }
.field { margin-bottom: 14px; }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.form-stack > * { margin-bottom: 14px; }
.hint { font-size: 13px; color: var(--muted); background: #eef6f8; padding: 10px 12px; border-radius: 10px; }
.section-h { margin: 8px 0 2px; font-size: 15px; color: var(--primary); }

/* ===== Login ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(160deg, var(--primary) 0%, var(--primary-dark) 100%); }
.login-card { background: #fff; border-radius: 20px; padding: 28px 24px; width: 100%; max-width: 380px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.brand { text-align: center; margin-bottom: 22px; }
.brand-logo { font-size: 32px; font-weight: 800; color: var(--primary); letter-spacing: 1px; }
.brand-sub { font-size: 13px; color: var(--muted); }

/* ===== App shell ===== */
.app-header { position: sticky; top: 0; z-index: 10; background: var(--primary); color: #fff;
  padding: 14px 16px; padding-top: calc(14px + env(safe-area-inset-top)); display: flex;
  align-items: center; justify-content: space-between; box-shadow: var(--shadow); }
.app-title { font-size: 20px; font-weight: 800; letter-spacing: .5px; white-space: nowrap; flex-shrink: 0; }
.app-user { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; background: rgba(255,255,255,.2); padding: 2px 8px; border-radius: 8px; text-transform: capitalize; }
.app-header .btn-ghost { color: #fff; }
.content { padding: 16px; max-width: 720px; margin: 0 auto; padding-bottom: 40px; }
.page-h { font-size: 18px; margin: 18px 0 10px; }
.sub-h { font-size: 14px; color: var(--muted); margin: 16px 0 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }
.placeholder { text-align: center; padding: 40px 16px; color: var(--muted); }

/* ===== SR card ===== */
.sr-card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.sr-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sr-no { font-weight: 700; color: var(--primary); font-size: 15px; }
.sr-tujuan { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.sr-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 2px; }
.card-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.card-actions .btn { flex: 1; min-width: 120px; }

.status-pill { font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 20px; text-transform: uppercase; letter-spacing: .3px; }
.status-assigned, .status-approved { background: #e0f2fe; color: #0369a1; }
.status-ready { background: #ccfbf1; color: #0f766e; }
.status-in_progress { background: #fef3c7; color: #b45309; }
.status-completed { background: #dcfce7; color: #15803d; }
.status-closed { background: #e5e7eb; color: #4b5563; }
.status-rejected, .status-cancelled { background: #fee2e2; color: #b91c1c; }

/* ===== Inspection segmented ===== */
.insp-list { display: flex; flex-direction: column; gap: 12px; }
.insp-row { display: flex; flex-direction: column; gap: 6px; }
.insp-label { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.badge-critical { font-size: 10px; background: #fee2e2; color: var(--red); padding: 1px 7px; border-radius: 8px; font-weight: 700; text-transform: uppercase; }
.segmented { display: flex; gap: 6px; }
.seg { flex: 1; padding: 11px 4px; border: 1.5px solid var(--border); background: #fff; border-radius: 10px;
  font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); text-transform: capitalize; }
.seg.active.seg-good { background: var(--green); border-color: var(--green); color: #fff; }
.seg.active.seg-warn { background: var(--orange); border-color: var(--orange); color: #fff; }
.seg.active.seg-bad { background: var(--red); border-color: var(--red); color: #fff; }

/* ===== Photo field ===== */
.photo-preview { margin-top: 8px; }
.photo-thumb { width: 100%; max-height: 200px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }

/* ===== Expense summary ===== */
.summary-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.sum-row { display: flex; justify-content: space-between; font-size: 14px; padding: 3px 0; }
.sum-row.total { border-top: 1px dashed var(--border); margin-top: 6px; padding-top: 8px; font-size: 16px; }
.verdict { margin-top: 10px; padding: 8px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; text-align: center; }
.verdict-verified { background: #dcfce7; color: #15803d; }
.verdict-pending { background: #fef3c7; color: #b45309; }
.verdict-flagged { background: #fee2e2; color: #b91c1c; }
.mini-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; font-size: 14px; }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-end;
  justify-content: center; z-index: 100; padding: 0; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: #fff; width: 100%; max-width: 560px; border-radius: 20px 20px 0 0; max-height: 92vh;
  overflow-y: auto; padding: 20px; padding-bottom: calc(20px + env(safe-area-inset-bottom)); animation: slideup .25s; }
.modal-sm { border-radius: 18px; max-width: 360px; align-self: center; margin: auto; }
@keyframes slideup { from { transform: translateY(40px); opacity: .6; } }
.modal-overlay:has(.modal-sm) { align-items: center; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-title { font-size: 18px; margin: 0; color: var(--primary); }
.modal-close { background: none; border: none; font-size: 28px; line-height: 1; color: var(--muted); cursor: pointer; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

/* ===== Toast ===== */
.toast-host { position: fixed; left: 0; right: 0; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 200;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: #1f2937; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 500;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); opacity: 0; transform: translateY(20px); transition: all .3s; max-width: 480px; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--green); }
.toast-error { background: var(--red); }
.toast-info { background: var(--primary); }

/* ===== Layout helpers ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sr-card.clickable { cursor: pointer; transition: box-shadow .15s, transform .05s; }
.sr-card.clickable:active { transform: scale(.995); }
.tag-fb { background: #fef9c3; color: #a16207; padding: 1px 8px; border-radius: 8px; font-weight: 700; font-size: 11px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ===== Detail SR ===== */
.detail-wrap { display: flex; flex-direction: column; gap: 14px; }
.detail-head { display: flex; flex-direction: column; gap: 8px; }
.detail-title { display: flex; align-items: center; gap: 10px; }
.detail-card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.detail-card .section-h { margin-top: 0; margin-bottom: 10px; }
.detail-row { display: flex; justify-content: space-between; gap: 14px; padding: 5px 0; font-size: 14px; border-bottom: 1px dashed var(--border); }
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--muted); flex-shrink: 0; }
.detail-val { text-align: right; font-weight: 500; }
.detail-actions { display: flex; flex-direction: column; gap: 10px; }
.detail-actions .card-actions { margin-top: 0; }

/* ===== Timeline ===== */
.timeline { display: flex; flex-direction: column; }
.tl-item { display: flex; gap: 12px; position: relative; padding-bottom: 16px; }
.tl-item:not(:last-child)::before { content: ''; position: absolute; left: 6px; top: 16px; bottom: 0; width: 2px; background: var(--border); }
.tl-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); flex-shrink: 0; margin-top: 3px; z-index: 1; }
.tl-status { font-weight: 600; font-size: 14px; }
.tl-meta { font-size: 12px; color: var(--muted); }

/* ===== Star rating ===== */
.star-row { display: flex; gap: 6px; }
.star { font-size: 30px; cursor: pointer; user-select: none; opacity: .3; transition: opacity .15s, transform .1s; }
.star.on { opacity: 1; }
.star:active { transform: scale(1.15); }
.star-caption { font-size: 12px; color: var(--green); font-weight: 600; margin-top: 4px; }

/* ===== Spinner ===== */
.spinner-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px 0; color: var(--muted); }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Laporan / Analitik ===== */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 18px 0 10px; }
.page-head .page-h { margin: 0; }
.muted { color: var(--muted); }

.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 6px; }
.kpi-card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); text-align: center; }
.kpi-value { font-size: 26px; font-weight: 800; color: var(--primary); line-height: 1.1; }
.kpi-label { font-size: 13px; font-weight: 600; margin-top: 4px; }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.chart-card .sub-h { margin-top: 0; }
.chart-box { position: relative; height: 260px; }

.mini-table { display: flex; flex-direction: column; }
.mini-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center;
  padding: 9px 0; font-size: 14px; border-bottom: 1px dashed var(--border); }
.mini-row:last-child { border-bottom: none; }
.mini-row .muted { font-size: 12px; text-align: right; }

@media (min-width: 560px) { .kpi-grid { grid-template-columns: repeat(4, 1fr); } }

/* ===== Cetak / PDF (client-side print) ===== */
#print-letterhead { display: none; }
@media print {
  @page { size: A4; margin: 14mm 14mm 16mm; }
  html, body { background: #fff !important; color: #000; }
  .app-header, .toast-host, .modal-overlay, .spinner-wrap,
  .no-print, .btn, .card-actions, .detail-actions, .seg-control { display: none !important; }
  .content, #content, #app, main.content { display: block !important; padding: 0 !important; max-width: none !important; box-shadow: none !important; }

  #print-letterhead { display: block; border-bottom: 2px solid #1a6070; padding-bottom: 8px; margin-bottom: 14px; }
  #print-letterhead .pl-brand { font-size: 18px; font-weight: 800; color: #1a6070; }
  #print-letterhead .pl-org { font-size: 12px; color: #333; }
  #print-letterhead .pl-title { font-size: 15px; font-weight: 700; margin-top: 8px; }
  #print-letterhead .pl-sub { font-size: 12px; color: #333; }
  #print-letterhead .pl-date { font-size: 10px; color: #666; margin-top: 4px; }

  .card, .detail-card, .kpi-card, .chart-card { box-shadow: none !important; border: 1px solid #ccc; break-inside: avoid; page-break-inside: avoid; }
  .chart-box { height: 220px !important; }
  .kpi-grid { display: grid !important; grid-template-columns: repeat(4, 1fr) !important; }
  .status-pill { border: 1px solid #999; }
  a[href]::after { content: ''; }
}
