:root {
  --bg: #f3f6f6;
  --surface: #ffffff;
  --surface-2: #eaf0f0;
  --ink: #12302f;
  --ink-2: #4a6362;
  --ink-3: #7a8f8e;
  --line: #d6e0df;
  --line-2: #e6eded;
  --brand: #0f5f5b;
  --brand-ink: #ffffff;
  --brand-hover: #0b4a47;
  --best: #17855f;
  --best-bg: #e2f3eb;
  --warn: #8f5200;
  --warn-bg: #fff0d1;
  --bad: #b3261e;
  --bad-bg: #fde8e6;
  --info: #2b5fa8;
  --info-bg: #e6eefa;
  --focus: #1b6fd1;
  --radius: 8px;
  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1c1c; --surface: #152727; --surface-2: #1c3333; --ink: #e3efee; --ink-2: #a5bdbb; --ink-3: #7c9593;
    --line: #2b4443; --line-2: #223837; --brand: #3cb5aa; --brand-ink: #062321; --brand-hover: #5cc9bf;
    --best: #4cc79a; --best-bg: #153a2e; --warn: #f0b755; --warn-bg: #3a2c0f; --bad: #ff8d84; --bad-bg: #3d1a18;
    --info: #8db6ee; --info-bg: #172b47; --focus: #7db4ff;
  }
}

* { box-sizing: border-box; }
html { font-family: var(--font); font-size: 16px; color: var(--ink); background: var(--bg); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; line-height: 1.45; font-variant-numeric: tabular-nums; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; font-weight: 650; }
h2 { font-size: 1.15rem; font-weight: 650; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--brand); color: var(--brand-ink); padding: .5rem 1rem; z-index: 100; }
.skip:focus { left: 0; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.right { text-align: right; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- barra superior ---- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-in { max-width: 1400px; margin: 0 auto; padding: 0 20px; display: flex; align-items: center; gap: 24px; min-height: 56px; }
.brand { font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--brand); display: grid; place-items: center; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 8px 12px; border-radius: 6px; text-decoration: none; color: var(--ink-2); font-weight: 550; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--surface-2); }
.user { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--ink-2); }

main { max-width: 1400px; margin: 0 auto; padding: 24px 20px 80px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }

/* ---- botões ---- */
.btn { border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 7px; font-weight: 550; cursor: pointer; min-height: 38px; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--ink); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 30px; padding: 3px 10px; font-size: .88rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- chips ---- */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: .8rem; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.chip.rascunho { background: var(--info-bg); color: var(--info); }
.chip.em_revisao { background: var(--warn-bg); color: var(--warn); }
.chip.fechada { background: var(--best-bg); color: var(--best); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }

/* ---- listas e tabelas simples ---- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.lista { width: 100%; border-collapse: collapse; }
table.lista th { text-align: left; font-weight: 600; font-size: .85rem; color: var(--ink-2); padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
table.lista td { padding: 12px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.lista tr:last-child td { border-bottom: 0; }
table.lista tbody tr.click { cursor: pointer; }
table.lista tbody tr.click:hover td { background: var(--surface-2); }
table.lista a.row-link { color: var(--ink); font-weight: 600; text-decoration: none; }
table.lista a.row-link:hover { text-decoration: underline; }
.progress { width: 120px; height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); }
.empty { padding: 48px 20px; text-align: center; color: var(--ink-2); }
.empty h2 { color: var(--ink); margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }

.search { position: relative; max-width: 360px; width: 100%; }
.search input { width: 100%; }

/* ---- formulários ---- */
label.f { display: block; font-weight: 550; font-size: .9rem; margin-bottom: 14px; }
label.f > span.hint { display: block; font-weight: 400; color: var(--ink-2); font-size: .82rem; margin-top: 2px; }
input[type=text], input[type=number], input[type=password], input[type=search], input[type=month], input[type=email], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 8px 10px; min-height: 38px; margin-top: 4px;
}
textarea { min-height: 70px; resize: vertical; }
input:disabled, select:disabled { background: var(--surface-2); color: var(--ink-3); }
.row { display: grid; gap: 12px; }
.row.two { grid-template-columns: 1fr 1fr; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-bottom: 12px; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); }
.erro { background: var(--bad-bg); color: var(--bad); border-radius: 7px; padding: 9px 12px; margin-bottom: 12px; font-size: .92rem; }
.aviso { background: var(--warn-bg); color: var(--warn); border-radius: 7px; padding: 9px 12px; margin-bottom: 12px; font-size: .92rem; }
.info { background: var(--info-bg); color: var(--info); border-radius: 7px; padding: 9px 12px; margin-bottom: 12px; font-size: .92rem; }
.preview { background: var(--surface-2); border-radius: 7px; padding: 10px 12px; margin-bottom: 14px; font-size: .92rem; }
.preview strong { font-weight: 650; }

