/**
 * Space Fun — estilos globales
 * Tema espacial / limpio / responsive
 */

:root {
  --bg: #0b1026;
  --bg-glow: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(108, 92, 231, 0.35), transparent);
  --surface: #141b3a;
  --surface-2: #1c2550;
  --primary: #6c5ce7;
  --primary-hover: #5a4bd1;
  --primary-light: #a29bfe;
  --accent: #00cec9;
  --success: #00b894;
  --warning: #fdcb6e;
  --danger: #e17055;
  --text: #f5f6fa;
  --text-muted: #a4b0be;
  --border: rgba(255, 255, 255, 0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --sidebar-width: 248px;
  --topbar-height: 56px;
  --focus-ring: 0 0 0 3px rgba(108, 92, 231, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: rgba(108, 92, 231, 0.45);
  color: #fff;
}

a {
  color: var(--primary-light);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn:focus-visible,
.form-control:focus-visible,
.menu-toggle:focus-visible,
.modal-close:focus-visible,
.app-nav a:focus-visible {
  box-shadow: var(--focus-ring);
}

/* Scrollbar sutil (WebKit) */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(162, 155, 254, 0.35);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(162, 155, 254, 0.55);
  background-clip: padding-box;
  border: 2px solid transparent;
}

/* ——— Utilidades ——— */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.muted {
  color: var(--text-muted);
}

/* ——— Botones y formularios ——— */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.15rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.btn:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.btn-block {
  width: 100%;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
}

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

.form-group {
  margin-bottom: 1rem;
  text-align: left;
}

.form-group label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.form-control {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.25);
}

.form-error {
  margin-top: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  background: rgba(225, 112, 85, 0.15);
  border: 1px solid rgba(225, 112, 85, 0.4);
  color: #ffb4a2;
  font-size: 0.9rem;
  display: none;
}

.form-error.visible {
  display: block;
}

/* ——— Login ——— */

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--bg) var(--bg-glow);
  position: relative;
  overflow: hidden;
}

.login-stars {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 10% 20%, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(1px 1px at 30% 70%, rgba(162, 155, 254, 0.8), transparent),
    radial-gradient(1.5px 1.5px at 70% 30%, rgba(0, 206, 201, 0.7), transparent),
    radial-gradient(1px 1px at 85% 60%, rgba(255, 255, 255, 0.55), transparent),
    radial-gradient(1.2px 1.2px at 50% 50%, rgba(253, 203, 110, 0.6), transparent),
    radial-gradient(1px 1px at 20% 90%, rgba(255, 255, 255, 0.4), transparent);
  opacity: 0.85;
  animation: stars-twinkle 6s ease-in-out infinite alternate;
}

@keyframes stars-twinkle {
  from { opacity: 0.55; }
  to { opacity: 0.95; }
}

