/* ============================================================
   MenuCraft — Main Stylesheet
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@300;400;500;600;700&family=DM+Serif+Display&display=swap');

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --brand:        #FF6B35;
  --brand-dark:   #e05520;
  --brand-light:  #fff3ee;
  --surface:      #ffffff;
  --surface-2:    #f8f9fb;
  --border:       #e8eaed;
  --text:         #1a1d23;
  --text-muted:   #6b7280;
  --text-light:   #9ca3af;
  --success:      #10b981;
  --danger:       #ef4444;
  --warning:      #f59e0b;
  --info:         #3b82f6;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg:    0 8px 32px rgba(0,0,0,.12);
  --sidebar-w:    260px;
  --header-h:     64px;
  --transition:   all .2s ease;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  /* Fix 1: always show scrollbar so page width never shifts */
  overflow-y: scroll;
}
body {
  font-family: 'Sora', sans-serif;
  color: var(--text);
  background: var(--surface-2);
  line-height: 1.6;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ── Utilities ─────────────────────────────────────────────── */
.hidden   { display: none !important; }
.flex     { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1  { gap: .25rem; } .gap-2 { gap: .5rem; }
.gap-3  { gap: .75rem; } .gap-4 { gap: 1rem; }
.gap-6  { gap: 1.5rem; } .gap-8 { gap: 2rem; }
.mt-1 { margin-top: .25rem; } .mt-2 { margin-top: .5rem; }
.mt-4 { margin-top: 1rem; }  .mt-6 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: .5rem; } .mb-4 { margin-bottom: 1rem; }
.text-sm   { font-size: .875rem; }
.text-xs   { font-size: .75rem; }
.text-muted { color: var(--text-muted); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .625rem 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 600; font-size: .875rem;
  cursor: pointer; border: none;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary   { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); transform: translateY(-1px); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { border-color: var(--brand); color: var(--brand); }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.05); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover  { filter: brightness(1.1); }
.btn-ghost     { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: .4rem .875rem; font-size: .8125rem; }
.btn-lg { padding: .875rem 1.75rem; font-size: 1rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none !important; }
.btn-loading { position: relative; pointer-events: none; }
.btn-loading::after {
  content: ''; position: absolute; width: 1rem; height: 1rem;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: spin .6s linear infinite; right: .75rem;
}

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }
.form-label {
  display: block; font-size: .8125rem; font-weight: 600;
  color: var(--text-muted); margin-bottom: .375rem; letter-spacing: .02em;
  text-transform: uppercase;
}
.form-control {
  width: 100%; padding: .625rem .875rem;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  transition: var(--transition);
  outline: none;
}
.form-control:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(255,107,53,.12); }
.form-control.is-invalid { border-color: var(--danger); }
.form-hint { font-size: .8rem; color: var(--text-muted); margin-top: .3rem; }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-weight: 700; font-size: 1rem; }
.card-body { padding: 1.5rem; }
.card-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
  padding: .875rem 1.125rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  margin-bottom: 1rem;
  display: flex; align-items: flex-start; gap: .625rem;
}
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #93c5fd; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fcd34d; }

/* ── Badge ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .2rem .6rem; border-radius: 999px;
  font-size: .725rem; font-weight: 700; letter-spacing: .03em;
  text-transform: uppercase;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-gray    { background: var(--surface-2); color: var(--text-muted); }

/* ── Table ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  padding: .75rem 1rem; text-align: left;
  font-size: .75rem; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--text-muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
td {
  padding: .875rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: .875rem; vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

/* ── Layout ────────────────────────────────────────────────── */
.layout-wrapper { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--text);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0;
  height: 100vh; z-index: 100;
  transition: transform .3s ease;
}
.sidebar-logo {
  padding: 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: .75rem;
}
.sidebar-logo .logo-mark {
  width: 36px; height: 36px;
  background: var(--brand);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.125rem; font-weight: 700; color: #fff;
}
.sidebar-logo .logo-text {
  font-family: 'DM Serif Display', serif;
  font-size: 1.25rem; color: #fff;
  letter-spacing: .02em;
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 1rem 0; }
.nav-section {
  padding: .5rem 1rem .25rem;
  font-size: .65rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: rgba(255,255,255,.3);
}
.nav-link {
  display: flex; align-items: center; gap: .75rem;
  padding: .7rem 1.25rem;
  color: rgba(255,255,255,.65);
  font-size: .875rem; font-weight: 500;
  border-radius: 0; transition: var(--transition);
  margin: .125rem .75rem;
  border-radius: var(--radius-sm);
}
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { background: var(--brand); color: #fff; }
/* Upgrade link has inline color:var(--brand) — override when active */
.nav-link.active { color: #fff !important; }
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .8; }
.nav-link.active svg, .nav-link:hover svg { opacity: 1; }
.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-user {
  display: flex; align-items: center; gap: .75rem;
}
.sidebar-avatar {
  width: 36px; height: 36px;
  background: var(--brand);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .875rem; color: #fff;
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: .8125rem; font-weight: 600; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: .725rem; color: rgba(255,255,255,.45);
}

/* Main content */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 100vh;
}
.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 2rem;
  gap: 1rem;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-weight: 700; font-size: 1.125rem; flex: 1; }
.page-content { padding: 2rem; flex: 1; }

