/* =========================================================================
   The Cookies Factory — Design System
   Tokens, tema claro/escuro, componentes e layout.
   ========================================================================= */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body, h1, h2, h3, h4, p, figure, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

/* ---------- Tokens base (compartilhados) ---------- */
:root {
  --brand-50:  #f6efe8;
  --brand-200: #d9bfa6;
  --brand-400: #b07f52;
  --brand-500: #8b5e3c;
  --brand-600: #744c2f;
  --brand-700: #5b3a23;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  --font: "Lora", Georgia, "Times New Roman", serif;
  --ease: cubic-bezier(.22,.61,.36,1);
  --t-fast: .16s var(--ease);
  --t: .26s var(--ease);

  --sidebar-w: 264px;
}

/* ---------- Tema escuro ---------- */
[data-theme="dark"] {
  --bg: #0c0c0d;
  --bg-elev: #131315;
  --surface: #17171a;
  --surface-2: #1e1e22;
  --surface-hover: #242429;
  --border: #26262b;
  --border-strong: #33333a;
  --text: #f2f0ee;
  --text-muted: #9d9a96;
  --text-soft: #6f6c69;
  --accent: var(--brand-400);
  --accent-strong: var(--brand-500);
  --accent-contrast: #fff8f1;
  --accent-soft: rgba(176,127,82,.16);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.5);
  --shadow: 0 10px 30px -12px rgba(0,0,0,.75);
  --shadow-lg: 0 28px 70px -24px rgba(0,0,0,.85);
  --scrim: rgba(0,0,0,.66);
}

/* ---------- Tema claro ---------- */
[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #fbfaf9;
  --surface: #f6f5f3;
  --surface-2: #f0eeec;
  --surface-hover: #eae7e3;
  --border: #e5e1dc;
  --border-strong: #d5cfc8;
  --text: #1b1917;
  --text-muted: #6d6862;
  --text-soft: #918b84;
  --accent: var(--brand-500);
  --accent-strong: var(--brand-600);
  --accent-contrast: #ffffff;
  --accent-soft: rgba(139,94,60,.10);
  --shadow-sm: 0 1px 2px rgba(27,25,23,.06);
  --shadow: 0 12px 32px -18px rgba(27,25,23,.30);
  --shadow-lg: 0 30px 70px -30px rgba(27,25,23,.35);
  --scrim: rgba(27,25,23,.38);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  letter-spacing: .1px;
  transition: background-color var(--t), color var(--t);
}

.material-symbols-rounded {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  font-size: 20px;
  line-height: 1;
  user-select: none;
}

