/* Pasticeria — internal app */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500;0,600;0,700;0,800;1,400&family=Inter:wght@300;400;500;600;700&family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Instrument+Serif:ital@0;1&family=Manrope:wght@300;400;500;600;700&family=DM+Sans:wght@400;500;600;700&family=Space+Grotesk:wght@400;500;600;700&display=swap');

:root {
  /* Palette defaults; overridden via Tweaks */
  --cream: #FDF8F3;
  --cream-2: #F6EEE3;
  --cream-3: #ECE0CE;
  --ink: #3B1F0A;
  --ink-2: #5C3D22;
  --ink-3: #8C6E51;
  --ink-mute: rgba(59, 31, 10, 0.55);
  --line: rgba(59, 31, 10, 0.12);
  --line-2: rgba(59, 31, 10, 0.22);
  --rose: #D4607A;
  --rose-soft: #F4D7DD;
  --green: #4CAF82;
  --green-soft: #D6EEDF;
  --amber: #D89331;
  --amber-soft: #F6E3BE;
  --teal: #4B948F;
  --teal-soft: #C9E1DF;
  --red: #C24A4A;
  --red-soft: #F5D5D2;
  --gray-soft: #E5DCCF;

  /* Density */
  --gap: 16px;
  --pad: 20px;
  --row-h: 56px;
  --radius: 14px;
  --radius-lg: 22px;

  /* Type */
  --font-display: 'Playfair Display', serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-size-base: 15px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01", "cv01";
  min-height: 100vh;
}

.display { font-family: var(--font-display); letter-spacing: -0.01em; }
.serif-italic { font-family: var(--font-display); font-style: italic; }
.tabular { font-variant-numeric: tabular-nums; }
.tracking-tight { letter-spacing: -0.02em; }
.muted { color: var(--ink-mute); }

/* ── App scaffold ─────────────────────────────────────────────────── */
#app {
  min-height: 100vh;
  display: flex;
  width: 100%;
}

/* Sidebar (desktop) */
.sidebar {
  width: 248px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: var(--cream);
  padding: 22px 16px 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  padding: 4px 10px 22px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar .brand-mark {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--cream);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 20px;
  font-weight: 600;
}
.sidebar .brand-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
}
.sidebar .brand-sub {
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-top: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--ink-2);
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  font-size: 14.5px;
  position: relative;
}
.nav-item:hover { background: var(--cream-2); color: var(--ink); }
.nav-item.active { background: var(--ink); color: var(--cream); }
.nav-item.active .nav-icon { color: var(--cream); }
.nav-item .nav-badge {
  margin-left: auto;
  background: var(--rose);
  color: white;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  min-width: 20px;
  text-align: center;
}
.nav-item.active .nav-badge { background: var(--rose); }

.sidebar-foot {
  margin-top: auto;
  padding: 12px 10px 4px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Main */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 28px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--cream);
  position: sticky; top: 0; z-index: 30;
}
.topbar h1 {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
  line-height: 1.05;
}
.topbar .crumbs {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 2px;
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
  padding-bottom: 60px;
}

