/* Selector de apariencia y tema oscuro. El modo claro conserva el diseño original. */
html {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --bg-app: #0b1120;
  --card: #111827;
  --card-bg: #111827;
  --surface: #111827;
  --text: #f1f5f9;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --muted: #94a3b8;
  --border-color: rgba(148, 163, 184, 0.22);
  --glass: rgba(255, 255, 255, 0.06);
}

.theme-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 12px;
  background: #fff;
  color: #334155;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}

.theme-picker-login {
  position: fixed;
  top: 18px;
  left: 20px;
  z-index: 20;
}

.login-preferences {
  position: fixed;
  top: 18px;
  left: 20px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-preferences .theme-picker {
  min-width: 350px;
}

.theme-picker-icon,
.appearance-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 10px;
  background: #fff1e8;
  color: #ea580c;
  font-size: 20px;
  font-weight: 800;
}

.language-picker-icon {
  background: #e0f2fe;
  color: #0369a1;
}

.theme-picker > span:nth-child(2) {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.theme-picker strong {
  font-size: 12px;
}

.theme-picker small {
  color: #94a3b8;
  font-size: 10px;
}

.theme-picker select,
.appearance-management select {
  min-width: 118px;
  padding: 8px 10px;
  border: 1px solid #d8dee8;
  border-radius: 9px;
  background: #f8fafc;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: none;
}

.appearance-management {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
  padding: 20px 24px;
  border: 1px solid rgba(15, 23, 42, 0.09);
  border-radius: 18px;
  background: linear-gradient(135deg, #fff 55%, #fff7f2 100%);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.appearance-management > div {
  display: flex;
  align-items: center;
  gap: 14px;
}

.appearance-management h3 {
  margin: 3px 0 5px;
  color: #111827;
  font-size: 18px;
}

.appearance-management p {
  margin: 0;
  color: #6b7280;
  font-size: 13px;
  line-height: 1.45;
}

.appearance-management > label,
.appearance-controls label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 165px;
  color: #64748b;
  font-size: 11px;
  font-weight: 750;
}

.appearance-controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.appearance-controls label {
  min-width: 145px;
}

.appearance-management select {
  width: 100%;
}

/* Base oscura */
html[data-theme="dark"] body,
html[data-theme="dark"] #login-area,
html[data-theme="dark"] .main,
html[data-theme="dark"] .page {
  background: #0b1120 !important;
  color: #f1f5f9 !important;
}

html[data-theme="dark"] .topbar,
html[data-theme="dark"] .sidebar,
html[data-theme="dark"] #login-form,
html[data-theme="dark"] #db-status,
html[data-theme="dark"] .theme-picker {
  background: #111827 !important;
  color: #e2e8f0 !important;
  border-color: rgba(148, 163, 184, 0.22) !important;
}

html[data-theme="dark"] .sidebar {
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.28);
}

html[data-theme="dark"] .sidebar-header {
  border-color: rgba(148, 163, 184, 0.15) !important;
}

html[data-theme="dark"] .sidebar a {
  color: #cbd5e1;
}

html[data-theme="dark"] .sidebar a:hover,
html[data-theme="dark"] .sidebar a.active {
  background: rgba(255, 107, 53, 0.14);
  color: #fb8b5d;
}

html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] strong,
html[data-theme="dark"] .stat-title,
html[data-theme="dark"] .pos-title,
html[data-theme="dark"] .menu-item {
  color: #f1f5f9 !important;
}

html[data-theme="dark"] p,
html[data-theme="dark"] small,
html[data-theme="dark"] label,
html[data-theme="dark"] .stat-sub {
  color: #94a3b8;
}

