/* =====================================================================
   Inventário EPS — folha de estilos
   Tokens, base, layout (sidebar/topbar), componentes e utilitários.
   ===================================================================== */

:root {
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: Consolas, "SFMono-Regular", Menlo, monospace;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;

  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --primary-200: #bfdbfe;

  --success: #15803d;
  --success-bg: #dcfce7;
  --success-border: #86efac;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --danger-border: #fca5a5;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --warning-border: #fcd34d;
  --info: #0369a1;
  --info-bg: #e0f2fe;
  --info-border: #7dd3fc;
  --neutral-bg: #f1f5f9;

  --sidebar-bg: #0f172a;
  --sidebar-bg-2: #111c33;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #64748b;
  --sidebar-active: #1d4ed8;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .08);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, .18);

  --sidebar-w: 256px;
  --topbar-h: 60px;
  --content-max: 1440px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.25; }
p { margin: 0 0 8px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; }
small { font-size: 12px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

/* --------------------------------------------------------------------
   Boot / spinner
   -------------------------------------------------------------------- */
.availability-page { min-height: 100vh; display: grid; place-items: center; padding: 32px 20px; background: radial-gradient(ellipse at 15% 0%, #dbeafe 0%, transparent 50%), var(--bg); }
.availability-card { width: min(100%, 620px); padding: 40px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-md); text-align: center; }
.availability-brand { display: flex; justify-content: center; align-items: center; gap: 12px; text-align: left; font-weight: 750; font-size: 18px; }
.availability-brand-subtitle { display: block; color: var(--text-2); font-size: 12px; font-weight: 400; }
.availability-symbol { width: 76px; height: 76px; display: grid; place-items: center; margin: 32px auto 20px; color: var(--primary); background: var(--primary-50); border-radius: 50%; }
.availability-eyebrow { color: var(--primary); font-size: 11px; font-weight: 700; letter-spacing: .12em; margin-bottom: 10px; }
.availability-card h1 { font-size: clamp(24px, 5vw, 32px); letter-spacing: -.03em; }
.availability-description { color: var(--text-2); font-size: 15px; margin: 16px 0 24px; }
.availability-hours { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 18px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); text-align: left; }
.availability-hours span, .availability-next span, .availability-next strong, .availability-next small { display: block; }
.availability-hours span, .availability-next small { color: var(--text-2); font-size: 12px; margin-top: 3px; }
.availability-next { margin: 22px 0; }
.availability-next span { color: var(--text-2); font-size: 12px; margin-bottom: 5px; }
.availability-next strong { font-size: 16px; }
.availability-card > .btn { margin-top: 22px; }
.availability-footnote { color: var(--text-2); font-size: 12px; margin: 18px 0 0; }
@media (max-width: 600px) { .availability-card { padding: 28px 20px; } .availability-hours { padding: 14px 10px; } }

.boot {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--text-2);
}

.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.spinner.lg { width: 34px; height: 34px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading-block {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 40px; color: var(--text-2);
}

/* --------------------------------------------------------------------
   Layout: shell, sidebar, topbar, content
   -------------------------------------------------------------------- */
.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: transform .22s ease;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  color: #fff;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary);
  display: grid; place-items: center;
  color: #fff; flex-shrink: 0;
}
.brand-title { font-weight: 700; font-size: 15px; letter-spacing: .01em; }
.brand-sub { font-size: 11.5px; color: var(--sidebar-muted); text-transform: uppercase; letter-spacing: .06em; }

.nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.nav-section { padding: 14px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--sidebar-muted); }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-weight: 500;
  text-decoration: none !important;
  transition: background .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: 0 4px 14px rgba(29,78,216,.35); }