/* =========================== Layout =========================== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: var(--sp-5) var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-6);
  position: sticky; top: 0; height: 100vh;
  transition: transform var(--t), background-color var(--t);
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-2); }
.brand-mark {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: linear-gradient(150deg, var(--accent), var(--brand-700));
  color: var(--accent-contrast);
  box-shadow: var(--shadow-sm);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 14.5px; font-weight: 600; letter-spacing: .2px; }
.brand-text span { font-size: 11.5px; color: var(--text-soft); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: var(--sp-3); }

.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%; padding: 10px var(--sp-3);
  background: transparent; border: 0; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 14px; text-align: left;
  cursor: pointer; transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item:active { transform: scale(.985); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.is-active .material-symbols-rounded { font-variation-settings: 'FILL' 1; }

.sidebar-backdrop {
  position: fixed; inset: 0; background: var(--scrim); opacity: 0;
  pointer-events: none; transition: opacity var(--t); z-index: 35;
}
.sidebar-backdrop.is-open { opacity: 1; pointer-events: auto; }

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

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-6);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 20px; font-weight: 600; letter-spacing: -.2px; }
.topbar-title p { font-size: 13px; color: var(--text-soft); margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: var(--sp-2); }

.view-area { padding: var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-5); }
.view { display: flex; flex-direction: column; gap: var(--sp-5); animation: rise .32s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* =========================== Botões =========================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: 13.5px; cursor: pointer; white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.btn:hover { background: var(--surface-hover); border-color: var(--accent); }
.btn:active { transform: scale(.98); }
.btn .material-symbols-rounded { font-size: 18px; }

.btn-primary {
  background: var(--accent-strong); border-color: var(--accent-strong);
  color: var(--accent-contrast); font-weight: 600; box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-danger:hover { border-color: #b4453c; color: #d8695f; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }

.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); cursor: pointer;
  transition: all var(--t-fast);
}
.icon-btn:hover { color: var(--text); background: var(--surface-hover); border-color: var(--border-strong); }
.only-mobile { display: none; }

/* =========================== Cards =========================== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  transition: border-color var(--t), box-shadow var(--t), transform var(--t), background var(--t);
}
.card-pad { padding: var(--sp-5); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: 15px; font-weight: 600; }
.card-head p { font-size: 12.5px; color: var(--text-soft); margin-top: 2px; }

.stat-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); }
.stat {
  padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-3);
  position: relative; overflow: hidden;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-strong); }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.stat-label { font-size: 12.5px; color: var(--text-muted); letter-spacing: .3px; }
.stat-ico {
  width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px;
  background: var(--accent-soft); color: var(--accent);
}
.stat-value { font-size: 27px; font-weight: 600; letter-spacing: -.6px; line-height: 1.1; }
.stat-hint { font-size: 12px; color: var(--text-soft); }
.stat.is-accent { background: linear-gradient(150deg, var(--accent-soft), transparent 70%); border-color: var(--accent); }

/* =========================== Tabelas =========================== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; padding: 11px var(--sp-5); font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .7px; color: var(--text-soft);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 13px var(--sp-5); border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { transition: background var(--t-fast); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
.cell-strong { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* =========================== Badges =========================== */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-neutral  { color: #9a938c; background: rgba(154,147,140,.12); border-color: rgba(154,147,140,.28); }
.badge-blue     { color: #5b8dd6; background: rgba(91,141,214,.12);  border-color: rgba(91,141,214,.28); }
.badge-amber    { color: #c9922f; background: rgba(201,146,47,.13);  border-color: rgba(201,146,47,.3); }
.badge-purple   { color: #9a7bc8; background: rgba(154,123,200,.13); border-color: rgba(154,123,200,.3); }
.badge-teal     { color: #3fa38f; background: rgba(63,163,143,.13);  border-color: rgba(63,163,143,.3); }
.badge-green    { color: #4d9d5f; background: rgba(77,157,95,.13);   border-color: rgba(77,157,95,.3); }
.badge-red      { color: #c8615a; background: rgba(200,97,90,.13);   border-color: rgba(200,97,90,.3); }
.badge-brown    { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }
.badge-plain::before { display: none; }

/* =========================== Formulários =========================== */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; letter-spacing: .2px; }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text);
  font-size: 13.5px; transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--text-soft); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 76px; }
.select { appearance: none; cursor: pointer; padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-soft) 50%), linear-gradient(135deg, var(--text-soft) 50%, transparent 50%);
  background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.form-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: 1 / -1; }

.search {
  position: relative; display: flex; align-items: center; flex: 1; min-width: 190px;
}
.search .material-symbols-rounded { position: absolute; left: 11px; color: var(--text-soft); font-size: 18px; pointer-events: none; }
.search .input { padding-left: 36px; }

.toolbar { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.toolbar .select { width: auto; min-width: 150px; }

.seg { display: inline-flex; padding: 3px; gap: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.seg button {
  padding: 7px 14px; border: 0; background: transparent; color: var(--text-muted);
  border-radius: 7px; font-size: 13px; cursor: pointer; transition: all var(--t-fast);
}
.seg button.is-active { background: var(--accent-strong); color: var(--accent-contrast); font-weight: 600; }

/* Contador de sabores */
.flavor-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: 11px var(--sp-4); border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-elev); transition: border-color var(--t-fast), background var(--t-fast);
}
.flavor-row.has-qty { border-color: var(--accent); background: var(--accent-soft); }
.flavor-name { font-size: 13.5px; font-weight: 600; }
.flavor-price { font-size: 12px; color: var(--text-soft); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); cursor: pointer; display: grid; place-items: center;
  transition: all var(--t-fast);
}
.stepper button:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-contrast); }
.stepper .qty { min-width: 30px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; }