.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: rgba(20, 27, 58, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow), 0 0 60px rgba(108, 92, 231, 0.15);
  padding: 2rem 1.75rem;
  text-align: center;
  animation: card-in 0.35s ease;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-brand {
  margin-bottom: 1.35rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.login-logo {
  display: block;
  width: min(220px, 72vw);
  height: auto;
  max-height: 200px;
  object-fit: contain;
  object-position: center;
  margin: 0 auto;
  /* Realce sutil sobre la tarjeta */
  filter: drop-shadow(0 0 18px rgba(108, 92, 231, 0.35));
}

.login-logo-sm {
  width: min(160px, 55vw);
  max-height: 140px;
}

.login-tagline {
  margin: 0.15rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.login-brand h1,
.not-found-code {
  margin: 0.35rem 0 0;
  font-size: 1.65rem;
  color: var(--primary-light);
  letter-spacing: 0.02em;
}

.not-found-code {
  font-size: 2rem;
  font-weight: 700;
}

.login-brand p {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.login-card .btn {
  margin-top: 0.5rem;
}

.login-hint {
  margin-top: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.password-field {
  position: relative;
  display: flex;
  align-items: center;
}

.password-field .form-control {
  padding-right: 4.75rem;
}

.password-toggle {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--primary-light);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
}

.password-toggle:hover {
  background: rgba(108, 92, 231, 0.2);
}

.not-found-actions {
  margin-top: 0.5rem;
}

.not-found-actions .btn {
  text-decoration: none;
}

/* ——— App shell (sidebar + topbar) ——— */

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

.app-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
  transform: translateX(0);
  transition: transform 0.2s ease;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  z-index: 200;
  background: var(--primary);
  color: #fff;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 0.75rem;
  text-decoration: none;
  box-shadow: var(--focus-ring);
}

.app-sidebar .brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem 1rem;
  color: var(--primary-light);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease;
}

.app-sidebar .brand:hover {
  background: rgba(108, 92, 231, 0.12);
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: auto;
  max-width: 100%;
  height: 72px;
  object-fit: contain;
  object-position: center;
  /* Logo ya trae fondo negro; se integra con el sidebar */
  border-radius: 10px;
}

.brand-tag {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.app-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.app-nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
  min-height: 44px;
}

.app-nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.app-nav a.active {
  background: rgba(108, 92, 231, 0.25);
  color: var(--primary-light);
  box-shadow: inset 3px 0 0 var(--primary-light);
}

.app-nav .nav-icon {
  font-size: 1.1rem;
  width: 1.4rem;
  text-align: center;
}

.app-sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.65rem;
  padding: 0.4rem 0.25rem;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(108, 92, 231, 0.25);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}

.user-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.user-meta strong {
  font-size: 0.92rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.role-badge {
  display: inline-block;
  margin-top: 0.2rem;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.role-badge-admin {
  background: rgba(0, 184, 148, 0.2);
  color: #55efc4;
  border: 1px solid rgba(0, 184, 148, 0.35);
}

.role-badge-viewer {
  background: rgba(253, 203, 110, 0.18);
  color: #ffeaa7;
  border: 1px solid rgba(253, 203, 110, 0.4);
}

body.role-viewer [data-requires-write] {
  display: none !important;
}

.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 60% 30% at 100% 0%, rgba(108, 92, 231, 0.08), transparent 60%);
}

.app-topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 16, 38, 0.88);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-logo {
  display: block;
  height: 36px;
  width: auto;
  max-width: 48px;
  object-fit: contain;
  object-position: center;
  flex-shrink: 0;
  border-radius: 6px;
}

.app-topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-meta {
  margin-left: auto;
  flex-shrink: 0;
}

.topbar-date {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-transform: capitalize;
  white-space: nowrap;
}

.app-footer {
  padding: 0.75rem 1.25rem 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid transparent;
}

.app-footer span:first-child {
  color: var(--primary-light);
  font-weight: 600;
}

.page-enter {
  animation: page-enter 0.28s ease;
}

@keyframes page-enter {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
}

.app-content {
  padding: 1.25rem;
  flex: 1;
}

/* Overlay móvil */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 35;
}

.sidebar-overlay.visible {
  display: block;
}

/* Placeholder de módulo (pasos siguientes) */
.module-placeholder {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  color: var(--text-muted);
}

.module-placeholder h2 {
  margin: 0 0 0.5rem;
  color: var(--primary-light);
  font-size: 1.25rem;
}

.module-placeholder p {
  margin: 0;
  max-width: 36rem;
  margin-inline: auto;
}

/* Toast */
.toast-host {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(380px, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.75rem 0.65rem 0.75rem 0.95rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  animation: toast-in 0.2s ease;
  pointer-events: auto;
}

.toast-text {
  flex: 1;
  min-width: 0;
}

.toast-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  padding: 0 0.25rem;
  border-radius: 4px;
}

.toast-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.toast.error {
  border-color: rgba(225, 112, 85, 0.5);
  background: rgba(225, 112, 85, 0.2);
}

