/* =========================================================
   Derrô Ateliê — identidade visual
   ========================================================= */
:root {
  --bg: #f4ece2;
  --surface: #fffbf6;
  --surface-2: #f3e9dd;
  --ink: #3b2a1f;
  --ink-2: #6b5444;
  --muted: #9a8574;
  --line: #e6d8c7;
  --brand: #a55a2e;
  --brand-strong: #8a4722;
  --brand-soft: #f3dfcf;
  --on-brand: #ffffff;
  --good: #2f7d4f;
  --good-soft: #e1f0e6;
  --warn: #a8690f;
  --warn-soft: #faeccf;
  --bad: #b03a2e;
  --bad-soft: #f8dfdb;
  --chart-grid: #ebe0d2;
  --chart-in: #1baf7a;
  --chart-out: #eb6834;
  --shadow: 0 1px 2px rgba(59, 42, 31, .06), 0 4px 16px rgba(59, 42, 31, .06);
  --radius: 14px;
  --font-title: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --font-body: "Nunito Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --nav-w: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1612; --surface: #261e18; --surface-2: #31271f; --ink: #f2e8dc; --ink-2: #cdbba8;
    --muted: #9c8a78; --line: #3d3128; --brand: #d0844f; --brand-strong: #e09a66; --brand-soft: #4a3122;
    --on-brand: #1c1612; --good: #5cbf85; --good-soft: #1f3a2a; --warn: #e3a64a; --warn-soft: #3d2f17;
    --bad: #e2766a; --bad-soft: #432220; --chart-grid: #3a2f27; --chart-in: #199e70; --chart-out: #d95926;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1612; --surface: #261e18; --surface-2: #31271f; --ink: #f2e8dc; --ink-2: #cdbba8;
  --muted: #9c8a78; --line: #3d3128; --brand: #d0844f; --brand-strong: #e09a66; --brand-soft: #4a3122;
  --on-brand: #1c1612; --good: #5cbf85; --good-soft: #1f3a2a; --warn: #e3a64a; --warn-soft: #3d2f17;
  --bad: #e2766a; --bad-soft: #432220; --chart-grid: #3a2f27; --chart-in: #199e70; --chart-out: #d95926;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--font-title); font-weight: 700; letter-spacing: .2px; margin: 0; color: var(--ink); }
h1 { font-size: 30px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 16px; }
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot img { border-radius: 50%; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

/* ---------- Layout ---------- */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--nav-w); background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 12px; z-index: 30; transition: transform .2s ease;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand img { width: 46px; height: 46px; border-radius: 50%; }
.brand b { font-family: var(--font-title); font-size: 22px; display: block; line-height: 1; }
.brand span { font-size: 11px; letter-spacing: 3px; color: var(--muted); text-transform: uppercase; }
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--ink-2);
  text-decoration: none; font-weight: 600;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--brand-soft); color: var(--brand-strong); }
