/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --brand: #E8470A;
  --brand-dark: #C73A06;
  --brand-light: #FF6B35;
  --bg: #FAFAF8;
  --surface: #FFFFFF;
  --surface2: #F4F3F0;
  --text: #1A1A18;
  --text2: #6B6B67;
  --text3: #A8A8A3;
  --border: #E8E8E3;
  --success: #22C55E;
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── App Shell ── */
#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* ── Screens ── */
.screen {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

.screen.active {
  display: flex;
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-top: calc(16px + var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.hamburger {
  width: 40px;
  height: 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all 0.2s;
}

.logo-small {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.logo-icon-sm {
  width: 22px;
  height: 22px;
  color: var(--brand);
}

/* ── Balance chip ── */
.balance-chip {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--surface2);
  border-radius: 100px;
  padding: 6px 6px 6px 12px;
}

.balance-chip span {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.add-credits-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brand);
  color: white;
  border: none;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.15s, transform 0.1s;
}

.add-credits-btn:active { transform: scale(0.92); background: var(--brand-dark); }

/* ── Sidebar ── */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  background: var(--surface);
  z-index: 101;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  padding-bottom: calc(24px + var(--safe-bottom));
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  padding: 24px 20px;
  padding-top: calc(24px + var(--safe-top));
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--brand);
}

.sidebar-logo .logo-icon {
  width: 28px;
  height: 28px;
  color: var(--brand);
}

.sidebar-nav {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}

.sidebar-nav li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 24px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s;
  border-radius: 0;
}

.sidebar-nav li svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-nav li:active,
.sidebar-nav li.active {
  color: var(--brand);
  background: rgba(232, 71, 10, 0.06);
}

.sidebar-logout {
  margin: 0 20px;
  padding: 14px;
  background: var(--surface2);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text2);
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
}

.sidebar-logout:active { background: var(--border); }

/* ── Auth Screen ── */
#screen-auth.active {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 32px 24px;
  padding-bottom: calc(32px + var(--safe-bottom));
}

.auth-wrap {
  width: 100%;
  max-width: 380px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 48px;
}

.logo-icon-lg {
  width: 64px;
  height: 64px;
  color: var(--brand);
  margin-bottom: 12px;
}

.auth-logo h1 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -1px;
}

.auth-logo p {
  color: var(--text2);
  font-size: 0.95rem;
  margin-top: 4px;
}

.auth-step {
  display: none;
  flex-direction: column;
  gap: 14px;
}

.auth-step.active { display: flex; }

.auth-step label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.phone-input-wrap {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
  transition: border-color 0.15s;
}

.phone-input-wrap:focus-within { border-color: var(--brand); }

.phone-flag {
  padding: 14px 12px;
  font-size: 0.95rem;
  color: var(--text2);
  border-right: 1.5px solid var(--border);
  white-space: nowrap;
}

.phone-input-wrap input {
  flex: 1;
  border: none;
  padding: 14px;
  font-size: 1rem;
  font-family: var(--font);
  color: var(--text);
  background: transparent;
  outline: none;
}

.field-row {
  display: flex;
  gap: 10px;
}

.field-row .text-input { flex: 1; }

.auth-note {
  font-size: 0.82rem;
  color: var(--text3);
  text-align: center;
}

