:root {
  --bg: #fdf8fb;
  --surface: #ffffff;
  --text: #1f1520;
  --muted: #6b5a66;
  --primary: #be185d;
  --primary-dark: #9d174d;
  --accent: #d97706;
  --border: #ecd5e0;
  --shadow: 0 10px 30px rgba(190, 24, 93, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 50% at 0% 0%, rgba(190, 24, 93, 0.1), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(217, 119, 6, 0.1), transparent 50%),
    linear-gradient(180deg, #fff7fb 0%, var(--bg) 100%);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* Login / Setup */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.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: #fff;
}
.form-group textarea { min-height: 100px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.error-msg {
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

/* Shell */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  background: rgba(255,255,255,0.92);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-logo-wrap { margin-bottom: 0.5rem; }
.brand-logo {
  max-width: 100%;
  max-height: 56px;
  object-fit: contain;
  display: block;
}
.auth-card .brand-logo {
  max-height: 72px;
  margin: 0 auto 0.75rem;
}
.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: #fff;
}
.sync-url code {
  display: block;
  word-break: break-all;
  font-size: 0.8rem;
  background: #fdf2f8;
  padding: 0.5rem;
  border-radius: 8px;
  margin: 0.5rem 0;
}
.import-help summary { cursor: pointer; font-weight: 600; }

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--primary);
}
.brand p { margin: 0.2rem 0 1rem; font-size: 0.8rem; color: var(--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(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.nav-btn:hover { background: #fce7f3; }
.nav-btn.active { background: var(--primary); color: #fff; }

.user-box {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}
.user-box strong { display: block; }
.user-box span { color: var(--muted); font-size: 0.8rem; }

.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);
  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;
}

.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: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fce7f3; color: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--border); 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);
  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: #fef3c7; color: #92400e; }
.badge-status[data-status="confirmado"] { background: #dbeafe; color: #1d4ed8; }
.badge-status[data-status="retirado"] { background: #dcfce7; color: #166534; }
.badge-status[data-status="reserva"] { background: #fce7f3; color: #9d174d; }
.badge-status[data-status="devolvido"] { background: #f3f4f6; color: #374151; }
.badge-status[data-status="cancelado"] { background: #fee2e2; color: #991b1b; }

.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);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  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: #faf5f8;
  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;
  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);
  border-radius: 8px;
  padding: 4px;
  background: #fff;
}
.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: #fce7f3; color: #9d174d; }
.evt-retirada { background: #dbeafe; color: #1e40af; }
.evt-devolucao { background: #ffedd5; color: #c2410c; }
.evt-evento { background: #ede9fe; color: #5b21b6; }
.cal-more { font-size: 0.65rem; color: var(--muted); }

.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);
}
.agenda-data { min-width: 110px; font-weight: 600; font-size: 0.9rem; }
.agenda-body span { display: block; color: var(--muted); font-size: 0.85rem; }

/* Wizard contrato */
.wizard-overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 21, 32, 0.45);
  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: #fff;
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.itens-resumo-list { margin: 0; padding-left: 1.2rem; }

.app-toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: #1f1520;
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  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: #b91c1c; }

@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; }
}
