/* Visual do sistema: cores neutras (tons de pedra e grafite), sem dependências externas. */
:root {
  --bg: #f5f4f1;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --sunken: #efede9;
  --border: #e6e3de;
  --border-strong: #d4d0c9;
  --text: #1f1e1b;
  --text-2: #55524c;
  --muted: #8a867e;
  --ink: #2a2825;
  --ink-hover: #3d3a36;
  --ok: #4a6652;
  --ok-bg: #e8eee9;
  --warn: #8a6a2d;
  --warn-bg: #f5eddc;
  --bad: #8d4a42;
  --bad-bg: #f5e6e3;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(31, 30, 27, .04), 0 4px 14px rgba(31, 30, 27, .04);
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 620; }
p { margin: 0; }
a { color: inherit; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.stack { display: grid; gap: 20px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Estrutura ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 22px 14px;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 22px; overflow-y: auto;
}
.brand { display: block; padding: 0 6px; }
.brand img { display: block; width: 100%; max-width: 150px; height: auto; margin: 0 auto; mix-blend-mode: multiply; filter: brightness(1.03); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--ink); color: #fff;
  display: grid; place-items: center; flex: none;
}
.brand-mark svg { width: 19px; height: 19px; }
.brand b { display: block; font-size: 14px; font-weight: 650; line-height: 1.2; }
.brand span { font-size: 12px; color: var(--muted); }
.nav { display: grid; gap: 2px; }
.nav-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 0 12px; margin: 8px 0 4px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-sm);
  text-decoration: none; color: var(--text-2); font-weight: 500; transition: background .12s, color .12s;
}
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: var(--sunken); color: var(--text); }
.nav a.ativo { background: var(--ink); color: #fff; }
.nav a.ativo svg { opacity: 1; }
.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 12px; }