/* Mobile nav */
.bottom-nav {
  display: none;
  position: sticky;
  bottom: 0;
  z-index: 30;
  background: rgba(253, 248, 243, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
  padding: 8px 4px 12px;
  justify-content: space-around;
}
.bottom-nav .nav-item {
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 10.5px;
  padding: 4px 6px 2px;
  letter-spacing: 0.02em;
  text-transform: none;
  background: transparent;
  color: var(--ink-mute);
  min-width: 60px;
  border-radius: 12px;
  transition: color 0.18s;
}
.bottom-nav .nav-item .nav-icon {
  width: 44px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  transition: background 0.18s, color 0.18s;
  color: inherit;
}
.bottom-nav .nav-item.active {
  background: transparent;
  color: var(--rose);
}
.bottom-nav .nav-item.active .nav-icon {
  background: color-mix(in srgb, var(--rose) 14%, transparent);
  color: var(--rose);
}

/* ── Generic UI ───────────────────────────────────────────────────── */
.card {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
}
.card-warm {
  background: var(--cream-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  border: none;
  background: var(--ink);
  color: var(--cream);
  font: inherit;
  font-weight: 500;
  font-size: 14.5px;
  cursor: pointer;
  user-select: none;
  transition: transform 80ms ease, background 100ms ease, box-shadow 100ms ease;
  white-space: nowrap;
}
.btn:hover { background: #2a1605; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line-2);
}
.btn.secondary:hover { background: var(--cream-2); }
.btn.rose { background: var(--rose); color: white; }
.btn.rose:hover { background: #c14d68; }
.btn.green { background: var(--green); color: white; }
.btn.green:hover { background: #3d9971; }
.btn.danger { background: transparent; color: var(--red); border: 1px solid rgba(194, 74, 74, 0.3); }
.btn.danger:hover { background: var(--red-soft); }
.btn.sm { height: 36px; padding: 0 14px; font-size: 13px; }
.btn.lg { height: 56px; padding: 0 24px; font-size: 16px; }
.btn.icon-only { width: 48px; padding: 0; }
.btn.icon-only.sm { width: 36px; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  display: grid; place-items: center;
  cursor: pointer;
  position: relative;
}
.icon-btn:hover { background: var(--cream-2); }
.icon-btn.bordered { border-color: var(--line); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  line-height: 1.1;
  border: 1px solid transparent;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }

.badge.pending { background: var(--gray-soft); color: #5a4a3a; }
.badge.in_progress { background: var(--amber-soft); color: #7a5418; }
.badge.dough_ready { background: #E8D5F5; color: #6B3A8C; }
.badge.ready { background: var(--green-soft); color: #285d3f; }
.badge.delivered { background: var(--teal-soft); color: #2e5856; }
.badge.cancelled { background: var(--red-soft); color: #8c2e2e; }

.badge.unpaid { background: var(--red-soft); color: #8c2e2e; }
.badge.deposit { background: var(--amber-soft); color: #7a5418; }
.badge.paid { background: var(--green-soft); color: #285d3f; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  font-weight: 500;
}
.chip:hover { background: var(--cream-2); }
.chip.active { background: var(--ink); color: var(--cream); border-color: var(--ink); }
.chip.active .count { background: rgba(255,255,255,0.18); color: var(--cream); }
.chip .count {
  background: var(--cream-3);
  color: var(--ink-2);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 600;
}

/* Form fields */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 600;
  color: var(--ink-mute);
}
.input, .textarea, .select {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--cream);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 100ms ease, background 100ms ease;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--ink);
  background: white;
}
.textarea {
  height: auto;
  min-height: 96px;
  padding: 12px 14px;
  resize: vertical;
  font-family: inherit;
}
.input.lg { height: 56px; font-size: 16px; }

/* Avatar */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  font-family: var(--font-display);
  font-style: italic;
}
.avatar.lg { width: 44px; height: 44px; font-size: 16px; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }

/* Order cards */
.order-card {
  display: flex;
  align-items: stretch;
  gap: 16px;
  padding: 16px;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 100ms ease, border-color 100ms ease, box-shadow 100ms ease;
}
.order-card:hover {
  border-color: var(--line-2);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px -10px rgba(59, 31, 10, 0.15);
}
.order-card .thumb {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 12px;
  overflow: hidden;
  background: var(--cream-2);
  position: relative;
}

/* Confidence bar */
.confidence-track {
  position: relative;
  height: 6px;
  background: var(--cream-3);
  border-radius: 999px;
  overflow: hidden;
}
.confidence-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  transition: width 600ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* PIN pad */
.pin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 320px;
  width: 100%;
}
.pin-key {
  height: 76px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: white;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: background 80ms ease, transform 60ms ease;
}
.pin-key:active { background: var(--cream-2); transform: scale(0.97); }
.pin-key.action {
  background: transparent;
  border: none;
  font-size: 14px;
  font-family: var(--font-body);
  font-weight: 500;
  color: var(--ink-mute);
}
.pin-dot {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--ink-3);
  transition: background 100ms ease, transform 200ms ease;
}
.pin-dot.filled { background: var(--ink); border-color: var(--ink); transform: scale(1.05); }
.pin-dot.error { background: var(--red); border-color: var(--red); animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* Dialog */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 17, 5, 0.42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
  animation: fadein 200ms ease;
}
.dialog {
  background: var(--cream);
  border-radius: var(--radius-lg);
  padding: 26px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,0.4);
  animation: popin 220ms cubic-bezier(0.18, 1.2, 0.4, 1);
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes popin {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

/* Notifications panel */
.notif-panel {
  position: absolute;
  top: 56px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px -10px rgba(59, 31, 10, 0.25);
  z-index: 60;
  overflow: hidden;
  animation: slidein 180ms cubic-bezier(0.18, 1.1, 0.4, 1);
}
@keyframes slidein {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

/* Density variants */
body[data-density="compact"] {
  --gap: 12px;
  --pad: 14px;
  --row-h: 48px;
  --radius: 10px;
  --radius-lg: 16px;
  --font-size-base: 14px;
}
body[data-density="compact"] .btn { height: 40px; padding: 0 14px; font-size: 13px; }
body[data-density="compact"] .topbar h1 { font-size: 24px; }
body[data-density="compact"] .order-card { padding: 12px; gap: 12px; }
body[data-density="compact"] .order-card .thumb { width: 56px; height: 56px; }
body[data-density="compact"] .scroll-area { padding: 20px; }

body[data-density="comfy"] {
  --gap: 22px;
  --pad: 26px;
  --row-h: 64px;
  --radius: 16px;
  --radius-lg: 26px;
  --font-size-base: 16px;
}
body[data-density="comfy"] .btn { height: 52px; }
body[data-density="comfy"] .topbar h1 { font-size: 36px; }
body[data-density="comfy"] .order-card { padding: 22px; gap: 20px; }
body[data-density="comfy"] .order-card .thumb { width: 80px; height: 80px; }
body[data-density="comfy"] .scroll-area { padding: 36px; }

/* Show/hide helpers */
.mobile-only { display: none !important; }

/* Responsive */
@media (max-width: 880px) {
  .mobile-only { display: grid !important; }
  #app { flex-direction: column; }
  .sidebar { display: none; }
  .bottom-nav { display: flex; }
  .topbar { padding: 14px 18px 12px; }
  .topbar h1 { font-size: 24px; }
  .scroll-area { padding: 18px; padding-bottom: 84px; }
  .order-card .thumb { width: 56px; height: 56px; }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .topbar h1 { font-size: 20px; }
  .scroll-area { padding: 14px; padding-bottom: 84px; }
  .bottom-nav { padding-bottom: max(12px, env(safe-area-inset-bottom)); }

  /* Settings: stack subnav above content on phones */
  .settings-grid { grid-template-columns: 1fr !important; }

  /* Payments: stack sparkline + aside vertically */
  .payments-grid { grid-template-columns: 1fr !important; }

  /* Corrections table: drop "Predicted" and "Δ" columns to fit screen */
  .corr-header { grid-template-columns: 44px 1fr 88px 64px !important; }
  .corr-row    { grid-template-columns: 44px 1fr 88px 64px !important; }
  .corr-header > span:nth-child(3),
  .corr-header > span:nth-child(5),
  .corr-row > div:nth-child(3),
  .corr-row > div:nth-child(5) { display: none; }

  /* Login screen: shrink oversized brand logo + name */
  .login-brand-logo { width: 56px !important; height: 56px !important; font-size: 26px !important; }
  .login-brand-name { font-size: 26px !important; }

  /* PIN pad: shorter keys on small phones */
  .pin-key { height: 64px; font-size: 26px; }
  .pin-grid { max-width: 100%; }
}

/* Decoration */
.gridlines {
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 24px 24px;
}

.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 16px 0;
}

.kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
  background: var(--cream);
  color: var(--ink-2);
}

/* Sparkline */
.spark { stroke: var(--rose); stroke-width: 2; fill: none; }
.spark-fill { fill: var(--rose); opacity: 0.08; }

/* status dot color helpers */
.dot-pending { background: #8C6E51; }
.dot-in_progress { background: var(--amber); }
.dot-dough_ready { background: #9B59B6; }
.dot-ready { background: var(--green); }
.dot-delivered { background: var(--teal); }
.dot-cancelled { background: var(--red); }

/* Subtle paper texture */
.paper-bg {
  background-color: var(--cream);
  background-image:
    radial-gradient(circle at 15% 30%, rgba(212, 96, 122, 0.04) 0, transparent 50%),
    radial-gradient(circle at 85% 70%, rgba(76, 175, 130, 0.04) 0, transparent 50%);
}

/* Loading spinner */
.spinner {
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: currentColor;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
.spinner.lg { width: 28px; height: 28px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Status timeline */
.timeline {
  display: flex;
  gap: 4px;
  width: 100%;
}
.timeline-step {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--cream-3);
}
.timeline-step.active { background: var(--ink); }
.timeline-step.cancelled { background: var(--red); }

/* Animations */
.fade-in { animation: fadein 240ms ease; }
.slide-up { animation: slideup 240ms cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes slideup {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

/* Font-pair variants */
body[data-fontpair="editorial"] {
  --font-display: 'Playfair Display', serif;
  --font-body: 'Inter', system-ui, sans-serif;
}
body[data-fontpair="modern"] {
  --font-display: 'Fraunces', serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
}
body[data-fontpair="warm"] {
  --font-display: 'Instrument Serif', serif;
  --font-body: 'Manrope', system-ui, sans-serif;
}
body[data-fontpair="utility"] {
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
}
body[data-fontpair="utility"] .display { font-weight: 600; letter-spacing: -0.02em; }
body[data-fontpair="warm"] .display { font-weight: 400; letter-spacing: -0.005em; }

/* Confidence pill */
.conf-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.conf-pill.high { background: var(--green-soft); color: #285d3f; }
.conf-pill.medium { background: var(--amber-soft); color: #7a5418; }
.conf-pill.low { background: var(--red-soft); color: #8c2e2e; }