.toast.success {
  border-color: rgba(0, 184, 148, 0.5);
  background: rgba(0, 184, 148, 0.15);
}

.toast.toast-out {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ——— Dashboard KPIs y gráficas ——— */

.dashboard-toolbar {
  align-items: flex-end;
}

.period-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-end;
}

.period-label {
  margin: 0;
  font-size: 0.95rem;
}

.results-section {
  margin-bottom: 1.35rem;
}

.results-header {
  margin-bottom: 0.85rem;
}

.results-title {
  margin: 0;
  font-size: 1.15rem;
  color: var(--primary-light);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.kpi-grid-finance {
  grid-template-columns: repeat(5, 1fr);
  margin-bottom: 0.85rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--primary);
}

.kpi-income::before {
  background: var(--success);
}

.kpi-operating::before,
.kpi-expense::before {
  background: var(--warning);
}

.kpi-withdrawals {
  background: linear-gradient(
    135deg,
    rgba(225, 112, 85, 0.12) 0%,
    var(--surface) 55%
  );
  border-color: rgba(225, 112, 85, 0.35);
}

.kpi-withdrawals::before {
  background: var(--danger);
  width: 5px;
}

.kpi-withdrawals .kpi-value {
  color: #ffb4a2;
}

.kpi-op-profit::before {
  background: var(--accent);
}

.kpi-profit::before {
  background: var(--primary-light);
}

.kpi-events::before {
  background: var(--primary-light);
}

.kpi-events-inline {
  min-width: 11rem;
  margin: 0;
  padding: 0.75rem 1rem;
}

.kpi-events-inline .kpi-value {
  font-size: 1.25rem;
}

.results-formula {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.formula-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.85rem;
  font-size: 0.92rem;
}

.formula-label {
  font-weight: 700;
  color: var(--primary-light);
  min-width: 9.5rem;
}

.formula-eq {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.formula-eq strong.is-positive {
  color: var(--success);
}

.formula-eq strong.is-negative {
  color: var(--danger);
}

.formula-line-net {
  padding-top: 0.55rem;
  border-top: 1px dashed var(--border);
}

.kpi-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.kpi-value {
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  margin-bottom: 0.35rem;
}

.kpi-value.is-negative {
  color: var(--danger);
}

.kpi-value.is-positive {
  color: var(--success);
}

.kpi-hint {
  font-size: 0.78rem;
  line-height: 1.35;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 0.75rem;
  min-width: 0;
}

.chart-wide {
  grid-column: 1 / -1;
}

.chart-card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem 0.75rem;
  margin-bottom: 0.65rem;
}

.chart-card-header h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--primary-light);
  font-weight: 600;
}

.chart-sub {
  font-size: 0.82rem;
}

.chart-canvas-wrap {
  position: relative;
  height: 260px;
}

.chart-pie-wrap {
  height: 280px;
  max-width: 360px;
  margin: 0 auto;
}

.panel-section {
  margin-bottom: 1.25rem;
}

.panel-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.panel-section-header h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--primary-light);
}

.dash-note {
  font-size: 0.85rem;
  margin: 0 0 1rem;
}

/* ——— Diario de ingresos + eventos del mes ——— */

.section-sub {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.journal-header-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.journal-total-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  background: rgba(0, 184, 148, 0.12);
  border: 1px solid rgba(0, 184, 148, 0.35);
  border-radius: 999px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.journal-total-chip strong {
  color: #55efc4;
  font-variant-numeric: tabular-nums;
}

.journal-summary-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1.25rem;
  margin-bottom: 0.85rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.journal-stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 6rem;
}