.nav-item .badge { margin-left: auto; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px;
  font-size: 12.5px;
}
.sidebar-footer .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,.1); display: grid; place-items: center; font-weight: 700; color: #fff;
}
.sidebar-footer .who { flex: 1; min-width: 0; }
.sidebar-footer .who strong { display: block; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .who span { color: var(--sidebar-muted); }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  background: rgba(255,255,255,.92);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
}
.topbar-title { font-size: 16px; font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .btn-icon.menu { display: none; }

.content { padding: 24px; width: 100%; max-width: var(--content-max); margin: 0 auto; flex: 1; }

.sidebar-backdrop { display: none; }

@media (max-width: 600px) {
  .topbar { gap: 8px; }
  .topbar .autosave span:last-child { display: none; }
  .topbar .btn-sm { padding: 0 10px; }
}

@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 35; }
  .main { margin-left: 0; }
  .topbar { padding: 0 14px; }
  .topbar .btn-icon.menu { display: inline-flex; }
  .content { padding: 16px; }
}

/* --------------------------------------------------------------------
   Page header
   -------------------------------------------------------------------- */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-title { font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-subtitle { color: var(--text-2); margin-top: 4px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* --------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card, .card + .kpi-grid, .kpi-grid + .card, .card + .grid, .grid + .card, .alert + .card, .card + .alert { margin-top: 18px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-title .muted { font-weight: 400; }
.card-body { padding: 20px; }
.card-body.tight { padding: 0; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-main { grid-template-columns: 1fr; } }

/* --------------------------------------------------------------------
   KPI cards
   -------------------------------------------------------------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px 14px 18px; box-shadow: var(--shadow);
  position: relative; overflow: hidden; min-width: 0;
}
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--kpi-color, var(--primary)); }
.kpi-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value.kpi-value-sm { font-size: 21px; }
.kpi-value.kpi-value-xs { font-size: 17px; white-space: normal; line-height: 1.2; }
.kpi-sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.kpi.tone-success { --kpi-color: var(--success); }
.kpi.tone-danger { --kpi-color: var(--danger); }
.kpi.tone-warning { --kpi-color: var(--warning); }
.kpi.tone-info { --kpi-color: var(--info); }
.kpi.tone-neutral { --kpi-color: var(--border-strong); }
.kpi.clickable { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.kpi.clickable:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

/* --------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600; font-size: 14px;
  white-space: nowrap;
  text-decoration: none !important;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  user-select: none;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: #94a3b8; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #991b1b; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #166534; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover:not(:disabled) { background: #92400e; }
.btn-outline-danger { background: var(--surface); color: var(--danger); border-color: var(--danger-border); }
.btn-outline-danger:hover:not(:disabled) { background: var(--danger-bg); }
.btn-outline-success { background: var(--surface); color: var(--success); border-color: var(--success-border); }
.btn-outline-success:hover:not(:disabled) { background: var(--success-bg); }
.btn-outline-warning { background: var(--surface); color: var(--warning); border-color: var(--warning-border); }
.btn-outline-warning:hover:not(:disabled) { background: var(--warning-bg); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; gap: 6px; }
.btn-xs { height: 28px; padding: 0 10px; font-size: 12px; gap: 6px; }
.btn-lg { height: 44px; padding: 0 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: var(--radius-sm); background: transparent; border: 1px solid transparent; color: var(--text-2); display: inline-flex; align-items: center; justify-content: center; }
.btn-icon:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-icon.sm { width: 30px; height: 30px; }
.btn-icon:disabled { opacity: .45; cursor: not-allowed; }
.btn-group { display: inline-flex; gap: 6px; }

/* --------------------------------------------------------------------
   Badges & chips
   -------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px;
  border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .01em;
  white-space: nowrap;
  background: var(--neutral-bg); color: var(--text-2);
  border: 1px solid transparent;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-primary { background: var(--primary-100); color: var(--primary-hover); }
.badge-neutral { background: var(--neutral-bg); color: var(--text-2); }
.badge-dark { background: var(--text); color: #fff; }
.badge-outline { background: transparent; border-color: var(--border-strong); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text-2);
  font-weight: 600; font-size: 13px;
}
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip .count { font-weight: 700; opacity: .8; }

/* --------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field-label .req { color: var(--danger); }
.field-hint { font-size: 12px; color: var(--text-3); }
.field-error { font-size: 12px; color: var(--danger); }

.input, .select, .textarea {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 92px; padding: 10px 12px; resize: vertical; line-height: 1.4; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-100); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-3); color: var(--text-3); cursor: not-allowed; }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }
.input.sm, .select.sm { height: 34px; font-size: 13px; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
.input-icon { position: relative; }
.input-icon .input { padding-left: 36px; }
.input-icon > svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-2); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }

.qty-input {
  width: 124px; height: 36px; text-align: right; font-weight: 600;
  font-variant-numeric: tabular-nums; padding: 0 10px;
}
.qty-input.is-saved { border-color: var(--success-border); }
.qty-input.is-saving { border-color: var(--primary-200); }
.qty-input.is-invalid { border-color: var(--danger); background: #fff5f5; }
input[type=number]::-webkit-inner-spin-button { opacity: .5; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters .field { flex: 1 1 160px; }
.filters .field.wide { flex: 2 1 240px; }
.filters .filter-actions { display: flex; gap: 8px; align-items: center; }

/* --------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.card .table-wrap { border: none; border-radius: 0; }
.card-body.tight .table-wrap { border-radius: 0 0 var(--radius) var(--radius); }
table.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  text-align: left;
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-2); font-weight: 700;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fafc; }
.table tr.clickable { cursor: pointer; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .center { text-align: center; }
.table .nowrap { white-space: nowrap; }
.table .cell-main { font-weight: 600; }
.table .cell-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.table tr.row-falta td { background: #fff7f7; }
.table tr.row-sobra td { background: #fffbeb; }
.table tr.row-pending td { background: #fafafa; }
.table tr.row-flag td { box-shadow: inset 3px 0 0 var(--warning); }
.table tr.row-falta:hover td, .table tr.row-sobra:hover td { filter: brightness(.985); }
.table.compact th, .table.compact td { padding: 7px 10px; }
/* Tabelas largas rolam horizontalmente dentro de .table-wrap em vez de espremer as colunas */
.table.wide { min-width: 960px; }
.table.wide-lg { min-width: 1180px; }
.table-empty { padding: 36px; text-align: center; color: var(--text-2); }
.table-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; font-size: 12.5px; color: var(--text-2); border-top: 1px solid var(--border); flex-wrap: wrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sortable .sort-ind { opacity: .5; margin-left: 4px; }

.diff-pos { color: var(--warning); font-weight: 700; }
.diff-neg { color: var(--danger); font-weight: 700; }
.diff-zero { color: var(--success); font-weight: 600; }

/* --------------------------------------------------------------------
   Mobile item cards
   -------------------------------------------------------------------- */
.item-cards { display: grid; gap: 12px; }
.item-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.item-card.row-falta { border-color: var(--danger-border); background: #fff8f8; }
.item-card.row-sobra { border-color: var(--warning-border); background: #fffcf0; }
.item-card .ic-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.item-card .ic-code { font-family: var(--mono); font-size: 12px; color: var(--text-2); }
.item-card .ic-desc { font-weight: 600; margin-top: 2px; }
.item-card .ic-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.item-card .ic-grid .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.item-card .ic-grid .val { font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.item-card .ic-actions { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-top: 12px; flex-wrap: wrap; }
.item-card .qty-input { width: 100%; max-width: 160px; }

.desktop-only { display: block; }
.mobile-only { display: none; }
@media (max-width: 767px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: block; }
}

/* --------------------------------------------------------------------
   Progress & autosave
   -------------------------------------------------------------------- */
.progress { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s ease; }
.progress-bar.success { background: var(--success); }
.progress-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--text-2); margin-top: 6px; }

.autosave { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); white-space: nowrap; }
.autosave .spinner { width: 14px; height: 14px; border-width: 2px; }
.autosave.saved { color: var(--success); }
.autosave.error { color: var(--danger); }

/* --------------------------------------------------------------------
   Alerts
   -------------------------------------------------------------------- */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.alert svg { flex-shrink: 0; margin-top: 1px; }
.alert-title { font-weight: 700; }
.alert-body { flex: 1; min-width: 0; }
.alert-warning { background: var(--warning-bg); border-color: var(--warning-border); color: #78350f; }
.alert-danger { background: var(--danger-bg); border-color: var(--danger-border); color: #7f1d1d; }
.alert-info { background: var(--info-bg); border-color: var(--info-border); color: #0c4a6e; }
.alert-success { background: var(--success-bg); border-color: var(--success-border); color: #14532d; }
.alert + .alert { margin-top: 10px; }
.alert .btn { flex-shrink: 0; }

/* --------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, .5);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: fade .15s ease;
}
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
  animation: pop .18s ease;
}
.modal.lg { max-width: 820px; }
.modal.sm { max-width: 440px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px 12px; }
.modal-title { font-size: 17px; font-weight: 700; }
.modal-body { padding: 6px 22px 18px; overflow: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@media (max-width: 600px) {
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92vh; }
}

/* --------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------- */
.toast-container { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 10px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--text); color: #fff; box-shadow: var(--shadow-lg);
  font-size: 13.5px; animation: pop .2s ease;
}
.toast svg { flex-shrink: 0; margin-top: 1px; }
.toast-success { background: #14532d; }
.toast-error { background: #7f1d1d; }
.toast-warning { background: #78350f; }
.toast-info { background: #0c4a6e; }
.toast .close { margin-left: auto; background: none; border: none; color: inherit; opacity: .7; padding: 0; }

/* --------------------------------------------------------------------
   Tabs
   -------------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab { padding: 10px 14px; border: none; background: none; color: var(--text-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* --------------------------------------------------------------------
   Timeline (auditoria)
   -------------------------------------------------------------------- */
.timeline { display: flex; flex-direction: column; }
.timeline-item { display: grid; grid-template-columns: 150px 1fr; gap: 14px; padding: 12px 0; border-bottom: 1px dashed var(--border); }
.timeline-item:last-child { border-bottom: none; }
.timeline-when { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.timeline-when strong { display: block; color: var(--text); }
.timeline-what { min-width: 0; }
.timeline-what .headline { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.timeline-what .details { color: var(--text-2); font-size: 13px; margin-top: 3px; }
@media (max-width: 600px) { .timeline-item { grid-template-columns: 1fr; gap: 4px; } }

/* --------------------------------------------------------------------
   Status steps
   -------------------------------------------------------------------- */
.steps { display: flex; gap: 6px; flex-wrap: wrap; }
.step { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--neutral-bg); color: var(--text-3); }
.step.done { background: var(--success-bg); color: var(--success); }
.step.current { background: var(--primary); color: #fff; }
.step.danger { background: var(--danger-bg); color: var(--danger); }
.step.warning { background: var(--warning-bg); color: var(--warning); }

/* --------------------------------------------------------------------
   Sticky actions, dropzone, charts, empty state, misc
   -------------------------------------------------------------------- */
.sticky-actions {
  position: sticky; bottom: 0; z-index: 20;
  margin-top: 18px;
  background: rgba(255,255,255,.95); backdrop-filter: blur(6px);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px;
  display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  box-shadow: 0 -6px 20px rgba(15,23,42,.06);
}
.sticky-actions .actions { display: flex; gap: 10px; flex-wrap: wrap; }

.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--text-2); background: var(--surface-2); }
.dropzone.active { border-color: var(--primary); background: var(--primary-50); }
.dropzone input { display: none; }

.chart-box { position: relative; width: 100%; }
.chart-box canvas { width: 100% !important; }

.empty { text-align: center; padding: 40px 20px; color: var(--text-2); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty .empty-icon { width: 52px; height: 52px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; color: var(--text-3); margin-bottom: 4px; }
.empty .empty-title { font-weight: 700; color: var(--text); font-size: 15px; }

.evidence-list { display: flex; flex-direction: column; gap: 8px; }
.evidence { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-size: 13px; }
.evidence .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.evidence .meta { color: var(--text-3); font-size: 12px; white-space: nowrap; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13.5px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }

.header-meta { display: flex; flex-wrap: wrap; gap: 8px 22px; color: var(--text-2); font-size: 13px; }
.header-meta strong { color: var(--text); }

.stale-pill { display: inline-flex; align-items: center; gap: 6px; }

.rank-bar { height: 6px; border-radius: 999px; background: var(--primary-100); overflow: hidden; }
.rank-bar > span { display: block; height: 100%; background: #2a78d6; }

/* Utilitários */
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; } .wrap { flex-wrap: wrap; }
.gap-1 { gap: 6px; } .gap-2 { gap: 10px; } .gap-3 { gap: 16px; }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 10px; } .mt-3 { margin-top: 16px; } .mt-4 { margin-top: 24px; }
.mb-2 { margin-bottom: 10px; } .mb-3 { margin-bottom: 16px; }
.muted { color: var(--text-2); } .faint { color: var(--text-3); }
.text-success { color: var(--success); } .text-danger { color: var(--danger); } .text-warning { color: var(--warning); } .text-primary { color: var(--primary); }
.fw-600 { font-weight: 600; } .fw-700 { font-weight: 700; }
.fs-12 { font-size: 12px; } .fs-13 { font-size: 13px; } .fs-16 { font-size: 16px; } .fs-20 { font-size: 20px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; }
.text-right { text-align: right; }
.tabular { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.link-btn { background: none; border: none; color: var(--primary); font-weight: 600; padding: 0; }
.link-btn:hover { text-decoration: underline; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }

/* --------------------------------------------------------------------
   Bipagem de seriais: formulário e leitor pela câmera
   -------------------------------------------------------------------- */
.serial-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.serial-form .serial-input { flex: 1 1 320px; }
@media (max-width: 600px) {
  .serial-form .serial-input { flex-basis: 100%; }
  .serial-form .btn { flex: 1 1 auto; }
  .serial-form .btn-camera { order: -1; flex-basis: 100%; height: 48px; font-size: 15px; }
}

.scanner-overlay { position: fixed; inset: 0; z-index: 150; background: #0b1220; color: #e2e8f0; display: flex; flex-direction: column; animation: fade .15s ease; }
.scanner-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
.scanner-heading { min-width: 0; }
.scanner-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; color: #fff; }
.scanner-sub { font-size: 12.5px; color: #94a3b8; margin-top: 2px; }
.scanner-top .btn-icon { color: #e2e8f0; flex-shrink: 0; }
.scanner-top .btn-icon:hover:not(:disabled) { background: rgba(255,255,255,.1); color: #fff; }
.scanner-stage { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }
.scanner-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner-frame { position: absolute; left: 50%; top: 50%; width: min(82%, 520px); aspect-ratio: 5 / 3; transform: translate(-50%, -50%); pointer-events: none; border-radius: 14px; box-shadow: 0 0 0 100vmax rgba(2, 6, 23, .45); }
.scanner-frame span { position: absolute; width: 26px; height: 26px; border: 3px solid #fff; border-radius: 4px; }
.scanner-frame span:nth-child(1) { left: -2px; top: -2px; border-right: 0; border-bottom: 0; }
.scanner-frame span:nth-child(2) { right: -2px; top: -2px; border-left: 0; border-bottom: 0; }
.scanner-frame span:nth-child(3) { left: -2px; bottom: -2px; border-right: 0; border-top: 0; }
.scanner-frame span:nth-child(4) { right: -2px; bottom: -2px; border-left: 0; border-top: 0; }
/* Linha de leitura fixa: só o código sob a linha (faixa .scanner-band) é lido; QR Codes podem ocupar a moldura. */
.scanner-frame::after { content: ""; position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; margin-top: -1px; background: rgba(248, 113, 113, .9); box-shadow: 0 0 10px rgba(248, 113, 113, .9); }
.scanner-band { position: absolute; left: -6%; right: -6%; top: 38%; bottom: 38%; border-radius: 6px; background: rgba(248, 113, 113, .10); border: 1px dashed rgba(248, 113, 113, .45); }
.scanner-frame.hit span { border-color: #4ade80; }
.scanner-frame.hit::after { background: #4ade80; box-shadow: 0 0 12px #4ade80; }
.scanner-frame.hit .scanner-band { background: rgba(74, 222, 128, .16); border-color: rgba(74, 222, 128, .6); }
.scanner-frame.paused::after { background: #fbbf24; box-shadow: 0 0 10px rgba(251, 191, 36, .9); }
.scanner-frame.paused .scanner-band { background: rgba(251, 191, 36, .12); border-color: rgba(251, 191, 36, .55); }
.scanner-message { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px; text-align: center; background: rgba(11, 18, 32, .9); color: #e2e8f0; }
.scanner-message p { margin: 0; max-width: 420px; }
.scanner-message .spinner { border-color: rgba(255,255,255,.25); border-top-color: #fff; }
.scanner-panel { padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom)); background: #0f172a; border-top: 1px solid rgba(255,255,255,.08); display: flex; flex-direction: column; gap: 10px; }
.scanner-hint { font-size: 13px; color: #94a3b8; text-align: center; }
.scanner-hint.scanner-warning { color: #fcd34d; }
.scanner-log { display: flex; flex-direction: column; gap: 6px; max-height: 118px; overflow: auto; }
.scanner-log-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-family: var(--mono); font-size: 13px; color: #fff; padding: 6px 10px; border-radius: var(--radius-sm); background: rgba(255,255,255,.06); }
.scanner-log-item .badge { font-family: var(--font); flex-shrink: 0; }
.scanner-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.scanner-actions .btn { flex: 1 1 auto; }
.scanner-actions .btn-secondary { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.18); color: #fff; }
.scanner-actions .btn-secondary:hover:not(:disabled) { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.3); }
.scanner-actions .btn-secondary.is-on { background: #fbbf24; border-color: #fbbf24; color: #1f2937; }
.scanner-actions .btn-secondary .spinner { border-color: rgba(255,255,255,.3); border-top-color: #fff; }
.scanner-confirm { display: flex; flex-direction: column; gap: 8px; }
.scanner-confirm-title { display: flex; align-items: center; gap: 8px; font-weight: 700; color: #fff; }
.scanner-confirm-value { font-family: var(--mono); font-size: 22px; font-weight: 700; letter-spacing: .5px; color: #fff; text-align: center; word-break: break-all; padding: 10px 12px; border-radius: var(--radius-sm); background: rgba(255,255,255,.08); border: 1px solid rgba(251, 191, 36, .5); }
.scanner-confirm-raw { font-family: var(--mono); font-size: 12px; color: #94a3b8; word-break: break-all; }

/* --------------------------------------------------------------------
   Login
   -------------------------------------------------------------------- */
.login-page {
  min-height: 100vh;
  display: grid; grid-template-columns: 1.1fr 1fr;
  background: var(--bg);
}
.login-hero {
  background: radial-gradient(1200px 600px at 10% 10%, rgba(37,99,235,.45), transparent 60%), linear-gradient(160deg, #0f172a 0%, #1e3a8a 100%);
  color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
}
.login-hero h1 { font-size: 34px; margin-top: 28px; letter-spacing: -.01em; }
.login-hero p { color: rgba(255,255,255,.75); font-size: 15px; max-width: 460px; }
.login-hero .flow { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 26px; }
.login-hero .flow span { padding: 6px 10px; border-radius: 999px; background: rgba(255,255,255,.1); font-size: 12.5px; font-weight: 600; }
.login-form-wrap { display: grid; place-items: center; padding: 32px 20px; }
.login-card { width: 100%; max-width: 420px; }
.login-card .card-body { padding: 30px 30px 26px; display: flex; flex-direction: column; gap: 16px; }
.login-card h2 { font-size: 22px; }
.demo-box { background: var(--primary-50); border: 1px dashed var(--primary-200); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13px; color: var(--primary-hover); }
.demo-box .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; }
@media (max-width: 900px) {
  .login-page { grid-template-columns: 1fr; }
  .login-hero { padding: 28px 22px; }
  .login-hero h1 { font-size: 26px; margin-top: 12px; }
  .login-hero .flow { display: none; }
}

@media print {
  .sidebar, .topbar, .sticky-actions, .page-actions, .toast-container { display: none !important; }
  .main { margin-left: 0; }
  .card { box-shadow: none; }
}
