/* Reusable components: buttons, fields, badges, tables, drawer, modal, toast, journey track */

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border: 1px solid transparent; border-radius: var(--radius-s);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
  background: var(--panel); color: var(--ink); border-color: var(--line-strong);
}
.btn:hover { background: var(--panel-2); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--teal); color: #fff; border-color: var(--teal); }
.btn-primary:hover { background: var(--teal-600); color: #fff; }
.btn-danger { background: var(--panel); color: var(--danger); border-color: #e3b2ac; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: var(--fs-s); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; background: transparent; color: inherit; border-radius: var(--radius-s); cursor: pointer; }

/* Fields */
.field { display: grid; gap: 4px; margin-bottom: var(--sp-4); }
.field > span, .field > legend { font-size: var(--fs-s); font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: var(--fs-xs); color: var(--ink-3); font-weight: 400; }
.field-note { margin: calc(var(--sp-4) * -1 + 4px) 0 var(--sp-4); font-size: var(--fs-s); color: var(--ink-2); background: var(--teal-50); border-radius: var(--radius-s); padding: 8px 10px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: var(--radius-s);
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--teal); box-shadow: var(--focus); }
.field[data-invalid] input, .field[data-invalid] select, .field[data-invalid] textarea { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: var(--fs-s); }
.form-error { color: var(--danger); background: var(--danger-bg); padding: 10px 12px; border-radius: var(--radius-s); }
.input-money { font-variant-numeric: tabular-nums; }
.check { display: flex; gap: 8px; align-items: flex-start; margin-bottom: var(--sp-3); }
.check input { width: 20px; height: 20px; margin-top: 2px; }
.field-grid { display: grid; gap: 0 var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* Badges: text always present */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 650; line-height: 1.6; white-space: nowrap;
  background: var(--muted-bg); color: var(--ink-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-teal { background: var(--teal-50); color: var(--teal); }
.badge-exception { background: var(--warn-bg); color: var(--warn); border: 1px dashed var(--warn); }

/* Panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: var(--sp-5); }
.panel + .panel { margin-top: var(--sp-4); }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-3); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.panel-head h2 { margin: 0; }

/* Definition list for request facts */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px var(--sp-4); margin: 0; }
.facts dt { color: var(--ink-3); font-size: var(--fs-s); }
.facts dd { margin: 0; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--panel); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-s); }
table.data th, table.data td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data th { position: sticky; top: 0; background: var(--panel-2); font-weight: 650; color: var(--ink-2); z-index: 1; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--teal-50); }
table.data tbody tr[aria-selected="true"] { background: #d7ebed; }
table.data td.money, table.data th.money { text-align: right; }
table.data tr:last-child td { border-bottom: 0; }
.table-empty { padding: var(--sp-6); text-align: center; color: var(--ink-3); }

.pager { display: flex; gap: var(--sp-2); align-items: center; justify-content: flex-end; padding: var(--sp-3) 0; font-size: var(--fs-s); }

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: var(--sp-4); overflow-x: auto; }
.tab { border: 0; background: transparent; font: inherit; padding: 10px 14px; cursor: pointer; color: var(--ink-2); border-bottom: 3px solid transparent; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--teal); border-bottom-color: var(--teal); font-weight: 650; }
.tab .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 999px; background: var(--muted-bg); font-size: var(--fs-xs); text-align: center; }

/* KPI strip */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-5); }
.kpi { padding: var(--sp-3) var(--sp-4); border-left: 3px solid var(--line-strong); background: var(--panel); border-radius: 0 var(--radius-s) var(--radius-s) 0; }
.kpi strong { display: block; font-size: var(--fs-xl); font-variant-numeric: tabular-nums; }
.kpi span { font-size: var(--fs-s); color: var(--ink-2); }
.kpi[data-tone="warn"] { border-left-color: var(--warn); }
.kpi[data-tone="danger"] { border-left-color: var(--danger); }
.kpi[data-tone="ok"] { border-left-color: var(--ok); }
.kpi[data-tone="teal"] { border-left-color: var(--teal); }

/* Drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(21,35,44,.35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100vw); background: var(--panel); z-index: 41;
  box-shadow: var(--shadow-drawer); display: flex; flex-direction: column; animation: drawer-in .18s ease-out;
}
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--sp-5); }
.drawer-foot { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--line); background: var(--panel-2); }
.drawer section + section { margin-top: var(--sp-5); }

/* Modal */
dialog.modal { border: 0; border-radius: var(--radius-m); padding: 0; width: min(480px, calc(100vw - 32px)); color: var(--ink); }
dialog.modal::backdrop { background: rgba(21,35,44,.45); }
.modal-body { padding: var(--sp-5); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); background: var(--panel-2); }

