/* Mon Jour — tema claro/escuro (mesmas cores do Escala Ministros: teal + neutros) */

html[data-theme='light'] {
  color-scheme: light;
  --bg: #f1f5f9;
  --bg-accent: rgba(13, 148, 136, 0.07);
  --surface: #ffffff;
  --surface-raised: #f8fafc;
  --border: #cbd5e1;
  --border-soft: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --subtle: #94a3b8;
  --primary: #0f766e;
  --primary-hover: #0d9488;
  --primary-soft: rgba(15, 118, 110, 0.14);
  --primary-text: #ffffff;
  --sidebar-bg: #0f1419;
  --sidebar-text: #e6edf3;
  --sidebar-muted: #9db0c4;
  --sidebar-border: #2a3542;
  --sidebar-active: #2dd4bf;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
  --card-shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
  --input-bg: #ffffff;
  --overlay: rgba(15, 23, 42, 0.45);
  --toast-bg: #1e293b;
  --error-bg: #fef2f2;
  --error-text: #b91c1c;
  --error-border: #fecaca;
  --radius: 14px;
}

html[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0f1419;
  --bg-accent: rgba(45, 212, 191, 0.08);
  --surface: #1a2129;
  --surface-raised: #222b35;
  --border: #3d4f61;
  --border-soft: #2a3542;
  --text: #e6edf3;
  --muted: #9db0c4;
  --subtle: #6b7d8f;
  --primary: #3dd6c3;
  --primary-hover: #6ee7d8;
  --primary-soft: rgba(61, 214, 195, 0.18);
  --primary-text: #0f1419;
  --sidebar-bg: #0a0e12;
  --sidebar-text: #e6edf3;
  --sidebar-muted: #9db0c4;
  --sidebar-border: #2a3542;
  --sidebar-active: #3dd6c3;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --card-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  --input-bg: #0d1117;
  --overlay: rgba(0, 0, 0, 0.55);
  --toast-bg: #222b35;
  --error-bg: rgba(248, 81, 73, 0.12);
  --error-text: #ff7b72;
  --error-border: rgba(248, 81, 73, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'DM Sans', 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

.app-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 100% 80% at 50% -30%, var(--bg-accent), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg) 100%);
}

.hidden { display: none !important; }

/* Login / Setup */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  position: relative;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--card-shadow);
  position: relative;
}

.auth-topbar {
  display: flex;
  justify-content: flex-end;
  margin: -0.5rem 0 0.75rem;
}

.auth-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
  color: var(--primary);
}

.auth-card p { color: var(--muted); margin: 0 0 1.5rem; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.9rem; margin-bottom: 0.35rem; color: var(--muted); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  background: var(--input-bg);
  color: var(--text);
}
.form-group textarea { min-height: 100px; resize: vertical; }
.form-group-cep { max-width: 160px; }
.form-group-uf { max-width: 90px; }
.form-group-wide { flex: 2; min-width: 200px; }
.field-hint {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.field-hint[data-type="loading"] { color: var(--primary); }
.field-hint[data-type="ok"] { color: #22c55e; }
.field-hint[data-type="error"] { color: var(--error-text, #f87171); }
.field-hint.hidden { display: none; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.error-msg {
  color: var(--error-text);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--primary); border-color: var(--primary); }

/* Shell */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  color: var(--sidebar-text);
}

.brand-logo-wrap { margin-bottom: 0.5rem; }
.brand-logo-panel {
  background: #000;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-logo {
  max-width: 100%;
  max-height: 56px;
  object-fit: contain;
  display: block;
}
.auth-card .brand-logo-panel { margin-bottom: 1rem; }
.auth-card .brand-logo { max-height: 64px; width: auto; margin: 0 auto; }
.sidebar .brand-logo-panel { padding: 0.65rem 0.75rem; }
.sidebar .brand-logo { max-height: 48px; }

.logo-preview { margin-top: 0.5rem; min-height: 48px; }
.logo-preview img {
  max-height: 80px;
  max-width: 200px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 4px;
  background: #000;
}

.sync-url code {
  display: block;
  word-break: break-all;
  font-size: 0.8rem;
  background: var(--primary-soft);
  color: var(--text);
  padding: 0.5rem;
  border-radius: 8px;
  margin: 0.5rem 0;
}

.import-help summary { cursor: pointer; font-weight: 600; color: var(--text); }

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--sidebar-text);
}
.brand p { margin: 0.2rem 0 1rem; font-size: 0.8rem; color: var(--sidebar-muted); }

.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--sidebar-muted);
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.nav-btn:hover { background: rgba(255,255,255,0.06); color: var(--sidebar-text); }
.nav-btn.active {
  background: rgba(45, 212, 191, 0.15);
  color: var(--sidebar-active);
  font-weight: 600;
}