html[data-theme="dark"] form label,
html[data-theme="dark"] .modal label,
html[data-theme="dark"] .user-form-field label,
html[data-theme="dark"] .ticket-sale-form-grid label > span,
html[data-theme="dark"] .expense-pay-options legend,
html[data-theme="dark"] .door-sale-payment legend {
  color: #cbd5e1 !important;
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .theme-picker select,
html[data-theme="dark"] .appearance-management select {
  background: #0f172a !important;
  color: #f1f5f9 !important;
  border-color: #334155 !important;
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: #94a3b8;
  opacity: 1;
}

/* Chrome y Safari pueden imponer un fondo claro al autocompletar credenciales. */
html[data-theme="dark"] input:-webkit-autofill,
html[data-theme="dark"] input:-webkit-autofill:hover,
html[data-theme="dark"] input:-webkit-autofill:focus,
html[data-theme="dark"] textarea:-webkit-autofill,
html[data-theme="dark"] select:-webkit-autofill {
  -webkit-text-fill-color: #f1f5f9 !important;
  caret-color: #f1f5f9;
  box-shadow: 0 0 0 1000px #0f172a inset !important;
  transition: background-color 9999s ease-out 0s;
}

html[data-theme="dark"] .event-form input[type="datetime-local"] {
  color-scheme: dark;
}

html[data-theme="dark"] select option {
  background: #0f172a;
  color: #f1f5f9;
}

html[data-theme="dark"] input:focus,
html[data-theme="dark"] select:focus,
html[data-theme="dark"] textarea:focus {
  border-color: #fb8b5d !important;
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.18) !important;
}

/* Superficies principales */
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .chart-card,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .context-menu,
html[data-theme="dark"] .users-management,
html[data-theme="dark"] .user-card,
html[data-theme="dark"] .users-empty,
html[data-theme="dark"] .expense-management,
html[data-theme="dark"] .reports-management,
html[data-theme="dark"] .ticket-management,
html[data-theme="dark"] .ticket-sale-card,
html[data-theme="dark"] .ticket-quick-actions,
html[data-theme="dark"] .ticket-summary,
html[data-theme="dark"] .pos-card,
html[data-theme="dark"] .pos-modal-container,
html[data-theme="dark"] table {
  background: #111827 !important;
  color: #e2e8f0 !important;
  border-color: rgba(148, 163, 184, 0.2) !important;
}

html[data-theme="dark"] .appearance-management,
html[data-theme="dark"] .users-management-header,
html[data-theme="dark"] .user-modal-header,
html[data-theme="dark"] .admin-approval-header,
html[data-theme="dark"] .expense-header,
html[data-theme="dark"] .expense-modal-header,
html[data-theme="dark"] .reports-header,
html[data-theme="dark"] .ticket-page-header,
html[data-theme="dark"] .ticket-sale-modal-header {
  background: linear-gradient(135deg, #111827 55%, #1c1917 100%) !important;
  border-color: rgba(148, 163, 184, 0.18) !important;
}

html[data-theme="dark"] .users-summary,
html[data-theme="dark"] .users-grid,
html[data-theme="dark"] .events-grid,
html[data-theme="dark"] .user-card-details,
html[data-theme="dark"] .expense-toolbar,
html[data-theme="dark"] .expense-stat,
html[data-theme="dark"] .reports-period,
html[data-theme="dark"] .reports-results-header,
html[data-theme="dark"] .ticket-sale-actions,
html[data-theme="dark"] .ticket-search,
html[data-theme="dark"] .ticket-sale-type-summary,
html[data-theme="dark"] .ticket-delivery-summary,
html[data-theme="dark"] .pos-products-area,
html[data-theme="dark"] .pos-cart-area {
  background: #0f172a !important;
  color: #cbd5e1 !important;
  border-color: rgba(148, 163, 184, 0.18) !important;
}

html[data-theme="dark"] .user-form-field input,
html[data-theme="dark"] .user-form-field select,
html[data-theme="dark"] .user-role-option,
html[data-theme="dark"] .user-secondary-action,
html[data-theme="dark"] .expense-toolbar input,
html[data-theme="dark"] .expense-toolbar select,
html[data-theme="dark"] .expense-form input,
html[data-theme="dark"] .expense-form select,
html[data-theme="dark"] .expense-action,
html[data-theme="dark"] .reports-period input,
html[data-theme="dark"] .reports-period .btn-ghost,
html[data-theme="dark"] .reports-export select,
html[data-theme="dark"] .reports-picker .btn-rep,
html[data-theme="dark"] .ticket-event-pill,
html[data-theme="dark"] .ticket-quick-actions button,
html[data-theme="dark"] .ticket-modal-close,
html[data-theme="dark"] .ticket-sale-form-grid input,
html[data-theme="dark"] .ticket-sale-form-grid select,
html[data-theme="dark"] .ticket-delivery-close,
html[data-theme="dark"] .door-sale-payment label > span,
html[data-theme="dark"] .expense-pay-options label > span {
  background: #111827 !important;
  color: #cbd5e1 !important;
  border-color: #334155 !important;
}

html[data-theme="dark"] .user-form,
html[data-theme="dark"] .event-form,
html[data-theme="dark"] .admin-approval-form,
html[data-theme="dark"] .expense-form,
html[data-theme="dark"] #ticket-sale-form {
  background: #111827 !important;
  color: #e2e8f0 !important;
}