/* ---- diálogos ---- */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 24px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.28); }
dialog.wide { width: min(760px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(10, 30, 30, .45); }
.dlg-head { padding: 18px 22px 0; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.dlg-body { padding: 16px 22px 8px; max-height: 70vh; overflow: auto; }
.dlg-foot { padding: 12px 22px 18px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.dlg-foot .spacer { flex: 1; }
.x { background: transparent; border: 0; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--ink-2); padding: 4px 8px; border-radius: 6px; }
.x:hover { background: var(--surface-2); }

/* ---- cotação: cabeçalho ---- */
.back { display: inline-block; margin-bottom: 8px; font-size: .9rem; text-decoration: none; }
.steps { display: flex; gap: 0; margin-top: 10px; font-size: .86rem; font-weight: 600; }
.steps li { list-style: none; display: flex; align-items: center; color: var(--ink-3); }
.steps { padding: 0; margin-bottom: 0; }
.steps li + li::before { content: ""; width: 28px; height: 2px; background: var(--line); margin: 0 8px; }
.steps li.feito { color: var(--ink-2); }
.steps li.feito + li::before, .steps li.atual::before { background: var(--brand); }
.steps li.atual { color: var(--brand); }
.steps li .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); margin-right: 7px; }
.steps li.feito .dot { background: var(--brand); }
.steps li.atual .dot { background: var(--brand); box-shadow: 0 0 0 4px var(--best-bg); }

.stats { display: flex; gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; overflow-x: auto; }
.stat { padding: 12px 20px; border-right: 1px solid var(--line-2); min-width: 140px; }
.stat:last-child { border-right: 0; }
.stat b { display: block; font-size: 1.35rem; font-weight: 650; line-height: 1.2; }
.stat span { font-size: .84rem; color: var(--ink-2); }
.stat.total { margin-left: auto; background: var(--surface-2); }
.stat.total + .stat.total { margin-left: 0; border-left: 1px solid var(--line); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

/* ---- matriz de comparação ---- */
.matrix-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); max-height: calc(100vh - 220px); }
table.matrix { border-collapse: separate; border-spacing: 0; width: 100%; }
.matrix th, .matrix td { border-bottom: 1px solid var(--line-2); vertical-align: top; }
.matrix thead th { position: sticky; top: 0; background: var(--surface); z-index: 3; padding: 10px 12px; text-align: left; font-size: .88rem; font-weight: 650; border-bottom: 1px solid var(--line); white-space: nowrap; }
.matrix .col-item { position: sticky; left: 0; z-index: 2; background: var(--surface); min-width: 250px; max-width: 300px; border-right: 1px solid var(--line); padding: 10px 12px; }
.matrix thead .col-item { z-index: 4; }
.matrix tr.cat td { background: var(--surface-2); font-size: .8rem; font-weight: 650; color: var(--ink-2); padding: 5px 12px; position: sticky; left: 0; }
.matrix .item-nome { font-weight: 600; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; color: var(--ink); }
.matrix .item-nome:hover { text-decoration: underline; }
.matrix .item-meta { font-size: .84rem; color: var(--ink-2); margin-top: 2px; }
.matrix td.cel { min-width: 168px; padding: 6px; }
.matrix td.dec { min-width: 200px; padding: 10px 12px; background: var(--surface); }
.matrix th.dec { min-width: 200px; }

