/* =============================================================================
   style.css
   -----------------------------------------------------------------------------
   Design tokens
   Paleta:   #0B5D66 (petróleo - primária), #0E7480 (petróleo claro),
             #E8A33D (âmbar - destaque/preço), #4C956C (sucesso),
             #C9483C (perigo/alerta), #F7F8FA (fundo claro), #0F1420 (fundo escuro)
   Tipografia: pilha de sistema (garante funcionamento 100% offline, sem
             depender de fontes externas), com peso/traço mais forte nos
             títulos para dar personalidade própria ao "recibo" digital.
   Assinatura visual: o cartão de nova venda é desenhado como um "ticket"
             com borda tracejada e recorte de perfuração, remetendo a um
             cupom fiscal — o elemento central de todo o aplicativo.
   ============================================================================= */

:root {
  --color-bg: #F5F7F8;
  --color-surface: #FFFFFF;
  --color-surface-alt: #F0F3F4;
  --color-primary: #0B5D66;
  --color-primary-light: #0E7480;
  --color-primary-dark: #073F46;
  --color-accent: #E8A33D;
  --color-danger: #C9483C;
  --color-success: #4C956C;
  --color-info: #5B7FBB;
  --color-text: #1C232B;
  --color-text-muted: #667085;
  --color-border: #E1E6E9;
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 2px 12px rgba(15, 30, 32, 0.07);
  --shadow-lg: 0 12px 32px rgba(15, 30, 32, 0.16);
  --font-display: 'Segoe UI Semibold', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-body: 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'Cascadia Mono', 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  --sidebar-width: 248px;
  --topbar-height: 64px;
}

body.theme-dark {
  --color-bg: #0F1420;
  --color-surface: #171E2C;
  --color-surface-alt: #1E2739;
  --color-primary: #16838F;
  --color-primary-light: #1CA0AD;
  --color-primary-dark: #0B5D66;
  --color-text: #E7EAF0;
  --color-text-muted: #9AA3B2;
  --color-border: rgba(255, 255, 255, 0.09);
  --shadow: 0 2px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 40px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s ease, color 0.25s ease;
}
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.01em; margin: 0; }
p { margin: 0 0 8px; }
.muted { color: var(--color-text-muted); font-size: 13.5px; }
.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ============================= LOADING ============================= */
#app-loading {
  position: fixed; inset: 0; z-index: 999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; background: var(--color-primary); color: #fff;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
#app-loading.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-mark { width: 64px; height: 64px; animation: pulse 1.4s ease-in-out infinite; }
.loading-mark .icon { width: 100%; height: 100%; }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.12); opacity: 0.75; } }

/* ============================= ÍCONES ============================= */
.icon { width: 18px; height: 18px; display: inline-block; vertical-align: middle; }
.icon svg { width: 100%; height: 100%; }

/* ============================= LAYOUT ============================= */
.app-shell { display: flex; min-height: 100vh; }

#sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-primary-dark);
  color: #EAF3F3;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.sidebar-logo { width: 34px; height: 34px; flex-shrink: 0; border-radius: 9px; background: var(--color-accent); display: flex; align-items: center; justify-content: center; color: var(--color-primary-dark); overflow: hidden; }
.sidebar-logo img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-brand span { font-family: var(--font-display); font-size: 18px; font-weight: 700; color: #fff; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  background: none; border: none; color: #C7DEDE;
  padding: 11px 12px; border-radius: var(--radius-sm);
  text-align: left; font-size: 14.5px; font-weight: 500;
  transition: background 0.18s ease, color 0.18s ease;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: var(--color-accent); color: var(--color-primary-dark); font-weight: 700; }
.nav-item .icon { flex-shrink: 0; }

.sidebar-install { color: #fff; border-color: rgba(255,255,255,0.35); }
.sidebar-install:hover { background: rgba(255,255,255,0.1); }

#sidebar-overlay { display: none; }

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-height); flex-shrink: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px; background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: 19px; flex: 1; }
.only-mobile { display: none; }

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