.journal-stat strong {
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.income-journal {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.journal-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.journal-day[open] {
  border-color: rgba(108, 92, 231, 0.35);
  box-shadow: 0 0 0 1px rgba(108, 92, 231, 0.12);
}

.journal-day-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background 0.15s ease;
}

.journal-day-summary::-webkit-details-marker {
  display: none;
}

.journal-day-summary::marker {
  content: '';
}

.journal-day-summary:hover {
  background: rgba(108, 92, 231, 0.08);
}

.journal-day-left {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
  min-width: 0;
}

.journal-day-date {
  font-weight: 700;
  font-size: 1rem;
}

.journal-day-weekday {
  font-size: 0.88rem;
}

.journal-day-count {
  font-size: 0.82rem;
}

.journal-day-right {
  flex-shrink: 0;
}

.journal-day-income {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
  color: var(--text-muted);
}

.journal-day-income.has-income {
  color: #55efc4;
}

.journal-day-body {
  border-top: 1px solid var(--border);
  padding: 0.35rem 0.65rem 0.75rem;
  background: rgba(0, 0, 0, 0.15);
}

.journal-event {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  padding: 0.7rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.journal-event:last-of-type {
  border-bottom: none;
}

.journal-event.is-cancelled {
  opacity: 0.55;
}

.journal-event-main {
  display: flex;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.journal-event-time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--primary-light);
  min-width: 3rem;
}

.journal-event-client {
  font-weight: 600;
}

.journal-event-pkg {
  font-size: 0.85rem;
}

.journal-event-pays {
  margin-top: 0.35rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.pay-chip {
  display: inline-flex;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(108, 92, 231, 0.18);
  border: 1px solid rgba(108, 92, 231, 0.3);
  color: var(--primary-light);
  white-space: nowrap;
}

.journal-event-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  flex-shrink: 0;
}

.journal-event-amounts {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.1rem;
  font-size: 0.85rem;
}

.journal-event-amounts strong {
  font-variant-numeric: tabular-nums;
  color: #55efc4;
}

.journal-day-footer {
  padding: 0.5rem 0.5rem 0.15rem;
  font-size: 0.82rem;
  border-top: 1px dashed var(--border);
  margin-top: 0.15rem;
}

.journal-day-footer strong {
  color: #55efc4;
}

.row-muted,
.card-muted {
  opacity: 0.6;
}

.data-table tbody tr.row-muted:hover {
  opacity: 0.8;
}

/* ——— FullCalendar (tema oscuro Space Fun) ——— */

.calendar-section .panel-section-header {
  flex-wrap: wrap;
}

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-pagado {
  background: #00b894;
}

.legend-pendiente {
  background: #fdcb6e;
}

.legend-cancelado {
  background: #636e72;
}

.calendar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.85rem 1rem;
  overflow: hidden;
}

#events-calendar {
  min-height: 420px;
}

/* Variables y overrides FullCalendar */
#events-calendar .fc {
  --fc-border-color: var(--border);
  --fc-page-bg-color: transparent;
  --fc-neutral-bg-color: var(--surface-2);
  --fc-list-event-hover-bg-color: rgba(108, 92, 231, 0.15);
  --fc-today-bg-color: rgba(108, 92, 231, 0.12);
  --fc-now-indicator-color: var(--accent);
  --fc-button-bg-color: var(--surface-2);
  --fc-button-border-color: var(--border);
  --fc-button-text-color: var(--text);
  --fc-button-hover-bg-color: var(--primary);
  --fc-button-hover-border-color: var(--primary);
  --fc-button-active-bg-color: var(--primary);
  --fc-button-active-border-color: var(--primary);
  --fc-event-border-color: transparent;
  color: var(--text);
  font-family: var(--font);
}

#events-calendar .fc .fc-toolbar-title {
  font-size: 1.15rem;
  color: var(--primary-light);
}

#events-calendar .fc .fc-button {
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-transform: capitalize;
  box-shadow: none !important;
}

#events-calendar .fc .fc-button-primary:not(:disabled).fc-button-active,
#events-calendar .fc .fc-button-primary:not(:disabled):active {
  background: var(--primary);
  border-color: var(--primary);
}

