/* ============================================================
   Design System — Giga Tester
   Paleta industrial: slate-900 navbar, fundo cinza-claro, cards brancos
   Status: verde(APROVADO), vermelho(REPROVADO), âmbar(PENDENTE)
   ============================================================ */

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-focus: #3b82f6;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-50: #eff6ff;

  --green-700: #15803d;
  --green-50: #dcfce7;
  --red-700: #b91c1c;
  --red-50: #fee2e2;
  --amber-700: #b45309;
  --amber-50: #fef3c7;

  --navy: #0f172a;
  --navy-light: #1e293b;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
}

/* ============================================================ TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--navy);
  color: #f1f5f9;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: .5px;
  color: #f8fafc;
}

.brand-icon {
  width: 28px;
  height: 28px;
  background: var(--blue-600);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: .8rem;
  color: #fff;
}

.nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav a {
  color: #94a3b8;
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: .9rem;
  font-weight: 500;
  transition: background .15s, color .15s;
}

.nav a:hover {
  background: var(--navy-light);
  color: #f1f5f9;
}

.nav a.nav-cta {
  background: var(--blue-600);
  color: #fff;
}

.nav a.nav-cta:hover {
  background: var(--blue-700);
}

/* ============================================================ LAYOUT */
.container {
  max-width: 1080px;
  margin: 28px auto;
  padding: 0 20px;
}

.container.narrow {
  max-width: 440px;
}

/* ============================================================ CARDS */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ============================================================ FORMS */
label {
  display: block;
  font-weight: 600;
  font-size: .88rem;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
  background: var(--surface);
  color: var(--text-primary);
  transition: border-color .15s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.form-group {
  margin-bottom: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

textarea {
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  resize: vertical;
  min-height: 80px;
}

/* ============================================================ BUTTONS */
.button, button[type="button"], button[type="submit"] {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  background: var(--blue-600);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, transform .1s;
}

.button:hover, button:not(:disabled):hover {
  background: var(--blue-700);
}

.button:active, button:not(:disabled):active {
  transform: scale(.98);
}

button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.button.secondary {
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
}

.button.secondary:hover {
  background: var(--border);
}

.button.danger {
  background: var(--red-700);
}

.button.danger:hover {
  background: #991b1b;
}

.button.success {
  background: var(--green-700);
}

.button.small {
  padding: 6px 12px;
  font-size: .82rem;
}

.button.large {
  padding: 14px 24px;
  font-size: 1.05rem;
  font-weight: 800;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ============================================================ STATUS BADGES */
.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
}

.status-aprovado { background: var(--green-50); color: var(--green-700); }
.status-reprovado { background: var(--red-50); color: var(--red-700); }
.status-pendente { background: var(--amber-50); color: var(--amber-700); }
.status-sem-dados { background: #f1f5f9; color: var(--text-muted); }

/* ============================================================ FLASH MESSAGES */
.flash { margin-bottom: 20px; }

.flash-error,
.flash-success {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: .92rem;
}

.flash-error { background: var(--red-50); color: var(--red-700); border-left: 4px solid var(--red-700); }
.flash-success { background: var(--green-50); color: var(--green-700); border-left: 4px solid var(--green-700); }

/* ============================================================ TABLES */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }

table thead th {
  text-align: left;
  padding: 10px 12px;
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 2px solid var(--border);
}

table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

table tbody tr:last-child td { border-bottom: none; }
table tbody tr:hover td { background: var(--surface-2); }

/* ============================================================ PAGE HEADERS */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}

.page-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: .9rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============================================================ FILTER BAR */
.filter-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

/* ============================================================ DASHBOARD */
.dashboard-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 24px;
  align-items: start;
}

.status-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.date-block {
  text-align: center;
  padding: 20px 16px;
  background: var(--navy);
  color: #f8fafc;
  border-radius: var(--radius-lg);
}

.date-text {
  font-size: 1rem;
  font-weight: 600;
  opacity: .8;
  margin-bottom: 4px;
}

