:root {
  --bg: #0a0a0b;
  --bg2: #111113;
  --card: #16161a;
  --card2: #1d1d22;
  --line: #2a2a31;
  --text: #f3f3f5;
  --muted: #9a9aa5;
  --red: #e10600;
  --red2: #ff2a1f;
  --red-soft: rgba(225, 6, 0, .14);
  --ok: #22c55e;
  --warn: #f59e0b;
  --info: #3b82f6;
  --radius: 12px;
  --font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --display: 'Barlow Condensed', 'Arial Narrow', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
body { min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: var(--display); letter-spacing: .02em; margin: 0; font-weight: 700; }
h1 { font-size: 30px; text-transform: uppercase; }
h2 { font-size: 20px; text-transform: uppercase; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.red { color: var(--red2); }
.hide { display: none !important; }
::selection { background: var(--red); color: #fff; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: linear-gradient(180deg, #0d0d0f, #070708);
  border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.brand svg { width: 42px; height: 42px; flex: none; }
.brand b { font: 800 22px/1 var(--display); letter-spacing: .04em; text-transform: uppercase; display: block; }
.brand b span { color: var(--red); }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted);
  font-weight: 600; position: relative; transition: .15s;
}
.nav a svg { width: 19px; height: 19px; flex: none; }
.nav a:hover { color: var(--text); background: var(--card); }
.nav a.on { color: #fff; background: var(--red-soft); }
.nav a.on::before { content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 4px 4px 0; background: var(--red); }
.side .user { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--red); display: grid; place-items: center; font-weight: 800; flex: none; }
.side .user > div:not(.avatar) { min-width: 0; flex: 1; }
.side .user b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side .user small { color: var(--muted); text-transform: capitalize; }
main { padding: 26px 30px 60px; min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.top .sub { color: var(--muted); margin-top: 2px; }
.mobile-top { display: none; }

/* ---------- Componentes ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line);
  background: var(--card2); color: var(--text); padding: 9px 14px; border-radius: 10px; font: 600 14px var(--font);
  cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: #3a3a44; background: #24242a; }
.btn svg { width: 17px; height: 17px; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red2); border-color: var(--red2); }
.btn.ghost { background: transparent; }
.btn.danger { color: #ff6b63; }
.btn.danger:hover { border-color: var(--red); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.icon { padding: 7px; }
.btn.wa { background: #128c4a; border-color: #128c4a; color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: 1fr 1fr; }
.g21 { grid-template-columns: 2fr 1fr; }
.kpi { position: relative; overflow: hidden; }
.kpi::after { content: ''; position: absolute; right: -30px; top: -30px; width: 100px; height: 100px; border-radius: 50%; background: var(--red-soft); }
.kpi small { color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-size: 11px; font-weight: 700; }
.kpi b { display: block; font: 700 32px/1.1 var(--display); margin-top: 6px; }
.kpi .ic { position: absolute; right: 16px; top: 16px; color: var(--red); z-index: 1; }
.kpi .ic svg { width: 22px; height: 22px; }

input, select, textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); color: var(--text); border-radius: 10px;
  padding: 10px 12px; font: 14px var(--font); outline: none; transition: .15s;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .05em; }
.f { margin-bottom: 12px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.search { position: relative; flex: 1; min-width: 200px; max-width: 380px; }
.search input { padding-left: 38px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; color: var(--muted); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); color: var(--muted); font-weight: 600; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--red); border-color: var(--red); color: #fff; }
.chip i { font-style: normal; opacity: .7; margin-left: 4px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 700; }
td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--card2); }
.tbl { overflow-x: auto; margin: -18px; }
.tbl table { min-width: 640px; }
.tbl tr:last-child td { border-bottom: 0; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; color: var(--line); display: block; margin: 0 auto 10px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; border: 1px solid transparent; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-orcamento { color: #c4b5fd; background: rgba(139, 92, 246, .14); }
.s-aprovado { color: #93c5fd; background: rgba(59, 130, 246, .14); }
.s-em_servico { color: #fdba74; background: rgba(249, 115, 22, .15); }
.s-aguardando_peca { color: #fcd34d; background: rgba(245, 158, 11, .14); }
.s-pronto { color: #86efac; background: rgba(34, 197, 94, .15); }
.s-entregue { color: #a1a1aa; background: rgba(161, 161, 170, .12); }
.s-cancelado { color: #ff7b74; background: var(--red-soft); }
.tag-low { color: #ff7b74; font-weight: 700; }
.plate { display: inline-block; font: 700 12px/1 ui-monospace, Menlo, monospace; letter-spacing: .08em; background: #f4f4f5; color: #111; padding: 4px 7px; border-radius: 4px; border-top: 4px solid #1e3a8a; }

/* Lista de OS como cards no mobile */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .grow b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.osnum { font: 700 18px/1 var(--display); color: var(--red2); min-width: 46px; }

/* Barra de status da OS */
.steps { display: flex; gap: 6px; flex-wrap: wrap; }
.step { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); color: var(--muted); font-weight: 600; font-size: 13px; cursor: pointer; }
.step:hover { color: var(--text); }
.step.on { background: var(--red); border-color: var(--red); color: #fff; }
.items td { padding: 6px; }
.items input { padding: 8px 10px; }
.totals { display: grid; gap: 8px; max-width: 340px; margin-left: auto; }
.totals div { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.totals input { width: 130px; text-align: right; }
.totals .grand { border-top: 1px solid var(--line); padding-top: 10px; font: 700 26px var(--display); }
.totals .grand span:last-child { color: var(--red2); }
.client-box { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; background: var(--bg2); }
.client-box .grow { flex: 1; min-width: 0; }

/* Gráfico */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 10px; }
.chart .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; min-width: 0; }
.chart .bar i { display: block; width: 100%; max-width: 26px; background: linear-gradient(180deg, var(--red2), #8f0400); border-radius: 4px 4px 0 0; min-height: 2px; }
.chart .bar small { font-size: 10px; color: var(--muted); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .7); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .15s; }
.modal { background: var(--card); border: 1px solid var(--line); border-radius: 16px; width: 100%; max-width: 560px; max-height: 92vh; display: flex; flex-direction: column; animation: up .2s; }
.modal.lg { max-width: 760px; }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-b { padding: 20px; overflow-y: auto; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(12px); opacity: 0; } }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #fff; color: #111; padding: 12px 18px; border-radius: 10px; font-weight: 600; z-index: 99; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); border-left: 5px solid var(--ok); animation: up .2s; max-width: 90vw; }
.toast.err { border-left-color: var(--red); }

/* Login */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login .hero {
  background: radial-gradient(circle at 30% 30%, rgba(225, 6, 0, .35), transparent 55%), repeating-linear-gradient(135deg, #0d0d0f 0 22px, #101013 22px 44px);
  display: flex; flex-direction: column; justify-content: center; padding: 60px; border-right: 1px solid var(--line); position: relative; overflow: hidden;
}
.login .hero svg.logo { width: 110px; height: 110px; }
.login .hero h1 { font-size: 64px; line-height: .95; margin-top: 20px; }
.login .hero h1 span { color: var(--red); }
.login .hero p { color: var(--muted); font-size: 16px; max-width: 420px; }
.login .stripe { position: absolute; bottom: 0; left: 0; right: 0; height: 8px; background: repeating-linear-gradient(90deg, var(--red) 0 40px, #000 40px 80px); }
.login form { display: flex; flex-direction: column; justify-content: center; padding: 60px; max-width: 460px; width: 100%; margin: 0 auto; }
.login form h2 { font-size: 28px; margin-bottom: 4px; }
.login .err { color: #ff7b74; min-height: 20px; margin: 4px 0 10px; font-weight: 600; }

/* Chat IA */
.chat { display: flex; flex-direction: column; height: calc(100vh - 150px); min-height: 420px; padding: 0; overflow: hidden; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 80%; padding: 12px 15px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--red); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: var(--card2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.ai b { color: #fff; }
.chat-in { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--line); background: var(--bg2); }
.chat-in textarea { min-height: 46px; max-height: 140px; resize: none; }
.sugs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.sugs button { background: var(--card2); border: 1px solid var(--line); color: var(--text); padding: 8px 12px; border-radius: 99px; cursor: pointer; font: 13px var(--font); }
.sugs button:hover { border-color: var(--red); }
.typing span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); margin: 0 2px; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: .2; } }

/* Impressão da OS */
#print { display: none; }
@media print {
  body { background: #fff; color: #000; }
  .app, .modal-bg, .toast, .login { display: none !important; }
  #print { display: block; font: 12px/1.4 Arial, sans-serif; color: #000; padding: 10px; }
  #print .ph { display: flex; justify-content: space-between; align-items: center; border-bottom: 3px solid #e10600; padding-bottom: 10px; margin-bottom: 12px; }
  #print h1 { font: 800 26px Arial; text-transform: uppercase; color: #000; }
  #print h1 span { color: #e10600; }
  #print .box { border: 1px solid #999; border-radius: 6px; padding: 8px 10px; margin-bottom: 10px; }
  #print .box b { font-size: 10px; text-transform: uppercase; color: #555; display: block; }
  #print table { width: 100%; border-collapse: collapse; margin: 8px 0; }
  #print th, #print td { border: 1px solid #999; padding: 5px 7px; color: #000; }
  #print th { background: #eee; font-size: 10px; }
  #print .tot { text-align: right; font-size: 14px; }
  #print .sign { display: flex; gap: 40px; margin-top: 50px; }
  #print .sign div { flex: 1; border-top: 1px solid #000; text-align: center; padding-top: 4px; }
  #print .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
}

/* ---------- Responsivo ---------- */
@media (max-width: 1100px) { .g4 { grid-template-columns: 1fr 1fr; } .g21 { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; flex-direction: row; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line); z-index: 40; background: #0b0b0d;
  }
  .side .brand, .side .user { display: none; }
  .nav { display: flex; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 3px; font-size: 10px; padding: 6px 4px; flex: 1; text-align: center; }
  .nav a.on::before { left: 25%; right: 25%; top: -7px; bottom: auto; width: auto; height: 3px; border-radius: 0 0 3px 3px; }
  .nav a.opt { display: none; }
  main { padding: 0 16px 100px; }
  .mobile-top { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; margin-bottom: 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 30; }
  .mobile-top .brand { border: 0; padding: 0; margin: 0; }
  .mobile-top .brand svg { width: 32px; height: 32px; }
  .mobile-top .brand b { font-size: 18px; }
  h1 { font-size: 24px; }
  .g3, .g2 { grid-template-columns: 1fr; }
  .g4 { gap: 10px; }
  .kpi b { font-size: 24px; }
  .card { padding: 14px; }
  .tbl { margin: -14px; }
  .login { grid-template-columns: 1fr; }
  .login .hero { padding: 40px 24px 30px; }
  .login .hero h1 { font-size: 42px; }
  .login form { padding: 30px 24px; }
  .msg { max-width: 92%; }
  .chat { height: calc(100vh - 200px); }
  .search { max-width: none; }
  .modal-bg { place-items: end center; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 94vh; }
}

/* ---- Painel de cobrança ---- */
.s-ativo { color: #86efac; background: rgba(34, 197, 94, .15); }
.s-vencendo { color: #fcd34d; background: rgba(245, 158, 11, .14); }
.s-atrasado { color: #fdba74; background: rgba(249, 115, 22, .15); }
.s-bloqueado { color: #ff7b74; background: var(--red-soft); }
.key { font: 12px ui-monospace, Menlo, monospace; background: var(--bg2); border: 1px solid var(--line); padding: 8px 10px; border-radius: 8px; word-break: break-all; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.brand b { white-space: nowrap; font-size: 20px; }