.prop { display: block; width: 100%; text-align: left; border: 1px solid var(--line-2); background: var(--surface); border-radius: 7px; padding: 7px 9px 7px 11px; cursor: pointer; position: relative; margin-bottom: 4px; }
.prop:last-of-type { margin-bottom: 0; }
.prop:hover { border-color: var(--ink-3); }
.prop .preco { font-weight: 700; font-size: 1.02rem; }
.prop .det { font-size: .8rem; color: var(--ink-2); }
.prop .marca { font-size: .8rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prop .flags { display: flex; gap: 4px; margin-top: 3px; flex-wrap: wrap; }
.prop.melhor { background: var(--best-bg); border-color: transparent; }
.prop.melhor::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 4px; border-radius: 0 3px 3px 0; background: var(--best); }
.prop.escolhida { outline: 2px solid var(--ink); outline-offset: -1px; }
.prop.nao { background: transparent; color: var(--ink-3); border-style: dashed; }
.prop .tag-escolha { position: absolute; top: 6px; right: 7px; font-size: .72rem; font-weight: 700; background: var(--ink); color: var(--surface); border-radius: 4px; padding: 1px 6px; }
.add-prop { width: 100%; min-height: 54px; border: 1px dashed var(--line); background: transparent; color: var(--ink-3); border-radius: 7px; cursor: pointer; font-size: .86rem; }
.add-prop:hover { border-color: var(--brand); color: var(--brand); background: var(--best-bg); }
.add-outra { background: none; border: 0; color: var(--brand); font-size: .78rem; cursor: pointer; padding: 3px 2px; }
.add-outra:hover { text-decoration: underline; }
.nada { color: var(--ink-3); font-size: .85rem; }

.dec .quem { font-weight: 600; }
.dec .motivo { font-size: .82rem; color: var(--ink-2); margin-top: 2px; }
.dec .btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.banner { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.revisao { background: var(--warn-bg); color: var(--warn); }
.banner.fechada { background: var(--best-bg); color: var(--best); }
.banner .spacer { flex: 1; }

.eventos { margin-top: 22px; }
.eventos summary { cursor: pointer; font-weight: 600; color: var(--ink-2); }
.eventos ul { margin: 10px 0 0; padding: 0; list-style: none; font-size: .88rem; color: var(--ink-2); }
.eventos li { padding: 3px 0; }

/* ---- produto: histórico ---- */
.spark { display: block; }

/* ---- pedido ---- */
.pedido { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 14px; }
.pedido header { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; gap: 10px; flex-wrap: wrap; }
.pedido table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.pedido td { padding: 8px 14px; border-top: 1px solid var(--line-2); }

/* ---- picker de produto ---- */
.pick-list { list-style: none; margin: 8px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 7px; max-height: 260px; overflow: auto; }
.pick-list li button { width: 100%; text-align: left; background: none; border: 0; padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.pick-list li button:hover:not([disabled]) { background: var(--surface-2); }
.pick-list li button[disabled] { color: var(--ink-3); cursor: not-allowed; }
.pick-list li + li { border-top: 1px solid var(--line-2); }

/* ---- login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .panel { padding: 28px; width: min(400px, 100%); }
.login h1 { margin: 14px 0 4px; }

/* ---- toasts ---- */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; font-weight: 550; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.erro { background: var(--bad); color: #fff; }

@media (max-width: 760px) {
  .topbar-in { gap: 10px; padding: 0 12px; flex-wrap: wrap; padding-bottom: 6px; }
  .brand span.t { display: none; }
  main { padding: 16px 12px 60px; }
  .row.two, .row.three { grid-template-columns: 1fr; }
  .matrix .col-item { min-width: 170px; }
  .user .nm { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in .18s ease-out; }
  @keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
}
@media print {
  .topbar, .toolbar, .actions, #toasts, .eventos { display: none !important; }
  .matrix-wrap { max-height: none; overflow: visible; }
}