/* OTP inputs */
.otp-inputs {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.otp-digit {
  width: 48px;
  height: 56px;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  font-family: var(--font);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, transform 0.1s;
}

.otp-digit:focus {
  border-color: var(--brand);
  transform: scale(1.04);
}

.otp-digit.filled {
  border-color: var(--brand);
  background: rgba(232, 71, 10, 0.04);
}

/* ── Buttons ── */
.btn-primary {
  width: 100%;
  padding: 16px;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  letter-spacing: -0.2px;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary:active { background: var(--brand-dark); transform: scale(0.98); }
.btn-primary:disabled { background: var(--text3); cursor: not-allowed; }

.btn-ghost {
  width: 100%;
  padding: 14px;
  background: transparent;
  color: var(--text2);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: color 0.15s;
}

.btn-ghost:active { color: var(--text); }

.btn-danger {
  width: 100%;
  padding: 16px;
  background: #FEE2E2;
  color: #DC2626;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s;
}

.btn-danger:active { background: #FCA5A5; }

/* ── Home ── */
.home-body {
  flex: 1;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(32px + var(--safe-bottom));
}

.greeting h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.greeting p {
  color: var(--text2);
  font-size: 0.95rem;
  margin-top: 4px;
}

/* Search */
.search-wrap {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text3);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 14px 14px 14px 42px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus { border-color: var(--brand); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.manual-entry-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 6px 0;
  cursor: pointer;
  text-decoration: underline;
  display: block;
  margin-top: 4px;
}

.manual-entry {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 4px;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}

.search-result-item {
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item:active { background: var(--surface2); }

.search-result-item strong {
  display: block;
  font-size: 0.95rem;
  color: var(--text);
}

.search-result-item span {
  display: block;
  font-size: 0.82rem;
  color: var(--text3);
  margin-top: 2px;
}

.hidden { display: none !important; }

/* Restaurant card */
.restaurant-card {
  background: var(--surface);
  border: 1.5px solid var(--brand);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.restaurant-card-info {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.restaurant-card-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.restaurant-card-info > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.restaurant-card-info strong {
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.restaurant-card-info span {
  font-size: 0.8rem;
  color: var(--text3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hours-badge {
  display: inline-block;
  font-size: 0.75rem !important;
  font-weight: 600 !important;
  padding: 2px 8px;
  border-radius: 100px;
  background: #DCFCE7;
  color: #16A34A !important;
}

.hours-badge.closed {
  background: #FEE2E2;
  color: #DC2626 !important;
}

.clear-restaurant {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}

/* Order form */
.order-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.text-input {
  width: 100%;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}

.text-input:focus { border-color: var(--brand); }

textarea {
  width: 100%;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  outline: none;
  resize: none;
  transition: border-color 0.15s;
  line-height: 1.5;
}

textarea:focus { border-color: var(--brand); }

/* ── Swipe to Confirm ── */
.swipe-wrap {
  padding: 4px 0;
}

.swipe-track {
  position: relative;
  height: 60px;
  background: rgba(232, 71, 10, 0.08);
  border: 1.5px solid rgba(232, 71, 10, 0.2);
  border-radius: 100px;
  display: flex;
  align-items: center;
  overflow: hidden;
  user-select: none;
}

.swipe-thumb {
  position: absolute;
  left: 4px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  z-index: 2;
  transition: transform 0.1s, left 0s;
  box-shadow: 0 4px 12px rgba(232, 71, 10, 0.35);
}

.swipe-thumb svg {
  width: 22px;
  height: 22px;
  stroke: white;
}

.swipe-thumb:active { cursor: grabbing; }

.swipe-thumb.confirmed {
  background: var(--success);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.35);
}

.swipe-label {
  width: 100%;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--brand);
  pointer-events: none;
  transition: opacity 0.2s;
}

.order-cost-note {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text3);
}

/* ── Calling Screen ── */
#screen-calling.active {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.calling-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: 60px 24px 40px;
  padding-top: calc(60px + var(--safe-top));
  padding-bottom: calc(40px + var(--safe-bottom));
}

.calling-top {
  text-align: center;
  margin-bottom: 32px;
}

.calling-status {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 8px;
}

.calling-restaurant {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.calling-attempt {
  font-size: 0.85rem;
  color: var(--text3);
}

/* ── Blob Canvas ── */
.blob-stage {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  max-height: 360px;
}

#blob-canvas {
  width: 100%;
  height: 100%;
  max-width: 360px;
  max-height: 360px;
}

.calling-bottom {
  text-align: center;
  margin-top: 24px;
}

.calling-order-preview {
  font-size: 0.88rem;
  color: var(--text2);
  margin-bottom: 12px;
  max-width: 280px;
  line-height: 1.5;
}

.calling-timer {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}

.cancel-order-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.5);
  font-size: 0.8rem;
  padding: 8px 20px;
  border-radius: 20px;
  cursor: pointer;
  margin-top: 16px;
}

/* ── Confirmed / Failed ── */
#screen-confirmed.active, #screen-failed.active {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}

.confirmed-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.confirmed-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.confirmed-icon svg {
  width: 32px;
  height: 32px;
}

.failed-icon { background: #EF4444; }

.confirmed-wrap h2 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.confirmed-wrap > p {
  color: var(--text2);
  font-size: 0.95rem;
}

.pickup-countdown {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 20px 0 8px;
}

.countdown-ring {
  position: relative;
  width: 80px;
  height: 80px;
}

.countdown-ring svg {
  width: 80px;
  height: 80px;
}

.countdown-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.countdown-text span {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  color: white;
}

.countdown-text small {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.7);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.countdown-label {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.6);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.confirmed-details {
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.confirmed-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.confirmed-row:last-child { border-bottom: none; }

.confirmed-row span {
  font-size: 0.88rem;
  color: var(--text2);
}

.confirmed-row strong {
  font-size: 0.95rem;
  color: var(--text);
}

.confirmed-sms {
  font-size: 0.82rem;
  color: var(--text3);
}

.failed-note {
  font-size: 0.9rem;
  color: var(--text2);
  line-height: 1.5;
}

/* ── Credits Screen ── */
.credits-body {
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.credits-subtitle {
  font-size: 0.9rem;
  color: var(--text2);
}

.topup-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.topup-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
  gap: 4px;
}

.topup-btn.selected {
  border-color: var(--brand);
  background: rgba(232, 71, 10, 0.04);
}

.topup-amount {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
}

.topup-orders {
  font-size: 0.75rem;
  color: var(--text3);
}

.topup-btn.selected .topup-amount { color: var(--brand); }

#card-element {
  padding: 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.error-msg {
  font-size: 0.85rem;
  color: #EF4444;
  min-height: 18px;
}

/* ── History Screen ── */
.history-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.empty-state {
  text-align: center;
  color: var(--text3);
  font-size: 0.95rem;
  padding: 48px 0;
}

.order-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.order-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.order-card-header strong {
  font-size: 1rem;
  color: var(--text);
}

.order-status-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 100px;
}

.status-confirmed { background: #DCFCE7; color: #16A34A; }
.status-failed, .status-no_answer { background: #FEE2E2; color: #DC2626; }
.status-calling, .status-pending { background: #FEF3C7; color: #D97706; }

.order-card-detail {
  font-size: 0.85rem;
  color: var(--text2);
  line-height: 1.5;
}

.order-card-date {
  font-size: 0.78rem;
  color: var(--text3);
}

/* ── Account Screen ── */
.account-body {
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.account-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
}

.account-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--brand);
  color: white;
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.account-card strong {
  font-size: 1.1rem;
  color: var(--text);
}

.account-card span {
  font-size: 0.9rem;
  color: var(--text3);
}

/* ── Loading overlay ── */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(250, 250, 248, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 200;
}

.loading.hidden { display: none; }

.loading-blob {
  width: 48px;
  height: 48px;
  background: var(--brand);
  border-radius: 50%;
  animation: loadingPulse 1.2s ease-in-out infinite;
}

@keyframes loadingPulse {
  0%, 100% { transform: scale(0.8); opacity: 0.6; border-radius: 50%; }
  50% { transform: scale(1.1); opacity: 1; border-radius: 40%; }
}

.loading p {
  font-size: 0.9rem;
  color: var(--text2);
  font-weight: 500;
}