#events-calendar .fc .fc-col-header-cell-cushion,
#events-calendar .fc .fc-daygrid-day-number {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
}

#events-calendar .fc .fc-daygrid-day-number:hover {
  color: var(--primary-light);
}

#events-calendar .fc-theme-standard td,
#events-calendar .fc-theme-standard th {
  border-color: var(--border);
}

#events-calendar .fc-event {
  cursor: pointer;
  border-radius: 4px;
  font-size: 0.78rem;
  padding: 1px 3px;
}

#events-calendar .fc-event-cancelled {
  opacity: 0.7;
  text-decoration: line-through;
}

#events-calendar .fc-daygrid-event-dot {
  border-color: currentColor;
}

#events-calendar .fc-list-event:hover td {
  background: rgba(108, 92, 231, 0.12);
}

#events-calendar .fc-list-day-cushion {
  background: var(--surface-2) !important;
}

.modal-sm {
  max-width: 420px;
}

.modal-body {
  padding: 1rem 1.15rem;
}

.cal-detail-grid {
  display: grid;
  gap: 0.55rem;
  font-size: 0.95rem;
}

.cal-detail-grid .muted {
  display: inline-block;
  min-width: 4.5rem;
  margin-right: 0.35rem;
}

.cal-detail-notes p {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

@media (max-width: 768px) {
  #events-calendar .fc .fc-toolbar {
    flex-direction: column;
    gap: 0.5rem;
    align-items: stretch;
  }

  #events-calendar .fc .fc-toolbar-chunk {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  #events-calendar .fc .fc-toolbar-title {
    font-size: 1rem;
    text-align: center;
  }

  #events-calendar {
    min-height: 360px;
  }
}

/* ——— Page toolbar / filters ——— */

.page-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-end;
  flex: 1;
  min-width: 0;
}

.filter-field {
  min-width: 120px;
}

.filter-field label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.filter-grow {
  flex: 1;
  min-width: 160px;
}

.filter-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.toolbar-actions {
  display: flex;
  gap: 0.5rem;
}

.table-meta {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
}

.table-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  justify-content: space-between;
}

.meta-total strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ——— Data table ——— */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.data-table th,
.data-table td {
  padding: 0.75rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  background: rgba(0, 0, 0, 0.15);
  white-space: nowrap;
}

.data-table tbody tr:hover {
  background: rgba(108, 92, 231, 0.08);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.data-table .actions-col {
  white-space: nowrap;
  width: 1%;
}

.empty-cell {
  text-align: center !important;
  color: var(--text-muted);
  padding: 2rem 1rem !important;
}

.cell-primary {
  font-weight: 600;
}

.cell-sub {
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

.row-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

/* ——— Buttons extras ——— */

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
}

.btn-danger-outline {
  background: transparent;
  border: 1px solid rgba(225, 112, 85, 0.55);
  color: #ffb4a2;
}

.btn-danger-outline:hover:not(:disabled) {
  background: rgba(225, 112, 85, 0.2);
}

/* ——— Badges ——— */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}

.badge-success {
  background: rgba(0, 184, 148, 0.2);
  color: #55efc4;
}

.badge-warning {
  background: rgba(253, 203, 110, 0.2);
  color: #ffeaa7;
}

.badge-danger {
  background: rgba(225, 112, 85, 0.2);
  color: #ffb4a2;
}

/* ——— Cards (móvil) ——— */

.card-list {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
}

.entity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.entity-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.entity-card-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.entity-card-body {
  display: grid;
  gap: 0.35rem;
  font-size: 0.92rem;
  margin-bottom: 0.85rem;
}

.entity-card-body .muted {
  display: inline-block;
  min-width: 4.5rem;
  margin-right: 0.35rem;
}

.entity-card-actions {
  display: flex;
  gap: 0.5rem;
}