.nav svg { width: 20px; height: 20px; flex: none; }
.nav-foot { border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; color: var(--muted); }
.nav-foot .user { padding: 4px 12px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { margin-left: var(--nav-w); padding: 28px 32px 48px; max-width: 1400px; }
.topbar { display: none; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.demo-banner {
  background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); border-radius: 10px;
  padding: 8px 12px; font-size: 13px; margin-bottom: 16px;
}
.scrim { display: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow); }
  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .main { margin-left: 0; padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20; background: var(--bg);
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--line);
  }
  .topbar img { width: 34px; height: 34px; border-radius: 50%; }
  .topbar b { font-family: var(--font-title); font-size: 20px; }
  h1 { font-size: 26px; }
  .bottom-nav {
    position: fixed; inset: auto 0 0 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line);
    display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a, .bottom-nav button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 11px;
    color: var(--muted); text-decoration: none; background: none; border: 0; font-weight: 600;
  }
  .bottom-nav a.active { color: var(--brand); }
  .bottom-nav svg { width: 22px; height: 22px; }
}
@media (min-width: 901px) { .bottom-nav { display: none; } }

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card h2, .card h3 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.kpi .value { font-family: var(--font-title); font-size: 28px; font-weight: 700; margin-top: 2px; font-variant-numeric: lining-nums tabular-nums; }
.kpi .hint { font-size: 12px; color: var(--muted); }
.kpi.alert { border-color: var(--bad); }
@media (max-width: 500px) { .kpis { grid-template-columns: 1fr 1fr; } .kpi .value { font-size: 23px; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); border-radius: 10px; padding: 9px 14px; font-weight: 700; cursor: pointer;
  min-height: 40px; text-decoration: none;
}
.btn:hover { border-color: var(--brand); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-strong); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { padding: 8px; min-width: 40px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .search { flex: 1 1 220px; }
.tabs { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 7px 12px; border-radius: 8px; font-weight: 700; color: var(--ink-2); cursor: pointer; }
.tabs button.active { background: var(--surface); color: var(--brand-strong); box-shadow: var(--shadow); }

/* ---------- Formulários ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.field .help { font-size: 12px; color: var(--muted); }
.field .err { font-size: 12px; color: var(--bad); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time],
input[type=search], input[type=tel], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 11px;
  min-height: 42px; outline: none;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.invalid input, .invalid select, .invalid textarea { border-color: var(--bad); }
.check, .field.check { display: flex; flex-direction: row; gap: 8px; align-items: center; font-weight: 600; cursor: pointer; }
.field.check > span { color: var(--ink); font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.form-section { grid-column: 1 / -1; font-family: var(--font-title); font-size: 19px; font-weight: 700; margin-top: 6px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.repeater { grid-column: 1 / -1; border: 1px dashed var(--line); border-radius: 12px; padding: 12px; }
.repeater > .rhead { display: flex; align-items: center; margin-bottom: 8px; font-weight: 700; color: var(--ink-2); font-size: 13px; }
.repeater .rrow { display: grid; gap: 8px; align-items: end; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)) 40px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.repeater .rrow:last-of-type { border-bottom: 0; }
.repeater .rrow .wide { grid-column: span 2; }
.repeater .empty { color: var(--muted); font-size: 13px; padding: 4px 0 8px; }
@media (max-width: 600px) { .repeater .rrow { grid-template-columns: 1fr 1fr; } .repeater .rrow .wide { grid-column: 1 / -1; } }
.file-box { border: 1px dashed var(--line); border-radius: 12px; padding: 10px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.file-box img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.calc-box { grid-column: 1 / -1; background: var(--surface-2); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px 18px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.calc-box div { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.calc-box b { font-variant-numeric: tabular-nums; }
.calc-box .total { font-size: 16px; color: var(--brand-strong); }

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: var(--surface-2); }
table.data th.right, table.data td.right { text-align: right; }
table.data tfoot td { font-weight: 700; border-bottom: 0; }
.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: var(--surface-2); display: block; }
.empty-state { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty-state b { display: block; color: var(--ink-2); font-size: 16px; margin-bottom: 4px; }
@media (max-width: 700px) {
  table.data.cards thead { display: none; }
  table.data.cards, table.data.cards tbody, table.data.cards tr, table.data.cards td { display: block; width: 100%; }
  table.data.cards tr { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; padding: 6px 4px; background: var(--surface); }
  table.data.cards td { border: 0; padding: 4px 10px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.data.cards td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 700; text-align: left; }
  table.data.cards td.primary { font-weight: 700; font-size: 15px; }
  table.data.cards td.primary::before { content: none; }
  table.data.cards tfoot { display: block; }
}

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.brand { background: var(--brand-soft); color: var(--brand-strong); }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* ---------- Modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(30, 20, 14, .45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal {
  background: var(--surface); border-radius: 18px; width: min(860px, 100%); max-height: calc(100vh - 32px);
  display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal.sm { width: min(440px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
@media (max-width: 600px) {
  .modal-back { padding: 0; place-items: end stretch; }
  .modal, .modal.sm { width: 100%; max-height: 94vh; border-radius: 18px 18px 0 0; }
  .modal-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}
.toasts { position: fixed; z-index: 60; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 600; max-width: 340px; }
.toast.error { background: var(--bad); color: #fff; }
@media (max-width: 900px) { .toasts { left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); } }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: min(400px, 100%); padding: 28px; }
.auth .logo { display: block; width: 150px; height: 150px; border-radius: 50%; margin: 0 auto 14px; }
.auth h1 { text-align: center; margin-bottom: 4px; }
.auth p.lead { text-align: center; color: var(--muted); margin: 0 0 20px; }
.auth form > * + * { margin-top: 14px; }
.msg { padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.msg.error { background: var(--bad-soft); color: var(--bad); }
.msg.ok { background: var(--good-soft); color: var(--good); }
.msg.info { background: var(--surface-2); color: var(--ink-2); }

/* ---------- Gráficos ---------- */
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list-plain li:last-child { border-bottom: 0; }

/* ---------- Ficha técnica / galeria ---------- */
.gallery { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.pcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; text-align: left; padding: 0; }
.pcard:hover { border-color: var(--brand); }
.pcard .ph { aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); }
.pcard .ph img { width: 100%; height: 100%; object-fit: cover; }
.pcard .ph svg { width: 44px; height: 44px; opacity: .6; }
.pcard .pb { padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.pcard .pb b { font-family: var(--font-title); font-size: 19px; }
.sheet { display: grid; gap: 18px; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); }
@media (max-width: 760px) { .sheet { grid-template-columns: 1fr; } }
.sheet .photo { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 14px; background: var(--surface-2); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 700; }
.kv dd { margin: 0; }
.timer { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.timer .clock { font-family: var(--font-title); font-size: 42px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 170px; }

/* ---------- Progresso ---------- */
.progress { display: flex; flex-direction: column; gap: 4px; }
.progress .bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress .bar i { display: block; height: 100%; border-radius: 999px; background: var(--brand); }
.progress.good .bar i { background: var(--good); }
.progress.warn .bar i { background: var(--warn); }
.progress.bad .bar i { background: var(--bad); }

/* ---------- Quadro de produção ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(190px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.col-head { display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 2px 4px; }
.col-head .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.ticket { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.ticket.late { border-left: 4px solid var(--bad); }
.ticket .t-top { display: flex; gap: 8px; align-items: baseline; }
.ticket .t-top b { font-family: var(--font-title); font-size: 17px; }
.ticket .t-items { font-size: 13px; color: var(--ink-2); }
.ticket .t-actions { display: flex; gap: 6px; }
.ticket .t-actions .btn { min-height: 32px; padding: 4px 10px; font-size: 13px; }
@media (max-width: 700px) { .board { grid-auto-flow: row; grid-auto-columns: auto; } }

/* ---------- Alertas ---------- */
.bell { position: relative; }
.bell .dot { position: absolute; top: 2px; right: 2px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }
.alert-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.alert-list a { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--ink); text-decoration: none; }
.alert-list a:hover { outline: 1px solid var(--brand); }
.alert-list svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.alert-list .bad svg { color: var(--bad); }
.alert-list .warn svg { color: var(--warn); }
.brand .bell { margin-left: auto; }

