/* ÓticaFácil — Claro Operacional (Ótica & Laboratório) Design System
 * Zero external CDNs. Base text >= 12px. Inputs >= 16px. Tap targets >= 44x44px.
 */

:root {
  /* Core Surfaces & Neutrals */
  --bg: #F6F8FA;
  --surface: #FFFFFF;
  --elevated: #ECF1F6;
  --surface-alt: var(--elevated);
  --border: #D5DFE9;
  --border-strong: #B6C6D8;

  /* Ink */
  --text: #0F172A;
  --muted: #475569;
  --text-muted: var(--muted);
  --subtle: #64748B;

  /* White-Label Brand Tokens */
  --primary: #154360;
  --primary-hover: #0F3349;
  --primary-soft: rgba(21, 67, 96, 0.10);
  --primary-ink: #FFFFFF;

  --accent: #0D9488;
  --accent-hover: #0F766E;
  --accent-soft: rgba(13, 148, 136, 0.12);
  --accent-ink: #0F766E;

  /* Feedback Tokens */
  --danger: #DC2626;
  --danger-hover: #B91C1C;
  --danger-soft: #FEF2F2;
  --danger-bd: #FCA5A5;

  --success: #15803D;
  --success-hover: #166534;
  --success-soft: #DCFCE7;
  --success-bd: #86EFAC;

  --warning: #D97706;
  --warning-soft: #FEF3C7;
  --warning-bd: #FCD34D;

  /* OS Status Semantic Palette */
  --st-orcamento: #D97706;
  --st-orcamento-bg: #FEF3C7;
  --st-orcamento-bd: #FCD34D;

  --st-aprovado: #2563EB;
  --st-aprovado-bg: #DBEAFE;
  --st-aprovado-bd: #93C5FD;

  --st-laboratorio: #7C3AED;
  --st-laboratorio-bg: #F3E8FF;
  --st-laboratorio-bd: #C4B5FD;

  --st-conferencia: #0284C7;
  --st-conferencia-bg: #E0F2FE;
  --st-conferencia-bd: #7DD3FC;

  --st-pronto: #15803D;
  --st-pronto-bg: #DCFCE7;
  --st-pronto-bd: #86EFAC;

  --st-entregue: #0F766E;
  --st-entregue-bg: #CCFBF1;
  --st-entregue-bd: #5EEAD4;

  --st-cancelada: #64748B;
  --st-cancelada-bg: #F1F5F9;
  --st-cancelada-bd: #CBD5E1;

  /* Annual Review Radar Palette */
  --rd-vencida: #DC2626;
  --rd-vencida-bg: #FEF2F2;
  --rd-vencida-bd: #FCA5A5;

  --rd-vencendo: #D97706;
  --rd-vencendo-bg: #FEF3C7;
  --rd-vencendo-bd: #FCD34D;

  --rd-em-dia: #15803D;
  --rd-em-dia-bg: #DCFCE7;
  --rd-em-dia-bd: #86EFAC;

  /* Geometry & Elevation */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 18px 44px rgba(15, 23, 42, 0.22);

  /* Safe Areas & Layout */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --topbar-h: 64px;
}

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

