:root {
  --bg: #0C0B09;
  --bg-2: #141311;
  --bg-3: #1C1A18;
  --surface: #171513;
  --surface-2: #24211D;
  --border: #2A2622;
  --border-2: #38332E;
  --text: #F4EFE6;
  --text-2: #C4BBAF;
  --text-3: #8C8477;
  --accent: #C8A97E;
  --accent-dim: #C8A97E33;
  --accent-bg: #2B2318;
  --nav-h: 0px;
  --safe-bottom: env(safe-area-inset-bottom, 20px);
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: #0A0A0A;
  color: var(--text);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  min-height: 100vh;
  background: var(--bg);
  box-shadow: 0 0 40px rgba(0,0,0,0.8);
  border-left: 1px solid var(--surface-2);
  border-right: 1px solid var(--surface-2);
  display: flex;
  flex-direction: column;
}
img { display: block; max-width: 100%; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea, select { font-family: inherit; }
.serif { font-family: 'Instrument Serif', serif; }

/* ─── Pages ─── */
.page { display: none; flex-direction: column; min-height: 100vh; }
.page.active { display: flex; }

/* ─── Header ─── */
.app-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px;
  background: rgba(12,11,9,0.85);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 100;
  border-bottom: 1px solid var(--border);
}
.header-logo { font-family: 'Instrument Serif', serif; font-size: 24px; color: var(--text); letter-spacing: -0.5px; }
.header-logo span { color: var(--accent); }
.header-actions { display: flex; gap: 12px; }
.header-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  transition: all 0.2s;
}
.header-btn:hover { background: var(--surface-2); color: var(--text); }

/* ─── Category Tabs ─── */
.category-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.cat-tab {
  flex-shrink: 0;
  padding: 7px 16px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: all 0.2s;
  white-space: nowrap;
}
.cat-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0C0B09;
  font-weight: 600;
}
.cat-tab:active { transform: scale(0.94); }

/* ─── Grid Catalog ─── */
.kue-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 0 0 calc(var(--safe-bottom) + 24px);
}
.kue-card {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
  cursor: pointer;
}
.kue-card img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}
.kue-card:active img { transform: scale(1.04); }
.kue-card-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 32px 12px 12px;
  background: linear-gradient(to top, rgba(12,11,9,0.92) 0%, transparent 100%);
  transform: translateY(4px);
  transition: transform 0.3s ease;
}
.kue-card:hover .kue-card-overlay { transform: translateY(0); }
.kue-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kue-card-price {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  margin-top: 2px;
}
.kue-card-badge {
  position: absolute;
  top: 8px; right: 8px;
  background: rgba(12,11,9,0.75);
  backdrop-filter: blur(8px);
  border-radius: 100px;
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  border: 1px solid var(--border);
}
.kue-card.sold-out { opacity: 0.5; }
.kue-card.sold-out .kue-card-badge { color: #E8706A; border-color: #E8706A40; }

/* ─── Skeleton Loading ─── */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-card {
  aspect-ratio: 1;
  border-radius: 0;
}

/* ─── Modal ─── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  z-index: 300;
  display: none;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s;
}
.modal-backdrop.open {
  display: flex;
  opacity: 1;
}
.modal-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--bg-2);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  overflow: hidden;
  position: relative;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 90dvh;
  overflow-y: auto;
  scrollbar-width: none;
}
.modal-sheet::-webkit-scrollbar { display: none; }
.modal-backdrop.open .modal-sheet { transform: translateY(0); }
.modal-drag-handle {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  width: 36px; height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.6);
  z-index: 10;
}
.modal-img { 
  width: 100%; 
  aspect-ratio: 4 / 5; 
  object-fit: cover; 
  background: var(--surface-2);
}
.modal-body { padding: 20px 20px 32px; }
.modal-name {
  font-family: 'Instrument Serif', serif;
  font-size: 32px;
  line-height: 1.1;
  color: var(--text);
  margin-bottom: 8px;
}
.modal-price {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 12px;
}
.modal-desc {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.7;
  margin-bottom: 24px;
}
.modal-kategori {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 100px;
  border: 1px solid var(--border-2);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 20px;
}

/* ─── Buttons ─── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  transition: all 0.2s;
  width: 100%;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent);
  color: #0C0B09;
}
.btn-primary:hover { background: #D4B88C; }
.btn-primary:disabled { opacity: 0.5; pointer-events: none; }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-wa {
  background: #FFFFFF;
  color: #000000;
}
.btn-wa:hover { background: #EAEAEA; transform: scale(0.98); }

/* ─── Checkout Page ─── */
.checkout-wrap {
  padding: 20px 16px;
  flex: 1;
  padding-bottom: calc(var(--safe-bottom) + 40px);
}
.co-product {
  display: flex; gap: 16px; align-items: center;
  padding-bottom: 20px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.co-img { width: 64px; height: 64px; border-radius: var(--radius-md); object-fit: cover; }
.co-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.co-price { font-size: 14px; color: var(--accent); }

.checkout-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.form-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-3); }

