:root {
  --brand: #0b3d91; --brand-2: #f5b301; --bg: #f3f5f9; --card: #fff; --text: #1b2333; --muted: #6b7489;
  --line: #e2e6ee; --danger: #c62828; --ok: #1b8a4b; --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0 0 12px; }
button, .btn { font: inherit; border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer; background: var(--brand); color: #fff; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button.secondary, .btn.secondary { background: #e7ecf6; color: var(--brand); }
button.danger { background: #fdecec; color: var(--danger); }
button.ghost { background: transparent; color: var(--muted); padding: 6px 8px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #c9d6f2; border-color: var(--brand); }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: repeat(3, 1fr); } .g4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 800px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: 0 1px 3px rgba(20,30,60,.06); margin-bottom: 16px; }
.card h3 { font-size: 15px; color: var(--brand); }
.muted { color: var(--muted); }
.error { background: #fdecec; color: var(--danger); padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Autenticação */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-hero { background: linear-gradient(140deg, #0b3d91, #062559); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: center; }
.auth-hero h1 { font-size: 38px; } .auth-hero p { opacity: .85; font-size: 16px; line-height: 1.5; max-width: 440px; }
.auth-hero .by { color: var(--brand-2); font-weight: 600; letter-spacing: .5px; }
.auth-hero ul { padding-left: 18px; line-height: 1.9; opacity: .9; }
.auth-form { padding: 40px; display: flex; align-items: center; justify-content: center; overflow-y: auto; }
.auth-form .card { width: 100%; max-width: 560px; }
@media (max-width: 900px) { .auth { grid-template-columns: 1fr; } .auth-hero { padding: 28px; } }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; }
.brand img { width: 34px; height: 34px; }
.brand small { display: block; font-weight: 500; font-size: 11px; opacity: .75; }

/* Layout principal */
.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: #071f4a; color: #cfd8ee; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; }
.sidebar .brand { color: #fff; padding: 4px 8px 18px; }
.sidebar a { color: #cfd8ee; text-decoration: none; padding: 9px 12px; border-radius: 8px; display: block; }
.sidebar a.active, .sidebar a:hover { background: rgba(255,255,255,.1); color: #fff; }
.sidebar .company { margin-top: auto; font-size: 12px; padding: 12px 8px; border-top: 1px solid rgba(255,255,255,.12); }
.main { padding: 24px 28px; max-width: 1200px; width: 100%; }
@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } .sidebar { flex-direction: row; flex-wrap: wrap; } .sidebar .company { display: none; } }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border-radius: var(--radius); padding: 16px; }
.stat b { display: block; font-size: 22px; margin-top: 4px; }
@media (max-width: 800px) { .stats { grid-template-columns: 1fr 1fr; } }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); }
table.list td { padding: 9px 8px; border-bottom: 1px solid var(--line); }
table.list tr.click { cursor: pointer; } table.list tr.click:hover { background: #f7f9fd; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: #e8f5ee; color: var(--ok); font-weight: 600; }
.badge.off { background: #fdecec; color: var(--danger); }
.type-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.type-pick button { background: #fff; color: var(--text); border: 2px solid var(--line); flex-direction: column; padding: 10px 6px; font-size: 12px; }
.type-pick button b { font-size: 16px; color: var(--brand); }
.type-pick button.on { border-color: var(--brand); background: #eef3fc; }
@media (max-width: 800px) { .type-pick { grid-template-columns: repeat(3, 1fr); } }
table.lines { width: 100%; border-collapse: collapse; }
table.lines th { font-size: 11px; color: var(--muted); text-align: left; padding: 4px; }
table.lines td { padding: 3px; }
table.lines input, table.lines select { padding: 6px 7px; }
.totals-box { margin-left: auto; width: 320px; }
.totals-box div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals-box .grand { font-size: 18px; font-weight: 800; border-top: 2px solid var(--text); margin-top: 4px; padding-top: 8px; }
.logo-prev { max-height: 70px; max-width: 200px; display: block; margin-top: 6px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.preview-wrap { background: #d9dde6; padding: 24px; border-radius: var(--radius); overflow: auto; display: flex; justify-content: center; }

/* ================= TALÃO TÉRMICO (80mm) ================= */
.talao { width: 80mm; background: #fff; padding: 6mm 4mm 8mm; font-family: "Courier New", Consolas, monospace; font-size: 11.5px; line-height: 1.35; color: #111; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.talao .c { text-align: center; } .talao .r { text-align: right; }
.talao .sp { height: 10px; }
.talao .dash { border-top: 1px dashed #333; margin: 4px 0; }
.talao .kv { display: grid; grid-template-columns: 1fr 10px auto; }
.talao .kv span:nth-child(2) { text-align: center; }
.talao .kv span:nth-child(3) { text-align: right; min-width: 70px; }
.talao .ln2 { display: grid; grid-template-columns: 1fr auto auto auto; gap: 6px; padding-left: 10px; }
.talao .hd { display: grid; grid-template-columns: 1fr auto auto auto; gap: 6px; padding-left: 6px; }
.talao .ivat { display: grid; grid-template-columns: 1fr 1fr 1fr 1.3fr; }
.talao .tear { border-top: 1px dashed #333; margin-top: 14px; padding-top: 6px; }
.talao .logo { max-width: 40mm; max-height: 18mm; display: block; margin: 0 auto 4px; filter: grayscale(1); }
.talao .anulado, .a4 .anulado { color: var(--danger); font-weight: 800; text-align: center; border: 2px solid var(--danger); padding: 4px; margin: 6px 0; }

/* ================= FACTURA A4 ================= */
.a4 { width: 210mm; min-height: 297mm; background: #fff; padding: 14mm 14mm 12mm; color: #1a1a1a; font-size: 11px; box-shadow: 0 2px 12px rgba(0,0,0,.18); display: flex; flex-direction: column; position: relative; }
.a4 .head { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 10px; border-bottom: 3px solid var(--doc-color, #0b3d91); }
.a4 .head img { max-height: 70px; max-width: 220px; margin-bottom: 6px; }
.a4 .comp-name { font-size: 16px; font-weight: 800; color: var(--doc-color, #0b3d91); }
.a4 .head .comp p { margin: 1px 0; }
.a4 .doc-title { text-align: right; }
.a4 .doc-title h1 { font-size: 26px; letter-spacing: 1px; color: var(--doc-color, #0b3d91); margin: 0 0 6px; text-transform: uppercase; }
.a4 .doc-title table td { padding: 1px 0 1px 12px; }
.a4 .doc-title table td:first-child { color: #666; }
.a4 .via { display: inline-block; border: 1px solid #999; padding: 1px 8px; font-size: 10px; margin-bottom: 6px; }
.a4 .parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 14px 0; }
.a4 .box { border: 1px solid #cfd4de; border-radius: 6px; padding: 8px 10px; }
.a4 .box .lbl { font-size: 9.5px; text-transform: uppercase; color: #777; font-weight: 700; margin-bottom: 4px; letter-spacing: .5px; }
.a4 .box p { margin: 1px 0; }
.a4 table.items { width: 100%; border-collapse: collapse; margin-top: 4px; }
.a4 table.items th { background: var(--doc-color, #0b3d91); color: #fff; font-weight: 600; padding: 6px 5px; text-align: left; font-size: 10.5px; }
.a4 table.items td { padding: 5px; border-bottom: 1px solid #e3e6ec; vertical-align: top; }
.a4 table.items tr:nth-child(even) td { background: #f7f8fb; }
.a4 .bottom { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; margin-top: 14px; }
.a4 table.ivas { width: 100%; border-collapse: collapse; }
.a4 table.ivas th, .a4 table.ivas td { border: 1px solid #cfd4de; padding: 3px 5px; font-size: 10px; }
.a4 table.ivas th { background: #eef1f6; }
.a4 .sum div { display: flex; justify-content: space-between; padding: 3px 4px; }
.a4 .sum .grand { background: var(--doc-color, #0b3d91); color: #fff; font-size: 14px; font-weight: 800; padding: 7px 6px; margin-top: 4px; border-radius: 4px; }
.a4 .extenso { margin-top: 10px; padding: 7px 10px; background: #f4f6fa; border-left: 3px solid var(--doc-color, #0b3d91); font-style: italic; }
.a4 .signs { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 34px; text-align: center; }
.a4 .signs div { border-top: 1px solid #444; padding-top: 4px; }
.a4 .foot { margin-top: auto; padding-top: 10px; border-top: 1px solid #cfd4de; font-size: 9.5px; color: #555; display: flex; justify-content: space-between; gap: 10px; }
.a4 .watermark { position: absolute; top: 40%; left: 0; right: 0; text-align: center; font-size: 110px; font-weight: 900; color: rgba(198,40,40,.12); transform: rotate(-30deg); pointer-events: none; }

/* ================= IMPRESSÃO ================= */
@media print {
  body { background: #fff; }
  .no-print, .sidebar, .toolbar { display: none !important; }
  .layout { display: block; } .main { padding: 0; max-width: none; }
  .preview-wrap { background: none; padding: 0; display: block; }
  .talao, .a4 { box-shadow: none; }
  .a4 { width: auto; min-height: 270mm; padding: 0; }
  .a4 table.items th, .a4 .sum .grand { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