html[data-theme="dark"] .user-form-actions,
html[data-theme="dark"] .ticket-sale-form-actions {
  border-color: rgba(148, 163, 184, 0.18) !important;
}

html[data-theme="dark"] .reports-picker .btn-rep.active,
html[data-theme="dark"] .reports-picker .report-choice-primary,
html[data-theme="dark"] .user-role-option:has(input:checked),
html[data-theme="dark"] .door-sale-payment input:checked + span {
  background: rgba(255, 107, 53, 0.13) !important;
  border-color: #fb8b5d !important;
}

/* Tablas y listados */
html[data-theme="dark"] th,
html[data-theme="dark"] td,
html[data-theme="dark"] .expense-table td {
  color: #cbd5e1 !important;
  border-color: rgba(148, 163, 184, 0.16) !important;
}

html[data-theme="dark"] table thead th,
html[data-theme="dark"] .sales-history-table .table-head-row th,
html[data-theme="dark"] #sales-list table tr:first-child th,
html[data-theme="dark"] #my-sales-list table tr:first-child th,
html[data-theme="dark"] .ticket-table th,
html[data-theme="dark"] .expense-table th {
  background: #0f172a !important;
  color: #94a3b8 !important;
}

html[data-theme="dark"] .sales-history-table thead,
html[data-theme="dark"] .sales-history-table .table-head-row,
html[data-theme="dark"] #sales-list table tr:first-child,
html[data-theme="dark"] #my-sales-list table tr:first-child {
  background: #0f172a !important;
  color: #94a3b8 !important;
}

html[data-theme="dark"] table tr:hover,
html[data-theme="dark"] .expense-table tbody tr:hover {
  background: rgba(148, 163, 184, 0.06) !important;
}

html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .ticket-table-wrap,
html[data-theme="dark"] .expense-table-wrap,
html[data-theme="dark"] .reports-results,
html[data-theme="dark"] .reports-empty-state {
  border-color: rgba(148, 163, 184, 0.2) !important;
}

/* Resultados de reportes: los selectores originales usan un ID y requieren
   reglas oscuras con la misma prioridad. */
html[data-theme="dark"] .reports-results,
html[data-theme="dark"] #report-output,
html[data-theme="dark"] #report-output table {
  background: #111827 !important;
  color: #e2e8f0 !important;
  border-color: rgba(148, 163, 184, 0.2) !important;
}

html[data-theme="dark"] #report-output th {
  background: #0f172a !important;
  color: #94a3b8 !important;
  border-color: rgba(148, 163, 184, 0.2) !important;
}

html[data-theme="dark"] #report-output td {
  background: #111827 !important;
  color: #cbd5e1 !important;
  border-color: rgba(148, 163, 184, 0.16) !important;
}

html[data-theme="dark"] #report-output tbody tr:hover td {
  background: #172033 !important;
}

html[data-theme="dark"] .closing-report {
  background: #0f172a !important;
  color: #e2e8f0 !important;
}

html[data-theme="dark"] .closing-card,
html[data-theme="dark"] .closing-section,
html[data-theme="dark"] .report-note {
  background: #111827 !important;
  color: #cbd5e1 !important;
  border-color: rgba(148, 163, 184, 0.2) !important;
}

html[data-theme="dark"] .closing-card-result {
  background: rgba(16, 185, 129, 0.1) !important;
  border-color: rgba(52, 211, 153, 0.35) !important;
}

