:root {
  color-scheme: light;
  --surface-1: #ffffff;
  --surface-2: #f1f0e9;
  --surface-page: #f6f5ef;
  --text-primary: #16211a;
  --text-secondary: #57624f;
  --text-muted: #8b9285;
  --gridline: #e5e2d6;
  --baseline: #cfccb9;
  --border: rgba(20,60,40,0.12);
  --series-1: #1f7a8c;   /* teal-blue: custo matéria-prima / preço / linha principal */
  --series-2: #c9722f;   /* terracota: custo indireto */
  --status-good: #1f8a3d;
  --status-warning: #d99a1f;
  --status-serious: #d9713f;
  --status-critical: #c23b3b;
  --brand: #145835;
  --brand-2: #237a4b;
  --brand-deep: #0a331e;
  --accent: #c9932f;
  --accent-soft: #f3e3bf;
  --shadow-sm: 0 1px 2px rgba(15,35,22,0.06);
  --shadow-md: 0 4px 14px rgba(15,35,22,0.08), 0 1px 3px rgba(15,35,22,0.06);
  --shadow-lg: 0 14px 40px rgba(15,35,22,0.14), 0 3px 10px rgba(15,35,22,0.08);
  --radius-sm: 7px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --sidebar-w: 260px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #17201a;
    --surface-2: #1e2921;
    --surface-page: #0c1310;
    --text-primary: #f3f5f0;
    --text-secondary: #bcc4b4;
    --text-muted: #7f887a;
    --gridline: #263229;
    --baseline: #38453c;
    --border: rgba(255,255,255,0.09);
    --series-1: #4fb0c4;
    --series-2: #e0935a;
    --status-good: #35b158;
    --status-warning: #f0b23a;
    --status-serious: #ec8a5a;
    --status-critical: #e56d6d;
    --brand-2: #2f9a5e;
    --accent: #e0ab4a;
    --accent-soft: rgba(201,147,47,0.18);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.35);
    --shadow-lg: 0 18px 44px rgba(0,0,0,0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #17201a;
  --surface-2: #1e2921;
  --surface-page: #0c1310;
  --text-primary: #f3f5f0;
  --text-secondary: #bcc4b4;
  --text-muted: #7f887a;
  --gridline: #263229;
  --baseline: #38453c;
  --border: rgba(255,255,255,0.09);
  --series-1: #4fb0c4;
  --series-2: #e0935a;
  --status-good: #35b158;
  --status-warning: #f0b23a;
  --status-serious: #ec8a5a;
  --status-critical: #e56d6d;
  --brand-2: #2f9a5e;
  --accent: #e0ab4a;
  --accent-soft: rgba(201,147,47,0.18);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.35);
  --shadow-lg: 0 18px 44px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }

::selection { background: var(--accent-soft); color: var(--text-primary); }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--baseline); border-radius: 8px; border: 3px solid var(--surface-page); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

html { scroll-behavior: smooth; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  margin: 0;
  color: var(--text-primary);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

h1, h2, h3, h4 { font-weight: 700; letter-spacing: -0.01em; }

/* ===================== app shell (sidebar + content) ===================== */
.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(480px 260px at 100% 0%, rgba(255,255,255,0.10), transparent 60%),
    linear-gradient(190deg, var(--brand-deep) 0%, var(--brand) 55%, var(--brand-2) 145%);
  color: #fff;
  box-shadow: var(--shadow-lg);
  z-index: 20;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.3rem 1.2rem 1.1rem;
  border-bottom: 1px solid rgba(255,255,255,0.14);
}
.brand-mark {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.2);
}
.brand-mark svg { display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 1rem; letter-spacing: -0.01em; }
.brand-text span { font-size: 0.74rem; color: rgba(255,255,255,0.68); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

nav#tabs {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 1rem 0.85rem;
  overflow-y: auto;
}

nav#tabs button {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: none;
  background: transparent;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  font-size: 0.87rem;
  font-weight: 600;
  text-align: left;
  border-radius: 10px;
  color: rgba(255,255,255,0.72);
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

nav#tabs button::before {
  content: "";
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  background-color: currentColor;
  opacity: 0.85;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-size: contain;
  mask-size: contain;
}