.main { padding: 34px 40px 64px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.page-head p { color: var(--muted); margin-top: 4px; }

/* ---------- Cartões ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head p { color: var(--muted); font-size: 13px; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 18px 22px 0; }
.grid { display: grid; gap: 20px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }

.stat .label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat .value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; }
.stat .hint { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.value.neg { color: var(--bad); }

.progress { height: 10px; background: var(--sunken); border-radius: 99px; overflow: hidden; margin: 14px 0 8px; }
.progress > i { display: block; height: 100%; background: var(--ink); border-radius: 99px; transition: width .4s ease; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid var(--ink);
  background: var(--ink); color: #fff; font: 600 14px/1.2 var(--font); text-decoration: none;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--ink-hover); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--sunken); }
.btn-danger { background: var(--surface); color: var(--bad); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--bad-bg); border-color: #dcbfba; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn[disabled], .btn.off { opacity: .45; pointer-events: none; }

/* ---------- Formulários ---------- */
label { display: grid; gap: 6px; font-size: 13px; font-weight: 550; color: var(--text-2); }
input, select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; min-height: 92px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(42, 40, 37, .1); }
input::placeholder { color: #aaa69e; }
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, 1fr); }
.form-grid .full { grid-column: 1 / -1; }
.help { font-size: 12.5px; font-weight: 400; color: var(--muted); }
.inline-form { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.inline-form label { flex: 1; min-width: 140px; }
.inline-form .w-sm { flex: 0 0 120px; min-width: 100px; }
.input-prefix { position: relative; }
.input-prefix > span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.input-prefix > input { padding-left: 38px; }
.input-suffix { position: relative; }
.input-suffix > input { padding-right: 34px; }
.input-suffix > span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  font-weight: 600; padding: 12px 22px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
td { padding: 14px 22px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .1s; }
tbody tr:hover { background: var(--surface-2); }
th.right, td.right { text-align: right; }
td .sub { display: block; font-size: 12.5px; color: var(--muted); }
td.acoes { text-align: right; white-space: normal; min-width: 150px; }
td.acoes > * { margin: 2px 0 2px 4px; }
td.acoes form { display: inline; }
tfoot td { background: var(--surface-2); font-weight: 600; border-top: 1px solid var(--border); border-bottom: 0; }

/* ---------- Selos e avisos ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px;
  font-size: 12px; font-weight: 600; background: var(--sunken); color: var(--text-2); white-space: nowrap;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }

.flashes { display: grid; gap: 10px; margin-bottom: 22px; }
.flash {
  padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); font-weight: 500; display: flex; gap: 10px; align-items: flex-start;
}
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: #cddbd0; }
.flash.erro { background: var(--bad-bg); color: var(--bad); border-color: #e6cbc7; }
.notice { padding: 14px 16px; border-radius: var(--radius-sm); background: var(--warn-bg); color: var(--warn); font-size: 14px; }
.notice a { font-weight: 600; }
.empty { padding: 36px 22px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text-2); margin-bottom: 4px; font-size: 15px; }

.subnav { display: flex; gap: 4px; padding: 4px; background: var(--sunken); border-radius: 10px; width: fit-content; margin-bottom: 24px; flex-wrap: wrap; }
.subnav a { padding: 7px 14px; border-radius: 7px; text-decoration: none; font-weight: 550; font-size: 14px; color: var(--text-2); }
.subnav a:hover { color: var(--text); }
.subnav a.ativo { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

/* Aviso fino de cadastros que faltam (uma linha só) */
.todo { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; padding: 9px 14px; border-radius: var(--radius-sm); background: var(--sunken); font-size: 13.5px; color: var(--text-2); }
.todo a { font-weight: 600; color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.todo a:hover { color: var(--ink-hover); }

/* Gastos da OS */
.atalhos { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip-btn { cursor: pointer; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font: 600 13px/1.2 var(--font); }
.chip-btn:hover { background: var(--sunken); color: var(--text); }
.gasto-row { display: grid; grid-template-columns: 1fr 200px 40px; gap: 12px; align-items: center; }
.gasto-row + .gasto-row { margin-top: 10px; }
.help.alerta { color: var(--bad); font-weight: 600; }
.help.ok { color: var(--ok); }
@media (max-width: 700px) { .gasto-row { grid-template-columns: 1fr 120px 40px; } }

/* Painel "Quanto cobrar" */
.dl .sub-linha { padding: 4px 0 4px 16px; }
.dl .sub-linha dt, .dl .sub-linha dd { font-size: 13px; color: var(--muted); font-weight: 500; }
.destaque { margin-top: 14px; padding: 12px 16px; border-radius: var(--radius-sm); background: var(--sunken); color: var(--text-2); font-size: 14px; }
.destaque:empty { display: none; }
.destaque b { color: var(--text); }
.destaque a { font-weight: 600; }

/* Empresa: logo e dados */
.logo-edit { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.logo-previa { width: 140px; height: 140px; object-fit: contain; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #f7f7f7; }
.folha-topo .empresa { display: flex; gap: 18px; align-items: center; }
.folha-logo { width: 96px; height: 96px; object-fit: contain; mix-blend-mode: multiply; filter: brightness(1.03); flex: none; }
.empresa-dados { display: grid; gap: 1px; font-size: 13px; color: var(--text-2); }
.empresa-dados b { font-size: 17px; color: var(--text); margin-bottom: 2px; }
@media (max-width: 860px) { .brand img { max-width: 72px; margin: 0; } .folha-topo { flex-wrap: wrap; } }

/* Entrada com senha e botão Sair */
.login { max-width: 380px; margin: 0 auto; padding: 48px 20px; display: grid; gap: 18px; text-align: center; }
.login img { width: 150px; margin: 0 auto; mix-blend-mode: multiply; filter: brightness(1.03); }
.login form { text-align: left; }
.link-sair { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; font-size: 12.5px; cursor: pointer; text-decoration: underline; }
.link-sair:hover { color: var(--text); }

/* Títulos de seção dentro de um cartão (fechamento) */
.secao-titulo { margin: 22px 0 4px; font-size: 12.5px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* Rede de segurança: nenhum ícone sem tamanho definido vira gigante */
svg { width: 1.1em; height: 1.1em; }

.dl { display: grid; gap: 0; }
.dl > div { display: flex; justify-content: space-between; gap: 16px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.dl > div:last-child { border-bottom: 0; }
.dl dt { color: var(--text-2); }
.dl dd { margin: 0; font-weight: 600; white-space: nowrap; }
.dl .total { font-size: 17px; }
.dl .total dt { color: var(--text); font-weight: 600; }

.split { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.split > div { padding: 18px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.split small { color: var(--muted); font-weight: 550; font-size: 13px; }
.split b { display: block; font-size: 24px; margin-top: 4px; letter-spacing: -.02em; }
.split b.neg { color: var(--bad); }
.split span { font-size: 12.5px; color: var(--muted); }

/* ---------- Formulário de OS ---------- */
.item-row {
  display: grid; grid-template-columns: 1.4fr 1fr 110px 1.2fr 40px; gap: 12px; align-items: start;
  padding: 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.item-row + .item-row { margin-top: 10px; }
.item-calc { font-size: 13px; color: var(--text-2); padding-top: 2px; min-height: 38px; display: flex; flex-direction: column; justify-content: center; }
.item-calc b { font-size: 15px; color: var(--text); }
.item-calc .desc { color: var(--ok); font-weight: 550; }
.item-calc .aviso { color: var(--bad); }
.item-labels { display: grid; grid-template-columns: 1.4fr 1fr 110px 1.2fr 40px; gap: 12px; padding: 0 14px 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.icon-btn { width: 38px; height: 38px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { color: var(--bad); background: var(--bad-bg); }
.icon-btn svg { width: 16px; height: 16px; }
.total-bar { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; padding: 18px 22px; background: var(--ink); color: #fff; border-radius: var(--radius); }
.total-bar small { color: #b5b1a9; display: block; font-size: 13px; }
.total-bar b { font-size: 28px; letter-spacing: -.02em; }
.total-bar .btn { background: #fff; color: var(--ink); border-color: #fff; }
.total-bar .btn:hover { background: #ece9e3; }
.total-bar .btn-ghost { background: transparent; color: #fff; border-color: #6b6760; }
.total-bar .btn-ghost:hover { background: #3d3a36; }
.hidden { display: none !important; }

/* ---------- Matriz de preços ---------- */
.matriz td, .matriz th { padding: 12px 16px; }
.matriz td:first-child { font-weight: 600; width: 28%; }
.matriz input { min-width: 110px; }

/* ---------- OS do cliente (folha para enviar/imprimir) ---------- */
.folha {
  max-width: 720px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 44px 48px;
}
.folha-topo { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 22px; border-bottom: 2px solid var(--ink); margin-bottom: 24px; }
.folha-topo h2 { font-size: 20px; }
.folha-topo .num-os { font-size: 13px; color: var(--muted); text-align: right; }
.folha-topo .num-os b { display: block; font-size: 20px; color: var(--text); }
.folha .meta-info { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 24px; }
.folha .meta-info small { color: var(--muted); display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.folha .descricao { padding: 16px; background: var(--surface-2); border-radius: var(--radius-sm); border: 1px solid var(--border); margin-bottom: 24px; white-space: pre-wrap; }
.folha table th, .folha table td { padding: 12px 10px; }
.folha table th { background: transparent; }
.folha .desc-linha { color: var(--ok); }
.folha .totais { margin-top: 18px; margin-left: auto; width: min(320px, 100%); }
.folha .rodape { margin-top: 36px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Responsivo ---------- */
@media (max-width: 1000px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-3 { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .item-row, .item-labels { grid-template-columns: 1fr 1fr; }
  .item-labels { display: none; }
  .item-row .icon-btn { justify-self: end; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; gap: 10px; }
  .nav { display: flex; flex-wrap: wrap; }
  .nav-title, .sidebar-foot { display: none; }
  .main { padding: 22px 16px 48px; }
  .grid.cols-2, .form-grid { grid-template-columns: 1fr; }
  .folha { padding: 26px 20px; }
}

/* ---------- Celular ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .main { min-width: 0; padding: 16px 14px 40px; }
  .sidebar {
    position: sticky; top: 0; z-index: 30; height: auto; overflow: visible; flex-direction: row; flex-wrap: nowrap;
    align-items: center; gap: 10px; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .brand { flex: none; padding: 0; }
  .brand img { width: 46px; max-width: 46px; margin: 0; }
  .nav { display: flex; flex: 1; min-width: 0; flex-wrap: nowrap; gap: 4px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { flex: none; white-space: nowrap; padding: 10px 12px; font-size: 14px; }
  .nav-title, .sidebar-foot { display: none; }
  h1 { font-size: 22px; }
  .page-head { gap: 10px; margin-bottom: 18px; }
  .card { padding: 16px; }
  .card.flush { padding: 0; }
  .card.flush .card-head { padding: 16px 16px 0; }
  .stat .value { font-size: 22px; white-space: nowrap; }
  .grid.cols-4 { gap: 12px !important; }
  input, select, textarea { font-size: 16px; }
  .subnav { width: 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .subnav a { white-space: nowrap; }
  .total-bar { padding: 14px 16px; }
  .total-bar b { font-size: 24px; }
  .total-bar .row { width: 100%; }
  .total-bar .row .btn { flex: 1; }
  .dl .total { font-size: 16px; }
  td, th { padding-left: 14px; padding-right: 14px; }
}
@media (max-width: 700px) {
  table.cartoes thead { display: none; }
  table.cartoes, table.cartoes tbody, table.cartoes tfoot, table.cartoes tr { display: block; width: 100%; }
  table.cartoes tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  table.cartoes tbody tr:last-child { border-bottom: 0; }
  table.cartoes td {
    display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 4px 0; border: 0; text-align: right;
  }
  table.cartoes td::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 12.5px; font-weight: 600; text-align: left; }
  table.cartoes td:not([data-label])::before { content: none; }
  table.cartoes td.acoes { justify-content: flex-start; flex-wrap: wrap; gap: 8px; padding-top: 10px; }
  table.cartoes td:empty { display: none; }
  table.cartoes td .sub { display: inline; margin-left: 8px; }
  table.cartoes tfoot tr { background: var(--surface-2); }
  table.cartoes tfoot td { background: transparent; border: 0; }

  /* Item da OS: serviço em cima, dificuldade e quantidade lado a lado */
  .item-row { grid-template-columns: 1fr 96px; gap: 10px; }
  .item-row > :nth-child(2), .item-row > :nth-child(5), .item-row > :nth-child(6) { grid-column: 1 / -1; }
  .item-row > :nth-child(6) { justify-self: end; }
  .gasto-row { grid-template-columns: 1fr 120px 40px; }
}

/* ---------- Impressão: só a folha da OS ---------- */
@media print {
  body { background: #fff; }
  .sidebar, .no-print, .flashes { display: none !important; }
  .app { display: block; }
  .main { padding: 0; max-width: none; }
  .folha { box-shadow: none; border: 0; padding: 0; max-width: none; }
}