html[data-theme="dark"] .closing-card-result.is-negative {
  background: rgba(239, 68, 68, 0.1) !important;
  border-color: rgba(248, 113, 113, 0.35) !important;
}

html[data-theme="dark"] .closing-card-warning {
  background: rgba(245, 158, 11, 0.1) !important;
  border-color: rgba(251, 191, 36, 0.35) !important;
}

html[data-theme="dark"] .closing-event-label,
html[data-theme="dark"] .closing-card span,
html[data-theme="dark"] .closing-card small,
html[data-theme="dark"] .closing-line,
html[data-theme="dark"] .report-note {
  color: #94a3b8 !important;
}

html[data-theme="dark"] .closing-line {
  border-color: rgba(148, 163, 184, 0.16) !important;
}

/* Configuración de precios de entradas */
html[data-theme="dark"] .ticket-price-panel {
  background: #111827 !important;
  color: #e2e8f0 !important;
  border-color: rgba(148, 163, 184, 0.22) !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

html[data-theme="dark"] .ticket-price-field {
  padding: 12px;
  background: #0f172a !important;
  border: 1px solid #334155;
  border-radius: 10px;
}

html[data-theme="dark"] .ticket-price-panel label {
  color: #cbd5e1 !important;
}

html[data-theme="dark"] .ticket-price-panel #cfg-ticket-price-advance,
html[data-theme="dark"] .ticket-price-panel #cfg-ticket-price-door {
  background: #0b1120 !important;
  color: #f1f5f9 !important;
  border-color: #475569 !important;
}

html[data-theme="dark"] .event-price-grid > div {
  background: #0f172a !important;
  border: 1px solid #334155;
}

html[data-theme="dark"] .event-price-grid span {
  color: #94a3b8 !important;
}

html[data-theme="dark"] .event-price-grid strong {
  color: #f1f5f9 !important;
}

/* POS y modales */
html[data-theme="dark"] .pos-header {
  background: #111827 !important;
  border-color: rgba(148, 163, 184, 0.2) !important;
}

html[data-theme="dark"] .pos-body,
html[data-theme="dark"] .pos-cart-title-row,
html[data-theme="dark"] .cart-items-wrapper,
html[data-theme="dark"] .cart-footer {
  background: #0f172a !important;
  color: #e2e8f0 !important;
  border-color: rgba(148, 163, 184, 0.2) !important;
}

html[data-theme="dark"] .pos-cart-title-row,
html[data-theme="dark"] .cart-footer {
  background: #111827 !important;
}

html[data-theme="dark"] .pos-cart-kicker,
html[data-theme="dark"] .cart-summary-item span,
html[data-theme="dark"] .cart-field label,
html[data-theme="dark"] .cart-empty-state span {
  color: #94a3b8 !important;
}

html[data-theme="dark"] .pos-count-badge,
html[data-theme="dark"] .cart-summary-item {
  background: #0f172a !important;
  color: #e2e8f0 !important;
  border-color: #334155 !important;
}

html[data-theme="dark"] #cart-table {
  background: transparent !important;
}

html[data-theme="dark"] .pos-submit-btn {
  background: #f97316 !important;
  color: #111827 !important;
}

html[data-theme="dark"] .pos-img {
  background: #0b1120 !important;
}

html[data-theme="dark"] .modal-overlay {
  background: rgba(2, 6, 23, 0.82);
}

html[data-theme="dark"] .menu-item:hover {
  background: rgba(148, 163, 184, 0.1);
}

.app-footer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  padding: 9px 16px;
  border-top: 1px solid rgba(15, 23, 42, 0.1);
  background: rgba(255, 255, 255, 0.92);
  color: #64748b;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-align: center;
  backdrop-filter: blur(10px);
}

.page {
  padding-bottom: 58px !important;
}

html[data-theme="dark"] .app-footer {
  border-top-color: #334155;
  background: rgba(15, 23, 42, 0.94);
  color: #94a3b8;
}

html[data-theme="dark"] .license-management,
html[data-theme="dark"] .license-current-status,
html[data-theme="dark"] .license-installation-row,
html[data-theme="dark"] .regional-settings-panel {
  background:#111827;
  border-color:#2b3a50;
}