.empty-card {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 1rem;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ——— Modal ——— */

body.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(5, 8, 20, 0.72);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1.25rem;
  overflow-y: auto;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal {
  width: 100%;
  max-width: 560px;
  margin: 1.5rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--primary-light);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
}

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

#event-form {
  padding: 1rem 1.15rem 1.15rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 0.85rem;
}

.form-span-2 {
  grid-column: span 2;
}

.payments-fieldset {
  margin: 0.5rem 0 1rem;
  padding: 0.85rem 1rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.payments-fieldset legend {
  padding: 0 0.35rem;
  color: var(--primary-light);
  font-weight: 600;
  font-size: 0.9rem;
}

.fieldset-hint {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
}

.payments-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}

.payments-summary {
  margin-top: 0.5rem;
  font-size: 0.85rem;
}

.text-warning {
  color: var(--warning) !important;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding-top: 0.25rem;
}

textarea.form-control {
  resize: vertical;
  min-height: 72px;
}

/* ——— Responsive ——— */

@media (max-width: 768px) {
  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .app-sidebar {
    transform: translateX(-100%);
  }

  .app-sidebar.open {
    transform: translateX(0);
  }

  .app-main {
    margin-left: 0;
  }

  .app-content {
    padding: 1rem;
  }

  .login-card {
    padding: 1.5rem 1.25rem;
  }

  .login-logo {
    width: min(180px, 68vw);
    max-height: 160px;
  }

  .brand-logo {
    height: 60px;
  }

  .topbar-logo {
    height: 30px;
    max-width: 40px;
  }

  .page-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions .btn {
    width: 100%;
  }

  .table-wrap {
    display: none;
  }

  .card-list {
    display: flex;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-span-2 {
    grid-column: span 1;
  }

  .payments-grid {
    grid-template-columns: 1fr;
  }

  .modal {
    margin: 0.5rem auto;
  }

  .modal-backdrop {
    padding: 0.5rem;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .kpi-grid-finance {
    grid-template-columns: 1fr 1fr;
  }

  .kpi-grid-finance .kpi-op-profit,
  .kpi-grid-finance .kpi-profit {
    grid-column: span 1;
  }

  .results-header {
    flex-direction: column;
    align-items: stretch;
  }

  .kpi-events-inline {
    width: 100%;
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .chart-canvas-wrap {
    height: 220px;
  }

  .kpi-value {
    font-size: 1.2rem;
  }
}

@media (max-width: 480px) {
  .kpi-grid,
  .kpi-grid-finance {
    grid-template-columns: 1fr;
  }

  .kpi-grid-finance .kpi-op-profit,
  .kpi-grid-finance .kpi-profit {
    grid-column: span 1;
  }

  .topbar-date {
    display: none;
  }

  .toolbar-actions {
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  .filter-actions {
    width: 100%;
  }

  .filter-actions .btn {
    flex: 1;
  }

  .journal-day-summary {
    flex-direction: column;
    align-items: flex-start;
  }

  .journal-day-right {
    width: 100%;
  }

  .journal-event {
    flex-direction: column;
  }

  .journal-event-side {
    align-items: flex-start;
    width: 100%;
    flex-direction: row;
    justify-content: space-between;
  }

  .panel-section-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Preferencias de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Impresión: solo contenido útil */
@media print {
  .app-sidebar,
  .app-topbar,
  .menu-toggle,
  .sidebar-overlay,
  .app-footer,
  .toast-host,
  .page-toolbar .toolbar-actions,
  .filter-actions,
  .skip-link {
    display: none !important;
  }

  .app-main {
    margin-left: 0 !important;
  }

  body,
  .app-content {
    background: #fff !important;
    color: #111 !important;
  }

  .kpi-card,
  .chart-card,
  .calendar-card,
  .table-wrap,
  .entity-card {
    break-inside: avoid;
    box-shadow: none !important;
    border-color: #ccc !important;
  }
}