.content { flex: 1; padding: 22px; max-width: 1280px; width: 100%; margin: 0 auto; }
.view { display: none; flex-direction: column; gap: 18px; animation: fadeIn 0.25s ease; }
.view.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ============================= CARDS ============================= */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 16px; margin-bottom: 12px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-header h2 { margin: 0; }
.card-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Assinatura visual: cabeçalho de venda em estilo "ticket" perfurado */
.sale-header-card {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-light));
  color: #fff;
  border: none;
  position: relative;
  border-radius: var(--radius-lg);
  padding: 18px 26px;
  overflow: hidden;
}
.sale-header-card::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(circle at 6px 50%, transparent 6px, rgba(255,255,255,0.85) 6.5px);
  background-size: 18px 100%;
  background-position: right -9px top 0;
  width: 16px; right: 0; left: auto;
  opacity: 0.25;
}
.sale-header-card .label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.75; margin-bottom: 2px; }
.sale-header-card strong { font-family: var(--font-mono); font-size: 20px; }

/* ============================= FORMULÁRIOS ============================= */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 14px; }
.form-grid--items { align-items: end; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field--grow { grid-column: span 2; }
.field--qty { min-width: 150px; }
.field--btn { justify-content: flex-end; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--color-text-muted); }
.field input, .field select, .field textarea {
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--color-border); background: var(--color-surface-alt);
  color: var(--color-text); outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--color-primary-light);
  box-shadow: 0 0 0 3px rgba(11, 93, 102, 0.15);
}
.field input[readonly] { opacity: 0.75; }
textarea { resize: vertical; font-family: inherit; }

.qty-control { display: flex; align-items: center; gap: 6px; }
.qty-control input { text-align: center; width: 100%; }
.qty-control .icon-btn { background: var(--color-surface-alt); border: 1px solid var(--color-border); }

.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.form-actions--start { justify-content: flex-start; }

