/* Kayazta Identity — design system
   Light, calm, mobile-first. All colours come from the tokens below; components never hardcode a colour. */

:root {
  color-scheme: light;

  /* Brand */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-active: #1e40af;
  --primary-soft: #eff6ff;
  --primary-pale: #dbeafe;
  --on-primary: #ffffff;

  /* Surfaces & text */
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --placeholder: #6b7a90;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  /* Status (each has a readable text colour and a soft background) */
  --success: #16a34a;
  --success-text: #15803d;
  --success-soft: #f0fdf4;
  --success-border: #bbf7d0;
  --warning: #d97706;
  --warning-text: #b45309;
  --warning-soft: #fffbeb;
  --warning-border: #fde68a;
  --error: #dc2626;
  --error-text: #b91c1c;
  --error-soft: #fef2f2;
  --error-border: #fecaca;

  /* Shape */
  --radius-card: 20px;
  --radius-control: 12px;
  --radius-small: 8px;
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-pop: 0 18px 50px rgba(15, 23, 42, 0.25);
  --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.35);

  /* Spacing scale (4px base) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;

  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Base ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  background-image: radial-gradient(48rem 22rem at 50% -9rem, var(--primary-pale), rgba(219, 234, 254, 0) 72%);
  background-repeat: no-repeat;
  color: var(--text);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-underline-offset: 3px; }
a:hover { color: var(--primary-hover); }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Layout ---------- */
.page { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; gap: var(--s-4); padding: var(--s-5) var(--s-4) var(--s-8); }
.page > * { width: 100%; max-width: 440px; }
.page.md > * { max-width: 560px; }
.page.wide > * { max-width: 880px; }
.page.center { justify-content: center; }

.brand { display: inline-flex; align-items: center; gap: 10px; align-self: center; width: auto !important; color: var(--text); font-weight: 700; font-size: 17px; letter-spacing: -0.01em; text-decoration: none; }
.brand:hover { color: var(--text); }
.brand b { color: var(--primary); font-weight: 700; }
.brand-mark { width: 36px; height: 36px; flex: none; border-radius: 10px; background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3l7 3v5c0 4.5-3 8.3-7 10-4-1.7-7-5.5-7-10V6z'/%3E%3Cpath d='M9 12l2 2 4-4'/%3E%3C/svg%3E") center / 22px no-repeat; box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: var(--s-5); box-shadow: var(--shadow-card); }
@media (min-width: 480px) { .card { padding: 28px; } .page { padding-top: var(--s-8); } }

.stack { display: grid; gap: var(--s-4); }

/* ---------- Typography ---------- */
h1 { margin: 0 0 var(--s-1); font-size: 22px; line-height: 1.3; font-weight: 700; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 17px; line-height: 1.35; font-weight: 700; }
h3 { margin: 0; font-size: 16px; font-weight: 700; }
h2.section { margin: 0 0 var(--s-1); }
.h-lg { margin: 0; font-size: 22px; line-height: 1.3; font-weight: 700; letter-spacing: -0.01em; }
.lead, p.subtitle { margin: 0 0 var(--s-5); color: var(--text-muted); font-size: 15px; }
.lead strong, p.subtitle strong { color: var(--text); }
.muted { color: var(--text-muted); }
.hint { margin: var(--s-2) 0 0; color: var(--text-muted); font-size: 13px; }
.step { margin: 0 0 var(--s-1); color: var(--primary); font-size: 13px; font-weight: 600; }

.back-link { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; margin: 0 0 var(--s-1); padding: 0 var(--s-2) 0 0; color: var(--text-muted); font-size: 14px; font-weight: 600; text-decoration: none; }
.back-link:hover { color: var(--primary); }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; margin-top: var(--s-4); }
.field:first-of-type { margin-top: 0; }
label { display: block; margin: 0; font-size: 14px; font-weight: 600; color: var(--text); }