html,
body {
  overflow-x: clip;
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body {
  padding-bottom: var(--safe-bottom);
}

body.of-modal-open {
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

img,
svg {
  max-width: 100%;
}

.of-icon {
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
}

.of-qr-svg {
  display: block;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #FFFFFF;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  color: var(--text);
  line-height: 1.25;
  letter-spacing: -0.012em;
}

h1 {
  font-size: 1.5rem;
  font-weight: 800;
}

h2 {
  font-size: 1.25rem;
  font-weight: 750;
}

h3 {
  font-size: 1.0625rem;
  font-weight: 700;
}

h4 {
  font-size: 0.9375rem;
  font-weight: 700;
}

p {
  margin: 0;
}

a {
  color: var(--primary);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--primary-hover);
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.mono {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;
  font-variant-numeric: tabular-nums;
}

.text-muted {
  color: var(--muted);
}

.text-subtle {
  color: var(--subtle);
}

.text-danger {
  color: var(--danger);
}

.text-success {
  color: var(--success);
}

.text-sm {
  font-size: 0.875rem;
}

.text-xs {
  font-size: 0.75rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Hard Mobile/iOS Invariants: Inputs >= 16px, Tap Targets >= 44x44px */
input,
select,
textarea {
  font-family: inherit;
  font-size: 16px;
  line-height: 1.35;
  min-height: 44px;
  color: var(--text);
}

button,
a.btn,
.btn,
.tab-btn,
.tap-target {
  min-height: 44px;
  min-width: 44px;
  font-family: inherit;
  touch-action: manipulation;
}

/* ==========================================================================
   Safe Auto-Update Banner (#app-update)
   ========================================================================== */
.update-banner,
#app-update {
  position: sticky;
  top: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
  background: var(--accent-soft);
  color: var(--primary);
  border-bottom: 2px solid var(--accent);
  font-size: 0.9375rem;
  font-weight: 600;
}

.update-banner-msg {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.update-banner-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ==========================================================================
   Topbar (Sticky Claro Operacional Header)
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  min-height: var(--topbar-h);
  padding: calc(8px + var(--safe-top)) calc(16px + var(--safe-right)) 8px calc(16px + var(--safe-left));
  background: var(--surface);
  border-top: 4px solid var(--primary);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.topbar-right {
  justify-content: flex-end;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  display: block;
  width: 38px;
  height: 38px;
  max-width: 120px;
  max-height: 38px;
  object-fit: contain;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-name {
  font-size: 1.0625rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-subtitle {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-pill > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Containers, Layout Utilities & Cards
   ========================================================================== */
.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px calc(16px + var(--safe-right)) calc(36px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

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

.container-sm {
  max-width: 560px;
}

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

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stack-xs {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cluster {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cluster-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.divider {
  height: 1px;
  background: var(--border);
  border: 0;
  margin: 14px 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.card-body {
  padding: 18px;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* ==========================================================================
   KPI Grid & Cards
   ========================================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 12px;
}

.kpi-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
}

.kpi-card.kpi-primary {
  border-left: 4px solid var(--primary);
}

.kpi-card.kpi-accent {
  border-left: 4px solid var(--accent);
}

.kpi-card.kpi-danger {
  border-left: 4px solid var(--rd-vencida);
}

.kpi-card.kpi-warning {
  border-left: 4px solid var(--rd-vencendo);
}

.kpi-card.kpi-success {
  border-left: 4px solid var(--rd-em-dia);
}

.kpi-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
}

.kpi-value {
  font-size: 1.625rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--subtle);
}

/* ==========================================================================
   Nav Tabs
   ========================================================================== */
.tabs,
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.tab-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.75);
}

.tab-btn.is-active,
.tab-btn[aria-selected="true"] {
  background: var(--surface);
  color: var(--primary);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}

/* ==========================================================================
   Buttons (>= 44x44px)
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 650;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.14s ease, border-color 0.14s ease, color 0.14s ease, transform 0.08s ease;
}

.btn:hover:not(:disabled) {
  background: var(--elevated);
  border-color: var(--subtle);
  color: var(--text);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: var(--primary-ink);
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #FFFFFF;
}

.btn-secondary {
  background: var(--elevated);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: #DCE5EF;
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--primary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--primary-soft);
  border-color: transparent;
  color: var(--primary-hover);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #FFFFFF;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  color: #FFFFFF;
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #FFFFFF;
}

.btn-success:hover:not(:disabled) {
  background: var(--success-hover);
  border-color: var(--success-hover);
  color: #FFFFFF;
}

.btn-sm {
  min-height: 44px;
  min-width: 44px;
  padding: 6px 12px;
  font-size: 0.875rem;
}

.btn-block {
  width: 100%;
}

/* ==========================================================================
   Badges, Status Pills & Radar Pills
   ========================================================================== */
.badge,
.status-pill,
.status-badge,
.radar-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--elevated);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.status-pill::before,
.status-badge::before,
.radar-badge::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* OS Status Colors */
.status-orcamento {
  background: var(--st-orcamento-bg);
  border-color: var(--st-orcamento-bd);
  color: #92400E;
}

.status-aprovado {
  background: var(--st-aprovado-bg);
  border-color: var(--st-aprovado-bd);
  color: #1D4ED8;
}

.status-laboratorio {
  background: var(--st-laboratorio-bg);
  border-color: var(--st-laboratorio-bd);
  color: #6D28D9;
}

.status-conferencia {
  background: var(--st-conferencia-bg);
  border-color: var(--st-conferencia-bd);
  color: #0369A1;
}

.status-pronto {
  background: var(--st-pronto-bg);
  border-color: var(--st-pronto-bd);
  color: #15803D;
}

.status-entregue {
  background: var(--st-entregue-bg);
  border-color: var(--st-entregue-bd);
  color: #0F766E;
}

.status-cancelada {
  background: var(--st-cancelada-bg);
  border-color: var(--st-cancelada-bd);
  color: #475569;
}

/* Radar Return Colors */
.radar-vencida {
  background: var(--rd-vencida-bg);
  border-color: var(--rd-vencida-bd);
  color: #B91C1C;
}

.radar-vencendo {
  background: var(--rd-vencendo-bg);
  border-color: var(--rd-vencendo-bd);
  color: #92400E;
}

.radar-em_dia {
  background: var(--rd-em-dia-bg);
  border-color: var(--rd-em-dia-bd);
  color: #15803D;
}

/* Quote Status Badges */
.quote-pendente {
  background: var(--st-orcamento-bg);
  border-color: var(--st-orcamento-bd);
  color: #92400E;
}

.quote-aprovado {
  background: var(--st-pronto-bg);
  border-color: var(--st-pronto-bd);
  color: #15803D;
}

.quote-recusado {
  background: var(--danger-soft);
  border-color: var(--danger-bd);
  color: #B91C1C;
}

.quote-substituido {
  background: var(--st-cancelada-bg);
  border-color: var(--st-cancelada-bd);
  color: #475569;
}

/* Utility Badges */
.badge-priority {
  background: #FFF7ED;
  border-color: #FDBA74;
  color: #9A3412;
}

.badge-warranty {
  background: #EDE9FE;
  border-color: #C4B5FD;
  color: #5B21B6;
}

.badge-success {
  background: var(--success-soft);
  border-color: var(--success-bd);
  color: #166534;
}

.badge-warning {
  background: var(--warning-soft);
  border-color: var(--warning-bd);
  color: #92400E;
}

.badge-danger {
  background: var(--danger-soft);
  border-color: var(--danger-bd);
  color: #B91C1C;
}

.badge-info {
  background: var(--primary-soft);
  border-color: #B6D0E2;
  color: var(--primary);
}

.badge-accent {
  background: var(--accent-soft);
  border-color: #99F6E4;
  color: var(--accent-ink);
}

/* ==========================================================================
   Callouts / Operational Alerts
   ========================================================================== */
.callout {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--elevated);
  font-size: 0.875rem;
  color: var(--text);
}

.callout-info {
  background: var(--primary-soft);
  border-color: #B6D0E2;
  color: var(--primary);
}

.callout-warn {
  background: var(--warning-soft);
  border-color: var(--warning-bd);
  color: #92400E;
}

.callout-danger {
  background: var(--danger-soft);
  border-color: var(--danger-bd);
  color: #991B1B;
}

.callout-success {
  background: var(--success-soft);
  border-color: var(--success-bd);
  color: #166534;
}

/* ==========================================================================
   Forms & Fields (>= 16px, Focus Ring)
   ========================================================================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.form-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label,
.field > label {
  font-size: 0.875rem;
  font-weight: 650;
  color: var(--text);
}

.field-hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.field-error {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--danger);
}

.input,
.select,
.textarea,
.field input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  min-height: 44px;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

.field textarea,
.textarea {
  min-height: 88px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  outline: none;
}

.field input[type="color"] {
  width: 56px;
  height: 44px;
  padding: 4px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 500;
}

.checkbox-row input[type="checkbox"],
.checkbox-row input[type="radio"] {
  width: 20px;
  height: 20px;
  min-height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.chip-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.chip-toggle:has(input:checked),
.chip-toggle.is-selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--primary);
}

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrap input {
  padding-right: 52px;
}

.password-toggle {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.password-toggle:hover {
  color: var(--text);
  background: var(--elevated);
}

/* ==========================================================================
   Optical Prescription Table & Grid (.rx-table, .rx-grid)
   ========================================================================== */
.rx-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.rx-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.rx-table thead th {
  padding: 9px 10px;
  font-size: 0.75rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: var(--elevated);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: center;
  white-space: nowrap;
}

.rx-table thead th:last-child {
  border-right: 0;
}

.rx-table thead tr.rx-group-row th {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: rgba(255, 255, 255, 0.22);
}

.rx-table thead tr.rx-group-row th.rx-group-near {
  background: var(--accent);
  color: #FFFFFF;
}

.rx-table tbody th,
.rx-table tbody td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: center;
  vertical-align: middle;
}

.rx-table tbody td:last-child {
  border-right: 0;
}

.rx-table tbody tr:last-child th,
.rx-table tbody tr:last-child td {
  border-bottom: 0;
}

.rx-table .rx-val {
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--text);
  white-space: nowrap;
}

.rx-table .rx-val-empty {
  color: var(--subtle);
  font-weight: 500;
}

.rx-eye-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.rx-eye-od {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid #B6D0E2;
}

.rx-eye-oe {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border: 1px solid #99F6E4;
}

.rx-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.8125rem;
  color: var(--muted);
}

