/* ══════════════════════════════════════════════════════════
   PedidoZap SaaS — Design System
   ══════════════════════════════════════════════════════════ */

:root {
  --bg: #f8f6f3;
  --surface: #ffffff;
  --border: #e8e2db;
  --border-light: #f0ebe5;
  --text: #2d2418;
  --text-secondary: #8a7e72;
  --text-muted: #b5ab9e;
  --accent: #c4713c;
  --accent-dark: #a85d2f;
  --accent-light: #f5e6d8;
  --accent-lighter: #faf3ec;
  --green: #22c55e;
  --green-light: #dcfce7;
  --red: #dc4a3f;
  --red-light: #fef2f1;
  --yellow: #f59e0b;
  --yellow-light: #fef3c7;
  --blue: #3b82f6;
  --blue-light: #dbeafe;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.04);
  --bg-rgb: 248,246,243;
  --alert-error-text: #b91c1c; --alert-error-border: #fecaca;
  --alert-success-text: #16a34a; --alert-success-border: #bbf7d0;
  --alert-warning-text: #92400e; --alert-warning-border: #fde68a;
  --alert-info-text: #1e40af; --alert-info-border: #93c5fd;
  --badge-green-text: #16a34a; --badge-yellow-text: #92400e; --badge-blue-text: #1e40af;
  --spinner-track: rgba(0,0,0,0.1); --spinner-fill: var(--accent);
  --loading-bg: rgba(248,246,243,0.85);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --transition: 0.2s ease;
}

/* ── Dark Mode ── */
:root.dark {
  --bg: #121212;
  --surface: #1e1e1e;
  --border: #2e2e2e;
  --border-light: #252525;
  --text: #e4ddd4;
  --text-secondary: #a09488;
  --text-muted: #6b6158;
  --accent: #d4814c;
  --accent-dark: #e8935e;
  --accent-light: #3d2a1a;
  --accent-lighter: #2a1d12;
  --green: #22c55e;
  --green-light: #0d2818;
  --red: #ef5350;
  --red-light: #2d1515;
  --yellow: #f59e0b;
  --yellow-light: #2d2010;
  --blue: #60a5fa;
  --blue-light: #152030;
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.5), 0 4px 10px rgba(0,0,0,0.4);
  --bg-rgb: 18,18,18;
  --alert-error-text: #fca5a5; --alert-error-border: #5c1e1e;
  --alert-success-text: #6ee7b7; --alert-success-border: #1a3a2a;
  --alert-warning-text: #fbbf24; --alert-warning-border: #3d2a10;
  --alert-info-text: #93c5fd; --alert-info-border: #1e2d4a;
  --badge-green-text: #6ee7b7; --badge-yellow-text: #fbbf24; --badge-blue-text: #93c5fd;
  --spinner-track: rgba(255,255,255,0.15); --spinner-fill: var(--accent);
  --loading-bg: rgba(18,18,18,0.85);
}

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

/* Global form elements — herdam tema */
input, select, textarea, button { color: inherit; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card-lg {
  box-shadow: var(--shadow-lg);
  padding: 40px 32px;
}

/* ── Botões ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  line-height: 1;
  background: var(--surface);
  color: var(--text);
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border-light); }

.btn-danger {
  background: var(--red);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: #c73b31; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 12px;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-full { width: 100%; }

/* ── Forms ── */
.form-group {
  margin-bottom: 16px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(196,113,60,0.12);
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group { flex: 1; }

/* ── Alerts/Badges ── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
}

.alert-error {
  background: var(--red-light);
  color: var(--alert-error-text);
  border: 1px solid var(--alert-error-border);
}

.alert-success {
  background: var(--green-light);
  color: var(--alert-success-text);
  border: 1px solid var(--alert-success-border);
}

.alert-warning {
  background: var(--yellow-light);
  color: var(--alert-warning-text);
  border: 1px solid var(--alert-warning-border);
}

.alert-info {
  background: var(--blue-light);
  color: var(--alert-info-text);
  border: 1px solid var(--alert-info-border);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-accent { background: var(--accent-light); color: var(--accent); }
.badge-green { background: var(--green-light); color: var(--badge-green-text); }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-yellow { background: var(--yellow-light); color: var(--badge-yellow-text); }
.badge-blue { background: var(--blue-light); color: var(--badge-blue-text); }
.badge-gray { background: var(--bg); color: var(--text-muted); }

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 3.7s forwards;
  max-width: 360px;
}

.toast-success { background: #16a34a; color: #fff; }
.toast-error { background: var(--red); color: #fff; }
.toast-info { background: var(--blue); color: #fff; }
.toast-warning { background: var(--yellow); color: #fff; }

@keyframes toastIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-10px); } }

/* ── Overlay / Modal ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.overlay.active {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 32px;
  transform: scale(0.95);
  transition: transform 0.2s ease;
}

.overlay.active .modal {
  transform: scale(1);
}

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

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

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

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

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

/* ── Table ── */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}

tr:hover td { background: var(--accent-lighter); }

/* ── Auth Layout ── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-container {
  width: 100%;
  max-width: 440px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px 32px;
  text-align: center;
}

.auth-logo { font-size: 48px; margin-bottom: 8px; }

.auth-brand h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.auth-brand p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.auth-footer {
  margin-top: 24px;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.auth-footer a:hover { text-decoration: underline; }

.auth-links {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Divider ── */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-muted);
  font-size: 12px;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Spinner ── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--spinner-track);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