.nav-group {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.nav-group-toggle::after {
  content: '▾';
  margin-left: auto;
  font-size: 0.75rem;
  opacity: 0.7;
  transition: transform 0.15s ease;
}
.nav-group:not(.open) .nav-sub { display: none; }
.nav-group:not(.open) .nav-group-toggle::after { transform: rotate(-90deg); }
.nav-sub {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding-left: 0.65rem;
  margin-bottom: 0.25rem;
  border-left: 1px solid var(--sidebar-border);
  margin-left: 0.85rem;
}
.nav-sub-btn {
  display: block;
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--sidebar-muted);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  text-align: left;
}
.nav-sub-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--sidebar-text);
}
.nav-sub-btn.active {
  background: rgba(45, 212, 191, 0.12);
  color: var(--sidebar-active);
  font-weight: 600;
}

.user-box {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--sidebar-border);
  font-size: 0.85rem;
}
.user-box strong { display: block; color: var(--sidebar-text); }
.user-box span { color: var(--sidebar-muted); font-size: 0.8rem; }
.sidebar .theme-toggle {
  width: 100%;
  justify-content: center;
  margin-bottom: 0.5rem;
  border-color: var(--sidebar-border);
  background: rgba(255,255,255,0.04);
  color: var(--sidebar-muted);
}
.sidebar .theme-toggle:hover {
  color: var(--sidebar-active);
  border-color: var(--sidebar-active);
}

.main {
  flex: 1;
  padding: 1.25rem 1.5rem 2rem;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.page-header h2 { margin: 0; font-size: 1.5rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}
.toolbar input[type="search"],
.toolbar input[type="text"] {
  flex: 1;
  min-width: 180px;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.6rem 1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--primary-soft); color: var(--primary); }