.map-pick-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 13px 16px;
  background: var(--surface);
  border: 1px dashed var(--border-2);
  border-radius: var(--radius-md);
  color: var(--text-2);
  font-size: 14px;
  transition: all 0.2s;
}
.map-pick-btn:active { background: var(--surface-2); }
.map-pick-btn svg { color: var(--accent); flex-shrink: 0; }

.co-summary {
  margin: 24px 0;
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 16px;
}
.co-row { display: flex; justify-content: space-between; margin-bottom: 12px; font-size: 14px; color: var(--text-2); }
.co-row:last-child { margin-bottom: 0; padding-top: 12px; border-top: 1px dashed var(--border-2); font-size: 16px; font-weight: 700; color: var(--text); }
.co-row.error { color: #E8706A; justify-content: center; text-align: center; font-size: 13px; }

/* ─── Map Modal ─── */
#map-container { width: 100%; height: 300px; border-radius: var(--radius-md); overflow: hidden; }
.leaflet-container { background: var(--bg-3) !important; }

/* ─── Empty State ─── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  padding: 60px 20px;
  gap: 12px;
  color: var(--text-3);
}
.empty-state svg { opacity: 0.3; }
.empty-state p { font-size: 14px; text-align: center; }

/* ─── Spinner ─── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Toast ─── */
.toast {
  position: fixed;
  top: 70px; left: 50%; transform: translateX(-50%) translateY(-20px);
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-size: 14px;
  color: var(--text);
  z-index: 999;
  white-space: nowrap;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── Responsive ─── */
@media (min-width: 480px) {
  .app-header { width: 100%; max-width: 480px; }
  .modal-backdrop { left: 50%; right: auto; transform: translateX(-50%); width: 100%; max-width: 480px; }
}

/* ─── LIGHT MODE (AUTO) ─── */
/* ─── LIGHT MODE CLASS (TOGGLEABLE) ─── */
body.light-theme {
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --surface-2: #F5F5F5;
  --border: #E5E5E5;
  --border-2: #D4D4D4;
  --text: #171513;
  --text-2: #5C5751;
  --text-3: #8C8477;
  --accent: #B89768;
  --accent-dim: rgba(184, 151, 104, 0.15);
}
body.light-theme .app-container { box-shadow: 0 0 40px rgba(0,0,0,0.06); }
body.light-theme .kue-card-overlay { background: linear-gradient(0deg, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.7) 50%, transparent 100%); }
body.light-theme .kue-card-name, body.light-theme .kue-card-price { text-shadow: none; }
body.light-theme .modal-backdrop, body.light-theme .drawer-backdrop { background: rgba(255, 255, 255, 0.8); }

/* Theme Toggle Button */
.btn-icon {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}
.btn-icon:hover { background: var(--surface-2); }