/* ---------- Biblioteca de nós ---------- */
.stars { color: var(--brand); letter-spacing: 1px; }
.steps { counter-reset: passo; list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.steps li { counter-increment: passo; display: grid; grid-template-columns: 34px 1fr; gap: 10px; }
.steps li::before { content: counter(passo); width: 30px; height: 30px; border-radius: 50%; background: var(--brand); color: var(--on-brand); display: grid; place-items: center; font-weight: 700; }
.steps img { max-width: 320px; width: 100%; border-radius: 10px; margin-top: 6px; display: block; }

@media print {
  .sidebar, .bottom-nav, .topbar, .toolbar, .btn, .modal-foot, .modal-head .btn { display: none !important; }
  body:has(.modal-back) .shell { display: none !important; }
  :root, :root[data-theme] {
    --bg: #fff !important; --surface: #fff !important; --surface-2: #f5efe8 !important; --ink: #2b1d14 !important;
    --ink-2: #5a4536 !important; --muted: #7d6a5b !important; --line: #ddd0c0 !important; --brand: #a55a2e !important; --brand-strong: #8a4722 !important;
  }
  body { background: #fff; color: #000; }
  .main { margin: 0; padding: 0; }
  .modal-back { position: static; background: none; padding: 0; }
  .modal { box-shadow: none; max-height: none; width: 100%; border-radius: 0; }
  .modal-body { overflow: visible; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
}