nav#tabs button[data-tab="visao-geral"]::before { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7.5' height='7.5' rx='1.5'/%3E%3Crect x='13.5' y='3' width='7.5' height='7.5' rx='1.5'/%3E%3Crect x='3' y='13.5' width='7.5' height='7.5' rx='1.5'/%3E%3Crect x='13.5' y='13.5' width='7.5' height='7.5' rx='1.5'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7.5' height='7.5' rx='1.5'/%3E%3Crect x='13.5' y='3' width='7.5' height='7.5' rx='1.5'/%3E%3Crect x='3' y='13.5' width='7.5' height='7.5' rx='1.5'/%3E%3Crect x='13.5' y='13.5' width='7.5' height='7.5' rx='1.5'/%3E%3C/svg%3E"); }
nav#tabs button[data-tab="precificador"]::before { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 11 L11 3 H19 V11 L11 19 Z'/%3E%3Ccircle cx='15' cy='7' r='1.4'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 11 L11 3 H19 V11 L11 19 Z'/%3E%3Ccircle cx='15' cy='7' r='1.4'/%3E%3C/svg%3E"); }
nav#tabs button[data-tab="materias-primas"]::before { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3C12 3 6 11.5 6 15A6 6 0 0 0 18 15C18 11.5 12 3 12 3Z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3C12 3 6 11.5 6 15A6 6 0 0 0 18 15C18 11.5 12 3 12 3Z'/%3E%3C/svg%3E"); }
nav#tabs button[data-tab="produtos"]::before { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 8L12 4L21 8L12 12Z'/%3E%3Cpath d='M3 8V16L12 20V12'/%3E%3Cpath d='M21 8V16L12 20'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 8L12 4L21 8L12 12Z'/%3E%3Cpath d='M3 8V16L12 20V12'/%3E%3Cpath d='M21 8V16L12 20'/%3E%3C/svg%3E"); }
nav#tabs button[data-tab="parametros"]::before { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='4' y1='6' x2='20' y2='6'/%3E%3Ccircle cx='9' cy='6' r='2'/%3E%3Cline x1='4' y1='12' x2='20' y2='12'/%3E%3Ccircle cx='15' cy='12' r='2'/%3E%3Cline x1='4' y1='18' x2='20' y2='18'/%3E%3Ccircle cx='11' cy='18' r='2'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='4' y1='6' x2='20' y2='6'/%3E%3Ccircle cx='9' cy='6' r='2'/%3E%3Cline x1='4' y1='12' x2='20' y2='12'/%3E%3Ccircle cx='15' cy='12' r='2'/%3E%3Cline x1='4' y1='18' x2='20' y2='18'/%3E%3Ccircle cx='11' cy='18' r='2'/%3E%3C/svg%3E"); }
nav#tabs button[data-tab="despesas"]::before { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 3H19V21L16.5 19L14 21L11.5 19L9 21L6.5 19L5 21Z'/%3E%3Cline x1='8' y1='8.5' x2='16' y2='8.5'/%3E%3Cline x1='8' y1='12.5' x2='16' y2='12.5'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 3H19V21L16.5 19L14 21L11.5 19L9 21L6.5 19L5 21Z'/%3E%3Cline x1='8' y1='8.5' x2='16' y2='8.5'/%3E%3Cline x1='8' y1='12.5' x2='16' y2='12.5'/%3E%3C/svg%3E"); }
nav#tabs button[data-tab="projecao"]::before { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 17L9 11L13 15L21 6'/%3E%3Cpath d='M15 6H21V12'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 17L9 11L13 15L21 6'/%3E%3Cpath d='M15 6H21V12'/%3E%3C/svg%3E"); }
nav#tabs button[data-tab="tabela-preco"]::before { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='16' rx='1.5'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3Cline x1='3' y1='15' x2='21' y2='15'/%3E%3Cline x1='9' y1='4' x2='9' y2='20'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='16' rx='1.5'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3Cline x1='3' y1='15' x2='21' y2='15'/%3E%3Cline x1='9' y1='4' x2='9' y2='20'/%3E%3C/svg%3E"); }

nav#tabs button:hover { background: rgba(255,255,255,0.09); color: #fff; }
nav#tabs button:hover::before { opacity: 1; }

nav#tabs button.active {
  background: rgba(255,255,255,0.15);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent), inset 0 0 0 1px rgba(255,255,255,0.12);
}
nav#tabs button.active::before { opacity: 1; }

.sidebar-footer {
  padding: 0.9rem 1.2rem 1.2rem;
  border-top: 1px solid rgba(255,255,255,0.14);
}
.header-badge {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: rgba(255,255,255,0.62);
}

.app-content {
  flex: 1;
  min-width: 0;
}