.total-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4); border-radius: var(--radius-sm);
  background: var(--accent-soft); border: 1px solid var(--accent);
}
.total-bar span { font-size: 13px; color: var(--text-muted); }
.total-bar strong { font-size: 22px; letter-spacing: -.5px; }

/* =========================== Modal =========================== */
.modal-root { position: fixed; inset: 0; z-index: 60; display: none; }
.modal-root.is-open { display: block; }
.modal-scrim { position: absolute; inset: 0; background: var(--scrim); backdrop-filter: blur(3px); animation: fade .2s var(--ease); }
.modal {
  position: relative; margin: 5vh auto; width: min(720px, calc(100% - 32px));
  max-height: 90vh; display: flex; flex-direction: column;
  background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: pop .3s var(--ease); overflow: hidden;
}
.modal.modal-sm { width: min(440px, calc(100% - 32px)); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); padding: var(--sp-5); border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; font-weight: 600; }
.modal-head p { font-size: 12.5px; color: var(--text-soft); margin-top: 3px; }
.modal-body { padding: var(--sp-5); overflow-y: auto; display: flex; flex-direction: column; gap: var(--sp-5); }
.modal-foot { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--sp-2); background: var(--surface); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.985); } }

/* =========================== Toast =========================== */
.toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-size: 13.5px;
  animation: slideIn .3s var(--ease);
}
.toast.is-out { animation: slideOut .25s var(--ease) forwards; }
@keyframes slideIn { from { opacity: 0; transform: translateX(24px); } }
@keyframes slideOut { to { opacity: 0; transform: translateX(24px); } }

/* =========================== Utilitários =========================== */
.section-title { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; color: var(--text); }
.section-title .material-symbols-rounded { color: var(--accent); font-size: 19px; }
.grid-2 { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.empty { padding: var(--sp-7) var(--sp-5); text-align: center; color: var(--text-soft); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty .material-symbols-rounded { font-size: 34px; opacity: .55; }
.muted { color: var(--text-muted); font-size: 13px; }
.soft { color: var(--text-soft); font-size: 12.5px; }
.divider { height: 1px; background: var(--border); }
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.list-line { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); padding: 12px var(--sp-5); border-bottom: 1px solid var(--border); }
.list-line:last-child { border-bottom: 0; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 12.5px; font-weight: 700; flex: 0 0 34px;
}
.alert {
  display: flex; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid var(--accent); align-items: flex-start;
}
.alert .material-symbols-rounded { color: var(--accent); }
.alert strong { display: block; font-size: 13.5px; margin-bottom: 2px; }
.alert p { font-size: 12.5px; color: var(--text-muted); }
.bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--brand-600)); }

/* =========================== Responsivo =========================== */
@media (max-width: 980px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); }
  .sidebar.is-open { transform: none; box-shadow: var(--shadow-lg); }
  .only-mobile { display: grid; }
  .view-area { padding: var(--sp-4); }
  .topbar { padding: var(--sp-3) var(--sp-4); }
}
@media (max-width: 620px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar-title p { display: none; }
  .btn-primary span:not(.material-symbols-rounded) { display: none; }
  .toast-root { left: 16px; right: 16px; }
}

/* Ajustes finos de tabela: evita quebras indesejadas em colunas curtas */
tbody td:first-child, tbody td:nth-child(2) .cell-strong { white-space: nowrap; }
tbody td:nth-child(2) { min-width: 190px; }
.toolbar input[type="date"] { min-width: 168px; }
