:root {
  --color-primary: #4f46e5;
  --color-primary-dark: #3730a3;
  --color-accent: #06b6d4;
  --color-dark: #0f172a;
  --color-light: #f8fafc;
  --color-white: #ffffff;
  --color-text: #334155;
  --color-text-light: #64748b;
  --color-ok: #16a34a;
  --color-warning: #ef4444;
  --color-preview: #f59e0b;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --font-heading: 'Poppins', sans-serif;
  --font-body: 'Inter', sans-serif;
}

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

.hidden { display: none !important; }

/* ===== MODAL (substitui alert/confirm/prompt nativos) ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: modal-fade-in 0.15s ease;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-box {
  background: var(--color-white);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: var(--color-dark);
  margin-bottom: 12px;
}

.modal-message {
  color: var(--color-text);
  font-size: 0.92rem;
  line-height: 1.5;
  white-space: pre-line;
  margin-bottom: 20px;
}

.modal-box .form-group { margin-bottom: 14px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.modal-actions .btn { margin: 0; width: auto; }

body {
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-light);
}

.layout {
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--color-dark);
  color: var(--color-white);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar__logo {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
  color: var(--color-white);
}

.sidebar__logo .accent { color: var(--color-accent); }

.sidebar__nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.sidebar__footer {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 14px;
  margin-top: 14px;
}

.sidebar__user {
  display: flex;
  flex-direction: column;
  padding: 0 12px 10px;
  color: var(--color-white);
}

.sidebar__user strong { font-size: 0.9rem; }
.sidebar__user span { font-size: 0.78rem; color: rgba(255, 255, 255, 0.55); }

.idioma-seletor {
  width: 100%;
  margin: 0 0 10px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  color: var(--color-white);
  font-size: 0.78rem;
  cursor: pointer;
}
.idioma-seletor option { color: #1a1a1a; }

.auth-card .idioma-seletor {
  width: auto;
  margin: 0 0 14px auto;
  display: block;
  border: 1px solid #d0d5dd;
  background: #fff;
  color: #333;
}

.logout-btn {
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  font-family: var(--font-body);
}

.nav-section {
  margin: 18px 0 6px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: rgba(255, 255, 255, 0.4);
  padding: 0 12px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.2s ease, color 0.2s ease;
}

.nav-link i { width: 18px; text-align: center; }

.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: var(--color-white); }

.nav-link.active {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: var(--color-white);
}

/* ===== MAIN ===== */
.main { flex: 1; padding: 32px 40px; overflow-x: auto; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--color-text-light);
  margin-bottom: 12px;
}

.breadcrumb i { font-size: 0.65rem; }

.subscription-banner {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.view-header { margin-bottom: 24px; }

.view-header h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  color: var(--color-dark);
}

.view-header p { color: var(--color-text-light); margin-top: 4px; }

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--color-text-light);
  padding: 60px 0;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #e2e8f0;
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ===== CARD ===== */
.card {
  background: var(--color-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
  overflow-x: auto;
}

.card h3 { font-family: var(--font-heading); font-size: 1.05rem; margin-bottom: 16px; }

.card.error { color: var(--color-warning); }

/* ===== FORM ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  align-items: end;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label { font-size: 0.85rem; font-weight: 500; color: var(--color-text); }

.form-group input,
.form-group select,
.form-group textarea {
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.9rem;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.form-total {
  margin: 16px 0;
  font-size: 1.05rem;
  text-align: right;
}

.form-hint { color: var(--color-text-light); font-size: 0.8rem; margin-top: 12px; }

/* ===== INFO GRID (dados somente leitura, ex: ficha, assinatura) ===== */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.info-grid > div { display: flex; flex-direction: column; gap: 4px; }

.info-grid strong {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--color-text-light);
}

.info-grid span { font-size: 0.95rem; color: var(--color-text); }

/* ===== BUTTONS ===== */
.btn {
  padding: 10px 22px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn--primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: var(--color-white);
}

.btn--primary:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(79, 70, 229, 0.3); }

.btn--secondary {
  background: var(--color-light);
  color: var(--color-primary);
  border: 1px solid #e2e8f0;
  margin: 16px 0;
}

.btn--danger {
  background: var(--color-warning);
  color: var(--color-white);
}

.btn--danger:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(239, 68, 68, 0.3); }

.btn:disabled,
.btn--primary:disabled,
.btn--danger:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--color-text-light);
  cursor: pointer;
  font-size: 0.95rem;
  padding: 6px;
  border-radius: 6px;
}