main { padding: 2rem 2.6rem 4rem; max-width: 1240px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: panel-in 0.18s ease; }
@keyframes panel-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

h2 { font-size: 1.4rem; margin: 0 0 0.3rem; }
main > .tab-panel > .hint:first-of-type { margin-bottom: 0.4rem; }

.hint { color: var(--text-secondary); font-size: 0.88rem; line-height: 1.5; }
code { background: var(--surface-2); padding: 0.1rem 0.4rem; border-radius: 4px; font-size: 0.85em; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.3rem 1.5rem;
  margin: 1.1rem 0;
  box-shadow: var(--shadow-md);
}

.card h3 {
  margin: 0 0 0.6rem;
  font-size: 1.02rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--gridline);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem;
}
@media (max-width: 860px) {
  .grid-2col { grid-template-columns: 1fr; }
}

/* ---------- KPI stat tiles ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin: 1.2rem 0 1.6rem;
}
.kpi-tile {
  position: relative;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.1rem 1.3rem 1.1rem 1.4rem;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.kpi-tile:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-tile::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: linear-gradient(var(--brand), var(--brand-2));
}
.kpi-tile:nth-of-type(4n+2)::before { background: linear-gradient(var(--accent), var(--series-2)); }
.kpi-tile:nth-of-type(4n+3)::before { background: linear-gradient(var(--series-1), #2a95a8); }
.kpi-tile:nth-of-type(4n+4)::before { background: linear-gradient(var(--status-good), var(--brand-2)); }
.kpi-label { font-size: 0.76rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.kpi-value { font-size: 1.85rem; font-weight: 800; margin-top: 0.3rem; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ---------- tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.9rem;
  background: var(--surface-1);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-md);
  overflow: hidden;
}

th, td {
  padding: 0.6rem 0.8rem;
  text-align: right;
  border-bottom: 1px solid var(--gridline);
  font-size: 0.89rem;
  font-variant-numeric: tabular-nums;
}

th:first-child, td:first-child { text-align: left; font-variant-numeric: normal; }

thead th {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: white;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: none;
  white-space: nowrap;
}

tbody tr { transition: background 0.1s ease; }
tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
tbody tr:hover { background: var(--accent-soft); }
tbody tr:last-child td { border-bottom: none; }

tfoot td { font-weight: 700; background: var(--surface-2); color: var(--text-primary); border-top: 2px solid var(--gridline); }

tr.row-alerta td:first-child { border-left: 3px solid var(--status-warning); }

/* ---------- buttons ---------- */
button { font-family: inherit; }
.btn-primary {
  padding: 0.55rem 1.2rem;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--brand) 35%, transparent);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 14px color-mix(in srgb, var(--brand) 45%, transparent); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
  padding: 0.45rem 1rem;
  background: var(--surface-1);
  color: var(--brand-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn-secondary:hover { background: color-mix(in srgb, var(--brand) 8%, transparent); border-color: var(--brand-2); }
.btn-danger {
  padding: 0.45rem 1rem;
  background: transparent;
  color: var(--status-critical);
  border: 1px solid color-mix(in srgb, var(--status-critical) 55%, transparent);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.12s ease;
}
.btn-danger:hover { background: color-mix(in srgb, var(--status-critical) 12%, transparent); }
.btn-icon {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 0.25rem 0.45rem;
  border-radius: 6px;
  color: var(--text-secondary);
  transition: background 0.12s ease, color 0.12s ease;
}
.btn-icon:hover { color: var(--status-critical); background: color-mix(in srgb, var(--status-critical) 12%, transparent); }

/* ---------- forms ---------- */
.param-form {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
}
.param-form label, .modal-box label {
  display: flex;
  flex-direction: column;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-secondary);
  gap: 0.3rem;
}
.checkbox-inline {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
}
.checkbox-inline input[type="checkbox"] {
  width: auto;
  accent-color: var(--brand);
}
input, select {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--baseline);
  border-radius: 7px;
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 400;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:hover, select:hover { border-color: var(--text-muted); }
input:focus, select:focus {
  outline: none;
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.status { margin-top: 0.6rem; font-size: 0.85rem; font-weight: 600; }

/* ---------- alertas ---------- */
.badge-count {
  display: inline-block;
  background: var(--status-critical);
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.08rem 0.55rem;
  border-radius: 999px;
  margin-left: 0.4rem;
  vertical-align: middle;
}
.alertas-lista { display: flex; flex-direction: column; gap: 0.55rem; margin-top: 0.9rem; }
.alerta-item {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  border-left: 4px solid transparent;
}
.alerta-item.critical { background: color-mix(in srgb, var(--status-critical) 10%, transparent); border-left-color: var(--status-critical); }
.alerta-item.warning { background: color-mix(in srgb, var(--status-warning) 14%, transparent); border-left-color: var(--status-warning); }
.alerta-icon { font-weight: 700; flex-shrink: 0; }
.alerta-item.critical .alerta-icon { color: var(--status-critical); }
.alerta-item.warning .alerta-icon { color: #8a6300; }
.alertas-vazio { color: var(--status-good); font-weight: 700; padding: 0.5rem 0; }

/* ===================== gráficos SVG ===================== */
.chart-box { width: 100%; overflow-x: auto; }
.chart-box svg { font-family: inherit; }
.chart-axis-label { fill: var(--text-muted); font-size: 11.5px; }
.chart-gridline { stroke: var(--gridline); stroke-width: 1; }
.chart-baseline { stroke: var(--baseline); stroke-width: 1.2; }
.chart-value-label { fill: var(--text-primary); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }

.chart-bar-track { fill: var(--surface-2); }
.chart-bar-rect {
  cursor: pointer;
  transition: width 0.7s cubic-bezier(0.16,1,0.3,1), x 0.7s cubic-bezier(0.16,1,0.3,1), filter 0.12s ease, opacity 0.12s ease;
}
.chart-bar-rect:hover { filter: brightness(1.1); }
.chart-row-band { fill: var(--accent-soft); opacity: 0; transition: opacity 0.12s ease; pointer-events: none; }
.chart-row-band.hover { opacity: 1; }
.chart-row-label { font-weight: 600; fill: var(--text-primary); }

.chart-line-path {
  transition: stroke-dashoffset 1.1s cubic-bezier(0.16,1,0.3,1);
}
.chart-area-fill { transition: opacity 0.3s ease; }
.chart-dot-halo { transition: opacity 0.12s ease, r 0.12s ease; }

.chart-legend { display: flex; gap: 1.1rem; margin-top: 0.7rem; font-size: 0.82rem; color: var(--text-secondary); font-weight: 600; }
.chart-legend-item { display: flex; align-items: center; gap: 0.4rem; }
.chart-legend-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-tooltip {
  position: absolute;
  background: var(--text-primary);
  color: var(--surface-1);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.45;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
  white-space: nowrap;
  z-index: 20;
  box-shadow: var(--shadow-lg);
}
.chart-tooltip .tt-swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 0.35rem; }
.chart-tooltip .tt-muted { opacity: 0.68; font-weight: 500; }

/* ---------- produtos / receita editor ---------- */
.produtos-lista { display: flex; flex-direction: column; gap: 1rem; margin-top: 1.1rem; }
.produto-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.3rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease;
}
.produto-card.aberto { box-shadow: var(--shadow-md); }
.produto-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  gap: 1rem;
}
.produto-card-header::before {
  content: "▸";
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-right: 0.6rem;
  transition: transform 0.15s ease;
  display: inline-block;
}
.produto-card.aberto .produto-card-header::before { transform: rotate(90deg); color: var(--brand-2); }
.produto-card-header h4 { margin: 0; flex: 1; }
.produto-preco {
  font-weight: 700;
  color: var(--brand-2);
  font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--brand) 10%, transparent);
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.9rem;
  white-space: nowrap;
}
.produto-detalhe { display: none; margin-top: 0.9rem; }
.produto-card.aberto .produto-detalhe { display: block; }
.receita-linha { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.45rem; }
.receita-linha select { flex: 2; }
.receita-linha input { flex: 1; }
.receita-contrib {
  flex: 1.3;
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}
.receita-soma { font-size: 0.85rem; margin-top: 0.5rem; font-weight: 700; }
.receita-soma.ok { color: var(--status-good); }
.receita-soma.erro { color: var(--status-critical); }