/* Toast */
.toast-region { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; width: min(440px, calc(100vw - 24px)); }
.toast { padding: 12px 16px; border-radius: var(--radius-s); background: var(--ink); color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast[data-tone="error"] { background: var(--danger); }
.toast[data-tone="ok"] { background: var(--ok); }

/* Flags / warnings list */
.flags { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.flags li { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: var(--radius-s); background: var(--panel-2); border-left: 3px solid var(--line-strong); font-size: var(--fs-s); }
.flags li[data-severity="BLOCKING"] { border-left-color: var(--danger); background: var(--danger-bg); }
.flags li[data-severity="HIGH"] { border-left-color: var(--danger); }
.flags li[data-severity="REVIEW"] { border-left-color: var(--warn); }
.flags li[data-severity="INFO"] { border-left-color: var(--info); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 var(--sp-3) var(--sp-4); font-size: var(--fs-s); }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--panel); border: 2px solid var(--teal); }
.timeline time { color: var(--ink-3); display: block; font-size: var(--fs-xs); }

/* Journey track — the signature element.
   Shows where a request is on its path. Maintenance has a pre-approval leg
   before the shared track; reimbursement joins at "Bukti". */
.journey { display: flex; align-items: flex-start; gap: 0; margin: var(--sp-2) 0 var(--sp-4); overflow-x: auto; padding-bottom: 4px; }
.journey-step { position: relative; flex: 1 0 64px; display: grid; justify-items: center; gap: 6px; text-align: center; font-size: var(--fs-xs); color: var(--ink-3); }
.journey-step::before { content: ""; position: absolute; top: 9px; left: -50%; right: 50%; height: 3px; background: var(--line); }
.journey-step:first-child::before { display: none; }
.journey-dot { position: relative; width: 20px; height: 20px; border-radius: 50%; background: var(--panel); border: 3px solid var(--line-strong); z-index: 1; }
.journey-step[data-state="done"] { color: var(--ink-2); }
.journey-step[data-state="done"]::before { background: var(--teal); }
.journey-step[data-state="done"] .journey-dot { background: var(--teal); border-color: var(--teal); }
.journey-step[data-state="current"] { color: var(--ink); font-weight: 650; }
.journey-step[data-state="current"]::before { background: var(--teal); }
.journey-step[data-state="current"] .journey-dot { border-color: var(--teal); box-shadow: 0 0 0 5px var(--teal-50); }
.journey-step[data-state="blocked"] { color: var(--danger); font-weight: 650; }
.journey-step[data-state="blocked"] .journey-dot { border-color: var(--danger); background: var(--danger-bg); }
.journey-step[data-state="attention"] { color: var(--warn); font-weight: 650; }
.journey-step[data-state="attention"] .journey-dot { border-color: var(--warn); background: var(--warn-bg); }
.journey-step[data-leg="pre"] .journey-dot { border-style: dashed; }
.journey-step[data-leg="pre"][data-state="done"] .journey-dot { border-style: solid; }

/* Upload */
.dropzone { display: grid; place-items: center; gap: 6px; padding: var(--sp-5); border: 2px dashed var(--line-strong); border-radius: var(--radius-m); background: var(--panel-2); text-align: center; cursor: pointer; }
.dropzone:hover, .dropzone:focus-within { border-color: var(--teal); background: var(--teal-50); }
.dropzone input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.preview-thumb { max-height: 220px; border-radius: var(--radius-s); border: 1px solid var(--line); }
.progress { height: 6px; background: var(--muted-bg); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--teal); width: 0; transition: width .15s; }

/* Receipt viewer */
.receipt-view { background: #20303a; border-radius: var(--radius-m); padding: var(--sp-3); display: grid; place-items: center; min-height: 200px; }
.receipt-view img { max-height: 60vh; border-radius: var(--radius-s); background: #fff; }
.receipt-view iframe { width: 100%; height: 60vh; border: 0; background: #fff; border-radius: var(--radius-s); }

/* Compare grid: submitted vs OCR */
.compare { display: grid; grid-template-columns: max-content 1fr 1fr; gap: 6px var(--sp-4); font-size: var(--fs-s); align-items: baseline; }
.compare .head { font-weight: 650; color: var(--ink-2); }

.empty { padding: var(--sp-6) var(--sp-4); text-align: center; color: var(--ink-2); }
.empty p { max-width: 42ch; margin: 0 auto var(--sp-3); }

.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: var(--sp-6); }
table.data td .mono { white-space: nowrap; }
.row-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-4); }
.jurnal-panel .callout ul { margin: 0; padding-left: 18px; }