.rx-meta strong {
  color: var(--text);
}

/* Editable optical input grid (forms) */
.rx-grid {
  display: grid;
  grid-template-columns: 64px repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.rx-grid-head {
  font-size: 0.75rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  text-align: center;
}

.rx-grid input {
  width: 100%;
  padding: 8px 10px;
  text-align: center;
  font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

/* ==========================================================================
   Tables
   ========================================================================== */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.table th,
.table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table th {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--bg);
  white-space: nowrap;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr:hover {
  background: #F8FAFC;
}

/* ==========================================================================
   Modals (Accessible Dialogs: scrollable body, sticky footer)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background: rgba(15, 23, 42, 0.56);
  backdrop-filter: blur(2px);
}

.modal-card,
.modal-dialog {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: calc(100dvh - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-sm {
  max-width: 440px;
}

.modal-md {
  max-width: 660px;
}

.modal-lg {
  max-width: 920px;
}

.modal-xl {
  max-width: 1080px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 750;
  color: var(--text);
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.modal-footer {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

/* ==========================================================================
   Toasts (#of-toasts)
   ========================================================================== */
#of-toasts,
.toast-region {
  position: fixed;
  right: calc(16px + var(--safe-right));
  bottom: calc(16px + var(--safe-bottom));
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(400px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
  font-size: 0.9375rem;
  font-weight: 600;
  pointer-events: auto;
}

.toast-body {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.toast-info {
  border-left: 4px solid var(--primary);
}

.toast-success {
  border-left: 4px solid var(--success);
  background: #F0FDF4;
  color: #14532D;
}

.toast-warn,
.toast-warning {
  border-left: 4px solid var(--warning);
  background: #FFFBEB;
  color: #78350F;
}

.toast-error {
  border-left: 4px solid var(--danger);
  background: #FEF2F2;
  color: #7F1D1D;
}

.toast-close {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   Login Shell (.login-shell with explicit ← Início link)
   ========================================================================== */
.login-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--safe-top)) calc(16px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background: linear-gradient(180deg, var(--primary-soft) 0%, var(--bg) 44%);
}

.login-card {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.login-back-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-brand .brand-logo {
  width: 48px;
  height: 48px;
  max-height: 48px;
}

.login-error {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--danger-bd);
  background: var(--danger-soft);
  color: #991B1B;
  font-size: 0.875rem;
  font-weight: 600;
}

/* ==========================================================================
   Photo Gallery Strip (Up to 4 Internal Photos <= 24 KB)
   ========================================================================== */
.photo-strip,
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.photo-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}

.photo-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--elevated);
  display: block;
  cursor: pointer;
}