/* ---------- prévia ao vivo do produto (preço/lucro/composição) ---------- */
.produto-preview {
  background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 7%, transparent), color-mix(in srgb, var(--accent) 6%, transparent));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.8rem 1.1rem;
  margin-bottom: 1.1rem;
}
.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.7rem;
  margin-top: 0.4rem;
}
.preview-grid > div { display: flex; flex-direction: column; }
.preview-label { font-size: 0.75rem; color: var(--text-secondary); font-weight: 600; }
.preview-grid strong { font-variant-numeric: tabular-nums; font-size: 1.02rem; }

/* ---------- precificador: linha expansível de composição ---------- */
.linha-expansivel { cursor: pointer; }
.linha-expansivel:hover { background: var(--accent-soft) !important; }
.expand-icon { color: var(--text-muted); width: 1.2rem; }
.linha-detalhe td { padding: 0.7rem 1.1rem; background: var(--surface-2); }
.tabela-composicao { width: 100%; font-size: 0.85rem; box-shadow: none; border-radius: 0; }
.tabela-composicao th, .tabela-composicao td { padding: 0.3rem 0.6rem; text-align: left; }
.tabela-composicao thead th { background: transparent; color: var(--text-secondary); font-weight: 700; border-bottom: 1px solid var(--gridline); }

