:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #111827;
  --ink-2: #6b7280;
  --ink-3: #9ca3af;
  --line: #e5e7eb;
  --line-2: #f1f3f5;
  --pill-bg: #ef4444;
  --flag-bg: #fef2f2;
  --flag-ink: #991b1b;
  --flag-pill-bg: #fee2e2;
  --min-bg: #eef2ff;
  --min-ink: #4338ca;
  --saved: #10b981;
  --saving: #f59e0b;
  --error: #dc2626;
  --warn-bg: #fef9c3;
  --warn-ink: #713f12;
  --btn-bg: #111827;
  --btn-ink: #ffffff;
  --btn-secondary-bg: #f3f4f6;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.app-header {
  background: var(--ink);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 5;
}
.app-header h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.auth-user {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #d1d5db;
  font-size: 12px;
  font-weight: 500;
}
.logout-btn {
  border: 1px solid rgba(255,255,255,.22);
  background: rgba(255,255,255,.08);
  color: #fff;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.pill {
  background: var(--pill-bg);
  color: #fff;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
}

.toggle {
  display: flex;
  background: var(--btn-secondary-bg);
  padding: 4px;
  margin: 12px;
  border-radius: 12px;
  font-size: 14px;
}
.login-panel {
  min-height: calc(100vh - 54px);
  display: grid;
  place-items: center;
  padding: 24px 14px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(17,24,39,.08);
}
.login-card h2 {
  margin: 0 0 14px;
  font-size: 20px;
}
.login-card label {
  display: block;
  margin: 12px 0;
}
.login-card label span {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
}
.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px 12px;
  color: var(--ink);
  font: inherit;
  background: #fff;
}
.login-card input:focus {
  outline: 2px solid var(--btn-bg);
  outline-offset: 2px;
}
.login-card .btn {
  width: 100%;
  margin-top: 8px;
}
.login-error {
  margin: 12px 0 0;
  color: var(--error);
  font-size: 13px;
}
.toggle .seg {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: 8px;
  color: var(--ink-2);
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.toggle .seg.active {
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.actions {
  display: flex;
  gap: 8px;
  padding: 0 12px 12px;
}
.btn {
  flex: 1;
  background: var(--btn-bg);
  color: var(--btn-ink);
  border: none;
  padding: 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn.secondary {
  background: var(--btn-secondary-bg);
  color: var(--ink);
}

.loading, .error {
  text-align: center;
  padding: 32px 16px;
  color: var(--ink-2);
}
.error {
  color: var(--error);
}

.view {
  padding: 0 0 80px;
}

.section-title {
  padding: 16px 16px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-3);
  font-weight: 600;
}

.brand-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 0 12px;
}
@media (min-width: 720px) {
  .brand-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (min-width: 1100px) {
  .brand-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.brand-block {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.brand-header {
  background: #f9fafb;
  padding: 10px 14px;
  font-weight: 700;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand-header .count {
  background: var(--pill-bg);
  color: #fff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.col-head {
  display: grid;
  grid-template-columns: 1fr 96px 96px 64px 44px;
  gap: 6px;
  padding: 6px 14px;
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: .05em;
  background: #fff;
}

.row {
  display: grid;
  grid-template-columns: 1fr 96px 96px 64px 44px;
  gap: 6px;
  align-items: center;
  padding: 10px 14px;
  border-top: 1px solid var(--line-2);
}
.row.flag {
  background: var(--flag-bg);
}
.row.flag .flavor::before {
  content: '⚠ ';
  color: var(--pill-bg);
}
.flavor {
  font-size: 14px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}

.stepper {
  display: inline-flex;
  align-items: center;
  background: var(--btn-secondary-bg);
  border-radius: 10px;
  overflow: hidden;
  height: 36px;
  user-select: none;
}
.stepper button {
  background: none;
  border: none;
  width: 30px;
  height: 36px;
  font-size: 20px;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.stepper button:disabled {
  color: var(--ink-3);
  cursor: not-allowed;
}
.stepper .val {
  min-width: 32px;
  text-align: center;
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  cursor: pointer;
}
.stepper .val:focus {
  outline: 2px solid var(--btn-bg);
  outline-offset: 2px;
}
.stepper.muted {
  background: #f9fafb;
}
.stepper.muted .val {
  color: var(--ink-2);
}

.min-pill {
  background: var(--min-bg);
  color: var(--min-ink);
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 999px;
  font-weight: 600;
  text-align: center;
  min-width: 36px;
  white-space: nowrap;
}
.min-pill.empty {
  background: var(--btn-secondary-bg);
  color: var(--ink-3);
}
.min-pill .label {
  font-weight: 500;
  opacity: .7;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-right: 2px;
}

.fill-btn {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
  font-size: 11px;
  padding: 6px 6px;
  border-radius: 8px;
  font-weight: 700;
  text-align: center;
  width: 44px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.fill-btn .arrow { font-size: 12px; }
.fill-btn .target { font-size: 11px; font-weight: 700; }
.fill-btn:hover { background: #d1fae5; }
.fill-btn:disabled {
  background: var(--btn-secondary-bg);
  color: var(--ink-3);
  border-color: var(--line);
  cursor: not-allowed;
}
.fill-btn.empty {
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--ink-3);
}

.save-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.save-dot.idle { background: transparent; }
.save-dot.saved { background: var(--saved); }
.save-dot.saving { background: var(--saving); animation: pulse 1s infinite; }
.save-dot.error { background: var(--error); }
@keyframes pulse { 50% { opacity: .35 } }

/* Order list */
.order-block { margin-bottom: 14px; padding: 0 12px; }
.order-row {
  background: var(--card);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-top: none;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
}
.order-row:first-of-type { border-top: 1px solid var(--line); border-radius: 10px 10px 0 0; }
.order-row:last-of-type { border-radius: 0 0 10px 10px; }
.order-row + .brand-header { margin-top: 12px; }
.order-row .flavor {
  font-size: 14px;
  font-weight: 500;
  grid-column: 1;
}
.order-row .badge {
  background: var(--flag-pill-bg);
  color: var(--flag-ink);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  font-weight: 600;
  grid-column: 2;
  grid-row: 1 / span 2;
}
.order-row .meta {
  grid-column: 1;
  color: var(--ink-2);
  font-size: 12px;
}
.meta b { color: var(--ink); }

.summary {
  padding: 14px 16px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 13px;
  border: 1px solid #fde68a;
  border-radius: 10px;
  margin: 12px;
}

#copy-preview {
  background: #1f2937;
  color: #e5e7eb;
  padding: 14px;
  border-radius: 10px;
  font-size: 12px;
  overflow-x: auto;
  margin: 12px;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
}
.toast.error { background: var(--error); }

.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #fef3c7;
  color: #78350f;
  padding: 8px 12px;
  text-align: center;
  font-size: 13px;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.btn-link {
  background: none;
  border: 1px solid #d97706;
  color: #78350f;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
