/* ── Reset & base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --orange:      #E8432C;
  --orange-dim:  rgba(232, 67, 44, 0.1);
  --orange-dark: #c73520;
  --bg:          #f4f4f4;
  --surface:     #ffffff;
  --border:      #e2e2e2;
  --border-lit:  #cccccc;
  --text:        #1a1a1a;
  --text-muted:  #666666;
  --text-dim:    #aaaaaa;
  --radius-sm:   10px;
  --radius:      14px;
  --radius-lg:   20px;
  --shadow:      0 1px 4px rgba(0,0,0,.08);
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* ── Header ────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  height: 26px;
  width: auto;
  display: block;
}

#settings-btn {
  background: none;
  border: 1px solid var(--border-lit);
  color: var(--text-muted);
  font-size: .85rem;
  cursor: pointer;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
#settings-btn:hover { background: var(--bg); color: var(--text); }

/* ── Main ──────────────────────────────────────────────── */
main {
  max-width: 560px;
  margin: 0 auto;
  padding: 1.25rem 1rem 7.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── Card ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .65rem;
  scroll-margin-top: 64px;
}

/* ── Pill grid ─────────────────────────────────────────── */
.pill-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
}

.pill-grid.cols-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .45rem;
}

/* ── Pill button ───────────────────────────────────────── */
.pill {
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: 100px;
  padding: .65rem 1rem;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  color: var(--text-muted);
  transition: all .12s;
  line-height: 1.3;
}

.pill:hover:not(:disabled) {
  border-color: var(--border-lit);
  color: var(--text);
}

.pill.active {
  border-color: var(--orange);
  background: var(--orange-dim);
  color: var(--orange-dark);
  font-weight: 600;
}

.pill:disabled {
  opacity: .3;
  cursor: not-allowed;
}

/* Stock badge on wine pills */
.pill .stock-count {
  display: block;
  font-size: .65rem;
  font-weight: 400;
  color: var(--text-dim);
  margin-top: .15rem;
}
.pill.active .stock-count { color: var(--orange); opacity: .75; }

/* ── Vintage row ───────────────────────────────────────── */
#vintage-row {
  display: flex;
  gap: .45rem;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#vintage-row::-webkit-scrollbar { display: none; }

/* ── Stock display ─────────────────────────────────────── */
#stock-display {
  font-size: .75rem;
  color: var(--text-dim);
}
#stock-display strong { color: var(--orange-dark); }

/* ── For section ───────────────────────────────────────── */
.cellar-door-badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: var(--orange-dim);
  border: 1.5px solid var(--orange);
  color: var(--orange-dark);
  border-radius: 100px;
  padding: .6rem 1rem;
  font-size: .9rem;
  font-weight: 600;
}
.cellar-door-badge::before { content: '✓'; }

.text-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s;
  appearance: none;
}
.text-input::placeholder { color: var(--text-dim); }
.text-input:focus { outline: none; border-color: var(--orange); }

/* ── Qty row ───────────────────────────────────────────── */
#qty-row {
  display: flex;
  gap: .45rem;
  flex-wrap: wrap;
  align-items: center;
}

#qty-custom {
  border: 1.5px solid var(--border);
  border-radius: 100px;
  padding: .65rem .9rem;
  font-size: .9rem;
  font-weight: 500;
  width: 5rem;
  color: var(--text);
  background: var(--surface);
  text-align: center;
  transition: border-color .15s;
}
#qty-custom::placeholder { color: var(--text-dim); }
#qty-custom:focus { outline: none; border-color: var(--orange); }

/* ── Submit ────────────────────────────────────────────── */
#submit-btn {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 2rem);
  max-width: 400px;
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: 100px;
  padding: 1rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: .01em;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(232, 67, 44, 0.35);
  transition: opacity .15s, box-shadow .15s;
  z-index: 50;
}
#submit-btn:active { opacity: .9; }
#submit-btn:disabled {
  background: var(--border);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

/* ── Toast ─────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  opacity: 0;
  pointer-events: none;
  background: var(--text);
  color: #fff;
  padding: .75rem 1.4rem;
  border-radius: 100px;
  font-size: .88rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
  transition: opacity .25s ease, transform .25s ease;
  white-space: nowrap;
  z-index: 999;
  max-width: 88vw;
  text-align: center;
}
#toast.error { background: var(--orange); }
#toast.show  { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }

/* ── Loading ───────────────────────────────────────────── */
#loading {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}
#loading.show { display: flex; }

/* ── Settings panel ────────────────────────────────────── */
#settings-panel {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 300;
  align-items: flex-end;
  justify-content: center;
}
#settings-panel.show { display: flex; }

#settings-inner {
  background: var(--surface);
  width: 100%;
  max-width: 560px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 1.5rem 1.25rem 2.5rem;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 -4px 24px rgba(0,0,0,.12);
}

#settings-inner h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#close-settings {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: .1rem .3rem;
}

.setting-group { margin-bottom: 1.1rem; }

.setting-group label {
  display: block;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  margin-bottom: .4rem;
}

.setting-group input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .65rem .9rem;
  font-size: .95rem;
  color: var(--text);
  background: var(--surface);
}
.setting-group input:focus { outline: none; border-color: var(--orange); }

.setting-hint { font-size: .7rem; color: var(--text-dim); margin-top: .25rem; }

#save-settings-btn {
  width: 100%;
  background: var(--orange);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: .85rem;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: .5rem;
}

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