/* ========================================
   tersOS Core — Variables, Reset, Typography
   ======================================== */

/* ---- Design Tokens ---- */
:root {
  /* Brand */
  --ui-primary: #e173f6;
  --ui-primary-hover: #d75bef;
  --ui-primary-subtle: rgba(225, 115, 246, 0.1);
  --ui-accent: #f8dc5b;
  --ui-dark: #21222c;

  /* Semantic */
  --ui-success: #10b981;
  --ui-warning: #f8dc5b;
  --ui-danger: #ef4444;
  --ui-info: #06b6d4;

  /* Neutral interactive (tabs, filter chips, sidebar active in light mode) */
  --ui-interactive: rgba(0, 0, 0, 0.06);
  --ui-interactive-hover: rgba(0, 0, 0, 0.10);

  /* Chart palette (brand-aligned) */
  --chart-1: #e173f6;
  --chart-2: #f8dc5b;
  --chart-3: #34d399;
  --chart-4: #60a5fa;
  --chart-5: #818cf8;
  --chart-6: #fb923c;

  /* Text */
  --ui-text: #212529;
  --ui-text-secondary: #495057;
  --ui-text-muted: rgba(0, 0, 0, 0.5);
  --ui-text-faint: rgba(0, 0, 0, 0.35);

  /* Backgrounds (warm off-white for light mode) */
  --ui-bg: #fafaf9;
  --ui-bg-body: #fafaf9;
  --ui-surface: rgba(255, 255, 255, 0.7);
  --ui-surface-solid: #ffffff;
  --ui-surface-hover: rgba(255, 255, 255, 0.9);

  /* Borders */
  --ui-border: rgba(0, 0, 0, 0.08);
  --ui-border-subtle: rgba(0, 0, 0, 0.04);
  --ui-border-strong: rgba(0, 0, 0, 0.15);

  /* Overlays */
  --ui-overlay: rgba(0, 0, 0, 0.05);
  --ui-overlay-hover: rgba(0, 0, 0, 0.08);

  /* Dropdowns */
  --ui-dropdown-bg: #ffffff;
  --ui-dropdown-border: rgba(0, 0, 0, 0.1);
  --ui-dropdown-hover: #e9ecef;
  --ui-dropdown-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);

  /* Tables */
  --ui-table-header-bg: #f8f9fa;
  --ui-table-hover-bg: #f8f9fa;
  --ui-table-border: rgba(0, 0, 0, 0.06);

  /* Effects */
  --ui-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --ui-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --ui-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);

  /* Shape */
  --ui-radius: 8px;
  --ui-radius-lg: 8px;

  /* RGB components for rgba() usage */
  --ui-primary-rgb: 225, 115, 246;
  --ui-accent-rgb: 248, 220, 91;
  --ui-success-rgb: 16, 185, 129;
  --ui-danger-rgb: 239, 68, 68;
  --ui-warning-rgb: 248, 220, 91;
  --ui-info-rgb: 6, 182, 212;

  /* Sidebar (always dark, independent of theme) */
  --sidebar-bg: #0f0f0f;
  --sidebar-text: rgba(255, 255, 255, 0.7);
  --sidebar-text-muted: rgba(255, 255, 255, 0.4);
  --sidebar-active-bg: #F8DC5B;
  --sidebar-active-text: #0f0f0f;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.06);
  --sidebar-border: rgba(255, 255, 255, 0.06);

  /* Status colors */
  --status-draft: #94a3b8;
  --status-created: #60a5fa;
  --status-sent: #818cf8;
  --status-pending: #fbbf24;
  --status-active: #34d399;
  --status-paid: #10b981;
  --status-overdue: #f87171;
  --status-cancelled: #6b7280;
  --status-declined: #ef4444;
  --status-picked-up: #10b981;
  --status-incoming: #60a5fa;

  /* Space Map */
  --map-available: #22c55e;
  --map-permanent: #3b82f6;
  --map-flex: #f59e0b;
  --map-meeting: #e173f6;
  --map-event: #8b5cf6;

  /* Font families */
  --ui-font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --ui-font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;

  /* Typography scale */
  --text-2xs: 0.625rem;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-lg: 1rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.75rem;
  --text-4xl: 2rem;

  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
}