html[data-theme="dark"] .license-management h3,
html[data-theme="dark"] .license-current-status > strong,
html[data-theme="dark"] .license-installation-row code,
html[data-theme="dark"] .regional-settings-panel h3,
html[data-theme="dark"] .regional-settings-panel h4 {
  color:#f8fafc;
}

html[data-theme="dark"] .license-management p,
html[data-theme="dark"] .license-current-status > small,
html[data-theme="dark"] .license-installation-row,
html[data-theme="dark"] .license-activation-form > label,
html[data-theme="dark"] .regional-settings-panel p,
html[data-theme="dark"] .regional-settings-panel label,
html[data-theme="dark"] .regional-settings-panel small {
  color:#a9b8cc;
}

html[data-theme="dark"] .license-activation-form input {
  background:#0b1220;
  border-color:#34445d;
  color:#f8fafc;
}

html[data-theme="dark"] .regional-settings-panel input,
html[data-theme="dark"] .regional-settings-panel select {
  border-color: #34445d !important;
  background: #0b1220 !important;
  color: #f8fafc !important;
}

html[data-theme="dark"] .tax-settings-group {
  border-color: #2b3a50;
}

html[data-theme="dark"] .free-ticket-license-notice {
  background:#0c2538;
  border-color:#164e63;
  color:#e0f2fe;
}

html[data-theme="dark"] .free-ticket-license-notice small {
  color:#7dd3fc;
}

html[data-theme="dark"] .pro-upgrade-hero,
html[data-theme="dark"] .pro-feature-grid article {
  background:#111827;
  border-color:#2b3a50;
}

html[data-theme="dark"] .pro-upgrade-hero h2,
html[data-theme="dark"] .pro-feature-grid h3 {
  color:#f8fafc;
}

html[data-theme="dark"] .pro-upgrade-hero p,
html[data-theme="dark"] .pro-feature-grid p {
  color:#a9b8cc;
}

html[data-theme="dark"] .pro-upgrade-cta {
  background:#070d19;
  border:1px solid #26354b;
}

/* Neutraliza colores claros definidos directamente en el HTML. */
html[data-theme="dark"] [style*="background:#ffffff"],
html[data-theme="dark"] [style*="background: #ffffff"],
html[data-theme="dark"] [style*="background:#fff"],
html[data-theme="dark"] [style*="background: #fff"],
html[data-theme="dark"] [style*="background:#f9fafb"],
html[data-theme="dark"] [style*="background:#f8fafc"],
html[data-theme="dark"] [style*="background:#f3f4f6"],
html[data-theme="dark"] [style*="background:#f1f5f9"] {
  background: #111827 !important;
}

html[data-theme="dark"] [style*="color:#000000"],
html[data-theme="dark"] [style*="color: #000000"],
html[data-theme="dark"] [style*="color:#1f2937"],
html[data-theme="dark"] [style*="color: #1f2937"],
html[data-theme="dark"] [style*="color:#111827"],
html[data-theme="dark"] [style*="color:#334155"],
html[data-theme="dark"] [style*="color:#374151"] {
  color: #e2e8f0 !important;
}

html[data-theme="dark"] .theme-picker-icon,
html[data-theme="dark"] .appearance-icon,
html[data-theme="dark"] .users-summary-icon,
html[data-theme="dark"] .ticket-sale-card-icon,
html[data-theme="dark"] .report-choice-icon {
  background: rgba(255, 107, 53, 0.15);
  color: #fb8b5d;
}

@media (max-width: 680px) {
  .login-preferences {
    top: 12px;
    left: 12px;
    right: 12px;
  }

  .login-preferences .theme-picker {
    min-width: 0;
    width: 100%;
    justify-content: space-between;
  }

  .login-preferences .theme-picker > span:nth-child(2) {
    display: none;
  }

  #db-status {
    top: 128px !important;
    right: 12px !important;
  }

  .appearance-management {
    align-items: stretch;
    flex-direction: column;
    padding: 18px;
  }

  .appearance-controls,
  .appearance-management > label {
    width: 100%;
  }

  .appearance-controls {
    align-items: stretch;
    flex-direction: column;
  }
}
