/* ============ Tokens ============
   Paleta e tipografia inspiradas no site pessoal (jp.bezerra): sans-serif
   neutra (Inter) para toda a interface e um par de temas — claro com acento
   verde-petróleo, escuro com acento dourado/mostarda. */
:root {
  --paper:      #f8f7f3;
  --paper-2:    #f1efe8;
  --card:       #ffffff;
  --ink:        #16181c;
  --ink-2:      #21242b;
  --line:       #e6e3da;
  --text:       #1c1e22;
  --text-dim:   #6a6d74;
  --accent:     #3d7a6c;
  --accent-ink: #ffffff;
  --accent-soft:#e3efe9;
  --ok:         #3d8b62;
  --err:        #c0453f;
  --info:       #3a6ea8;
  --warn:       #b8862f;
  --radius: 10px;
  --radius-sm: 7px;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --shadow-sm: 0 1px 2px rgba(20,20,15,.05), 0 1px 1px rgba(20,20,15,.03);
  --shadow-md: 0 8px 24px rgba(20,20,15,.08);
}

/* Escuro: segue prefers-color-scheme por padrão, ou data-theme explícito */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:      #0b0b0d;
    --paper-2:    #131316;
    --card:       #17181b;
    --ink:        #000000;
    --ink-2:      #1c1d21;
    --line:       #2a2b30;
    --text:       #f2efe6;
    --text-dim:   #928f87;
    --accent:     #c9a24c;
    --accent-ink: #1a1508;
    --accent-soft: rgba(201,162,76,.14);
    --ok:         #4fae7c;
    --err:        #e2665f;
    --info:       #5f9bda;
    --warn:       #d6a94a;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 10px 28px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  --paper:      #0b0b0d;
  --paper-2:    #131316;
  --card:       #17181b;
  --ink:        #000000;
  --ink-2:      #1c1d21;
  --line:       #2a2b30;
  --text:       #f2efe6;
  --text-dim:   #928f87;
  --accent:     #c9a24c;
  --accent-ink: #1a1508;
  --accent-soft: rgba(201,162,76,.14);
  --ok:         #4fae7c;
  --err:        #e2665f;
  --info:       #5f9bda;
  --warn:       #d6a94a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 10px 28px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.55 var(--sans); color: var(--text); background: var(--paper);
  transition: background .15s ease, color .15s ease;
}
h1, h2, h3 { margin: 0 0 .4em; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; }
.muted { color: var(--text-dim); }
[hidden] { display: none !important; }
.brand-accent { font-family: inherit; font-style: normal; font-weight: 700; color: var(--accent); }

input, select, textarea {
  font: inherit; color: inherit; width: 100%;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card);
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }

.eyebrow {
  font-size: 11px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: var(--accent);
}

/* ============ Ícones ============ */
[data-lucide] { display: inline-block; width: 16px; height: 16px; }
svg.icon, svg[data-lucide] { width: 16px; height: 16px; stroke-width: 1.9; vertical-align: -3px; flex-shrink: 0; }
.icon-lg { width: 20px !important; height: 20px !important; }
.icon-sm { width: 13px !important; height: 13px !important; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.status-dot.aberta      { background: var(--text-dim); }
.status-dot.em_andamento{ background: var(--info); }
.status-dot.concluida   { background: var(--ok); }
.status-dot.cancelada   { background: var(--err); }

/* ============ Botões ============ */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  transition: border-color .12s ease, filter .12s ease;
}
.btn:hover { border-color: var(--text-dim); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.06); border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }
.btn-danger { color: var(--err); }

/* ============ Tema toggle ============ */
.theme-toggle {
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); color: var(--text); display: grid; place-items: center;
  cursor: pointer; flex-shrink: 0; padding: 0;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle svg { width: 15px; height: 15px; }
.theme-toggle .i-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: block; }
}