/* ---------- modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(8,18,12,0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.active { display: flex; animation: modal-fade 0.15s ease; }
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal-box {
  background: var(--surface-1);
  border-radius: var(--radius-lg);
  border-top: 4px solid var(--brand);
  padding: 1.5rem 1.7rem;
  max-width: 520px;
  width: 92%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-box h3 { margin-top: 0; }
.modal-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; margin: 1.1rem 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.1rem; }

/* ---------- projeção ---------- */
.projecao-sliders { display: flex; flex-direction: column; gap: 1rem; }
.projecao-sliders label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; font-weight: 600; }
input[type="range"] { width: 100%; accent-color: var(--brand-2); }
.slider-with-input, .mix-row { display: flex; align-items: center; gap: 0.7rem; }
.slider-with-input input[type="range"], .mix-row input[type="range"] { flex: 1; }
.slider-with-input input[type="number"] {
  width: 6.5rem;
  flex-shrink: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.mix-row input[type="number"] {
  width: 4.6rem;
  flex-shrink: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.mix-pct-sign { font-size: 0.85rem; color: var(--text-secondary); font-weight: 600; flex-shrink: 0; }
.sliders-mix { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); gap: 0.9rem; }
.mix-total { font-size: 0.9rem; font-weight: 700; }
.mix-total.ok { color: var(--status-good); }
.mix-total.erro { color: var(--status-critical); }
.projecao-actions { display: flex; gap: 0.6rem; margin-top: 1.1rem; flex-wrap: wrap; }
.projecao-actions input[type="text"] { flex: 1; min-width: 220px; }

#select-cenario { margin-right: 0.5rem; }

/* ===================== responsive: sidebar collapses to top bar ===================== */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    align-items: center;
    top: auto;
  }
  .sidebar-brand { border-bottom: none; border-right: 1px solid rgba(255,255,255,0.14); padding: 0.7rem 1rem; }
  .brand-text span { display: none; }
  nav#tabs { flex-direction: row; overflow-x: auto; padding: 0.5rem; flex: 1; }
  nav#tabs button { flex-shrink: 0; }
  .sidebar-footer { display: none; }
  main { padding: 1.5rem 1.2rem 3rem; }
}

/* ===================== V3: barras, tabelas largas, DRE ===================== */
nav#tabs button[data-tab="mix"]::before { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3v9l7.8 4.5'/%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3v9l7.8 4.5'/%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3C/svg%3E"); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; margin-top: 0.8rem; }
.toolbar input[type="search"] { min-width: 260px; }
.toolbar label:not(.checkbox-inline) { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; font-size: 0.85rem; }

.table-scroll {
  overflow-x: auto;
  margin-top: 0.9rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  background: var(--surface-1);
}
.table-scroll > table { margin-top: 0; box-shadow: none; border-radius: 0; overflow: visible; min-width: 100%; }
.card .table-scroll { box-shadow: none; border: 1px solid var(--gridline); }