[data-theme="dark"] {
  /* Our tokens */
  --ui-text: #ffffff;
  --ui-text-secondary: #e0e0e0;
  --ui-text-muted: rgba(255, 255, 255, 0.5);
  --ui-text-faint: rgba(255, 255, 255, 0.35);

  --ui-interactive: rgba(255, 255, 255, 0.08);
  --ui-interactive-hover: rgba(255, 255, 255, 0.14);

  --ui-bg: #0f0f0f;
  --ui-bg-body: #1a1a1a;
  --ui-surface: rgba(33, 34, 44, 0.72);
  --ui-surface-solid: #21222c;
  --ui-surface-hover: rgba(33, 34, 44, 0.92);

  --ui-border: rgba(255, 255, 255, 0.08);
  --ui-border-subtle: rgba(255, 255, 255, 0.04);
  --ui-border-strong: rgba(255, 255, 255, 0.15);

  --ui-overlay: rgba(255, 255, 255, 0.05);
  --ui-overlay-hover: rgba(255, 255, 255, 0.08);

  --ui-dropdown-bg: #2a2b35;
  --ui-dropdown-border: rgba(255, 255, 255, 0.1);
  --ui-dropdown-hover: rgba(255, 255, 255, 0.1);
  --ui-dropdown-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);

  --ui-table-header-bg: rgba(255, 255, 255, 0.05);
  --ui-table-hover-bg: rgba(255, 255, 255, 0.05);
  --ui-table-border: rgba(255, 255, 255, 0.08);

  --ui-primary-subtle: rgba(225, 115, 246, 0.12);
  --ui-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --ui-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.35);
  --ui-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.45);

  /* Override Bootstrap's own variables so everything cascades */
  --bs-body-bg: #1a1a1a;
  --bs-body-color: #e0e0e0;
  --bs-card-bg: rgba(33, 34, 44, 0.72);
  --bs-card-border-color: rgba(255, 255, 255, 0.08);
  --bs-table-bg: transparent;
  --bs-table-color: #e0e0e0;
  --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
  --bs-table-hover-bg: rgba(255, 255, 255, 0.05);
  --bs-table-border-color: rgba(255, 255, 255, 0.08);
  --bs-border-color: rgba(255, 255, 255, 0.08);
  --bs-secondary-bg: rgba(255, 255, 255, 0.06);
  --bs-tertiary-bg: rgba(255, 255, 255, 0.04);
  --bs-modal-bg: #21222c;
  --bs-heading-color: #ffffff;
  --bs-light-rgb: 33, 34, 44;
  --bs-dark-rgb: 255, 255, 255;
  --bs-link-color: #e173f6;
  --bs-link-hover-color: #d75bef;
  color-scheme: dark;
}


/* ---- Reset & Globals ---- */