/* ── Stats ─────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1.5rem;
  display: flex; align-items: center; gap: 1rem;
}
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.375rem; flex-shrink: 0;
}
.stat-icon.orange { background: #fff3ee; }
.stat-icon.green  { background: #ecfdf5; }
.stat-icon.blue   { background: #eff6ff; }
.stat-icon.purple { background: #f5f3ff; }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .8125rem; color: var(--text-muted); margin-top: .25rem; }

/* ── Builder specific ──────────────────────────────────────── */
.builder-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  align-items: start;
}
.builder-panel {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.builder-panel-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.builder-panel-title {
  font-size: .875rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted);
}
.category-list { list-style: none; }
.category-item {
  border-bottom: 1px solid var(--border);
  transition: background .15s;
}
.category-item:last-child { border-bottom: none; }
.category-header {
  display: flex; align-items: center; gap: .5rem;
  padding: .875rem 1.25rem; cursor: pointer;
}
.category-header:hover { background: var(--surface-2); }
.category-drag { cursor: grab; color: var(--text-light); font-size: 1rem; }
.category-name { flex: 1; font-weight: 600; font-size: .9rem; }
.category-count {
  font-size: .75rem; color: var(--text-muted);
  background: var(--surface-2);
  padding: .15rem .5rem; border-radius: 999px;
}
.category-actions { display: flex; gap: .25rem; }
.icon-btn {
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; cursor: pointer;
  color: var(--text-muted); transition: var(--transition);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: #fee2e2; color: var(--danger); }

.items-list { padding: .5rem; }
.item-card {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: .5rem;
  background: var(--surface);
  transition: var(--transition);
  cursor: grab;
}
.item-card:hover { border-color: var(--brand); box-shadow: 0 2px 8px rgba(255,107,53,.12); }
.item-thumb {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  background: var(--surface-2); object-fit: cover; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-light); font-size: 1.25rem; overflow: hidden;
}
.item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-info { flex: 1; min-width: 0; }
.item-name { font-weight: 600; font-size: .875rem; }
.item-price { font-size: .8rem; color: var(--brand); font-weight: 600; }
.item-meta  { font-size: .75rem; color: var(--text-muted); }

/* ── Color picker ──────────────────────────────────────────── */
.color-swatch-row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.color-swatch {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid transparent; cursor: pointer;
  transition: var(--transition);
}
.color-swatch.active, .color-swatch:hover {
  border-color: var(--text);
  transform: scale(1.15);
}

/* ── Theme cards ───────────────────────────────────────────── */
.themes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}
.theme-card {
  border: 2.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden; cursor: pointer;
  transition: var(--transition);
}
.theme-card:hover { border-color: var(--brand); }
.theme-card.selected { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(255,107,53,.18); }
.theme-preview {
  height: 100px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
}
.theme-label {
  padding: .5rem .75rem;
  font-size: .8125rem; font-weight: 600; text-align: center;
  border-top: 1px solid var(--border);
}

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%; max-width: 520px;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}
@keyframes modalIn { from { transform: scale(.95) translateY(8px); opacity: 0; } }
.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-weight: 700; font-size: 1rem; }
.modal-close {
  width: 32px; height: 32px;
  background: var(--surface-2); border: none;
  border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.125rem; color: var(--text-muted);
  transition: var(--transition);
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body { padding: 1.5rem; }
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: .75rem;
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ── Auth pages ────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 2rem;
  background: var(--surface-2);
  position: relative; overflow: hidden;
}
.auth-page::before {
  content: '';
  position: absolute; top: -30%; right: -10%;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(255,107,53,.12) 0%, transparent 70%);
  pointer-events: none;
}
.auth-card {
  width: 100%; max-width: 460px;
  background: var(--surface);
  border-radius: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem;
  position: relative; z-index: 1;
}
.auth-logo {
  display: flex; align-items: center; gap: .75rem;
  margin-bottom: 2rem;
}
.auth-logo-mark {
  width: 42px; height: 42px; background: var(--brand);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; font-size: 1.25rem;
}
.auth-logo-text {
  font-family: 'DM Serif Display', serif;
  font-size: 1.5rem; color: var(--text);
}
.auth-title  { font-size: 1.625rem; font-weight: 700; margin-bottom: .375rem; }
.auth-subtitle { color: var(--text-muted); font-size: .9375rem; margin-bottom: 2rem; }
.auth-footer { text-align: center; margin-top: 1.5rem; font-size: .875rem; color: var(--text-muted); }
.divider {
  display: flex; align-items: center; gap: 1rem; margin: 1.5rem 0;
  color: var(--text-muted); font-size: .8125rem;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ── Drag states ───────────────────────────────────────────── */
.drag-over { border: 2px dashed var(--brand) !important; background: var(--brand-light) !important; }
.dragging  { opacity: .5; }

/* ── Responsive ────────────────────────────────────────────── */
.mobile-toggle {
  display: none; background: none; border: none; cursor: pointer;
  color: var(--text); padding: .5rem;
}
@media (max-width: 900px) {
  .builder-layout { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  /* Fix 2: use .sidebar-open to match the JS class name */
  .sidebar { transform: translateX(-100%); }
  .sidebar.sidebar-open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .mobile-toggle { display: flex; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-content { padding: 1rem; }
}

/* ── Animations ────────────────────────────────────────────── */
@keyframes spin  { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadeIn .3s ease; }

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 3rem 1.5rem;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h3   { font-size: 1.125rem; color: var(--text); margin-bottom: .5rem; }

/* ── Toast notifications ───────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  z-index: 9999; display: flex; flex-direction: column; gap: .5rem;
}
.toast {
  background: var(--text); color: #fff;
  padding: .75rem 1.25rem; border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: fadeIn .25s ease;
  max-width: 320px;
  display: flex; align-items: center; gap: .625rem;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); color: var(--text); }