:root {
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-input: #16213e;
  --bg-header: #0e0e1a;
  --text: #e0e0e0;
  --text-muted: #8888aa;
  --accent: #4f6ef7;
  --accent-hover: #3b5ae0;
  --success: #2ecc71;
  --warning: #f39c12;
  --danger: #e74c3c;
  --border: #2a2a40;
  --radius: 12px;
  --radius-sm: 8px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ─── Screens ───────────────────────────────────────── */
.screen {
  display: none;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ─── Header ────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 12px;
}

.app-header h2 {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* ─── Buttons ───────────────────────────────────────── */
.btn {
  border: none;
  cursor: pointer;
  font-size: 16px;
  font-family: inherit;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: white;
  padding: 14px 24px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  width: 100%;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-icon {
  background: transparent;
  color: var(--text);
  font-size: 22px;
  padding: 8px;
  border-radius: var(--radius-sm);
  min-width: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover { background: var(--bg-card); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 500;
  border: 1px solid var(--border);
}

.btn-secondary:hover { border-color: var(--accent); }

.btn-copy {
  background: var(--success);
  color: white;
  padding: 16px 24px;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 700;
  width: 100%;
  min-height: 56px;
}

.btn-copy:active { transform: scale(0.97); }
.btn-copy.copied { background: #27ae60; }

/* ─── Login ─────────────────────────────────────────── */
.login-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px;
  min-height: 100dvh;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 32px;
  text-align: center;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
}

.form-group input.invalid {
  border-color: var(--danger);
}

.error-msg {
  color: var(--danger);
  font-size: 14px;
  margin-top: 12px;
  text-align: center;
}

/* ─── Store Tabs ────────────────────────────────────── */
.store-tabs {
  display: flex;
  padding: 8px 16px;
  gap: 8px;
  background: var(--bg-header);
}

.tab {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  transition: all 0.15s;
}

.tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* ─── Content Area ──────────────────────────────────── */
.content-area {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
}

/* ─── Cards ─────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.card:hover { border-color: var(--accent); }
.card:active { transform: scale(0.99); }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ─── Badges ────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-pending {
  background: rgba(243, 156, 18, 0.15);
  color: var(--warning);
}

.badge-fulfilled {
  background: rgba(46, 204, 113, 0.15);
  color: var(--success);
}

.badge-cmd {
  background: rgba(79, 110, 247, 0.15);
  color: var(--accent);
  font-size: 12px;
}

/* ─── Order Info ────────────────────────────────────── */
.order-info {
  margin-top: 10px;
}

.order-info-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

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

.info-label {
  color: var(--text-muted);
  min-width: 80px;
}

.line-item-props {
  margin: 8px 0 12px;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

/* ─── VIN Edit ─────────────────────────────────────── */
.vin-edit-row {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}

.vin-edit-input {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.vin-edit-input:focus { border-color: var(--accent); }

.btn-vin-lookup {
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

.btn-vin-lookup:hover { border-color: var(--accent); }

/* ─── Double VIN Cards ──────────────────────────────── */
.double-vin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.double-vin-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  color: var(--text);
  transition: all 0.15s;
}

.double-vin-card:hover { border-color: var(--accent); }

.dv-model { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.dv-meta { font-size: 12px; color: var(--text-muted); }
.dv-vin { font-size: 13px; color: var(--accent); font-weight: 600; margin-top: 6px; }
.dv-date { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ─── VIN Info ──────────────────────────────────────── */
.vin-info-container {
  margin: 8px 0 12px;
}

.vin-info {
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

.vin-info .loading {
  padding: 12px 0;
  font-size: 13px;
}

/* ─── Line Items ────────────────────────────────────── */
.line-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.line-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.line-item-title {
  font-size: 15px;
  font-weight: 500;
  flex: 1;
  margin-right: 8px;
}

.line-item-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.line-item-status {
  margin-bottom: 10px;
}

.line-item-fulfilled {
  opacity: 0.6;
  padding: 12px;
}

.line-item-fulfilled .line-item-meta {
  margin-bottom: 0;
}

.line-item-fulfilled.expanded {
  opacity: 1;
}

.fulfilled-expand {
  margin-top: 10px;
}

.badge-warning {
  background: rgba(243, 156, 18, 0.15);
  color: var(--warning);
}

.btn-process {
  background: var(--accent);
  color: white;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  width: 100%;
  min-height: 44px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.btn-process:active { transform: scale(0.98); }

.btn-delete {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  width: 100%;
  margin-top: 16px;
  cursor: pointer;
  font-family: inherit;
}

.btn-delete:hover { background: rgba(231, 76, 60, 0.1); }
.btn-delete:disabled { opacity: 0.5; }

/* ─── Feature Form ──────────────────────────────────── */
.download-type-selector {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 0;
}

.download-type-btn {
  padding: 16px 20px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  transition: all 0.15s;
}

.download-type-btn:hover { border-color: var(--accent); }
.download-type-btn.selected {
  border-color: var(--accent);
  background: rgba(79, 110, 247, 0.1);
}

.feature-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-order-info {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
}

.form-order-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.form-order-variant {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 6px;
}

.form-order-info .order-info-row {
  font-size: 12px;
}

.vin-display {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.option-btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  min-height: 48px;
}

.option-btn:hover { border-color: var(--accent); }
.option-btn.selected {
  border-color: var(--accent);
  background: rgba(79, 110, 247, 0.1);
}

/* ─── Result ────────────────────────────────────────── */
.result-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.result-box strong, .result-box b {
  color: white;
}

.result-nav {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.result-nav .btn {
  flex: 1;
}

/* ─── Loading & Empty States ────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
  color: var(--text-muted);
  font-size: 15px;
}

.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 12px;
}

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

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}

/* ─── Utilities ─────────────────────────────────────── */
.hidden { display: none !important; }

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }

/* ─── Toast / Notification ──────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  color: var(--text);
  padding: 12px 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 14px;
  z-index: 100;
  animation: fadeInUp 0.2s ease;
}

.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── Bottom bar ────────────────────────────────────── */
.bottom-bar {
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* ─── Feature Grid ──────────────────────────────────── */
.feature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}

.feature-grid-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  font-family: inherit;
  transition: all 0.15s;
}

.feature-grid-btn:hover { border-color: var(--accent); }
.feature-grid-btn:active { transform: scale(0.97); }

/* ─── Sync bar ──────────────────────────────────────── */
.sync-bar {
  padding: 8px 16px 16px;
  text-align: center;
}

.btn-sync-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  font-family: inherit;
  padding: 8px;
}

.btn-sync-link:hover { color: var(--accent); }
.btn-sync-link:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Sync button loading state ─────────────────────── */
.btn-icon.loading-spin {
  animation: spin 1s linear infinite;
}
