@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Inter:wght@300;400;500;600&display=swap');

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #1e1e1e;
  --border: #2a2a2a;
  --border-hover: #444;
  --text: #e8e8e8;
  --text-dim: #888;
  --text-muted: #555;
  --accent: #fff;
  --card-woolworths: #000;
  --card-lidl: #003778;
  --card-kmarket: #ff6400;
  --radius: 12px;
  --radius-sm: 8px;
  --check-stroke: #0a0a0a;
}

[data-theme="light"] {
  --bg: #f5f3f0;
  --surface: #ffffff;
  --surface-2: #eae8e5;
  --border: #d5d3d0;
  --border-hover: #b0ada8;
  --text: #1a1a1a;
  --text-dim: #666;
  --text-muted: #999;
  --accent: #1a1a1a;
  --check-stroke: #ffffff;
}

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

html {
  font-size: 14px;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* --- Header --- */

.header {
  padding: 24px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: 1rem;
  line-height: 1;
}

.theme-toggle:hover {
  border-color: var(--border-hover);
  background: var(--surface-2);
}

.icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

.logo {
  font-family: 'Space Mono', monospace;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text);
}

.logo span {
  color: var(--text-muted);
  font-weight: 400;
}

.header-tag {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* --- Main Container --- */

.main {
  max-width: 480px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* --- Card Carousel --- */

.carousel-section {
  margin-bottom: 40px;
}

.section-label {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 16px;
}

.cafe-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.carousel-wrapper {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
}

.carousel-track {
  display: flex;
  transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  cursor: grab;
}

.carousel-track:active {
  cursor: grabbing;
}

.card-preview {
  min-width: 100%;
  aspect-ratio: 1.585 / 1;
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  user-select: none;
}

.card-preview::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  pointer-events: none;
}

.card-store-name {
  font-family: 'Space Mono', monospace;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: white;
}

.card-description {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
  letter-spacing: 0.05em;
  margin-top: 4px;
}

.card-barcode {
  display: flex;
  align-items: center;
  gap: 12px;
}

.barcode-stripes {
  display: flex;
  gap: 1.5px;
  align-items: center;
  height: 40px;
  flex: 1;
}

.barcode-stripes span {
  display: block;
  height: 100%;
  background: rgba(255, 255, 255, 0.85);
}

.card-number-preview {
  font-family: 'Space Mono', monospace;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 0.1em;
}

/* QR Code Preview */

.qr-preview {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  width: 48px;
  height: 48px;
}

.qr-cell {
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.15);
}

.qr-cell.filled {
  background: rgba(255, 255, 255, 0.85);
}

/* Carousel dots */

.carousel-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.carousel-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 0;
}

.carousel-dot.active {
  background: var(--accent);
  width: 20px;
  border-radius: 3px;
}

/* Nav arrows */

.carousel-nav {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}

.carousel-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.carousel-btn:hover {
  border-color: var(--border-hover);
  background: var(--surface-2);
}

/* --- Form --- */

.form-section {
  margin-bottom: 32px;
}

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

.form-label {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 8px;
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'Space Mono', monospace;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-input:focus {
  border-color: var(--border-hover);
}

.form-input::placeholder {
  color: var(--text-muted);
}

/* --- Card Input Row + Scan Button --- */

.card-input-row {
  display: flex;
  gap: 8px;
}

.card-input-row .form-input {
  flex: 1;
}

.scan-btn {
  width: 50px;
  min-width: 50px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.scan-btn:hover {
  border-color: var(--border-hover);
  background: var(--surface-2);
}

.scan-btn:active {
  background: var(--border);
}

/* --- Scanner Overlay --- */

.scanner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.scanner-overlay.active {
  display: flex;
}

.scanner-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  overflow: hidden;
}

.scanner-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.scanner-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.scanner-close:hover {
  border-color: var(--border-hover);
  background: var(--surface-2);
}

#scannerView {
  width: 100%;
  min-height: 300px;
}

#scannerView video {
  border-radius: 0 !important;
}

.scanner-hint {
  padding: 12px 20px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* --- Location Picker --- */

.locations-section {
  margin-bottom: 32px;
}

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

.locations-count {
  font-family: 'Space Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-dim);
}

.locations-search {
  margin-bottom: 12px;
}

.locations-list {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--surface);
}

.location-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
}

.location-item:last-child {
  border-bottom: none;
}

.location-item:hover {
  background: var(--surface);
}

.location-item.selected {
  background: var(--surface-2);
}

.location-checkbox {
  width: 18px;
  height: 18px;
  min-width: 18px;
  border-radius: 4px;
  border: 1px solid var(--border-hover);
  background: transparent;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.location-item.selected .location-checkbox {
  background: var(--accent);
  border-color: var(--accent);
}

.location-checkbox svg {
  width: 12px;
  height: 12px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.location-item.selected .location-checkbox svg {
  opacity: 1;
}

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

.location-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
}

.location-address {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.locations-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.locations-city-header {
  padding: 8px 16px;
  font-family: 'Space Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

/* --- Wallet Button --- */

.wallet-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 12px;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.wallet-btn img {
  height: 64px;
  width: auto;
}

.wallet-btn svg {
  height: 64px;
  width: auto;
}

.wallet-btn:hover {
  opacity: 0.85;
  transform: translateY(-1px);
}

.wallet-btn:active {
  transform: translateY(0);
}

.wallet-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* --- Error --- */

.error-msg {
  margin-top: 12px;
  padding: 12px 16px;
  background: rgba(255, 60, 60, 0.08);
  border: 1px solid rgba(255, 60, 60, 0.2);
  border-radius: var(--radius-sm);
  color: #ff6b6b;
  font-size: 0.8rem;
  text-align: center;
  display: none;
}

/* --- Divider --- */

.divider {
  height: 1px;
  background: var(--border);
  margin: 32px 0;
}

/* --- Responsive --- */

@media (max-width: 520px) {
  .main {
    padding: 24px 16px 60px;
  }

  .header {
    padding: 16px 20px;
  }

  .card-preview {
    padding: 20px;
  }
}

/* --- Scrollbar --- */

.locations-list::-webkit-scrollbar {
  width: 4px;
}

.locations-list::-webkit-scrollbar-track {
  background: var(--surface);
}

.locations-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}