input[type="text"], input[type="tel"], input[type="password"], input[type="search"], input[type="email"], input:not([type]) {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px stops iOS from zooming on focus */
}
input::placeholder { color: var(--placeholder); opacity: 1; }
input:hover { border-color: #94a3b8; }
input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
input[readonly] { background: var(--bg); color: var(--text-muted); }
input[aria-invalid="true"] { border-color: var(--error); }
input:disabled { background: var(--bg); cursor: not-allowed; }

label.check { display: flex; align-items: center; gap: 10px; margin: var(--s-4) 0 0; font-weight: 500; cursor: pointer; }
label.check input { width: 20px; height: 20px; min-height: 0; margin: 0; flex: none; accent-color: var(--primary); }

.pw-field { position: relative; }
.pw-field input { padding-right: 52px; }
.pw-toggle { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; min-height: 44px; margin: 0; padding: 0; border: 0; border-radius: var(--radius-control); background: transparent; color: var(--text-muted); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.pw-toggle:hover { color: var(--primary); background: var(--primary-soft); }

/* ---------- Buttons ---------- */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  width: 100%;
  min-height: 48px;
  margin-top: var(--s-5);
  padding: 0 var(--s-5);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: var(--primary);
  color: var(--on-primary);
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
button:hover, .btn:hover { background: var(--primary-hover); color: var(--on-primary); }
button:active, .btn:active { background: var(--primary-active); }
button:disabled, button[aria-busy="true"] { opacity: 0.55; cursor: not-allowed; }

button.secondary, .btn.secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
button.secondary:hover, .btn.secondary:hover { background: var(--bg); border-color: #94a3b8; color: var(--text); }
button.danger, .btn.danger { background: var(--error); color: #fff; }
button.danger:hover, .btn.danger:hover { background: #b91c1c; color: #fff; }
button.danger-outline, .btn.danger-outline { background: var(--surface); border-color: var(--error-border); color: var(--error-text); }
button.danger-outline:hover, .btn.danger-outline:hover { background: var(--error-soft); color: var(--error-text); }
button.linkbtn { width: auto; min-height: 44px; margin: 0; padding: 0 var(--s-3); background: transparent; border: 0; color: var(--error-text); font-size: 14px; }
button.linkbtn:hover { background: var(--error-soft); color: var(--error-text); }
.btn.inline, button.inline { width: auto; margin-top: 0; }

.btn-row { display: flex; flex-wrap: wrap; gap: var(--s-3); margin-top: var(--s-5); }
.btn-row .btn, .btn-row button { flex: 1 1 140px; margin-top: 0; }

/* ---------- Feedback ---------- */
.msg { display: none; margin-top: var(--s-4); padding: 12px 14px; border: 1px solid; border-radius: var(--radius-control); font-size: 14px; line-height: 1.5; }
.msg.error { display: block; background: var(--error-soft); border-color: var(--error-border); color: var(--error-text); }
.msg.ok { display: block; background: var(--success-soft); border-color: var(--success-border); color: var(--success-text); }
.msg.info { display: block; background: var(--primary-soft); border-color: var(--primary-pale); color: var(--primary-active); }
.msg.error::before { content: "Gagal — " / ""; font-weight: 700; }
.msg.ok::before { content: "Berhasil — " / ""; font-weight: 700; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--radius-small); font-size: 13px; font-weight: 600; background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.badge.ok { background: var(--success-soft); border-color: var(--success-border); color: var(--success-text); }
.badge.warn { background: var(--warning-soft); border-color: var(--warning-border); color: var(--warning-text); }
.badge.ok::before { content: "✓" / ""; }
.badge.warn::before { content: "!" / ""; font-weight: 700; }

.spinner { width: 24px; height: 24px; border: 3px solid var(--primary-pale); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.status-center { display: grid; justify-items: center; gap: var(--s-3); padding: var(--s-2) 0; text-align: center; }
.status-center h1 { margin: 0; }
.status-center .lead { margin: 0; }
.status-icon { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 16px; background: var(--primary-soft); color: var(--primary); }
.status-icon.warn { background: var(--warning-soft); color: var(--warning); }
.status-icon.err { background: var(--error-soft); color: var(--error); }

.links { margin-top: var(--s-5); text-align: center; font-size: 14px; color: var(--text-muted); }
.links a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px; font-weight: 600; }

/* ---------- Profile pieces ---------- */
.avatar-pic { position: relative; flex: none; width: 64px; height: 64px; border-radius: 50%; overflow: hidden; display: grid; place-items: center; background: var(--primary); color: #fff; font-size: 26px; font-weight: 700; }
.avatar-pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar-pic.lg { width: 96px; height: 96px; font-size: 38px; overflow: visible; cursor: pointer; }
.avatar-pic.lg img { border-radius: 50%; }
.avatar-pic.lg:hover { filter: brightness(1.06); }
.avatar-badge { position: absolute; right: -2px; bottom: -2px; z-index: 2; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); color: var(--primary); border: 1px solid var(--border-strong); box-shadow: 0 2px 6px rgba(15, 23, 42, 0.15); }

.profile-head { display: flex; align-items: center; gap: var(--s-4); }
.profile-head h1 { font-size: 20px; margin: 0; overflow-wrap: anywhere; }
.profile-head p { margin: 2px 0 0; color: var(--text-muted); font-size: 14px; }

.info-list { display: grid; margin: var(--s-5) 0 0; }
.info-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: 14px 0; border-top: 1px solid var(--border); font-size: 15px; }
.info-row dt { color: var(--text-muted); font-weight: 500; }
.info-row dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }

.photo { display: flex; align-items: center; gap: var(--s-5); margin-top: var(--s-4); }
.photo-actions { display: grid; justify-items: start; gap: var(--s-2); min-width: 0; }
.photo-actions .btn, .photo-actions button { width: auto; margin: 0; }
.photo:focus-within .avatar-pic { outline: 2px solid var(--primary); outline-offset: 3px; }
@media (max-width: 380px) { .photo { flex-direction: column; text-align: center; } .photo-actions { justify-items: center; } }

.tile { display: flex; align-items: center; gap: var(--s-4); min-height: 64px; padding: 14px var(--s-4); border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); text-decoration: none; transition: border-color 0.15s ease, background 0.15s ease; }
.tile:hover { border-color: var(--primary-pale); background: var(--primary-soft); color: var(--text); }
.tile-icon { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: var(--radius-control); background: var(--primary-soft); color: var(--primary); }
.tile-body { flex: 1; min-width: 0; }
.tile-title { display: block; font-weight: 600; }
.tile-desc { display: block; color: var(--text-muted); font-size: 13px; }
.tile-chev { color: var(--text-muted); font-size: 20px; line-height: 1; }
.tiles { display: grid; gap: var(--s-3); margin-top: var(--s-5); }

/* ---------- Saved addresses (swipe list) ---------- */
#list { list-style: none; padding: 0; margin: 0 0 var(--s-4); display: grid; gap: var(--s-3); }
.addr-empty { padding: var(--s-5) var(--s-2); text-align: center; color: var(--text-muted); }
.addr-item { --peek: 40px; position: relative; overflow: hidden; border-radius: 16px; background: var(--surface); }
.addr-actions { position: absolute; top: 0; right: 0; bottom: 0; width: 240px; max-width: 80%; display: flex; opacity: 0; transition: opacity 0.12s; }
.addr-item.open .addr-actions, .addr-item.swiping .addr-actions, .addr-item:has(.addr-card.nudge) .addr-actions { opacity: 1; }
.addr-actions button { flex: 1; width: auto; min-height: 0; margin: 0; padding: 0; border: 0; border-radius: 0; font-size: 15px; font-weight: 600; color: #fff; }
.addr-actions .edit { background: var(--primary); }
.addr-actions .edit:hover { background: var(--primary-hover); }
.addr-actions .pin { background: var(--success-text); }
.addr-actions .pin:hover { background: #166534; }
.addr-actions .del { background: var(--error); }
.addr-actions .del:hover { background: #b91c1c; }
.addr-peek { position: absolute; top: 0; right: 0; bottom: 0; width: var(--peek); z-index: 0; display: grid; place-items: center; border-radius: 0 16px 16px 0; background: var(--primary-soft); color: var(--primary); font-size: 24px; font-weight: 700; pointer-events: none; transition: opacity 0.15s; animation: peek-pulse 2.4s ease-in-out 1s 2; }
.addr-item.open .addr-peek { opacity: 0; }
@keyframes peek-pulse { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(-3px); } }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 40%, 60% { transform: translateX(-64px); } }
.addr-card { position: relative; z-index: 1; width: calc(100% - var(--peek)); padding: 14px var(--s-4); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; transition: transform 0.2s ease; touch-action: pan-y; user-select: none; -webkit-user-select: none; cursor: grab; }
.addr-card.nudge { animation: nudge 1.1s ease-in-out; }
.addr-card.dragging { transition: none; cursor: grabbing; }
.addr-item.open .addr-card { border-radius: 16px 0 0 16px; }
.addr-card strong { font-size: 16px; }
.addr-card strong .badge { margin-left: 6px; vertical-align: middle; }
.addr-detail { margin-top: 2px; color: var(--text-muted); font-size: 14px; line-height: 1.5; }

/* ---------- Address flow ---------- */
.area-list { list-style: none; padding: 0; margin: var(--s-3) 0 0; display: grid; gap: var(--s-2); }
.area-list li a { display: block; min-height: 56px; padding: 12px var(--s-4); border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--surface); color: var(--text); text-decoration: none; }
.area-list li a:hover, .area-list li a:focus-visible { border-color: var(--primary); background: var(--primary-soft); }
.area-list li a b { display: block; font-weight: 600; }
.area-list li a small { color: var(--text-muted); }
.area-chip { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin: var(--s-4) 0 0; padding: 12px var(--s-4); background: var(--primary-soft); border: 1px solid var(--primary-pale); border-radius: var(--radius-control); }
.area-chip small { color: var(--text-muted); }
.area-chip a { flex: none; display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px; font-weight: 600; text-decoration: none; }

/* Pin page: full screen map */
body.pinpage { display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: var(--surface); background-image: none; }
.pin-top { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-3); background: var(--surface); border-bottom: 1px solid var(--border); }
.pin-top a { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--radius-control); color: var(--text); font-size: 22px; text-decoration: none; }
.pin-top a:hover { background: var(--bg); }
.pin-top div { flex: 1; min-width: 0; }
.pin-top b { display: block; }
.pin-top small { display: block; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-top button { flex: none; width: auto; min-height: 44px; margin: 0; padding: 0 var(--s-3); font-size: 14px; }
.pin-wrap { position: relative; flex: 1; min-height: 0; }
#pinmap { position: absolute; inset: 0; padding: var(--s-4); background: var(--primary-soft); color: var(--text-muted); }
#hint { position: absolute; left: 50%; top: var(--s-3); z-index: 500; transform: translateX(-50%); max-width: 90%; padding: 8px 14px; border-radius: var(--radius-control); background: rgba(15, 23, 42, 0.85); color: #fff; font-size: 13px; text-align: center; pointer-events: none; }
.pin-bar { display: grid; gap: var(--s-2); padding: var(--s-3) var(--s-4) calc(var(--s-4) + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
.pin-bar small { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.pin-bar button { margin: 0; }
.pin-bar .msg { margin: 0; }

/* ---------- Dialog ---------- */
.dlg-overlay { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: flex-end; justify-content: center; padding: var(--s-4); background: rgba(15, 23, 42, 0); transition: background 0.18s ease; }
.dlg-overlay.show { background: rgba(15, 23, 42, 0.5); }
.dlg { width: 100%; max-width: 380px; padding: 24px var(--s-5) var(--s-5); background: var(--surface); border-radius: var(--radius-card); text-align: center; box-shadow: var(--shadow-pop); transform: translateY(24px) scale(0.98); opacity: 0; transition: transform 0.2s ease, opacity 0.18s ease; }
.dlg-overlay.show .dlg { transform: none; opacity: 1; }
.dlg-icon { width: 52px; height: 52px; margin: 0 auto var(--s-3); display: grid; place-items: center; border-radius: 50%; background: var(--primary-soft); color: var(--primary); }
.dlg-icon.danger { background: var(--error-soft); color: var(--error); }
.dlg h3 { margin: 0 0 6px; font-size: 18px; }
.dlg p { margin: 0 0 var(--s-5); color: var(--text-muted); font-size: 15px; line-height: 1.5; overflow-wrap: anywhere; }
.dlg-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
.dlg-actions button { margin: 0; }
body.dlg-open { overflow: hidden; }
@media (min-width: 560px) { .dlg-overlay { align-items: center; } }

/* ---------- Permission (consent) page ---------- */
.perm-list { list-style: none; margin: 0 0 var(--s-2); padding: 0; display: grid; gap: var(--s-2); }
.perm-list li { display: flex; align-items: center; gap: var(--s-3); padding: 12px var(--s-4); background: var(--primary-soft); border: 1px solid var(--primary-pale); border-radius: var(--radius-control); font-weight: 500; }
.perm-list li::before { content: "✓" / ""; flex: none; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; background: var(--primary); color: #fff; font-size: 14px; font-weight: 700; }

/* ---------- Admin ---------- */
.table-wrap { margin-top: var(--s-4); }
table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users th, table.users td { padding: 12px var(--s-3); border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.users th { color: var(--text-muted); font-size: 13px; font-weight: 600; background: var(--bg); }
table.users td:last-child { text-align: right; }
table.users button { width: auto; min-height: 40px; margin: 0; padding: 0 var(--s-3); font-size: 14px; }
@media (max-width: 719px) {
  table.users, table.users tbody { display: block; }
  table.users thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.users tr { display: grid; gap: 2px; margin-bottom: var(--s-3); padding: var(--s-3) var(--s-4); border: 1px solid var(--border); border-radius: 16px; }
  table.users td { display: flex; justify-content: space-between; gap: var(--s-3); padding: 6px 0; border: 0; text-align: right; }
  table.users td::before { content: attr(data-label); color: var(--text-muted); font-weight: 500; text-align: left; }
  table.users td:last-child { padding-top: var(--s-2); }
  table.users td:last-child::before { content: ""; }
  table.users td:last-child button { width: 100%; }
}

/* ---------- Small screens ---------- */
@media (max-width: 359px) {
  .page { padding-left: var(--s-3); padding-right: var(--s-3); }
  .card { padding: var(--s-4); }
  h1 { font-size: 20px; }
}

.links a.plain { display: inline; min-height: 0; padding: 0; }
