/* KOSMOS theme layer
   Shared semantic tokens. Keep component geometry in main.css/public.css. */
:root,
:root[data-theme="light"] {
  color-scheme: light;
  /* Alias de compatibilidad: todos los componentes consumen la identidad compartida. */
  --k-bg: var(--kosmos-canvas);
  --k-surface: var(--kosmos-surface);
  --k-surface-raised: var(--kosmos-surface-2);
  --k-ink: var(--kosmos-ink);
  --k-muted: var(--kosmos-muted);
  --k-line: var(--kosmos-line);
  --k-accent: var(--kosmos-forest);
  --k-accent-hover: var(--kosmos-forest-deep);
  --k-accent-soft: var(--kosmos-accent-soft);
  --k-sidebar: var(--kosmos-forest-deep);
  --k-sidebar-ink: #f4f1e8;
  --k-shadow: var(--kosmos-shadow);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  /* Alias de compatibilidad: todos los componentes consumen la identidad compartida. */
  --k-bg: var(--kosmos-canvas);
  --k-surface: var(--kosmos-surface);
  --k-surface-raised: var(--kosmos-surface-2);
  --k-ink: var(--kosmos-ink);
  --k-muted: var(--kosmos-muted);
  --k-line: var(--kosmos-line);
  --k-accent: var(--kosmos-forest);
  --k-accent-hover: var(--kosmos-forest-deep);
  --k-accent-soft: var(--kosmos-accent-soft);
  --k-sidebar: var(--kosmos-forest-deep);
  --k-sidebar-ink: #f4f1e8;
  --k-shadow: var(--kosmos-shadow);
}
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body { background: var(--k-bg); color: var(--k-ink); transition: background-color .18s ease, color .18s ease; }
button, input, select, textarea { font: inherit; }
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 38px; padding: 0 13px; border: 1px solid var(--k-line);
  border-radius: 8px; background: var(--k-surface); color: var(--k-ink);
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background-color .16s ease, border-color .16s ease, transform .16s ease;
}
.theme-toggle:hover { border-color: var(--k-accent); transform: translateY(-1px); }
.theme-toggle:focus-visible { outline: 3px solid color-mix(in srgb, var(--k-accent) 35%, transparent); outline-offset: 2px; }
.theme-toggle-icon { font-size: 15px; line-height: 1; }
html[data-theme="dark"] body { background: var(--k-bg); color: var(--k-ink); }
/* Public website */
html[data-theme="dark"] .site-header,
html[data-theme="dark"] .site-nav,
html[data-theme="dark"] .mock-window,
html[data-theme="dark"] .floating-note,
html[data-theme="dark"] .feature-card,
html[data-theme="dark"] .plan-card,
html[data-theme="dark"] .page-card,
html[data-theme="dark"] .auth-card,
html[data-theme="dark"] .empty-public,
html[data-theme="dark"] .workflow-card,
html[data-theme="dark"] .faq-item,
html[data-theme="dark"] .device-visual,
html[data-theme="dark"] .about-preview,
html[data-theme="dark"] .trust-grid > *,
html[data-theme="dark"] .notice-panel {
  background: var(--k-surface); color: var(--k-ink); border-color: var(--k-line);
}
html[data-theme="dark"] .intro-band,
html[data-theme="dark"] .mock-caption,
html[data-theme="dark"] .mock-main,
html[data-theme="dark"] .mock-table,
html[data-theme="dark"] .empty-public,
html[data-theme="dark"] .help-layout .page-card { background: var(--k-surface-raised); }
html[data-theme="dark"] .site-header { background: rgba(21, 26, 24, .96); }
html[data-theme="dark"] .site-nav a,
html[data-theme="dark"] .login-link,
html[data-theme="dark"] .page-card h2,
html[data-theme="dark"] .auth-card h2,
html[data-theme="dark"] .inner-hero h1,
html[data-theme="dark"] .hero h1,
html[data-theme="dark"] .section-wrap h2,
html[data-theme="dark"] .brand strong { color: var(--k-ink); }
html[data-theme="dark"] .hero h1 em,
html[data-theme="dark"] .workflow-grid h2 em { color: #a9c8b3; }
html[data-theme="dark"] .hero-lead,
html[data-theme="dark"] .inner-hero > p,
html[data-theme="dark"] .page-card p,
html[data-theme="dark"] .editorial-copy p,
html[data-theme="dark"] .auth-card p,
html[data-theme="dark"] .intro-grid > p:last-child { color: var(--k-muted); }
html[data-theme="dark"] .button-primary { background: #a9c8b3; color: #17231c; }
html[data-theme="dark"] .button-primary:hover { background: #c0d8c7; }
html[data-theme="dark"] .site-footer { background: #101713; }
/* Workspace */
html[data-theme="dark"] .main-content,
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .welcome,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .recent-activity,
html[data-theme="dark"] .quick-actions,
html[data-theme="dark"] .clients-table-container,
html[data-theme="dark"] .client-detail-card,
html[data-theme="dark"] .budget-form-section,
html[data-theme="dark"] #business-editor-content,
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .business-selector-menu,
html[data-theme="dark"] .client-detail-page,
html[data-theme="dark"] .products-page,
html[data-theme="dark"] .clients-page,
html[data-theme="dark"] .budgets-page,
html[data-theme="dark"] .document-module-page,
html[data-theme="dark"] .budget-editor-page,
html[data-theme="dark"] .budget-view-page,
html[data-theme="dark"] .trash-page {
  background-color: var(--k-surface); color: var(--k-ink); border-color: var(--k-line);
}
html[data-theme="dark"] .sidebar { background: var(--k-sidebar); color: var(--k-sidebar-ink); }
html[data-theme="dark"] .topbar { border-bottom-color: var(--k-line); }
html[data-theme="dark"] .welcome p,
html[data-theme="dark"] .stat-label,
html[data-theme="dark"] .stat-card p,
html[data-theme="dark"] .section-heading span,
html[data-theme="dark"] .action-description,
html[data-theme="dark"] .dashboard-empty-state { color: var(--k-muted); }
html[data-theme="dark"] .stat-card h3,
html[data-theme="dark"] .page-header h1,
html[data-theme="dark"] .page-header h2,
html[data-theme="dark"] .client-detail-page .page-header h1 { color: var(--k-accent); }
html[data-theme="dark"] .action-card,
html[data-theme="dark"] .user-profile,
html[data-theme="dark"] .business-selector > button,
html[data-theme="dark"] .business-selector-menu button { background: var(--k-surface-raised); color: var(--k-ink); border-color: var(--k-line); }
html[data-theme="dark"] .action-title { color: var(--k-ink); }
html[data-theme="dark"] th { color: var(--k-muted); border-bottom-color: var(--k-line); }
html[data-theme="dark"] td { color: var(--k-ink); border-bottom-color: var(--k-line); }
html[data-theme="dark"] .form-group input,
html[data-theme="dark"] .form-group select,
html[data-theme="dark"] .form-group textarea,
html[data-theme="dark"] .clients-toolbar input,
html[data-theme="dark"] #product-form input,
html[data-theme="dark"] #product-form select,
html[data-theme="dark"] #product-form textarea,
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]),
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: var(--kosmos-surface); color: var(--kosmos-ink); border-color: var(--kosmos-line);
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: var(--kosmos-muted); }
html[data-theme="dark"] .module-status { background: #403724; color: #e8c98b; }
html[data-theme="dark"] .app-public-link { color: #c4d9cb; }
@media (prefers-reduced-motion: reduce) {
  body, .theme-toggle { transition: none; }
}

/* Final contrast pass for less common workspace and public components. */
html[data-theme="dark"] .main-content h1,
html[data-theme="dark"] .main-content h2,
html[data-theme="dark"] .main-content h3,
html[data-theme="dark"] .main-content label,
html[data-theme="dark"] .main-content legend,
html[data-theme="dark"] .main-content .section-heading h2,
html[data-theme="dark"] .main-content .modal-header h2,
html[data-theme="dark"] .main-content .client-detail-card h2,
html[data-theme="dark"] .main-content .budget-document h1,
html[data-theme="dark"] .main-content .budget-document h2,
html[data-theme="dark"] .main-content .budget-document h3 { color: var(--k-ink); }
html[data-theme="dark"] .main-content .form-group > label,
html[data-theme="dark"] .main-content .form-label,
html[data-theme="dark"] .main-content .page-description,
html[data-theme="dark"] .main-content .muted,
html[data-theme="dark"] .main-content small { color: var(--k-muted); }
html[data-theme="dark"] .main-content .modal,
html[data-theme="dark"] .main-content .modal-content { background: rgba(0,0,0,.55); }
html[data-theme="dark"] .main-content .modal-content { background: var(--k-surface); }
html[data-theme="dark"] .main-content .business-selector-header,
html[data-theme="dark"] .main-content .business-selector-divider { border-color: var(--k-line); color: var(--k-muted); }
html[data-theme="dark"] .main-content .budget-document { background: var(--k-surface); color: var(--k-ink); }
html[data-theme="dark"] .main-content .budget-document table th,
html[data-theme="dark"] .main-content .budget-document table td { border-color: var(--k-line); }
html[data-theme="dark"] .feature-card h3,
html[data-theme="dark"] .plan-card h3,
html[data-theme="dark"] .page-card h2,
html[data-theme="dark"] .editorial-copy h2,
html[data-theme="dark"] .auth-card h2,
html[data-theme="dark"] .empty-public h2 { color: var(--k-ink); }
html[data-theme="dark"] .feature-card p,
html[data-theme="dark"] .plan-card p,
html[data-theme="dark"] .plan-card li,
html[data-theme="dark"] .faq-item p,
html[data-theme="dark"] .workflow-grid p { color: var(--k-muted); }
html[data-theme="dark"] .feature-card a,
html[data-theme="dark"] .text-link { color: var(--k-accent); }
html[data-theme="dark"] .site-nav a { border-color: var(--k-line); }
html[data-theme="dark"] .nav-toggle { background: var(--k-surface); border-color: var(--k-line); }
html[data-theme="dark"] .nav-toggle span { background: var(--k-ink); }
.theme-toggle-public { flex-shrink: 0; }
.theme-toggle-app { flex-shrink: 0; }
@media (max-width: 700px) {
  .theme-toggle { min-height: 36px; padding-inline: 10px; }
  .theme-toggle-app { align-self: flex-end; }
}