/* ============================= BOTÕES ============================= */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-weight: 600; font-size: 14px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-lg { padding: 12px 26px; font-size: 15px; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-light); }
.btn-outline { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: var(--color-surface-alt); }
.btn-ghost { background: transparent; color: var(--color-text-muted); }
.btn-ghost:hover { background: var(--color-surface-alt); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn.active { outline: 2px solid var(--color-accent); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid transparent; color: var(--color-text);
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: var(--color-surface-alt); }
.icon-btn.btn-danger { color: #fff; background: var(--color-danger); }
.icon-btn.btn-danger:hover { filter: brightness(1.1); }
.file-btn { position: relative; display: inline-flex; }

/* ============================= TABELAS ============================= */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; padding: 10px 12px; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--color-text-muted); border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
tbody tr:hover { background: var(--color-surface-alt); }
.table-actions { display: flex; gap: 4px; white-space: nowrap; }
.empty-state { text-align: center; color: var(--color-text-muted); padding: 26px !important; font-style: italic; }

/* ============================= BADGES ============================= */
.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge--ok { background: rgba(76, 149, 108, 0.15); color: var(--color-success); }
.badge--warning { background: rgba(232, 163, 61, 0.18); color: #A8631C; }
.badge--danger { background: rgba(201, 72, 60, 0.15); color: var(--color-danger); }
.badge--info { background: rgba(91, 127, 187, 0.15); color: var(--color-info); }
body.theme-dark .badge--warning { color: var(--color-accent); }

/* ============================= TOTAIS ============================= */
.totals-panel {
  display: flex; gap: 22px; flex-wrap: wrap; justify-content: flex-end;
  padding: 14px 18px; background: var(--color-surface-alt); border-radius: var(--radius-sm); margin-bottom: 14px;
}
.totals-panel > div { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.totals-panel span { font-size: 11.5px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.totals-panel strong { font-family: var(--font-mono); font-size: 16px; }
.totals-panel__final strong { color: var(--color-primary); font-size: 20px; }
body.theme-dark .totals-panel__final strong { color: var(--color-accent); }

/* ============================= KPIs & GRÁFICOS ============================= */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.kpi-card { display: flex; flex-direction: column; gap: 4px; }
.kpi-card strong { font-family: var(--font-mono); font-size: 26px; color: var(--color-primary); }
body.theme-dark .kpi-card strong { color: var(--color-accent); }
.kpi-card small { color: var(--color-text-muted); }

.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.chart-canvas { width: 100%; height: 220px; display: block; }

/* ============================= LOGO / UPLOAD ============================= */
.logo-upload { display: flex; align-items: center; gap: 18px; margin-top: 10px; flex-wrap: wrap; }
.logo-preview {
  width: 84px; height: 84px; border-radius: var(--radius-sm);
  border: 1px dashed var(--color-border); display: flex; align-items: center; justify-content: center;
  overflow: hidden; background: var(--color-surface-alt); color: var(--color-text-muted); font-size: 11px; text-align: center;
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }
.logo-upload-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============================= MODAIS ============================= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 15, 20, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  opacity: 0; visibility: hidden; transition: opacity 0.2s ease, visibility 0.2s ease; z-index: 200;
}
.modal-overlay.show { opacity: 1; visibility: visible; }
.modal {
  background: var(--color-surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg); transform: translateY(14px); transition: transform 0.22s ease;
}
.modal-overlay.show .modal { transform: translateY(0); }
.modal--sm { max-width: 400px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--color-border); }
.modal-header h3 { font-size: 16px; }
.modal-body { padding: 20px; }
.modal-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ============================= TOASTS ============================= */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 500; display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
.toast {
  background: var(--color-text); color: #fff; padding: 12px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 13.5px; opacity: 0; transform: translateX(30px); transition: all 0.3s ease;
}
.toast--show { opacity: 1; transform: translateX(0); }
.toast--success { background: var(--color-success); }
.toast--error { background: var(--color-danger); }
.toast--info { background: var(--color-info); }

/* ============================= PRINT ============================= */
#print-area { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { display: block; position: absolute; top: 0; left: 0; width: 100%; }
  .print-doc { padding: 24px; font-family: var(--font-body); color: #111; }
  .print-header { display: flex; gap: 14px; align-items: center; border-bottom: 2px solid #0B5D66; padding-bottom: 12px; margin-bottom: 16px; }
  .print-logo { width: 64px; height: 64px; object-fit: contain; }
  .print-header h1 { font-size: 18px; margin: 0 0 4px; }
  .print-header p { font-size: 12px; margin: 0; color: #444; }
  .print-title { font-size: 15px; margin-bottom: 6px; }
  .print-meta { font-size: 13px; margin-bottom: 12px; }
  .print-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
  .print-table th, .print-table td { border: 1px solid #ccc; padding: 6px 8px; font-size: 12.5px; text-align: left; }
  .print-totals { text-align: right; font-size: 13px; margin-bottom: 10px; }
  .print-total-final { font-size: 16px; font-weight: 700; color: #0B5D66; }
  .print-notes { font-size: 12.5px; margin-bottom: 10px; }
  .print-footer { font-size: 10.5px; color: #888; border-top: 1px solid #ddd; padding-top: 8px; margin-top: 16px; }
}

/* ============================= RESPONSIVO ============================= */
@media (max-width: 900px) {
  .only-mobile { display: inline-flex; }
  #sidebar {
    position: fixed; left: 0; top: 0; height: 100vh; transform: translateX(-100%);
    transition: transform 0.25s ease; box-shadow: var(--shadow-lg);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 39;
  }
  #sidebar.open ~ #sidebar-overlay,
  #sidebar.open + #sidebar-overlay { display: block; }
  .content { padding: 14px; }
  .field--grow { grid-column: span 1; }
  .toolbar { gap: 2px; }
  .toolbar .icon-btn { width: 34px; height: 34px; }
  table thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr { border: 1px solid var(--color-border); border-radius: var(--radius-sm); margin-bottom: 10px; padding: 6px 4px; }
  tbody td { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dashed var(--color-border); text-align: right; }
  tbody td::before { content: attr(data-label); font-weight: 600; color: var(--color-text-muted); text-align: left; }
  tbody td:last-child { border-bottom: none; }
  .table-actions { justify-content: flex-end; width: 100%; }
  .sale-header-card { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* ============================= TELAS EM TELA CHEIA (AUTH / PIN / ASSINATURA) ============================= */
.full-screen {
  position: fixed; inset: 0; z-index: 600;
  display: none; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--color-primary-dark), var(--color-primary));
  padding: 20px; overflow-y: auto;
}
.full-screen.active { display: flex; }

.auth-box, .pin-box {
  background: var(--color-surface); color: var(--color-text);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 400px; padding: 32px 28px; text-align: center;
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 18px; }
.auth-brand .sidebar-logo { width: 48px; height: 48px; background: var(--color-accent); color: var(--color-primary-dark); }
.auth-brand h1 { font-size: 20px; }

.auth-panel { display: none; text-align: left; }
.auth-panel.active { display: block; animation: fadeIn 0.2s ease; }
.auth-panel h2 { text-align: center; margin-bottom: 16px; font-size: 18px; }
.auth-panel form { display: flex; flex-direction: column; gap: 12px; }
.auth-links { display: flex; justify-content: space-between; margin-top: 16px; font-size: 13px; flex-wrap: wrap; gap: 8px; }
.auth-links a, .auth-links-single { color: var(--color-primary); text-decoration: none; font-weight: 600; }
.auth-links a:hover, .auth-links-single:hover { text-decoration: underline; }
.auth-links-single { display: block; margin-top: 16px; font-size: 13px; }

.btn-block { width: 100%; justify-content: center; }
.form-error { color: var(--color-danger); font-size: 13px; background: rgba(201,72,60,0.1); padding: 8px 10px; border-radius: var(--radius-sm); }

.pin-box h2 { font-size: 18px; margin-bottom: 6px; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin: 20px 0; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--color-border); transition: background 0.15s ease, transform 0.15s ease; }
.pin-dot.filled { background: var(--color-primary); border-color: var(--color-primary); transform: scale(1.15); }
.pin-keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 260px; margin: 0 auto; }
.pin-key {
  aspect-ratio: 1; border-radius: 50%; border: 1px solid var(--color-border);
  background: var(--color-surface-alt); font-size: 20px; font-weight: 700; color: var(--color-text);
  display: flex; align-items: center; justify-content: center; transition: background 0.15s ease, transform 0.1s ease;
}
.pin-key:hover { background: var(--color-border); }
.pin-key:active { transform: scale(0.92); }
.pin-key--empty { visibility: hidden; }
.pin-key--action { background: transparent; border: none; color: var(--color-text-muted); }
.pin-forgot-panel { margin-top: 18px; text-align: left; border-top: 1px solid var(--color-border); padding-top: 16px; }
.pin-forgot-panel form { display: flex; flex-direction: column; gap: 10px; }

.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 20px 0; }
.plan-card { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.plan-card h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-text-muted); }
.plan-card strong { font-family: var(--font-mono); font-size: 22px; }
.plan-card strong small { font-size: 12px; font-weight: 400; color: var(--color-text-muted); }
.plan-card--highlight { border-color: var(--color-accent); box-shadow: 0 0 0 2px rgba(232,163,61,0.25); }
#screen-subscription-blocked .auth-box { max-width: 480px; }
#screen-subscription-blocked .btn-outline { margin-top: 10px; }


@media (min-width: 901px) {
  #sidebar-overlay { display: none !important; }
}
