/* DESIGN TOKENS & SYSTEM VARIABLES */
:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Outfit', var(--font-sans);
  --font-mono: 'JetBrains Mono', monospace;

  /* Accent Color Palettes */
  --primary-50: #eef2ff;
  --primary-100: #e0e7ff;
  --primary-400: #818cf8;
  --primary-500: #6366f1;
  --primary-600: #4f46e5;
  --primary-700: #4338ca;

  --success-bg: rgba(16, 185, 129, 0.15);
  --success-text: #10b981;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --warning-text: #f59e0b;
  --info-bg: rgba(59, 130, 246, 0.15);
  --info-text: #3b82f6;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --danger-text: #ef4444;

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-pill: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.25);

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* DARK THEME (DEFAULT) */
:root,
:root[data-theme="dark"],
[data-theme="dark"] {
  color-scheme: dark;
  --bg-app: #0b0f19;
  --bg-sidebar: #0e1322;
  --bg-surface: #141b2d;
  --bg-surface-elevated: #1a233a;
  --bg-surface-hover: #212c48;
  --bg-input: #121827;

  --border-subtle: #1e293b;
  --border-medium: #2a374f;
  --border-focus: #6366f1;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #0b0f19;

  --grid-line: #1c2538;
  --table-header-bg: #111728;
}

/* LIGHT THEME */
:root[data-theme="light"],
[data-theme="light"] {
  color-scheme: light;
  --bg-app: #f4f6fa;
  --bg-sidebar: #ffffff;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f8fafc;
  --bg-surface-hover: #eef2f6;
  --bg-input: #ffffff;

  --border-subtle: #e2e8f0;
  --border-medium: #cbd5e1;
  --border-focus: #6366f1;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-inverse: #ffffff;

  --grid-line: #e2e8f0;
  --table-header-bg: #f1f5f9;
}

/* GLOBAL CUSTOM SCROLLBARS */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-surface, #141b2d);
}