::selection {
  background: var(--ui-dark);
  color: #fff;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ui-accent); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #e6c94f; }
::-webkit-scrollbar-corner { background: transparent; }
* { scrollbar-width: thin; scrollbar-color: var(--ui-accent) transparent; }

.bi, [class^="bi-"], [class*=" bi-"] {
  vertical-align: middle;
  line-height: 1;
}

body {
  background: var(--ui-bg-body);
  color: var(--ui-text-secondary);
  font-family: var(--ui-font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Monospace override for Bootstrap's .font-monospace */
.font-monospace, code, kbd, pre, samp {
  font-family: var(--ui-font-mono) !important;
}

main {
  color: var(--ui-text-secondary);
  padding-bottom: 3rem;
  min-height: calc(100vh - 200px);
}

h1, h2, h3, h4, h5, h6 {
  color: var(--ui-text);
  font-weight: 600;
}

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


/* ---- Typography ---- */

main h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

main h2 {
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.3;
}

main h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.3;
}

main h4 {
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.4;
}

main h5 {
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.4;
}

main h6 {
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.4;
}


/* ---- Links ---- */

.ui-link {
  color: var(--ui-primary);
  text-decoration: none;
  font-weight: 600;
}

.ui-link:hover {
  color: var(--ui-primary-hover);
}

/* No blue links inside UI components */
.ui-card a,
.ui-table a,
.ui-tab-btn,
.ui-stat-card a,
.ui-list a,
.ui-modal a:not(.btn) {
  color: inherit;
  text-decoration: none;
}

.ui-card a:hover,
.ui-table a:hover,
.ui-stat-card a:hover,
.ui-list a:hover {
  color: var(--ui-primary);
}

/* Global anchor reset — no underlines, inherit color */
a {
  text-decoration: none;
  color: inherit;
}

a:hover {
  text-decoration: none;
  color: inherit;
}

/* Explicit links — only when you WANT pink link styling */
.ui-link,
main a[href^="mailto:"],
main a[href^="tel:"] {
  color: var(--ui-primary);
}

.ui-link:hover,
main a[href^="mailto:"]:hover,
main a[href^="tel:"]:hover {
  color: var(--ui-primary-hover);
}

/* Icon action links */
.icon-action,
a.icon-action,
a.icon-action i {
  color: var(--ui-text);
  transition: color 0.15s ease;
}

a.icon-action:hover,
a.icon-action:hover i {
  color: var(--ui-primary);
}


/* ---- Animation ---- */

@keyframes uiFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.ui-card, .ui-stat-card, .ui-alert {
  animation: uiFadeIn 0.3s ease-out forwards;
}

@media (prefers-reduced-motion: reduce) {
  .ui-card, .ui-stat-card, .ui-alert {
    animation: none;
  }
}


/* ---- Bootstrap Overrides (using variables) ---- */

/* Brand color overrides */
.text-primary { color: var(--ui-primary) !important; }
.bg-primary { background-color: var(--ui-primary) !important; }

/* Borders */
.border, hr {
  border-color: var(--ui-border);
}

/* Dropdowns */
.dropdown-menu {
  background: var(--ui-dropdown-bg);
  border: 1px solid var(--ui-dropdown-border);
  box-shadow: var(--ui-dropdown-shadow);
  color: var(--ui-text);
}

.dropdown-item {
  color: var(--ui-text);
  display: flex;
  align-items: center;
}

.dropdown-item i,
.dropdown-item svg {
  color: inherit;
}

.dropdown-item:hover,
.dropdown-item:focus {
  background: var(--ui-dropdown-hover);
  color: var(--ui-text);
}

.dropdown-divider {
  border-color: var(--ui-border);
}

/* Tables (Bootstrap) */
.table {
  color: var(--ui-text-secondary);
  --bs-table-bg: transparent;
  --bs-table-striped-bg: transparent;
  --bs-table-hover-bg: var(--ui-table-hover-bg);
}

.table > thead > tr > th {
  background: var(--ui-table-header-bg);
  color: var(--ui-text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--ui-border);
}

.table > tbody > tr {
  border-bottom: 1px solid var(--ui-table-border);
}

.table > tbody > tr > td {
  background: var(--ui-surface);
  color: var(--ui-text-secondary);
  vertical-align: middle;
}

.table-hover > tbody > tr:hover > td {
  background: var(--ui-table-hover-bg);
}

/* Cards (Bootstrap) */
.card {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-lg);
  position: relative;
  z-index: 1;
  overflow: hidden;
  isolation: isolate;
}

.card::before, .card::after {
  display: none;
  content: none;
}

.card > * {
  position: relative;
  z-index: 2;
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--ui-border);
}

.card-footer {
  background: transparent;
  border-top: 1px solid var(--ui-border);
}

.card-title {
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--ui-text-muted);
}