.time-text {
  font-size: 2.8rem;
  font-weight: 900;
  letter-spacing: 3px;
  font-variant-numeric: tabular-nums;
}

.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}

.info-label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 6px;
}

.info-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-primary);
  word-break: break-all;
}

.info-value.small {
  font-size: 1rem;
}

.start-btn-wrap { margin-bottom: 8px; }

.button-cta {
  display: block;
  width: 100%;
  text-align: center;
  padding: 18px;
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: .5px;
  border-radius: var(--radius-lg);
  background: var(--blue-600);
  color: #fff;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.button-cta:hover { background: var(--blue-700); }
.button-cta:active { transform: scale(.99); }

/* ============================================================ BOX ID PREVIEW */
.box-id-preview {
  padding: 14px 16px;
  margin-top: 8px;
  border: 2px dashed var(--border-focus);
  border-radius: var(--radius-lg);
  font-size: 1.4rem;
  font-weight: 900;
  text-align: center;
  background: var(--blue-50);
  color: var(--blue-700);
  letter-spacing: 1px;
}

/* ============================================================ WIZARD */
.wizard-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 24px;
  align-items: start;
}

.wizard-sidebar {
  position: sticky;
  top: 72px;
}

.wizard-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.wizard-meta {
  text-align: right;
  font-size: .88rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* Steps sidebar */
.step-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: .85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.step-item.active {
  background: var(--blue-50);
  color: var(--blue-600);
  font-weight: 700;
}

.step-item.done {
  color: var(--green-700);
}

.step-number {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 800;
  flex-shrink: 0;
}

.step-item.active .step-number {
  background: var(--blue-600);
  color: #fff;
}

.step-item.done .step-number {
  background: var(--green-50);
  color: var(--green-700);
}

/* Wizard content */
.wizard-steps { min-height: 380px; }
.wizard-step { display: none; }
.wizard-step.active { display: block; }

.step-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.step-badge {
  background: var(--blue-600);
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 900;
  flex-shrink: 0;
}

.step-photo {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.question {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
}

/* Yes/No buttons */
.btn-choice {
  padding: 11px 24px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: .95rem;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}

.btn-choice:hover {
  border-color: var(--blue-600);
  color: var(--blue-600);
}

.btn-choice.selected[data-value="SIM"] {
  background: var(--green-50);
  border-color: var(--green-700);
  color: var(--green-700);
}

.btn-choice.selected[data-value="NAO"] {
  background: var(--amber-50);
  border-color: var(--amber-700);
  color: var(--amber-700);
}

/* Pendency textarea */
.pending-block {
  margin-top: 14px;
  padding: 14px;
  background: var(--amber-50);
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
}

.pending-label {
  display: block;
  font-size: .85rem;
  font-weight: 700;
  color: var(--amber-700);
  margin-bottom: 6px;
}

.pending-textarea {
  width: 100%;
  border: 1.5px solid #fcd34d;
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: .9rem;
  resize: none;
  min-height: 60px;
  background: #fffbeb;
}

/* Warning box */
.warning-box {
  background: #fff7ed;
  border: 1.5px solid #fed7aa;
  color: #9a3412;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  margin-bottom: 16px;
  font-size: .92rem;
}

.connection-targets {
  margin-top: 10px;
  font-weight: 500;
  font-size: .88rem;
  display: grid;
  gap: 3px;
  color: #7c3f22;
}

/* Wizard nav */
.wizard-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ============================================================ TELEMETRY */
.telemetry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}

.telemetry-status { display: flex; align-items: center; gap: 10px; }
.warning-text { color: var(--red-700); font-weight: 700; font-size: .9rem; }

.telemetry-dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin: 8px 0 16px;
}

