/* ═══════════════════════════════════════════════════════════════
   app.css — Santo Spirito Dashboard
   Design system: modern SaaS, Inter font, burgundy brand
═══════════════════════════════════════════════════════════════ */

:root {
  --brand:        #8B1A1A;
  --brand-light:  #a93226;
  --brand-dark:   #6b1414;
  --brand-50:     #fdf2f2;
  --brand-100:    #fce4e4;
  --sidebar-w:    260px;
  --sidebar-w-collapsed: 68px;
  --header-h:     60px;
  --radius-card:  14px;
  --shadow-card:  0 1px 4px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.06);
  --shadow-hover: 0 4px 8px rgba(0,0,0,0.08), 0 8px 24px rgba(0,0,0,0.1);
  --transition:   0.18s cubic-bezier(0.4,0,0.2,1);
}

*,*::before,*::after { box-sizing: border-box; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; margin: 0; background: #f4f5f7; }

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ══════════════════════════════════════════════════════════════
   LAYOUT
══════════════════════════════════════════════════════════════ */
#app {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition), transform var(--transition);

  /* Gradient dark sidebar */
  background: linear-gradient(180deg, #12100e 0%, #1c1614 40%, #1a1010 100%);
  border-right: 1px solid rgba(255,255,255,0.06);
}

#sidebar.collapsed { width: var(--sidebar-w-collapsed); }

/* Logo area */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  text-decoration: none;
  flex-shrink: 0;
}
.sidebar-logo-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(139,26,26,0.4);
}
.sidebar-logo-text {
  overflow: hidden;
  transition: opacity var(--transition), width var(--transition);
}
.sidebar-logo-name { color: #fff; font-size: 0.9375rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }
.sidebar-logo-sub  { color: rgba(255,255,255,0.35); font-size: 0.6875rem; }

#sidebar.collapsed .sidebar-logo-text { opacity: 0; width: 0; }

/* Nav section */
.nav-section {
  flex: 1;
  padding: 10px 8px;
  overflow-y: auto;
  overflow-x: hidden;
}
.nav-section-label {
  color: rgba(255,255,255,0.22);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 10px 6px;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--transition);
}
#sidebar.collapsed .nav-section-label { opacity: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: rgba(255,255,255,0.5);
  transition: all var(--transition);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  position: relative;
  white-space: nowrap;
  margin-bottom: 1px;
}
.nav-item:hover {
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.9);
}
.nav-item.active {
  background: rgba(139,26,26,0.25);
  color: #fff;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--brand);
}
.nav-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: 0.75;
}
.nav-item.active .nav-icon { opacity: 1; }
.nav-label {
  overflow: hidden;
  transition: opacity var(--transition), width var(--transition);
  white-space: nowrap;
}
#sidebar.collapsed .nav-label { opacity: 0; width: 0; }

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: default;
}
.sidebar-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 0.75rem; font-weight: 700;
  flex-shrink: 0;
}
.sidebar-user-name { color: rgba(255,255,255,0.7); font-size: 0.8125rem; font-weight: 500; overflow: hidden; }
#sidebar.collapsed .sidebar-user-name { opacity: 0; width: 0; }

/* ── Main content area ─────────────────────────────────────── */
#main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--transition);
}
#main-wrap.sidebar-collapsed { margin-left: var(--sidebar-w-collapsed); }

/* ── Header ────────────────────────────────────────────────── */
#header {
  height: var(--header-h);
  background: #fff;
  border-bottom: 1px solid #e8eaed;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 30;
}
#page-title {
  flex: 1;
  font-size: 1rem;
  font-weight: 600;
  color: #111827;
  letter-spacing: -0.01em;
}
.header-icon-btn {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: none;
  background: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: #6b7280;
  transition: background var(--transition), color var(--transition);
}
.header-icon-btn:hover { background: #f3f4f6; color: #111827; }

/* Credits badge in header */
#header-credits-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1.5px solid #e5e7eb;
  background: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  color: #374151;
  cursor: pointer;
  transition: all var(--transition);
}
#header-credits-btn:hover { border-color: var(--brand); color: var(--brand); }
#header-credits-btn.low { border-color: #fca5a5; color: #dc2626; background: #fef2f2; }