/* Forms (Bootstrap) */
.form-control, .form-select {
  border-color: var(--ui-border-strong);
  background-color: var(--ui-surface-solid);
  color: var(--ui-text);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.form-control:focus, .form-select:focus {
  border-color: var(--ui-primary);
  box-shadow: 0 0 0 3px rgba(var(--ui-primary-rgb), 0.15);
  outline: none;
}

.form-control::placeholder {
  color: var(--ui-text-faint);
}

/* Buttons (Bootstrap) */
.btn {
  border-radius: var(--ui-radius);
  font-weight: 500;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--ui-primary);
  border-color: var(--ui-primary);
}

.btn-primary:hover {
  background: var(--ui-primary-hover);
  border-color: var(--ui-primary-hover);
}

/* Alerts (Bootstrap) */
.alert {
  border-radius: var(--ui-radius);
  border: none;
}

/* Modals */
.modal-content {
  background: var(--ui-surface-solid);
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.modal-header { border-bottom-color: var(--ui-border); }
.modal-footer { border-top-color: var(--ui-border); gap: 0.5rem; }

[data-theme="dark"] .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}

/* Bootstrap bg-body fix */
[data-theme="dark"] .bg-body-secondary {
  background-color: rgba(255, 255, 255, 0.06) !important;
}
[data-theme="dark"] .bg-body-tertiary {
  background-color: rgba(255, 255, 255, 0.04) !important;
}


/* ---- Minimal dark-mode-only fixes ---- */
/* Only for things variables can't handle (Bootstrap !important conflicts) */

[data-theme="dark"] header {
  border-bottom: none;
  border-top: none;
}

/* Button groups & outline buttons in dark mode */
[data-theme="dark"] .btn-outline-secondary,
[data-theme="dark"] .btn-outline-primary,
[data-theme="dark"] .btn-outline-light,
[data-theme="dark"] .btn-light {
  color: var(--ui-text-secondary);
  border-color: rgba(255, 255, 255, 0.15);
  background: transparent;
}

[data-theme="dark"] .btn-outline-secondary:hover,
[data-theme="dark"] .btn-outline-primary:hover,
[data-theme="dark"] .btn-outline-light:hover,
[data-theme="dark"] .btn-light:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
}

[data-theme="dark"] .btn-outline-secondary.active,
[data-theme="dark"] .btn-outline-primary.active,
[data-theme="dark"] .btn-check:checked + .btn-outline-secondary,
[data-theme="dark"] .btn-check:checked + .btn-outline-primary,
[data-theme="dark"] .btn-check:checked + .btn {
  background: var(--ui-primary);
  border-color: var(--ui-primary);
  color: #000;
}

[data-theme="dark"] .btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--ui-text-secondary);
}

[data-theme="dark"] .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

/* Icon buttons with light background */
[data-theme="dark"] .btn-light,
[data-theme="dark"] .btn[class*="btn-outline"] {
  --bs-btn-bg: transparent;
  --bs-btn-hover-bg: rgba(255, 255, 255, 0.1);
}

/* Input groups in dark mode */
[data-theme="dark"] .input-group-text {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.7);
}

/* Button group borders */
[data-theme="dark"] .btn-group .btn {
  border-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .btn-group .btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

/* Calendar resource cards with inline background-color */
.card[style*="background-color"] {
  background-color: inherit !important;
}
.card[style*="background-color"] .card-body {
  background-color: transparent !important;
  color: #fff !important;
}
.card[style*="background-color"] * {
  color: #fff !important;
}


/* ---- Utilities ---- */

.ui-text-primary { color: var(--ui-primary); }
.ui-text-accent { color: var(--ui-accent); }
.ui-pre-wrap { white-space: pre-wrap; }
.ui-icon-circle-sm { width: 32px; height: 32px; }

.ui-input.input-uppercase, input.input-uppercase { text-transform: uppercase; }
.ui-input.input-w-sm { width: 150px; }
.ui-input.input-w-md { width: 200px; }
.ui-input.input-w-lg { width: 300px; }

#themeSwitcher {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
}

/* Content containment */
main > * { max-width: 100%; }
main .table-responsive { max-width: 100%; overflow-x: auto; }