/* ============ Login ============ */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; background: var(--ink);
  background-image: radial-gradient(circle at 15% 20%, rgba(201,162,76,.06), transparent 45%);
}
.login-card {
  width: min(380px, 92vw); background: var(--card); border-radius: 14px;
  padding: 30px; box-shadow: var(--shadow-md); border: 1px solid var(--line);
}
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand h1 { margin: 10px 0 4px; font-size: 21px; }
.login-brand p.muted { font-size: 12.5px; }
.form-error { color: var(--err); font-size: 13px; margin: 10px 0 0; }

.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink);
}
.brand-mark svg { width: 16px; height: 16px; }

/* ============ Layout ============ */
.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; transition: grid-template-columns .2s ease; }
.sidebar {
  background: var(--ink); color: #b9bcc4; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; height: 100dvh; min-width: 0;
  border-right: 1px solid var(--ink-2); z-index: 20;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 6px; padding: 18px 8px 14px;
  color: #fff; font-weight: 700; font-size: 15px;
}
.sidebar-brand-name { white-space: nowrap; letter-spacing: -.4px; }
.sidebar-toggle { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; min-height: 36px; padding: 2px;
  border: 0; border-radius: 8px; background: transparent; color: inherit; font: inherit; cursor: pointer; }
.sidebar-toggle:hover { background: var(--ink-2); }
.sidebar-brand .theme-toggle { flex-shrink: 0; }
.sidebar :is(a, button):focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.flyout-title { display: none; }
.menu { flex: 1; padding: 6px 8px; overflow-y: auto; }
.menu-link {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; margin: 1px 0; border-radius: 7px;
  color: inherit; text-decoration: none; font-weight: 500; font-size: 13.5px;
}
.menu-link svg { color: #82858f; flex-shrink: 0; }
.menu-link:hover { background: var(--ink-2); color: #fff; }
.menu-link:hover svg { color: #fff; }
.menu-link.active { background: var(--ink-2); color: var(--accent); }
.menu-link.active svg { color: var(--accent); }

.menu-group { margin: 2px 0; }
.menu-group-head {
  width: 100%; text-align: left; background: none; border: 0; color: #b9bcc4;
  font: inherit; font-weight: 500; font-size: 13.5px;
  padding: 11px 10px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; gap: 9px;
}
.menu-group-head .grp-label { flex: 1; display: flex; align-items: center; gap: 9px; }
.menu-group-head svg { color: #82858f; }
.menu-group-head:hover { color: #fff; background: var(--ink-2); }
.menu-group-head:hover svg { color: #fff; }
.menu-group-head .chev { transition: transform .15s ease; width: 13px; height: 13px; }
.menu-group.open .menu-group-head .chev { transform: rotate(90deg); }
.menu-group-body { display: none; padding-left: 12px; margin: 3px 0 8px 17px; border-left: 1px solid #ffffff18; }
.menu-group.open .menu-group-body { display: block; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--ink-2); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-footer .btn-ghost { color: #b9bcc4; }
.user-chip { font-size: 12.5px; line-height: 1.3; min-width: 0; }
.user-chip .role { color: var(--accent); text-transform: capitalize; font-size: 11px; }

/* Barra compacta: grupos abrem um painel ao lado, mantendo todas as rotas. */
[data-sidebar="collapsed"] .app { grid-template-columns: 68px minmax(0, 1fr); }
[data-sidebar="collapsed"] .sidebar-brand { flex-direction: column; gap: 12px; padding: 18px 0 14px; }
[data-sidebar="collapsed"] .sidebar-brand-name,
[data-sidebar="collapsed"] .menu > .menu-link span,
[data-sidebar="collapsed"] .grp-name,
[data-sidebar="collapsed"] .menu-group-head .chev,
[data-sidebar="collapsed"] .user-chip,
[data-sidebar="collapsed"] #btn-logout span { display: none; }
[data-sidebar="collapsed"] .sidebar-toggle { flex: none; width: 42px; justify-content: center; }
[data-sidebar="collapsed"] .menu > .menu-link,
[data-sidebar="collapsed"] .menu-group-head { justify-content: center; min-height: 44px; padding: 12px; }
[data-sidebar="collapsed"] .grp-label { flex: none; }
[data-sidebar="collapsed"] .menu-group.has-active > .menu-group-head,
[data-sidebar="collapsed"] .menu-group.flyout-open > .menu-group-head { background: var(--ink-2); color: var(--accent); }
[data-sidebar="collapsed"] .menu-group.has-active > .menu-group-head svg { color: var(--accent); }
[data-sidebar="collapsed"] .menu-group .menu-group-body { display: none; }
[data-sidebar="collapsed"] .menu-group.flyout-open .menu-group-body {
  display: block; position: fixed; width: 242px; max-width: calc(100vw - 84px); max-height: calc(100dvh - 16px);
  overflow-y: auto; padding: 8px; margin: 0; border: 1px solid #ffffff20; border-radius: 12px;
  background: var(--ink); box-shadow: 0 12px 36px #0004; z-index: 25;
}
[data-sidebar="collapsed"] .flyout-title { display: block; padding: 8px 10px 10px; font-size: 12px; font-weight: 700; color: #fff; }
[data-sidebar="collapsed"] .sidebar-footer { justify-content: center; padding: 12px 8px; }
[data-sidebar="collapsed"] #btn-logout { width: 42px; min-height: 40px; padding: 8px; justify-content: center; }
@media (prefers-reduced-motion: reduce) { .app { transition: none; } }

.content { padding: 26px 30px 60px; max-width: 1280px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { display: flex; align-items: center; gap: 10px; }
.page-head .subtitle { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============ Cards e KPIs ============ */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.kpi .kpi-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; }
.kpi .kpi-sub { color: var(--text-dim); font-size: 12px; margin-top: 4px; }
.kpi-icon {
  width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center;
  flex-shrink: 0;
}
.kpi-icon svg { width: 17px; height: 17px; }
.kpi-icon.amber { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.kpi-icon.green { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.kpi-icon.red   { background: color-mix(in srgb, var(--err) 14%, transparent); color: var(--err); }
.kpi-icon.violet{ background: color-mix(in srgb, var(--info) 16%, transparent); color: var(--info); }
.kpi-icon.accent{ background: var(--accent-soft); color: var(--accent); }

.section-head { display: flex; justify-content: space-between; align-items: baseline; margin: 26px 0 12px; }
.section-head h2 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.section-head .muted { font-size: 12.5px; }

.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }

/* Cartão de relatório/etapa clicável */
.card[data-report] { transition: transform .12s ease, border-color .12s ease; }
.card[data-report]:hover { transform: translateY(-2px); border-color: var(--accent); }
.card[data-report] .report-icon {
  width: 38px; height: 38px; border-radius: 9px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center;
}
.card[data-report] .report-icon svg { width: 18px; height: 18px; }

/* Cartão de etapa (Tecelagem/Tinturaria/Revisão) */
.stage-card .stage-title { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.stage-card .stage-title .kpi-icon { width: 32px; height: 32px; }
.stage-card .stage-title h3 { margin: 0; font-size: 15px; }
.stage-card .stage-title p { margin: 0; font-size: 12px; color: var(--text-dim); }
.stage-card .stage-value { font-size: 22px; font-weight: 700; margin: 10px 0 2px; }
.bar { height: 6px; border-radius: 99px; background: var(--paper-2); overflow: hidden; margin: 8px 0; }
.bar-fill { height: 100%; background: var(--accent); }
.stage-card .stage-badges { display: flex; gap: 6px; margin: 6px 0; }
.stage-card .stage-note { font-size: 12.5px; color: var(--text-dim); background: var(--paper-2); border-radius: 6px; padding: 8px 10px; margin: 8px 0; }
.stage-card .stock-box { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; }
.stock-box .stock-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.stock-box .stock-values { display: flex; gap: 18px; }
.stock-box .stock-values div span { display: block; font-size: 15px; font-weight: 700; color: var(--text); }

/* Mapa de locais */
.loc-card .loc-name { font-weight: 700; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.loc-card .loc-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin-top: 10px; }
.loc-card .loc-stats .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); }
.loc-card .loc-stats .val { font-weight: 700; font-size: 14.5px; }

/* Composições / listas com detalhe expansível */
.comp-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.comp-row:last-child { border-bottom: none; }
.comp-row .comp-head { display: flex; justify-content: space-between; align-items: baseline; }
.comp-row .comp-head .val { font-weight: 700; }
.comp-row .comp-sub { font-size: 12px; color: var(--text-dim); }
.collapsible summary { cursor: pointer; font-size: 12.5px; color: var(--info); font-weight: 600; margin-top: 4px; list-style: none; display: flex; align-items: center; gap: 4px; }
.collapsible summary::-webkit-details-marker { display: none; }
.collapsible summary::before { content: '▸'; font-size: 10px; }
.collapsible[open] summary::before { content: '▾'; }
.collapsible .color-list { margin: 6px 0 0; padding: 0; list-style: none; font-size: 12.5px; }
.collapsible .color-list li { display: flex; justify-content: space-between; padding: 3px 0; }

/* ============ Tabelas ============ */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim); background: var(--paper-2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--paper-2); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge-ok    { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge-off   { background: var(--paper-2); color: var(--text-dim); }
.badge-warn  { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.badge-info  { background: color-mix(in srgb, var(--info) 16%, transparent); color: var(--info); }

.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--line); vertical-align: -2px; margin-right: 6px; }

/* Toggle switch (ativo/inativo) */
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle .track { position: absolute; inset: 0; background: var(--line); border-radius: 99px; transition: background .15s; }
.toggle .thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.toggle input:checked + .track { background: var(--ok); }
.toggle input:checked + .track .thumb { transform: translateX(16px); }
.toggle input:disabled { cursor: default; }

/* Botões de ícone (editar/excluir em linhas de tabela) */
.icon-btn {
  display: inline-grid; place-items: center; width: 28px; height: 28px;
  border-radius: 6px; border: 1px solid transparent; background: transparent;
  color: var(--text-dim); cursor: pointer;
}
.icon-btn:hover { background: var(--paper-2); border-color: var(--line); color: var(--text); }
.icon-btn.danger:hover { color: var(--err); }

/* Filtro por local (chips) */
.chip-filter { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.chip {
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card);
  font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text);
}
.chip:hover { border-color: var(--text-dim); }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }

.search-input { position: relative; flex: 1; min-width: 220px; }
.search-input input { padding-left: 32px; }
.search-input::before {
  content: ''; position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; background: var(--text-dim); pointer-events: none;
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>') center / contain no-repeat;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>') center / contain no-repeat;
}

/* ============ Modal e toast ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10,10,10,.5);
  display: grid; place-items: center; z-index: 50;
}
.modal {
  background: var(--card); border-radius: 14px; padding: 20px;
  width: min(480px, 94vw); max-height: 90vh; overflow-y: auto;
  border: 1px solid var(--line); box-shadow: var(--shadow-md);
}
.modal h2 { margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

#toast-root { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast {
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent); font-size: 13.5px; max-width: 340px;
  animation: toast-in .18s ease-out; box-shadow: var(--shadow-md);
}
.toast-error { border-left-color: var(--err); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }

.empty { padding: 32px; text-align: center; color: var(--text-dim); }
.env-flag {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 12px;
  padding: 6px 14px; border-radius: 99px; z-index: 40; box-shadow: var(--shadow-md);
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  [data-sidebar="collapsed"] .sidebar { position: sticky; height: 100dvh; }
  .content { padding: 18px 14px 40px; }
  .form-grid { grid-template-columns: 1fr; }
}