.telemetry-card {
  border-radius: var(--radius);
  padding: 12px 14px;
  color: #fff;
  text-align: center;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

.telemetry-label {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .6px;
  font-weight: 800;
  opacity: .9;
}

.telemetry-value { font-size: 1rem; font-weight: 900; }
.telemetry-var { font-size: .6rem; opacity: .75; margin-top: 2px; }

.telemetry-ok { background: linear-gradient(135deg, #166534, #15803d); }
.telemetry-pending { background: linear-gradient(135deg, #b45309, #d97706); }
.telemetry-fail { background: linear-gradient(135deg, #991b1b, #dc2626); }
.telemetry-neutral { background: linear-gradient(135deg, #334155, #475569); }

.telemetry-raw details summary {
  cursor: pointer;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 8px 0;
}

.telemetry-raw pre {
  background: var(--navy);
  color: #e2e8f0;
  padding: 14px;
  border-radius: var(--radius);
  overflow: auto;
  max-height: 260px;
  font-size: .82rem;
  margin-top: 6px;
}

/* Serial card */
.serial-card {
  background: #0b1220;
  color: #e2e8f0;
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-top: 14px;
  border: 1px solid var(--navy-light);
}

.serial-status {
  font-size: .82rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: #94a3b8;
}

.serial-card pre {
  white-space: pre-wrap;
  max-height: 220px;
  overflow: auto;
  font-size: .8rem;
  color: #cbd5e1;
}

/* ============================================================ LED CHECK */
.led-check-card { display: grid; gap: 20px; }

.door-check-panel {
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.door-check-panel h3 {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.door-status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.door-status-label { font-weight: 600; color: var(--text-secondary); font-size: .9rem; }

.downlink-debug {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--navy);
  color: #94a3b8;
  white-space: pre-wrap;
  font-size: .78rem;
  overflow: auto;
}

/* ============================================================ LABEL PAGE */
.label-page { max-width: 500px; margin: 0 auto; }

.label-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-md);
  border: 2px solid var(--border);
}

.label-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.label-logo {
  width: 40px;
  height: 40px;
  background: var(--navy);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 900;
  font-size: .85rem;
}

.label-title {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 700;
}

.label-id {
  font-size: 2rem;
  font-weight: 900;
  margin: 4px 0 20px;
  color: var(--text-primary);
  letter-spacing: 1px;
}

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.label-row:last-child { border-bottom: none; }
.label-key { color: var(--text-secondary); font-weight: 600; font-size: .9rem; }
.label-reason { color: var(--red-700); font-weight: 700; font-size: .9rem; }

.label-actions { display: flex; gap: 10px; margin-top: 20px; }

/* ============================================================ PHOTOS */
.capture-area {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 16px;
}

.camera-panel {
  background: var(--navy);
  border-radius: var(--radius-lg);
  padding: 14px;
  color: #f1f5f9;
}

.camera-panel video {
  width: 100%;
  border-radius: var(--radius);
  background: #111;
  display: block;
}

.camera-status {
  margin-top: 8px;
  font-size: .85rem;
  color: #94a3b8;
}

/* Camera nao abriu: o teste segue sem foto, entao o aviso precisa saltar aos olhos
   (o cinza padrao do .camera-status passava despercebido). */
.camera-status-warn {
  color: #fbbf24;
  background: rgba(251, 191, 36, .1);
  border: 1px solid rgba(251, 191, 36, .4);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.45;
}

.camera-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.capture-previews { display: grid; gap: 12px; }

.capture-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
}

.capture-title {
  font-size: .82rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.capture-card img {
  width: 100%;
  border-radius: var(--radius);
  object-fit: cover;
  min-height: 120px;
  background: var(--surface-2);
}

.stamp {
  padding: 10px 14px;
  border: 1.5px dashed var(--border-focus);
  border-radius: var(--radius);
  margin-bottom: 14px;
  background: var(--blue-50);
  font-weight: 700;
  font-size: .88rem;
  color: var(--blue-700);
}

/* ============================================================ SETTINGS */
.settings-form h2 {
  margin-top: 28px;
  margin-bottom: 12px;
  font-size: 1rem;
  font-weight: 800;
  color: var(--navy);
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-form h2::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 18px;
  background: var(--blue-600);
  border-radius: 2px;
}

/* ============================================================ RULES TABLE */
.rules-table {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 14px;
}

.rules-row {
  display: grid;
  grid-template-columns: 1.6fr 0.9fr 1fr repeat(4, 0.8fr) 0.7fr;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.rules-row:last-child { border-bottom: none; }

.rules-header {
  background: var(--surface-2);
  font-size: .78rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .4px;
}

.rule-status {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================ PHOTO PLACEHOLDER */
.photo-placeholder {
  height: 180px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-weight: 600;
  font-size: .9rem;
  background: var(--surface-2);
}

/* ============================================================ HEADINGS */
h1 {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -.2px;
}

h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* ============================================================ ACTIVE BUTTON (filter) */
.button.active {
  background: var(--blue-600);
  color: #fff;
  border: none;
}

.button.active:hover { background: var(--blue-700); }

/* ============================================================ CHOICE ROW (yes/no group) */
.choice-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

/* ============================================================ MISC */
.hint {
  margin-top: 8px;
  font-size: .85rem;
  color: var(--text-muted);
}

.muted { color: var(--text-muted); font-size: .85rem; }

/* ============================================================ PRINT */
/* .no-print/.print-only: qualquer tela pode marcar o que some e o que so
   aparece no papel (ex: cabecalho com o filtro aplicado) sem escrever um
   novo bloco @media print por pagina. */
.print-only { display: none; }

@media print {
  .topbar, .wizard-sidebar, .wizard-nav, .flash,
  .hint, .telemetry-raw, .serial-card, .button-row,
  .label-actions, .camera-panel, .capture-area > .camera-panel,
  .no-print {
    display: none !important;
  }

  .print-only { display: block !important; }

  body { background: #fff; }

  .report-box { border-color: #cbd5e1; }
  .report-table tr { break-inside: avoid; }
  .report-table { font-size: .8rem; }
  .report-table td { padding: 4px 12px; }

  .label-card {
    box-shadow: none;
    border: 1.5px solid #000;
  }

  /* Sem isto, alguns navegadores tiram o fundo/cor no print por padrao (a
     opcao "graficos de fundo" do dialogo de impressao vem desmarcada) — e o
     relatorio colorido vira tudo cinza. */
  .tally-dot, .report-table .report-item, .report-table th, .status-badge {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* ============================================================ RESPONSIVE */
@media (max-width: 900px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .wizard-layout { grid-template-columns: 1fr; }
  .wizard-sidebar { display: none; }
  .capture-area { grid-template-columns: 1fr; }

  .wizard-header-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .wizard-meta { text-align: left; }

  .rules-row { grid-template-columns: 1fr; }
  .rules-header { display: none; }

  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
}

@media (max-width: 600px) {
  .nav a { padding: 6px 8px; font-size: .82rem; }
  .container { margin: 16px auto; padding: 0 14px; }
  .telemetry-dashboard { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================ ESTOQUE
   Modulo de estoque: le como um kardex/ficha de prateleira, nao como um
   dashboard de cards — colunas numericas alinhadas (tabular-nums), linhas
   finas em vez de card-por-item, e o nivel de cada item mostrado como uma
   barra de nivel (o jeito fisico de olhar para uma prateleira acabando),
   nao um badge colorido solto. Paleta 100% reaproveitada do resto do app.
   ============================================================ */

.ledger-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
  overflow-x: auto;
}

.ledger-tab {
  padding: 10px 4px;
  margin-right: 22px;
  font-size: .92rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}

.ledger-tab:hover { color: var(--text-secondary); }

.ledger-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--blue-600);
}

/* Numero-hero: unico numero grande da tela — o resto fica quieto ao redor. */
.stat-hero-row {
  display: flex;
  gap: 40px;
  flex-wrap: wrap;
  padding: 4px 0 28px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.stat-hero { min-width: 140px; }

.stat-hero .stat-value {
  font-size: 3.1rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  letter-spacing: -.02em;
}

.stat-hero.stat-warn .stat-value { color: var(--amber-700); }
.stat-hero.stat-critical .stat-value { color: var(--red-700); }

.stat-hero .stat-label {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Tabela-ficha: numeros alinhados a direita, tabular, hairline entre linhas —
   e um kardex, nao uma lista de cards. */
.ledger-table td.num,
.ledger-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.ledger-table td.mono { font-family: monospace; font-size: .85rem; }

.ledger-table tbody tr:hover td { background: var(--surface-2); }

.item-name { font-weight: 600; }
.item-unit { color: var(--text-muted); font-size: .78rem; margin-left: 4px; }

/* Barra de nivel: metafora fisica de prateleira — trilho cinza, preenchimento
   colorido por proximidade do minimo, tracinho marcando onde fica o minimo. */
.stock-gauge {
  position: relative;
  width: 100px;
  height: 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow: visible;
}

.stock-gauge-fill {
  height: 100%;
  border-radius: 1px;
  background: var(--green-700);
}

.stock-gauge.gauge-warn .stock-gauge-fill { background: var(--amber-700); }
.stock-gauge.gauge-critical .stock-gauge-fill { background: var(--red-700); }

.stock-gauge-min-tick {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--text-secondary);
  opacity: .55;
}

.gauge-cell { display: flex; align-items: center; gap: 10px; }

.gauge-level-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
  white-space: nowrap;
}

.gauge-level-label.level-ok { color: var(--green-700); }
.gauge-level-label.level-warn { color: var(--amber-700); }
.gauge-level-label.level-critical { color: var(--red-700); }

/* Relatorio de Projecao: uma caixa so (tela e papel). A cor de status fica
   num ponto e num filete a esquerda do item — nunca pintando a linha inteira
   (20 linhas vermelhas viram uma parede) e nunca sozinha: sempre com texto. */
.report-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 24px;
  overflow: hidden;
}
.report-box-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.report-box-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-primary);
}
.report-box-sub { margin: 4px 0 0; font-size: .85rem; color: var(--text-secondary); }
.report-tally { display: flex; gap: 18px; flex-wrap: wrap; }
.tally { display: inline-flex; align-items: center; gap: 6px; font-size: .88rem; color: var(--text-secondary); }
.tally b { color: var(--text-primary); font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.tally-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}
.tally .tally-dot { margin-right: 0; }
.report-box-body { overflow-x: auto; }
.report-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.report-table th {
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-2);
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  text-transform: none;
  letter-spacing: 0;
}
.report-table td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}
.report-table tbody tr:last-child td { border-bottom: none; }
.report-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.report-table .report-item { font-weight: 600; box-shadow: inset 3px 0 0 var(--status); }
.report-table .report-neg { color: var(--red-700); }
.report-table .report-buy { font-weight: 800; }
.report-box-foot, .report-box-empty {
  margin: 0;
  padding: 12px 22px;
  font-size: .8rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.report-box-empty { border-top: none; background: none; padding: 22px; font-size: .9rem; }

/* Formularios do modulo: reaproveita .card, so ajusta a largura em telas largas
   para nao esticar um input de 3 campos por toda a pagina. */
.stock-form { max-width: 480px; }

.stock-form .field { margin-bottom: 16px; }

.stock-filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 16px;
  margin-bottom: 22px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue-600);
  background: var(--surface-1);
}

.stock-filter-bar .field { margin: 0; }
.stock-filter-bar label { display: block; font-size: .78rem; font-weight: 600; margin-bottom: 4px; }
.stock-filter-bar input, .stock-filter-bar select { margin: 0; min-width: 175px; }
.stock-filter-note { color: var(--text-muted); font-size: .78rem; padding-bottom: 9px; }
.stock-report-heading { margin-bottom: 14px; }
.stock-report-summary { display: flex; gap: 34px; flex-wrap: wrap; margin: 0 0 22px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.stock-report-summary div { display: flex; flex-direction: column; }
.stock-report-summary strong { font-size: 1.55rem; font-variant-numeric: tabular-nums; }
.stock-report-summary span { color: var(--text-muted); font-size: .76rem; }
.stock-positive { color: var(--green-700); font-weight: 700; }
.stock-negative { color: var(--red-700); font-weight: 700; }
.stock-empty { text-align: center; padding: 48px; color: var(--text-muted); }

@media (max-width: 600px) {
  .stock-filter-bar { align-items: stretch; }
  .stock-filter-bar .field, .stock-filter-bar input, .stock-filter-bar select { width: 100%; }
  .stock-filter-bar .button { flex: 1; text-align: center; }
}

.stock-form label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.stock-form .field-hint {
  font-size: .76rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.balance-preview {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius);
  font-size: .85rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.balance-preview strong { font-size: 1.1rem; color: var(--text-primary); font-variant-numeric: tabular-nums; }

.movement-kind {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.movement-entrada { background: var(--green-50); color: var(--green-700); }
.movement-saida-auto { background: #f1f5f9; color: var(--text-secondary); }
.movement-saida-forcada { background: var(--red-50); color: var(--red-700); }
.movement-ajuste { background: var(--amber-50); color: var(--amber-700); }

@media (max-width: 700px) {
  .stat-hero-row { gap: 24px; }
  .stat-hero .stat-value { font-size: 2.2rem; }
}

/* ============================================================ MODAL (dialog)
   Popup nativo (<dialog>) para formularios curtos do Estoque — sem lib nova,
   sem overlay proprio: o browser ja cuida de foco, ESC e backdrop-click. */
dialog.modal-card {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 480px;
  width: 92vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
  /* O reset global (* { margin:0 }) anula o "margin:auto" que o browser usa
     pra centralizar <dialog>. Refaz a centralizacao na mao. */
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}

dialog.modal-card::backdrop {
  background: rgba(15, 23, 42, .55);
}

dialog.modal-card .modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

dialog.modal-card .modal-header .card-title { margin: 0; }

dialog.modal-card .modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
}

dialog.modal-card .modal-close:hover { color: var(--text-primary); }

dialog.modal-card .modal-body { padding: 20px; }

/* ── Fechamento de producao (caixas prontas + retirada) ─────────────────── */
.fech-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin: 8px 0 14px; }
.fech-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 20px; }
.fech-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; display: grid; gap: 14px; }
.fech-box-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.fech-client { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.fech-client i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.fech-saldo { display: flex; align-items: baseline; gap: 8px; }
.fech-saldo b { font-size: 2.6rem; font-weight: 800; letter-spacing: -1px; line-height: 1; font-variant-numeric: tabular-nums; }
.fech-saldo span { color: var(--text-secondary); font-size: .9rem; }
.fech-flow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: .8rem; color: var(--text-secondary); border-top: 1px solid var(--border); padding-top: 12px; }
.fech-flow b { color: var(--text-primary); font-variant-numeric: tabular-nums; margin-left: 4px; }
.fech-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { .fech-layout { grid-template-columns: 1fr; } }
.fech-retirada { display: grid; gap: 18px; }
.fech-retirada textarea { margin: 0; }
.fech-qty { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.fech-qty:last-child { border-bottom: 0; }
.fech-qty-label { font-weight: 600; }
.fech-qty-label small { display: block; font-weight: 400; color: var(--text-muted); font-size: .8rem; }
.fech-stepper { display: flex; align-items: center; border: 1.5px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.fech-stepper button[type="button"] { display: flex; align-items: center; justify-content: center; border: 0; border-radius: 0; background: var(--surface-2); color: var(--text-secondary); width: 38px; height: 40px; padding: 0; font-size: 1.1rem; font-weight: 700; }
.fech-stepper button[type="button"]:hover { background: var(--border); }
.fech-stepper input[type="number"] { width: 72px; height: 40px; margin: 0; border: 0; border-radius: 0; text-align: center; font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.fech-stepper:focus-within { border-color: var(--blue-600); }
.fech-qty.acima .fech-stepper { border-color: var(--red-700); }
.fech-qty-err { grid-column: 1 / -1; color: var(--red-700); font-size: .8rem; }
.fech-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.fech-fields select { margin: 0; width: 100%; }
.fech-summary { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; font-size: .9rem; color: var(--text-secondary); }
.fech-summary b { color: var(--text-primary); }
.fech-note { font-size: .84rem; color: var(--text-secondary); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.fech-note-warn { background: var(--amber-50); border-color: #fde68a; }
.fech-note-warn b { color: var(--amber-700); }
.fech-pill { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; text-decoration: none; white-space: nowrap; }
.fech-pill-in { background: var(--green-50); color: var(--green-700); }
.fech-pill-out { background: var(--blue-50); color: var(--blue-700); }
.fech-pill-off { background: var(--surface-2); color: var(--text-muted); text-decoration: line-through; }
.fech-dlg-lines { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.fech-dlg-lines > div { display: flex; justify-content: space-between; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.fech-dlg-lines > div:last-child { border-bottom: 0; }

/* ── Abas do Estoque em dois grupos (Insumos | Caixas prontas) ──────────── */
.stock-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 4px; }
.stock-switch { display: inline-flex; gap: 2px; padding: 3px; background: var(--border); border-radius: 10px; }
.stock-switch a { display: flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 8px; font-size: .86rem; font-weight: 600; color: var(--text-secondary); text-decoration: none; white-space: nowrap; }
.stock-switch a:hover { color: var(--text-primary); }
.stock-switch a[aria-current] { background: var(--surface); color: var(--text-primary); box-shadow: 0 1px 2px rgba(15, 23, 42, .12); }
.stock-switch small { font-size: .7rem; font-weight: 700; color: var(--text-muted); background: var(--surface-2); border-radius: 99px; padding: 0 6px; }
.stock-switch a[aria-current] small { background: var(--blue-50); color: var(--blue-700); }
.stock-tabs { display: flex; gap: 26px; margin: 14px 0 24px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.stock-tabs::-webkit-scrollbar { display: none; }
.stock-tabs a { display: flex; align-items: center; padding: 10px 0; margin-bottom: -1px; font-size: .9rem; font-weight: 600; color: var(--text-muted); text-decoration: none; white-space: nowrap; border-bottom: 2px solid transparent; transition: color .15s, border-color .15s; }
.stock-tabs a:hover { color: var(--text-secondary); }
.stock-tabs a.active { color: var(--text-primary); border-bottom-color: var(--blue-600); }
.stock-step { display: inline-grid; place-items: center; width: 18px; height: 18px; margin-right: 6px; border-radius: 50%; font-style: normal; font-size: .68rem; color: var(--text-muted); background: var(--surface-2); border: 1px solid var(--border); }
.stock-tabs a.active .stock-step { background: var(--blue-600); border-color: var(--blue-600); color: #fff; }

/* ── Menu de cima: vira ☰ quando nao cabe (admin tem muito mais links) ─── */
.topbar .nav-toggle { display: none; background: transparent; border: 0; color: #cbd5e1; font-size: 1.35rem; line-height: 1; padding: 6px 10px; border-radius: 6px; }
.topbar button.nav-toggle:not(:disabled):hover { background: var(--navy-light); color: #fff; }
.brand { white-space: nowrap; }
@media (max-width: 760px) {
  .topbar .nav-toggle { display: block; }
  .topbar .nav { display: none; position: absolute; top: 56px; left: 0; right: 0; flex-direction: column; align-items: stretch; gap: 2px; padding: 8px 16px 14px; background: var(--navy); box-shadow: 0 8px 16px rgba(0, 0, 0, .25); }
  .topbar .nav.open { display: flex; }
  .topbar .nav a { padding: 10px 12px; font-size: .95rem; }
}
@media (max-width: 1320px) {
  .topbar-long .nav-toggle { display: block; }
  .topbar-long .nav { display: none; position: absolute; top: 56px; left: 0; right: 0; flex-direction: column; align-items: stretch; gap: 2px; padding: 8px 16px 14px; background: var(--navy); box-shadow: 0 8px 16px rgba(0, 0, 0, .25); }
  .topbar-long .nav.open { display: flex; }
  .topbar-long .nav a { padding: 10px 12px; font-size: .95rem; }
}

/* ── Planejamento de compra (Estoque: Status e Projecao) ─────────────────── */
.plan-meta { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 20px; padding: 14px 20px; margin-bottom: 18px; }
.plan-meta input[type="number"] { width: 130px; margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.plan-meta-eq { font-size: .86rem; color: var(--text-secondary); padding-bottom: 9px; }
.plan-meta-eq b { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.plan-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.plan-kpi { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.plan-kpi b { display: block; font-size: 1.8rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.plan-kpi span { font-size: .82rem; color: var(--text-secondary); }
.plan-kpi-r { border-top-color: var(--red-700); } .plan-kpi-r b { color: var(--red-700); }
.plan-kpi-a { border-top-color: var(--amber-700); } .plan-kpi-a b { color: var(--amber-700); }
.plan-kpi-g { border-top-color: var(--green-700); }
.plan-aviso { background: var(--amber-50); border: 1px solid #fde68a; border-radius: 8px; padding: 10px 14px; font-size: .85rem; color: var(--text-secondary); margin-bottom: 16px; }
.plan-aviso b { color: var(--amber-700); }
.plan-filtros { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 20px 10px; }
.plan-chip[type="button"] { background: var(--surface); color: var(--text-secondary); border: 1.5px solid var(--border); border-radius: 99px; padding: 4px 12px; font-size: .8rem; font-weight: 600; }
.plan-chip[type="button"]:not(:disabled):hover { background: var(--surface-2); }
.plan-chip[type="button"][aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.plan-orig { font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.orig-imp { background: #ede9fe; color: #6d28d9; }
.orig-nac { background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--border); }
.orig-fdl { color: var(--text-muted); border: 1px dashed var(--border); }
.plan-obs { display: block; font-size: .74rem; color: var(--text-muted); }
.plan-manual { font-size: .66rem; color: var(--text-muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; margin-left: 4px; }
.plan-cob { display: block; font-size: .74rem; color: var(--text-muted); white-space: nowrap; margin-top: 2px; }
.plan-neg { color: var(--red-700); font-weight: 700; }
.plan-pos { color: var(--green-700); }
.plan-sit { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: .78rem; white-space: nowrap; }
.plan-sit i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.sit-falta { color: var(--red-700); } .sit-pedir { color: var(--amber-700); } .sit-ok { color: var(--green-700); } .sit-fdl { color: var(--text-muted); }
.plan-calc { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: .84rem; display: grid; gap: 3px; margin-bottom: 14px; }
.plan-grupo td { background: var(--surface-2); font-weight: 700; font-size: .76rem; color: var(--text-secondary); }
.plan-legenda { display: flex; gap: 16px; flex-wrap: wrap; font-size: .78rem; color: var(--text-secondary); padding: 8px 20px 10px; }
.plan-legenda i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.plan-tl { position: relative; height: 24px; }
.plan-tl-rail { position: absolute; left: 0; right: 0; top: 10px; height: 4px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); }
.plan-tl-run { position: absolute; left: 0; top: 10px; height: 4px; border-radius: 99px; background: var(--blue-600); }
.plan-tl-mk { position: absolute; top: 3px; width: 2px; height: 18px; }
.plan-tl-pedir { background: var(--amber-700); }
.plan-tl-zera { background: var(--red-700); }
.plan-table td.num, .plan-table th.num { white-space: nowrap; }
.plan-table td:first-child { min-width: 190px; }