::-webkit-scrollbar-thumb {
  background: var(--border-medium, #2a374f);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-500, #6366f1);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-medium, #2a374f) var(--bg-surface, #141b2d);
}

[data-theme="light"] ::-webkit-scrollbar-track {
  background: var(--bg-surface, #ffffff);
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: var(--border-medium, #cbd5e1);
}

[data-theme="light"] * {
  scrollbar-color: var(--border-medium, #cbd5e1) var(--bg-surface, #ffffff);
}

/* BASE RESETS */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  cursor: default;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

[data-theme="dark"] select,
[data-theme="dark"] option,
[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] datalist {
  color-scheme: dark;
}

[data-theme="light"] select,
[data-theme="light"] option,
[data-theme="light"] input,
[data-theme="light"] textarea,
[data-theme="light"] datalist {
  color-scheme: light;
}

select {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xs);
}

select option {
  background-color: var(--bg-surface);
  color: var(--text-primary);
  padding: 8px 12px;
}

select:focus,
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* Native datalist picker arrow styling */
input::-webkit-calendar-picker-indicator {
  filter: invert(0.8);
  cursor: pointer;
  opacity: 0.7;
}

input::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}

/* APP SHELL LAYOUT */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* SIDEBAR */
.app-sidebar {
  width: 250px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform var(--transition-normal);
  z-index: 40;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary-500), #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.brand-text {
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  background: linear-gradient(to right, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  background: var(--primary-600);
  color: #ffffff;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.db-status-pill {
  margin: 12px 16px 4px 16px;
  padding: 6px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}

.status-dot.warning {
  background: #f59e0b;
  box-shadow: 0 0 6px #f59e0b;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  padding: 12px 10px 4px 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: all var(--transition-fast);
  position: relative;
}

.nav-item:hover {
  background-color: var(--bg-surface-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background-color: var(--bg-surface-elevated);
  color: var(--primary-400);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background-color: var(--primary-500);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-counter {
  margin-left: auto;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg-surface-hover);
  color: var(--text-secondary);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
}

.nav-counter.badge-accent {
  background: rgba(99, 102, 241, 0.2);
  color: var(--primary-400);
}

.nav-badge-pill {
  margin-left: auto;
  font-size: 0.65rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary-500), #ec4899);
  color: #fff;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border-subtle);
  background-color: var(--bg-sidebar);
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary-400);
}

.user-meta {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

.user-role {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* MAIN AREA */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background-color: var(--bg-app);
}

/* HEADER */
.app-header {
  height: 52px;
  background-color: var(--bg-sidebar);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 30;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.mobile-toggle {
  display: none;
}

.theme-icon-dark,
.theme-icon-light {
  pointer-events: none;
}

[data-theme="dark"] .theme-icon-dark {
  display: block;
}
[data-theme="dark"] .theme-icon-light {
  display: none;
}
[data-theme="light"] .theme-icon-dark {
  display: none;
}
[data-theme="light"] .theme-icon-light {
  display: block;
}

[data-theme="light"] input::-webkit-calendar-picker-indicator {
  filter: none;
  opacity: 0.6;
}

/* VIEW CONTAINER */
.app-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px;
  background-color: var(--bg-app);
  position: relative;
}

/* RESPONSIVE BREAKPOINTS */
@media (max-width: 900px) {
  .app-header {
    height: 52px;
    background-color: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    padding: 0 16px;
    z-index: 30;
    flex-shrink: 0;
  }
  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .app-sidebar.open {
    transform: translateX(0);
  }
  .mobile-toggle {
    display: flex;
  }
}

/* ============================================================
   FINAL SAFE CURSOR OVERRIDE (GLOBAL)
   ============================================================ */

/* 1. All non-editable content by default: normal arrow cursor & no text caret */
*,
*::before,
*::after {
  cursor: default;
  caret-color: transparent;
}

html,
body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
span,
label,
div,
section,
article,
main,
header,
footer,
nav,
aside,
table,
thead,
tbody,
tr,
th,
td,
li,
small,
strong,
b,
em {
  cursor: default;
  caret-color: transparent;
}

button,
a,
[role="button"],
.clickable {
  cursor: pointer;
}

/* Ensure buttons, links and clickable containers keep pointer on all child elements */
button *,
a *,
[role="button"] *,
.clickable *,
.btn,
.btn *,
.icon-button,
.icon-button *,
.nav-item,
.nav-item *,
.workbook-card,
.workbook-card *,
.recipe-card,
.recipe-card *,
.kanban-card,
.kanban-card *,
.wb-back-btn,
.wb-back-btn *,
.table-tab-btn,
.table-tab-btn *,
.table-tab-add-btn,
.table-tab-add-btn *,
.tab-close-btn,
.tab-close-btn *,
.col-menu-trigger,
.col-menu-trigger *,
.col-dropdown-item,
.col-dropdown-item *,
.btn-add-col-header,
.btn-add-col-header *,
.toggle-mode-btn,
.toggle-mode-btn *,
.org-name-click,
.org-name-click *,
.history-org-name-click,
.history-org-name-click *,
.campaign-history-badge,
.campaign-history-badge *,
.org-type-suggestion-row,
.org-type-suggestion-row *,
.country-suggestion-row,
.country-suggestion-row *,
.state-suggestion-row,
.state-suggestion-row *,
.export-menu-item,
.export-menu-item * {
  cursor: pointer;
}

/* Actual editable inputs and form fields ONLY */
input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]):not([type="image"]),
textarea,
[contenteditable="true"] {
  cursor: text;
  caret-color: auto;
}

/* Protect links, buttons, and badges inside editable table cells from inheriting text cursor */
[contenteditable="true"] a,
[contenteditable="true"] a *,
.cell-editable a,
.cell-editable a * {
  cursor: pointer !important;
}

[contenteditable="true"] .wb-tag,
[contenteditable="true"] .badge,
[contenteditable="true"] .cell-star-rating,
.cell-editable .wb-tag,
.cell-editable .badge,
.cell-editable .cell-star-rating {
  cursor: default !important;
}

/* Checkbox, radio, and button-like inputs */
input[type="checkbox"],
input[type="radio"],
input[type="button"],
input[type="submit"],
input[type="reset"],
input[type="file"],
input[type="range"],
input[type="color"] {
  cursor: pointer;
}

select,
select * {
  cursor: pointer;
}

/* Disabled elements */
:disabled,
:disabled *,
[disabled],
[disabled] *,
.disabled,
.disabled * {
  cursor: not-allowed;
}