html[data-theme='dark'] .btn-secondary { color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-google {
  background: #fff;
  color: #1f2937;
  border: 1px solid var(--border);
}
.btn-google:hover { background: #f8fafc; }
html[data-theme='dark'] .btn-google {
  background: var(--surface-raised);
  color: var(--text);
}
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.85rem; }

.data-table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.data-table th, .data-table td {
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
}
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; }
.actions-cell { white-space: nowrap; display: flex; gap: 0.35rem; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-warn { background: rgba(210, 153, 34, 0.15); color: #d29922; }
.badge-status[data-status="confirmado"] { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.badge-status[data-status="retirado"] { background: rgba(63, 185, 80, 0.15); color: #3fb950; }
.badge-status[data-status="reserva"] { background: var(--primary-soft); color: var(--primary); }
.badge-status[data-status="devolvido"] { background: rgba(148, 163, 184, 0.15); color: var(--muted); }
.badge-status[data-status="cancelado"] { background: rgba(248, 81, 73, 0.12); color: #f85149; }

.empty-state { color: var(--muted); text-align: center; padding: 2rem 1rem; }
.hint { color: var(--muted); font-size: 0.9rem; }

/* Produtos grid */
.produtos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.produto-card {
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}
.produto-card.indisponivel { opacity: 0.55; }
.produto-card.selected { outline: 2px solid var(--primary); }
.produto-foto {
  aspect-ratio: 3/4;
  background: var(--surface-raised);
  display: flex;
  align-items: center;
  justify-content: center;
}
.produto-foto img { width: 100%; height: 100%; object-fit: cover; }
.produto-foto-placeholder { color: var(--muted); font-size: 0.85rem; }
.produto-info { padding: 0.75rem; flex: 1; }
.produto-codigo { font-size: 0.75rem; color: var(--muted); }
.produto-info h3 { margin: 0.2rem 0; font-size: 0.95rem; }
.produto-info p { margin: 0; font-size: 0.85rem; color: var(--muted); }
.produto-valor { color: var(--primary) !important; font-weight: 600; margin-top: 0.35rem !important; }
.produto-actions { padding: 0 0.75rem 0.75rem; }

/* Calendário */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.cal-header h2 { margin: 0; font-size: 1.2rem; }
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-cell {
  min-height: 95px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 4px;
  background: var(--surface);
}
.cal-empty { background: transparent; border-color: transparent; }
.cal-today { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.cal-day-num { font-size: 0.8rem; font-weight: 600; margin-bottom: 2px; }
.cal-evt {
  font-size: 0.62rem;
  line-height: 1.2;
  padding: 2px 3px;
  border-radius: 4px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.evt-prova { background: rgba(236, 72, 153, 0.15); color: #ec4899; }
.evt-retirada { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.evt-devolucao { background: rgba(251, 146, 60, 0.15); color: #fb923c; }
.evt-evento { background: rgba(167, 139, 250, 0.15); color: #a78bfa; }
.evt-masculino { background: rgba(59, 130, 246, 0.2); color: #3b82f6; }
.evt-feminino { background: rgba(236, 72, 153, 0.2); color: #ec4899; }
.evt-realizada { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.cal-evt-time { display: block; font-weight: 600; }
.cal-evt-name { display: block; }
.cal-evt-phone { display: block; font-size: 0.58rem; opacity: 0.9; }
.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: auto;
}
.cal-legend .leg {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 0.25rem;
  vertical-align: middle;
}
.leg-masc { background: #3b82f6; }
.leg-fem { background: #ec4899; }
.leg-ok { background: #22c55e; }
.cal-more { font-size: 0.65rem; color: var(--muted); }

.report-filters {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-soft);
}
.agenda-subview.hidden { display: none; }

.agenda-lista { list-style: none; padding: 0; margin: 0; }
.agenda-item {
  display: flex;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-soft);
}
.agenda-data { min-width: 110px; font-weight: 600; font-size: 0.9rem; }
.agenda-body span { display: block; color: var(--muted); font-size: 0.85rem; }

.agenda-sync-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.agenda-google-panel { margin-bottom: 1rem; }
.agenda-sync-hint { margin: 0.75rem 0 0; }
.agenda-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}
.agenda-tab {
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.agenda-tab:hover { color: var(--text); border-color: var(--primary); }
.agenda-tab.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
}
html[data-theme='dark'] .agenda-tab.active { color: var(--primary-hover); }
.agenda-integrated-layout {
  display: grid;
  gap: 1rem;
}
.agenda-layout-combinado {
  grid-template-columns: 1fr 1fr;
  align-items: start;
}
.agenda-tab-panel.hidden { display: none; }
.google-calendar-embed {
  width: 100%;
  min-height: 520px;
  height: 62vh;
  border: 0;
  border-radius: 10px;
  background: #fff;
}
.google-setup-steps {
  margin: 0 0 1rem;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}
.google-connected-badge { color: #22c55e; font-weight: 600; }

.qr-panel { width: min(380px, 100%); text-align: center; }
.qr-print-area { margin: 1rem 0; }
.qr-url { word-break: break-all; font-size: 0.75rem; }
#qr-canvas { border-radius: 12px; border: 1px solid var(--border-soft); }

@media print {
  body * { visibility: hidden; }
  #qr-modal, #qr-modal * { visibility: visible; }
  #qr-modal {
    position: absolute;
    inset: 0;
    background: #fff !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 2rem;
  }
  .wizard-panel.qr-panel {
    box-shadow: none;
    border: none;
    width: 100%;
    max-width: 320px;
  }
  #qr-close, #qr-print, #qr-copy, .page-header .btn { display: none !important; }
}

@media (max-width: 900px) {
  .agenda-layout-combinado { grid-template-columns: 1fr; }
  .google-calendar-embed { min-height: 420px; height: 50vh; }
}

/* Wizard contrato */
.wizard-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
}
.wizard-panel {
  width: min(900px, 100%);
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--card-shadow);
}

.itens-resumo-list { margin: 0; padding-left: 1.2rem; }

.app-toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--toast-bg);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  opacity: 0;
  transform: translateY(8px);
  transition: 0.2s ease;
  z-index: 100;
  max-width: 320px;
}
.app-toast.visible { opacity: 1; transform: translateY(0); }
.app-toast[data-type="error"] {
  background: var(--error-bg);
  color: var(--error-text);
  border-color: var(--error-border);
}

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .nav-btn { width: auto; flex: 1 1 auto; }
  .user-box { width: 100%; }
  .form-row { grid-template-columns: 1fr; }
}
