:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --text: #0f172a;
  --muted: #475569;
  --subtle: #64748b;
  --bg: #f8fafc;
  --surface: #fff;
  --surface-muted: #f1f5f9;
  --border: #e2e8f0;
  --success: #059669;
  --success-bg: #d1fae5;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --radius: 8px;
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }

button { font: inherit; cursor: pointer; border: 0; border-radius: var(--radius);
  background: var(--primary); color: #fff; padding: 10px 16px; font-weight: 700; }
button:hover { background: var(--primary-dark); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
button.ghost:hover { background: var(--surface-muted); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--border); padding: 6px 12px; }
button.danger:hover { background: var(--danger-bg); }

input, select, textarea { font: inherit; width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.muted { color: var(--muted); }
.err { color: var(--danger); font-size: 13px; min-height: 18px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 20px; }

/* App shell — sidebar lateral + conteudo */
.app { display: flex; min-height: 100vh; align-items: stretch; }
.sidebar { width: 224px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px; padding: 16px 12px;
  position: sticky; top: 0; height: 100vh; }
.sb-brand { font-weight: 800; font-size: 16px; padding: 6px 12px 14px; }
.sb-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.tab { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: transparent; color: var(--muted); padding: 10px 12px; font-weight: 700; }
.tab svg { width: 18px; height: 18px; flex-shrink: 0; }
.tab:hover { background: var(--surface-muted); color: var(--text); }
.tab.active { background: var(--primary); color: #fff; }
.sb-logout { display: flex; align-items: center; gap: 10px; width: 100%; margin-top: auto;
  background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 10px 12px; }
.sb-logout svg { width: 18px; height: 18px; flex-shrink: 0; }
.sb-logout:hover { background: var(--surface-muted); color: var(--text); }
.content { flex: 1; max-width: 1100px; margin: 0 auto; padding: 24px 28px;
  display: flex; flex-direction: column; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; flex: 1; display: flex; flex-direction: column; }
.panel h2 { margin: 0; font-size: 16px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  margin-bottom: 16px; flex-wrap: wrap; min-height: 44px; }
.panel-titles { display: flex; flex-direction: column; gap: 2px; }
.panel-sub { margin: 0; color: var(--subtle); font-size: 13px; }
.search { max-width: 340px; }

/* Form gerar */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; color: var(--muted); }
.form-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.result { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 16px;
  display: flex; flex-direction: column; gap: 10px; }
.result-row { display: flex; gap: 8px; align-items: center; }
.result textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-all; }

/* Tabelas */
.table-wrap { flex: 1; overflow: auto; }
.toolbar-row { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.prod-preco { max-width: 120px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: 12px; color: var(--subtle); text-transform: uppercase; letter-spacing: .03em; }
.table tbody tr:hover { background: var(--surface-muted); }
.table .mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 700; }
.tag.ok { background: var(--success-bg); color: var(--success); }
.tag.off { background: var(--danger-bg); color: var(--danger); }
.tag.pend { background: var(--warning-bg); color: var(--warning); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text);
  color: #fff; padding: 12px 20px; border-radius: var(--radius); font-weight: 600;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 24px;
  width: 100%; max-width: 440px; box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
}
.modal h3 { margin: 0 0 16px; font-size: 16px; }
.form-stack { display: flex; flex-direction: column; gap: 12px; }
.form-stack label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Combobox de cliente (busca + dropdown) */
.combo { position: relative; }
.combo-list { position: absolute; top: 100%; left: 0; right: 0; z-index: 30; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  max-height: 260px; overflow-y: auto; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12); }
.combo-item { padding: 9px 12px; cursor: pointer; }
.combo-item:hover, .combo-item.active { background: var(--surface-muted); }
.combo-item .sub { color: var(--subtle); font-size: 12px; margin-top: 2px; }
.combo-empty { padding: 10px 12px; color: var(--subtle); }

/* Detalhe da auditoria — empilhado na vertical, legivel */
.table td.detalhe-cell { white-space: normal; min-width: 220px; }
.aud-detalhe { display: flex; flex-direction: column; gap: 2px; }
.aud-detalhe .k { color: var(--subtle); font-weight: 600; }

@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center;
    gap: 4px; padding: 8px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .sb-brand { display: none; }
  .sb-nav { flex-direction: row; flex: 1; }
  .tab { width: auto; white-space: nowrap; }
  .sb-logout { width: auto; margin-top: 0; }
}
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .search { max-width: none; }
}