.spinner-dark {
  border-color: var(--spinner-track);
  border-top-color: var(--spinner-fill);
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Loading / Error / Skeleton states ── */
.loading-state{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:60px 20px;gap:12px;color:var(--text-muted)}
.loading-state .spinner{width:32px;height:32px;border:3px solid var(--border);border-top-color:var(--accent);border-radius:50%;animation:spin 0.8s linear infinite}
.error-state{text-align:center;padding:60px 20px;color:var(--text-muted)}
.error-state .icon{font-size:48px;margin-bottom:12px}
.skeleton{background:linear-gradient(90deg,var(--border-light) 25%,var(--bg) 50%,var(--border-light) 75%);background-size:200% 100%;animation:shimmer 1.5s infinite;border-radius:var(--radius-sm)}
@keyframes shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}

/* ── Loading Skeleton ── */
.loading-skeleton {
  position: relative;
  overflow: hidden;
  background: var(--border-light);
  border-radius: var(--radius-sm);
}
.loading-skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.5) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}
.loading-skeleton.skeleton-text {
  height: 14px;
  width: 80%;
  margin-bottom: 8px;
}
.loading-skeleton.skeleton-text-sm {
  height: 12px;
  width: 60%;
  margin-bottom: 6px;
}
.loading-skeleton.skeleton-title {
  height: 20px;
  width: 50%;
  margin-bottom: 12px;
}
.loading-skeleton.skeleton-card {
  height: 120px;
  width: 100%;
  margin-bottom: 12px;
}
.loading-skeleton.skeleton-stat {
  height: 60px;
  width: 100%;
}
.loading-skeleton.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
}
.loading-skeleton.skeleton-row {
  height: 48px;
  width: 100%;
  margin-bottom: 8px;
}

/* ── Loading Spinner ── */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 20px;
  gap: 12px;
}
.loading-spinner::before {
  content: '';
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.loading-spinner::after {
  content: 'Carregando...';
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Page Loading Overlay ── */
.page-loading {
  position: fixed;
  inset: 0;
  background: var(--loading-bg);
  backdrop-filter: blur(2px);
  z-index: 8000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.page-loading::before {
  content: '';
  width: 44px;
  height: 44px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.page-loading::after {
  content: 'Carregando...';
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ── Empty State (enhanced) ── */
.empty-state-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  max-width: 420px;
  margin: 40px auto;
}
.empty-state-box .empty-icon {
  font-size: 52px;
  margin-bottom: 16px;
  line-height: 1;
}
.empty-state-box .empty-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.empty-state-box .empty-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.5;
}
.empty-state-box .btn {
  min-height: 44px;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .auth-card { padding: 32px 20px; }
  .form-row { flex-direction: column; gap: 0; }
  .modal { padding: 24px 20px; }
}

/* ── Mobile responsive ── */
@media (max-width: 768px) {
  .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-container table { min-width: 600px; }
  .modal { width: 100%; max-width: 100%; border-radius: var(--radius) var(--radius) 0 0; margin-top: auto; }
  .btn { min-height: 44px; }
  .form-group input,
  .form-group select,
  .form-group textarea { font-size: 16px; }
  .toast-container { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: 100%; }
}

/* ── Offline Banner (P2-9) ── */
.offline-banner{position:fixed;top:0;left:0;right:0;z-index:9999;background:#e53e3e;color:#fff;text-align:center;padding:8px;font-size:13px;font-weight:500;transform:translateY(-100%);transition:transform 0.3s}
.offline-banner.visible{transform:translateY(0)}
body.modal-open{overflow:hidden}

/* ── Dark mode overrides for status badges (shared across pages) ── */
:root.dark .badge-ativa,
:root.dark .status-conectado { background: var(--green-light); color: var(--green); }
:root.dark .badge-pausada,
:root.dark .status-qr_pendente { background: var(--yellow-light); color: var(--yellow); }
:root.dark .badge-arquivada,
:root.dark .status-desconectado { background: var(--red-light); color: var(--red); }
:root.dark .badge-erro { background: var(--red-light); color: var(--red); }

/* Dark mode: selects, inputs, buttons */
:root.dark select,
:root.dark input[type="date"] { color-scheme: dark; }
:root.dark select option { background: var(--surface); color: var(--text); }
.dark select { color: var(--text); background: var(--surface); border-color: var(--border); }
.dark .view-toggle { color: var(--text-muted); }
.dark .view-toggle button { color: var(--text); }
