:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2d3f56;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #ef4444;
  --accent-dark: #b91c1c;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

body.alarm-active {
  overflow: hidden;
}

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 8px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #1a1215 0%, var(--bg) 100%);
}

.header h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.6);
}

.status-dot.alarm {
  background: var(--accent);
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.9);
  animation: pulse-dot 0.6s ease-in-out infinite alternate;
}

@keyframes pulse-dot {
  from { transform: scale(1); opacity: 1; }
  to { transform: scale(1.35); opacity: 0.7; }
}

.main {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 16px;
}

.hint strong {
  color: var(--accent);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field span {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field input,
.field textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  resize: vertical;
  transition: border-color 0.2s;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.coords-row {
  display: flex;
  gap: 12px;
}

.field-half {
  flex: 1;
  min-width: 0;
}

/* Mode toggle (Otomatis / Manual) */
.mode-toggle {
  display: flex;
  gap: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 14px;
}

.mode-btn {
  flex: 1;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.mode-btn.active {
  background: var(--accent-dark);
  color: white;
  box-shadow: 0 2px 8px rgba(185, 28, 28, 0.4);
}

/* Coordinate pills */
.coord-pill {
  flex: 1;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.coord-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.coord-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.coord-value.live {
  color: var(--success);
}

.gps-status {
  margin: 10px 0 12px;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.gps-status.live {
  color: var(--success);
}

.gps-status.error {
  color: var(--accent);
}

/* Disable address textarea visually when readonly (auto mode) */
.field textarea[readonly] {
  background: var(--surface-2);
  color: var(--muted);
  cursor: default;
}

.field textarea[readonly]:focus {
  border-color: var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s, background 0.2s;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #2e4058;
}

.btn-outline {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-outline:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--muted);
}

.btn-stop {
  background: #334155;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-stop:hover:not(:disabled) {
  background: #475569;
}

.btn-map {
  text-decoration: none;
  background: #1d4ed8;
  color: white;
  margin-bottom: 10px;
}

.btn-map:hover {
  background: #2563eb;
}

.audio-status {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.audio-status.ready {
  color: var(--success);
}

.emergency-card {
  border-color: rgba(239, 68, 68, 0.35);
  background: linear-gradient(160deg, #2a1518 0%, var(--surface) 50%);
}

.btn-emergency {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 120px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(145deg, #ef4444, #b91c1c);
  color: white;
  cursor: pointer;
  overflow: hidden;
  box-shadow:
    0 0 0 4px rgba(239, 68, 68, 0.25),
    0 12px 40px rgba(185, 28, 28, 0.55);
  transition: transform 0.15s, box-shadow 0.2s;
}

.btn-emergency:hover:not(:disabled) {
  box-shadow:
    0 0 0 6px rgba(239, 68, 68, 0.35),
    0 16px 48px rgba(185, 28, 28, 0.65);
}

.btn-emergency:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-emergency:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

.btn-emergency-ring {
  position: absolute;
  inset: -20%;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  animation: ring-pulse 2s ease-out infinite;
}

@keyframes ring-pulse {
  0% { transform: scale(0.6); opacity: 0.8; }
  100% { transform: scale(1.4); opacity: 0; }
}

.btn-emergency-text {
  position: relative;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  z-index: 1;
}

.admin-card .active-hint {
  color: var(--accent);
  font-weight: 600;
}

/* Alarm overlay */
.alarm-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.92);
}

.alarm-overlay[hidden] {
  display: none !important;
}

.alarm-overlay-inner {
  position: relative;
  width: 100%;
  max-width: 420px;
  text-align: center;
  padding: 28px 22px;
  border-radius: 20px;
  border: 2px solid var(--accent);
  background: linear-gradient(160deg, #3b0f14 0%, #1a0a0c 100%);
  box-shadow: 0 0 60px rgba(239, 68, 68, 0.45);
  animation: overlay-shake 0.4s ease-in-out;
}

@keyframes overlay-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.alarm-flash {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  background: rgba(239, 68, 68, 0.15);
  animation: flash 0.8s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes flash {
  from { opacity: 0.2; }
  to { opacity: 0.7; }
}

.alarm-icon {
  font-size: 3.5rem;
  margin-bottom: 8px;
  animation: bounce 0.5s ease infinite alternate;
  position: relative;
  z-index: 1;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}

.alarm-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: #fecaca;
  letter-spacing: 0.04em;
  position: relative;
  z-index: 1;
}

.alarm-subtitle {
  font-size: 0.9rem;
  color: #fca5a5;
  margin: 6px 0 20px;
  position: relative;
  z-index: 1;
}

.alarm-details {
  text-align: left;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 18px;
  position: relative;
  z-index: 1;
}

.detail-row {
  margin-bottom: 12px;
}

.detail-row:last-child {
  margin-bottom: 0;
}

.detail-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #f87171;
  margin-bottom: 4px;
}

.detail-value {
  font-size: 0.95rem;
  color: var(--text);
  word-break: break-word;
}

.overlay-stop {
  position: relative;
  z-index: 1;
}

/* ============ AUTH PAGES ============ */
.auth-container {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.auth-card h1 {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 24px;
}

.auth-card form {
  text-align: left;
}

.auth-card select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}

.auth-link {
  margin-top: 16px;
  font-size: 0.85rem;
  color: var(--muted);
}

.auth-link a {
  color: var(--accent);
  text-decoration: none;
}

.error-msg {
  background: rgba(239,68,68,0.15);
  border: 1px solid rgba(239,68,68,0.4);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.success-msg {
  background: rgba(34,197,94,0.15);
  border: 1px solid rgba(34,197,94,0.4);
  color: #86efac;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.btn-primary {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: white;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 8px;
}

.btn-primary:hover { opacity: 0.9; }

/* ============ USER INFO HEADER ============ */
.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-info span {
  font-size: 0.8rem;
  color: var(--muted);
}

.btn-logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.75rem;
  cursor: pointer;
  text-decoration: none;
}

.btn-logout:hover { color: var(--text); border-color: var(--muted); }

/* ============ ALARM TYPE SELECTOR ============ */
.alarm-types {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.alarm-type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 8px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, color 0.2s, transform 0.1s;
}

.alarm-type-btn .at-icon { font-size: 1.8rem; }
.alarm-type-btn .at-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }

.alarm-type-btn.selected {
  border-color: var(--accent);
  background: rgba(239,68,68,0.12);
  color: var(--text);
}

.alarm-type-btn[data-type="kecelakaan"].selected { border-color: #f59e0b; background: rgba(245,158,11,0.12); }
.alarm-type-btn[data-type="kejahatan"].selected { border-color: #8b5cf6; background: rgba(139,92,246,0.12); }
.alarm-type-btn[data-type="banjir"].selected { border-color: #3b82f6; background: rgba(59,130,246,0.12); }

.alarm-type-btn:active { transform: scale(0.96); }

/* ============ ADMIN PANEL ============ */
.user-row, .history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.user-row:last-child, .history-row:last-child { border-bottom: none; }

.user-row small, .history-row small { color: var(--muted); font-size: 0.75rem; }

.user-actions { display: flex; gap: 6px; }

.btn-sm {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-approve { background: #22c55e; color: white; }
.btn-reject { background: #ef4444; color: white; }

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.role-warga { background: rgba(34,197,94,0.2); color: #86efac; }
.role-petugas { background: rgba(59,130,246,0.2); color: #93c5fd; }
.role-admin { background: rgba(245,158,11,0.2); color: #fcd34d; }

.history-row { align-items: flex-start; }
.h-icon { font-size: 1.5rem; flex-shrink: 0; }
.h-info { flex: 1; min-width: 0; }
.h-info strong { font-size: 0.85rem; }

/* ============ SELFIE ============ */
.selfie-container {
  width: 200px;
  height: 200px;
  margin: 0 auto 12px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--border);
  background: var(--surface-2);
}

.selfie-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.selfie-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 8px;
}

.selfie-actions .btn {
  width: auto;
  padding: 10px 16px;
  font-size: 0.85rem;
}

/* Admin panel selfie thumbnail */
.user-selfie {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--border);
}

/* Status badge */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-left: 4px;
}
.status-active { background: rgba(34,197,94,0.2); color: #86efac; }
.status-inactive { background: rgba(239,68,68,0.2); color: #fca5a5; }

.btn-warn { background: #f59e0b; color: #1a1a1a; }

/* ============ KTP UPLOAD ============ */
.ktp-container {
  width: 100%;
  max-width: 320px;
  height: 200px;
  margin: 0 auto 12px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px dashed var(--border);
  background: var(--surface-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ktp-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.ktp-placeholder {
  text-align: center;
  color: var(--muted);
}

.ktp-placeholder span {
  font-size: 3rem;
  display: block;
  margin-bottom: 8px;
}

.ktp-placeholder p {
  font-size: 0.85rem;
}

/* Admin KTP thumbnail */
.user-ktp {
  width: 60px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
  cursor: pointer;
}
.user-ktp:hover { border-color: var(--accent); }

/* ============ ADMIN TABS ============ */
.admin-tabs {
  display: flex;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 16px;
}
.tab-btn {
  flex: 1;
  padding: 10px 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.tab-btn.active { background: var(--accent-dark); color: white; }
.tab-content { display: none; }
.tab-content.active { display: block; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stat-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 12px;
  text-align: center;
}
.stat-num {
  font-size: 1.6rem;
  font-weight: 800;
  color: #fecaca;
  line-height: 1.1;
}
.stat-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Report filters */
.report-filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.report-filters .field { flex: 1; min-width: 140px; margin-bottom: 0; }
.report-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.report-actions .btn { flex: 1; min-width: 140px; }
