:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --primary: #1f6feb; --primary-d: #1a5fcc; --primary-l: #eaf2ff;
  --ok: #15803d; --ok-l: #e7f6ec; --warn: #b45309; --warn-l: #fef3e2; --bad: #b91c1c; --bad-l: #fdecec; --grey-l: #eef0f3;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; color: var(--text); background: var(--bg); -webkit-text-size-adjust: 100%; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

/* shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 232px; background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 15px; }
.brand i { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); display: inline-block; position: relative; }
.brand i::after { content: ""; position: absolute; inset: 7px 8px; border: 2px solid #fff; border-radius: 2px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #374151; font-weight: 500; }
.nav a:hover { background: var(--grey-l); }
.nav a.active { background: var(--primary-l); color: var(--primary-d); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); font-size: 13px; }
.side-foot .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .co { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot button { margin-top: 8px; }
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; max-width: 1180px; }
.topbar { display: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap; min-height: 36px; }
.btn:hover { background: var(--grey-l); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 12px; font-weight: 600; color: #374151; }
.input, select.input, textarea.input { width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff; min-height: 38px; }
.input:focus { outline: 2px solid var(--primary-l); border-color: var(--primary); }
textarea.input { resize: vertical; min-height: 70px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.hint { color: var(--muted); font-size: 12px; }
.err { color: var(--bad); font-size: 13px; margin: 6px 0; min-height: 1px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.b-rascunho { background: var(--grey-l); color: #4b5563; }
.b-enviado { background: var(--primary-l); color: var(--primary-d); }
.b-aprovado { background: var(--ok-l); color: var(--ok); }
.b-recusado { background: var(--bad-l); color: var(--bad); }
.b-expirado { background: var(--warn-l); color: var(--warn); }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #fafbfc; }
.tbl .num, .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat .k { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 2px; letter-spacing: -.02em; }
.stat .s { color: var(--muted); font-size: 12px; margin-top: 2px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar .input { max-width: 300px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 600; font-size: 13px; }
.chip.on { background: var(--text); border-color: var(--text); color: #fff; }

/* modal + toast */
.overlay { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 14px 14px; overflow-y: auto; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 680px; }
.modal h2 { font-size: 17px; margin-bottom: 16px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.toast-box { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 80; width: max-content; max-width: 92vw; }
.toast { background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); }

/* editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.summary { position: sticky; top: 16px; }
.items { width: 100%; border-collapse: collapse; }
.items th { font-size: 11px; color: var(--muted); text-align: left; padding: 0 6px 6px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.items td { padding: 4px 4px; vertical-align: top; }
.items .input { padding: 6px 8px; min-height: 34px; }
.items .c-desc { min-width: 220px; }
.items .c-qty { width: 78px; } .items .c-unit { width: 64px; } .items .c-price { width: 100px; } .items .c-pct { width: 70px; }
.items .c-tot { width: 96px; text-align: right; padding-top: 12px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.items .c-del { width: 34px; }
.items textarea.input { min-height: 34px; height: 34px; }
.sum-row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; color: #374151; }
.sum-row.total { border-top: 2px solid var(--text); margin-top: 8px; padding-top: 10px; font-size: 18px; font-weight: 700; color: var(--text); }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack .btn { width: 100%; }
.hist { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.hist li { padding: 7px 0; border-bottom: 1px solid var(--line); color: #374151; }
.hist li:last-child { border-bottom: 0; }
.hist .when { color: var(--muted); font-size: 12px; }

/* login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth { width: 100%; max-width: 420px; }
.auth .brand { justify-content: center; padding-bottom: 6px; font-size: 18px; }
.auth .sub { text-align: center; color: var(--muted); margin-bottom: 18px; }
.tabs { display: flex; background: var(--grey-l); border-radius: 9px; padding: 3px; margin-bottom: 16px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 7px; border-radius: 7px; font-weight: 600; cursor: pointer; color: var(--muted); }
.tabs button.on { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.logo-prev { max-height: 56px; max-width: 160px; display: block; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }
.color-row { display: flex; gap: 10px; align-items: center; }
.color-row input[type=color] { width: 44px; height: 38px; padding: 2px; border: 1px solid #d1d5db; border-radius: 8px; background: #fff; }

@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  body.nav-open .sidebar { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 14px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; font-weight: 700; }
  .topbar button { border: 0; background: none; font-size: 22px; padding: 4px 8px; cursor: pointer; }
  .main { padding: 18px 14px 60px; }
  .editor { grid-template-columns: 1fr; }
  .summary { position: static; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .items thead { display: none; }
  .items, .items tbody, .items tr, .items td { display: block; width: 100%; }
  .items tr { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; position: relative; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .items td { padding: 0; }
  .items td.c-desc { grid-column: 1 / -1; min-width: 0; }
  .items td.c-del { position: absolute; top: 6px; right: 6px; width: auto; }
  .items td.c-qty, .items td.c-unit, .items td.c-price, .items td.c-pct { width: auto; }
  .items td[data-l]::before { content: attr(data-l); display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
  .items .c-tot { grid-column: 1 / -1; text-align: right; padding-top: 4px; width: auto; }
  .tbl .hide-m { display: none; }
}
@media print { .sidebar, .topbar, .page-head .actions { display: none; } }