/* Lang selector */
.lang-btns { display: flex; align-items: center; gap: 2px; }
.lang-btn {
  width: 30px; height: 30px;
  border-radius: 6px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  opacity: 0.4;
  transition: opacity var(--transition), background var(--transition);
}
.lang-btn:hover { opacity: 0.8; background: #f3f4f6; }
.lang-btn.active { opacity: 1; background: #f3f4f6; }

/* ── Page content ──────────────────────────────────────────── */
#page-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}
.page { display: none; }
.page.active { display: block; animation: fadeUp 0.22s ease; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ══════════════════════════════════════════════════════════════
   COMPONENT LIBRARY
══════════════════════════════════════════════════════════════ */

/* ── KPI Cards ─────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: #fff;
  border-radius: var(--radius-card);
  padding: 20px;
  border: 1px solid #e8eaed;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: box-shadow var(--transition), transform var(--transition);
}
.kpi-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-1px); }
.kpi-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.kpi-icon svg { width: 22px; height: 22px; }
.kpi-icon.blue   { background: #eff6ff; color: #2563eb; }
.kpi-icon.green  { background: #f0fdf4; color: #16a34a; }
.kpi-icon.purple { background: #faf5ff; color: #7c3aed; }
.kpi-icon.brand  { background: var(--brand-50); color: var(--brand); }
.kpi-icon.orange { background: #fff7ed; color: #ea580c; }

.kpi-body { flex: 1; min-width: 0; }
.kpi-label { font-size: 0.75rem; font-weight: 500; color: #9ca3af; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 1.875rem; font-weight: 700; color: #111827; line-height: 1; letter-spacing: -0.02em; }
.kpi-trend { font-size: 0.75rem; font-weight: 500; margin-top: 6px; display: flex; align-items: center; gap: 3px; }
.kpi-trend.up     { color: #16a34a; }
.kpi-trend.down   { color: #dc2626; }
.kpi-trend.neutral{ color: #9ca3af; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius-card);
  border: 1px solid #e8eaed;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  margin-bottom: 16px;
}
.card:last-child { margin-bottom: 0; }
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: #111827;
  letter-spacing: -0.01em;
}
.card-subtitle {
  font-size: 0.8125rem;
  color: #9ca3af;
  margin-top: 1px;
}
.card-body { padding: 20px; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.badge-green  { background: #dcfce7; color: #166534; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-gray   { background: #f3f4f6; color: #4b5563; }
.badge-purple { background: #ede9fe; color: #6d28d9; }
.badge-brand  { background: var(--brand-100); color: var(--brand); }
.badge-yellow { background: #fef9c3; color: #854d0e; }

/* ── Data Table ─────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.875rem;
}
.data-table th {
  padding: 10px 16px;
  background: #f9fafb;
  font-size: 0.6875rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid #e8eaed;
  text-align: left;
}
.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid #f3f4f6;
  color: #374151;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr { cursor: pointer; transition: background var(--transition); }
.data-table tbody tr:hover { background: #fafafa; }
.data-table tbody tr.selected { background: var(--brand-50); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 2px 8px rgba(139,26,26,0.3);
}
.btn-primary:hover { background: var(--brand-light); box-shadow: 0 4px 12px rgba(139,26,26,0.4); }
.btn-secondary {
  background: #fff;
  color: #374151;
  border: 1.5px solid #e5e7eb;
}
.btn-secondary:hover { background: #f9fafb; border-color: #d1d5db; }
.btn-danger {
  background: #fff;
  color: #dc2626;
  border: 1.5px solid #fecaca;
}
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 5px 10px; font-size: 0.8125rem; border-radius: 6px; }
.btn-icon { padding: 7px; border-radius: 8px; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: 5px;
}
.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: 'Inter', sans-serif;
  color: #111827;
  background: #fff;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(139,26,26,0.1);
}
.form-input::placeholder { color: #9ca3af; }
select.form-input { cursor: pointer; }

/* ── Slide panel ────────────────────────────────────────────── */
#slide-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 49;
  cursor: pointer;
}
#slide-overlay.open { display: block; }

#slide-panel {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: 420px;
  background: #fff;
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
  box-shadow: -8px 0 32px rgba(0,0,0,0.12);
}
#slide-panel.open { transform: translateX(0); }

.panel-header {
  padding: 18px 20px;
  border-bottom: 1px solid #f3f4f6;
  display: flex; align-items: center; justify-content: space-between;
}
.panel-body { flex: 1; overflow-y: auto; padding: 20px; }
.panel-footer {
  padding: 16px 20px;
  border-top: 1px solid #f3f4f6;
  display: flex; gap: 8px;
}

/* ── Modals ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  backdrop-filter: blur(3px);
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.2);
  max-width: 560px; width: 100%;
  max-height: 88vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid #f3f4f6;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-body { flex: 1; overflow-y: auto; padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid #f3f4f6;
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ── Credit progress bar ────────────────────────────────────── */
.credit-bar-track {
  height: 8px; border-radius: 99px;
  background: #e5e7eb;
  overflow: hidden;
}
.credit-bar-fill {
  height: 100%; border-radius: 99px;
  transition: width 0.5s cubic-bezier(0.4,0,0.2,1);
}
.credit-bar-fill.high   { background: linear-gradient(90deg,#22c55e,#4ade80); }
.credit-bar-fill.medium { background: linear-gradient(90deg,#f59e0b,#fbbf24); }
.credit-bar-fill.low    { background: linear-gradient(90deg,#ef4444,#f87171); }

/* ── Low credit banner ──────────────────────────────────────── */
#credit-alert-banner {
  display: none;
  background: linear-gradient(90deg,#fffbeb,#fefce8);
  border-bottom: 1px solid #fcd34d;
  padding: 8px 24px;
  font-size: 0.875rem; font-weight: 500; color: #92400e;
  text-align: center;
}

/* ── Spinner ─────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2.5px solid rgba(139,26,26,0.15);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pagination ─────────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; align-items: center; }
.page-btn {
  padding: 5px 10px;
  border-radius: 7px;
  border: 1.5px solid #e5e7eb;
  font-size: 0.8125rem; font-family: 'Inter', sans-serif;
  cursor: pointer; color: #374151; background: #fff;
  transition: all var(--transition);
}
.page-btn:hover:not(:disabled) { background: #f9fafb; border-color: #d1d5db; }
.page-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.page-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── FullCalendar overrides ─────────────────────────────────── */
.fc-toolbar-title { font-size: 1rem !important; font-weight: 600 !important; font-family: 'Inter', sans-serif !important; }
.fc-button { font-family: 'Inter', sans-serif !important; }
.fc-button-primary { background: var(--brand) !important; border-color: var(--brand) !important; }
.fc-button-primary:not(:disabled):hover { background: var(--brand-light) !important; }
.fc-button-primary:not(:disabled):active,.fc-button-primary.fc-button-active { background: var(--brand-dark) !important; }

/* ── ApexCharts overrides ───────────────────────────────────── */
.apexcharts-toolbar { display: none !important; }
.apexcharts-legend-text { font-family: 'Inter', sans-serif !important; font-size: 0.8rem !important; }
.apexcharts-tooltip { font-family: 'Inter', sans-serif !important; }

/* ── Detail grid (meta info in panels/modals) ───────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.detail-item label {
  display: block; font-size: 0.6875rem; font-weight: 600;
  color: #9ca3af; text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 3px;
}
.detail-item span { font-size: 0.875rem; color: #111827; font-weight: 500; }

/* ── Historial log ───────────────────────────────────────────── */
.historial-entry {
  padding: 8px 0;
  border-bottom: 1px solid #f3f4f6;
  font-size: 0.8125rem;
  color: #4b5563;
  line-height: 1.6;
}
.historial-entry:last-child { border-bottom: none; }

/* ── Bottom nav (mobile only) ───────────────────────────────── */
#bottom-nav { display: none; }

/* ══════════════════════════════════════════════════════════════
   MOBILE
══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.mobile-open { transform: translateX(0); width: var(--sidebar-w); }
  #sidebar.collapsed { transform: translateX(-100%); }
  #main-wrap { margin-left: 0 !important; }

  #bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: #fff;
    border-top: 1px solid #e8eaed;
    z-index: 40;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.07);
  }

  #page-content { padding: 16px; padding-bottom: calc(70px + env(safe-area-inset-bottom)); }

  .nav-item-mobile {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 8px 4px;
    font-size: 0.625rem; font-weight: 500; color: #9ca3af;
    cursor: pointer; transition: color var(--transition);
    background: none; border: none; font-family: 'Inter', sans-serif;
  }
  .nav-item-mobile.active { color: var(--brand); }
  .nav-item-mobile svg { width: 20px; height: 20px; }

  #slide-panel { width: 100%; }
  .modal-box { max-height: 92vh; border-radius: 16px 16px 0 0; margin-top: auto; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

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

/* ── Utility classes ─── */
.overflow-x-auto { overflow-x: auto; }
.mb-4 { margin-bottom: 16px; }
.mt-4 { margin-top: 16px; }
.chart-grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 16px; }
@media (min-width: 1024px) { .chart-grid { grid-template-columns: 2fr 1fr; } }
.analytics-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 1024px) { .analytics-grid { grid-template-columns: 1fr 1fr; } }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; align-items: center; }
.calendar-legend { margin-top: 16px; display: flex; gap: 16px; font-size: 0.875rem; color: #4b5563; align-items: center; }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.table-footer { padding: 12px 16px; border-top: 1px solid #f3f4f6; display: flex; align-items: center; justify-content: space-between; }
.text-muted { font-size: 0.875rem; color: #9ca3af; }
.divide-y > * + * { border-top: 1px solid #f3f4f6; }
.sm-show { display: none; }
@media (min-width: 640px) { .sm-show { display: inline; } }
.packages-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) { .packages-grid { grid-template-columns: repeat(3, 1fr); } }
.w-full { width: 100%; }