.photo-meta {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--muted);
}

.photo-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.75);
  background: rgba(15, 23, 42, 0.72);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.photo-remove:hover {
  background: var(--danger);
}

/* ==========================================================================
   Stepper & Timeline
   ========================================================================== */
.stepper {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.stepper-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
}

.stepper-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--elevated);
  border: 2px solid var(--border-strong);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.stepper-item.is-done {
  border-color: var(--st-pronto-bd);
  background: #F0FDF4;
  color: #166534;
}

.stepper-item.is-done .stepper-dot {
  background: var(--success);
  border-color: var(--success);
  color: #FFFFFF;
}

.stepper-item.is-current {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  box-shadow: var(--shadow-xs);
}

.stepper-item.is-current .stepper-dot {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}

.stepper-item.is-cancelled {
  border-color: var(--st-cancelada-bd);
  background: var(--st-cancelada-bg);
  color: #475569;
}

.stepper-item.is-cancelled .stepper-dot {
  background: var(--st-cancelada);
  border-color: var(--st-cancelada);
  color: #FFFFFF;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.timeline-item {
  position: relative;
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.timeline-dot {
  width: 12px;
  height: 12px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--primary-soft);
}

.timeline-content {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
}

.timeline-title {
  font-size: 0.9375rem;
  font-weight: 650;
  color: var(--text);
}

.timeline-detail {
  margin-top: 4px;
  font-size: 0.875rem;
  color: var(--muted);
  white-space: pre-wrap;
}

.timeline-meta {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--subtle);
}

/* ==========================================================================
   Empty State
   ========================================================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

.empty-state-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--elevated);
  color: var(--primary);
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */
@media (max-width: 768px) {
  .topbar {
    padding: calc(8px + var(--safe-top)) 12px 8px 12px;
  }

  .container {
    padding: 14px 12px calc(28px + var(--safe-bottom)) 12px;
  }

  .form-grid-2,
  .form-grid-3,
  .form-grid-4 {
    grid-template-columns: 1fr;
  }

  .card-header,
  .card-body {
    padding: 14px;
  }

  .user-pill {
    max-width: 190px;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.3125rem;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .modal-card,
  .modal-dialog {
    border-radius: var(--radius-md);
  }
}

/* ==========================================================================
   Print Helpers
   ========================================================================== */
@media print {
  html,
  body {
    background: #FFFFFF !important;
    color: #000000 !important;
    overflow: visible !important;
  }

  .no-print,
  .topbar,
  .update-banner,
  #app-update,
  #of-toasts,
  .toast-region,
  .modal-backdrop {
    display: none !important;
  }

  .card {
    box-shadow: none !important;
    border-color: #CBD5E1 !important;
  }
}