.th-sub { font-weight: 500; font-size: 0.72rem; color: #fff; opacity: 0.92; text-transform: none; letter-spacing: 0; }
td.negativo, .negativo { color: var(--status-critical); }
td.celula-texto { text-align: left; }
td.acoes { white-space: nowrap; }
tr.linha-grupo td {
  background: var(--surface-2);
  color: var(--brand);
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: left;
}
.tag-alerta {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--status-critical);
  border: 1px solid currentColor;
}
.preview-sub { font-size: 0.75rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.editor-titulo { margin: 1.1rem 0 0.5rem; font-size: 0.95rem; }
.editor-grid { margin-top: 1rem; }
.detalhe-produto { align-items: start; }
.detalhe-produto .tabela-composicao { margin-top: 0; margin-bottom: 0.8rem; }

td input, td select { width: 100%; min-width: 90px; }
td input[type="checkbox"] { width: auto; min-width: 0; }
#tabela-mix .mix-input { max-width: 110px; }
.tabela-compacta td, .tabela-compacta th { padding: 0.35rem 0.4rem; }
.tabela-compacta .vol-input { min-width: 96px; font-variant-numeric: tabular-nums; }

/* DRE: primeira coluna fixa ao rolar na horizontal */
.tabela-dre th, .tabela-dre td { white-space: nowrap; }
.tabela-dre th:first-child, .tabela-dre td:first-child,
#tabela-precificador td:nth-child(2), #tabela-precificador th:nth-child(2),
#tabela-mix td:first-child, #tabela-mix th:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface-1);
  white-space: nowrap;
}
.tabela-dre tbody tr:nth-child(even) td:first-child { background: var(--surface-2); }
.tabela-dre tr.forte td { font-weight: 700; }
.tabela-dre tr.sub td { color: var(--text-secondary); font-size: 0.82rem; }
.tabela-dre th.pos-be { box-shadow: inset 0 -3px 0 var(--accent); }

@media (max-width: 720px) {
  .toolbar input[type="search"] { min-width: 0; width: 100%; }
}
thead th:first-child, thead th:nth-child(2) { background: var(--brand); }
#tabela-precificador th:nth-child(2), #tabela-precificador td:nth-child(2) { text-align: left; }
.tabela-composicao td:first-child { min-width: 160px; }
.chart-box { overflow: visible; }
.produto-detalhe .modal-form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.produto-detalhe .checkbox-inline { display: flex; align-items: center; gap: 0.45rem; margin: 0.35rem 0; }

/* ---------- Login e usuários ---------- */
[hidden] { display: none !important; }
nav#tabs button[data-tab="usuarios"]::before {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='9' cy='8' r='3.5'/%3E%3Cpath d='M3 20c0-3.5 2.7-6 6-6s6 2.5 6 6'/%3E%3Cpath d='M16 4.8a3.5 3.5 0 0 1 0 6.4'/%3E%3Cpath d='M18 14.5c1.8.8 3 2.8 3 5.5'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='9' cy='8' r='3.5'/%3E%3Cpath d='M3 20c0-3.5 2.7-6 6-6s6 2.5 6 6'/%3E%3Cpath d='M16 4.8a3.5 3.5 0 0 1 0 6.4'/%3E%3Cpath d='M18 14.5c1.8.8 3 2.8 3 5.5'/%3E%3C/svg%3E");
}
.tela-acesso {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--surface-page);
}
.cartao-acesso {
  width: 100%;
  max-width: 24rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 2rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.cartao-acesso h1 { margin: 0; font-size: 1.4rem; color: var(--text-primary); }
.cartao-acesso .hint { margin: 0; }
.cartao-acesso .hint:empty, #acesso-erro:empty { display: none; }
.cartao-acesso label { display: block; margin-bottom: 0.7rem; color: var(--text-secondary); font-size: 0.85rem; font-weight: 600; }
.cartao-acesso input { display: block; width: 100%; margin-top: 0.3rem; box-sizing: border-box; }
.acesso-marca { color: var(--text-secondary); }
.usuario-logado { color: #fff; font-size: 0.85rem; font-weight: 600; overflow-wrap: anywhere; }
.usuario-acoes { display: flex; gap: 0.8rem; margin: 0.35rem 0 0.7rem; }
.usuario-acoes button {
  padding: 0;
  border: 0;
  background: none;
  color: #fff;
  font-size: 0.75rem;
  text-decoration: underline;
  cursor: pointer;
}
.usuario-acoes button:hover { color: #fff; }
#form-senha label { display: block; margin-bottom: 0.8rem; }
#form-senha input { display: block; width: 100%; margin-top: 0.3rem; box-sizing: border-box; }
#tabela-usuarios { margin-top: 1rem; }
#tabela-usuarios th, #tabela-usuarios td { text-align: left; }
.acoes-usuario { display: flex; gap: 0.4rem; justify-content: flex-end; white-space: nowrap; }
.senha-temporaria { display: inline-block; padding: 0.5rem 0.8rem; font-size: 1.05rem; user-select: all; background: var(--accent-soft); border-radius: 6px; }

/* ---------- Aviso de dados novos ---------- */
.aviso-dados-novos {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  padding: 0.7rem 1.2rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent);
}