.btn-icon:hover { background: #fee2e2; color: var(--color-warning); }

/* ===== TABLE ===== */
.data-table { width: 100%; min-width: 640px; border-collapse: collapse; margin-top: 8px; }

/* Barra de rolagem horizontal sempre visível (não só ao passar o mouse), para deixar
   claro que há mais colunas fora da tela em telas menores. */
.card::-webkit-scrollbar { height: 10px; }
.card::-webkit-scrollbar-track { background: var(--color-light); border-radius: 10px; }
.card::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
.card::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.card { scrollbar-width: thin; scrollbar-color: #cbd5e1 var(--color-light); }

.data-table th {
  text-align: left;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--color-text-light);
  padding: 10px 12px;
  border-bottom: 2px solid var(--color-light);
}

.data-table td {
  padding: 12px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.9rem;
}

.data-table .empty { text-align: center; color: var(--color-text-light); padding: 24px; }

.text-warning { color: var(--color-warning); font-weight: 600; }
.text-ok { color: var(--color-ok); }

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 50px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge--ok { background: #dcfce7; color: var(--color-ok); }
.badge--warning { background: #fee2e2; color: var(--color-warning); }
.badge--neutral { background: #e2e8f0; color: var(--color-text-light); }

/* ===== STATS (dashboard) ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--color-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-card span { font-size: 0.8rem; color: var(--color-text-light); }
.stat-card strong { font-family: var(--font-heading); font-size: 1.4rem; color: var(--color-dark); }
.stat-card small { color: var(--color-text-light); font-size: 0.78rem; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; padding: 14px; }
  .sidebar__logo { margin-bottom: 0; margin-right: auto; }
  .nav-section { display: none; }
  .main { padding: 20px; }
}

@media (max-width: 560px) {
  .main { padding: 12px; }
  .form-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .card { padding: 16px; }
  .data-table th, .data-table td { padding: 8px 6px; font-size: 0.8rem; }
  .view-header h2 { font-size: 1.25rem; }
  .btn { width: 100%; }
  .btn--secondary { width: auto; }
}

/* ===== ASISTENTE (widget flotante) ===== */
.asistente-burbuja {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: var(--color-white);
  border: none;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
  font-size: 1.3rem;
  cursor: pointer;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

.asistente-burbuja .asistente-punto {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-ok);
  border: 2px solid var(--color-white);
}

.asistente-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: min(560px, calc(100vh - 120px));
  background: var(--color-white);
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
  z-index: 900;
  overflow: hidden;
}

.asistente-panel__header {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: var(--color-white);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}

.asistente-panel__header button {
  background: none;
  border: none;
  color: var(--color-white);
  font-size: 1.1rem;
  cursor: pointer;
}

.asistente-panel__estado {
  padding: 10px 16px;
  font-size: 0.85rem;
  border-bottom: 1px solid #f1f5f9;
  background: var(--color-light);
}

.asistente-panel__mensajes {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.asistente-burbuja-msg {
  border-radius: 12px;
  padding: 9px 13px;
  font-size: 0.88rem;
  line-height: 1.4;
  max-width: 88%;
}

.asistente-burbuja-msg--usuario {
  background: var(--color-primary);
  color: var(--color-white);
  align-self: flex-end;
}

.asistente-burbuja-msg--sistema {
  background: var(--color-light);
  color: var(--color-text);
  align-self: flex-start;
}

.asistente-burbuja-msg--fallo {
  background: #fee2e2;
  color: #991b1b;
  align-self: flex-start;
}

.asistente-panel__acciones {
  padding: 0 16px 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.asistente-panel__acciones .btn { margin: 0; padding: 8px 14px; font-size: 0.82rem; }

.asistente-panel__form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid #f1f5f9;
}

.asistente-panel__form textarea {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 100px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  font-family: var(--font-body);
  font-size: 0.88rem;
}

.asistente-panel__form button {
  border: none;
  border-radius: 8px;
  width: 40px;
  background: var(--color-primary);
  color: var(--color-white);
  cursor: pointer;
}

@media (max-width: 480px) {
  .asistente-panel { right: 16px; left: 16px; width: auto; }
  .asistente-burbuja { right: 16px; bottom: 16px; }
}

/* ===== AMBIENTE DE PRUEBA (preview del asistente de desarrollo) ===== */
.ambiente-prueba-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1200;
  background: var(--color-preview);
  color: #451a03;
  text-align: center;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.4px;
  padding: 8px 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Baja todo el contenido para no quedar tapado por el banner fijo, y le da un
   borde de color al costado para que se note el ambiente distinto incluso
   haciendo scroll (el banner queda fijo arriba, pero el borde acompaña). */
html.es-ambiente-prueba body { padding-top: 36px; }
html.es-ambiente-prueba .sidebar { border-right: 4px solid var(--color-preview); }
html.es-ambiente-prueba .auth-card { border-top: 4px solid var(--color-preview); }

.asistente-highlight {
  outline: 3px solid var(--color-preview);
  outline-offset: 3px;
  border-radius: 6px;
  animation: asistente-pulso 1s ease-in-out 3;
  transition: outline-color 1.5s ease;
}

.asistente-highlight--fade {
  outline-color: rgba(245, 158, 11, 0.35);
}

@keyframes asistente-pulso {
  0%, 100% { outline-color: var(--color-preview); }
  50% { outline-color: rgba(245, 158, 11, 0.25); }
}
