:root {
  --bg: #f2f5f9;
  --surface: #ffffff;
  --surface-2: #edf2f8;
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.09);
  --primary: #007aff;
  --primary-pressed: #0062cc;
  --primary-soft: rgba(0, 122, 255, 0.12);
  --success: #16a34a;
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
  --radius: 16px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #141e33;
    --surface-2: #1d2a44;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.09);
    --primary: #3898ff;
    --primary-pressed: #1d7fe8;
    --primary-soft: rgba(56, 152, 255, 0.18);
    --success: #22c55e;
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.14);
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding-top: var(--safe-top);
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  flex-shrink: 0;
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
}

/* Layout */
.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}

.order-layout {
  padding-bottom: calc(112px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.center-screen {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

h1 {
  margin: 0 0 8px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.muted {
  color: var(--muted);
  margin: 0;
}

.small {
  font-size: 14px;
}

.sublabel {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.hint.center {
  text-align: center;
}

/* Buttons */
button,
a.primary-btn {
  font-family: inherit;
  cursor: pointer;
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 12px 18px;
  border: none;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.08s ease, opacity 0.15s ease, background 0.15s ease;
}

.primary-btn:active:not(:disabled) {
  transform: scale(0.985);
  background: var(--primary-pressed);
}

.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 46px;
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.ghost-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 6px 11px;
  font-size: 13px;
  font-weight: 600;
}

.text-btn {
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  padding: 4px 6px;
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.field input,
.field select,
.inline-select select {
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.inline-error {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
}

/* Preset Banner */
.preset-banner {
  background: linear-gradient(135deg, var(--primary-soft), color-mix(in srgb, var(--surface) 88%, var(--primary)));
  border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preset-title {
  font-size: 14px;
  font-weight: 700;
}

.preset-sub {
  font-size: 13px;
  color: var(--muted);
}

.chip-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.chip-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Segmented Tabs */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 11px;
  gap: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* Product Cards */
.product-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.product-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.product-card.selected {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--surface) 95%, var(--primary));
}

.product-img {
  width: 58px;
  height: 58px;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
  padding: 4px;
  flex-shrink: 0;
}

.product-info {
  flex: 1;
  min-width: 0;
}

.product-title {
  font-size: 15px;
  font-weight: 650;
  line-height: 1.25;
}

.product-meta {
  margin-top: 3px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.product-price {
  color: var(--text);
  font-weight: 700;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.step-btn {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.step-btn.add {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.step-qty {
  min-width: 24px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Days Horizontal Strip */
.days-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.days-strip::-webkit-scrollbar {
  display: none;
}

.day-pill {
  flex: 0 0 auto;
  min-width: 84px;
  padding: 10px 12px;
  border-radius: 13px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
}

.day-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.day-pill-top {
  font-size: 13px;
  font-weight: 700;
}

.day-pill-sub {
  font-size: 12px;
  opacity: 0.78;
  font-variant-numeric: tabular-nums;
}

/* Intervals Grid */
.intervals-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.slot-pill {
  padding: 12px 10px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.slot-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.info-note {
  margin-top: 8px;
  padding: 9px 11px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--text);
  font-size: 13px;
}

/* Delivery Option Toggles */
.options-block {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.toggle-title {
  font-size: 15px;
  font-weight: 600;
}

.toggle-sub {
  font-size: 12px;
  color: var(--muted);
}

.ios-switch {
  appearance: none;
  -webkit-appearance: none;
  width: 50px;
  height: 30px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 32%, transparent);
  position: relative;
  flex-shrink: 0;
  transition: background 0.18s ease;
  cursor: pointer;
}

.ios-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.18s ease;
}

.ios-switch:checked {
  background: var(--primary);
}

.ios-switch:checked::after {
  transform: translateX(20px);
}

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

.time-subselect {
  padding-left: 4px;
}

.inline-select {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  color: var(--muted);
}

.inline-select select {
  width: auto;
  min-width: 124px;
  min-height: 40px;
  padding: 6px 12px;
}

/* Payment */
.pay-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.pay-card {
  text-align: left;
  padding: 12px;
  border-radius: 13px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.pay-card.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.pay-card:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pay-title {
  font-size: 14px;
  font-weight: 700;
}

.pay-sub {
  font-size: 12px;
  color: var(--muted);
}

/* Sticky Bottom Order Bar */
.order-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
}

.order-bar-inner {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.order-summary {
  min-width: 0;
  flex: 1;
}

.bar-total {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.bar-slot {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-btn {
  width: auto;
  min-width: 148px;
  padding: 12px 20px;
}

/* Success Screen */
.success-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 20px;
}

.success-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--success) 16%, transparent);
  color: var(--success);
  font-size: 32px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.yoomoney-btn {
  background: #8b3ffd;
}

/* Toast & Spinner */
.toast {
  position: fixed;
  top: calc(68px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #1e293b;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.toast.error {
  background: var(--danger);
}

.slots-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.spinner.sm {
  width: 18px;
  height: 18px;
  border-width: 2.5px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
