/* ========================================
   TRIDENT COMMAND CENTER — Design Tokens
   Dark theme default with light toggle
   ======================================== */

:root {
  /* Type Scale */
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);

  /* Spacing */
  --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;
  --space-16: 4rem;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Content widths */
  --content-narrow: 640px;
  --content-default: 960px;
  --content-wide: 1200px;

  /* Fonts */
  --font-body: 'Satoshi', 'Inter', sans-serif;
  --font-display: 'Satoshi', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
}

/* ====== DARK MODE (Default) ====== */
:root, [data-theme="dark"] {
  --color-bg:             #0f1117;
  --color-surface:        #161822;
  --color-surface-2:      #1c1e2e;
  --color-surface-offset: #1a1c2a;
  --color-surface-offset-2: #22243a;
  --color-surface-dynamic: #282a40;
  --color-divider:        #2a2d42;
  --color-border:         #333654;
  --color-text:           #e0e1e8;
  --color-text-muted:     #8b8fa5;
  --color-text-faint:     #565b73;
  --color-text-inverse:   #0f1117;

  /* Trident Teal — primary */
  --color-primary:        #38bec9;
  --color-primary-hover:  #2da0a9;
  --color-primary-active: #268890;
  --color-primary-highlight: #1a3a40;
  --color-primary-glow:   rgba(56, 190, 201, 0.12);

  /* Success */
  --color-success:        #4ade80;
  --color-success-hover:  #22c55e;
  --color-success-bg:     rgba(74, 222, 128, 0.1);

  /* Warning */
  --color-warning:        #fbbf24;
  --color-warning-hover:  #f59e0b;
  --color-warning-bg:     rgba(251, 191, 36, 0.1);

  /* Error */
  --color-error:          #f87171;
  --color-error-hover:    #ef4444;
  --color-error-bg:       rgba(248, 113, 113, 0.1);

  /* Chart colors */
  --chart-1: #38bec9;
  --chart-2: #818cf8;
  --chart-3: #fb923c;
  --chart-4: #4ade80;
  --chart-5: #f472b6;
  --chart-6: #fbbf24;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
}

/* ====== LIGHT MODE ====== */
[data-theme="light"] {
  --color-bg:             #f4f5f7;
  --color-surface:        #ffffff;
  --color-surface-2:      #fafbfc;
  --color-surface-offset: #eef0f4;
  --color-surface-offset-2: #e4e7ed;
  --color-surface-dynamic: #dbe0e8;
  --color-divider:        #d0d5df;
  --color-border:         #c0c6d4;
  --color-text:           #1a1d2e;
  --color-text-muted:     #6b7088;
  --color-text-faint:     #9ea3b5;
  --color-text-inverse:   #ffffff;

  --color-primary:        #0e8a93;
  --color-primary-hover:  #0a6f77;
  --color-primary-active: #085a60;
  --color-primary-highlight: #d0f0f3;
  --color-primary-glow:   rgba(14, 138, 147, 0.08);

  --color-success:        #16a34a;
  --color-success-hover:  #15803d;
  --color-success-bg:     rgba(22, 163, 74, 0.08);

  --color-warning:        #d97706;
  --color-warning-hover:  #b45309;
  --color-warning-bg:     rgba(217, 119, 6, 0.08);

  --color-error:          #dc2626;
  --color-error-hover:    #b91c1c;
  --color-error-bg:       rgba(220, 38, 38, 0.08);

  --chart-1: #0e8a93;
  --chart-2: #6366f1;
  --chart-3: #ea580c;
  --chart-4: #16a34a;
  --chart-5: #db2777;
  --chart-6: #ca8a04;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --color-bg:             #f4f5f7;
    --color-surface:        #ffffff;
    --color-surface-2:      #fafbfc;
    --color-surface-offset: #eef0f4;
    --color-surface-offset-2: #e4e7ed;
    --color-surface-dynamic: #dbe0e8;
    --color-divider:        #d0d5df;
    --color-border:         #c0c6d4;
    --color-text:           #1a1d2e;
    --color-text-muted:     #6b7088;
    --color-text-faint:     #9ea3b5;
    --color-text-inverse:   #ffffff;
    --color-primary:        #0e8a93;
    --color-primary-hover:  #0a6f77;
    --color-primary-active: #085a60;
    --color-primary-highlight: #d0f0f3;
    --color-primary-glow:   rgba(14, 138, 147, 0.08);
    --color-success:        #16a34a;
    --color-success-hover:  #15803d;
    --color-success-bg:     rgba(22, 163, 74, 0.08);
    --color-warning:        #d97706;
    --color-warning-hover:  #b45309;
    --color-warning-bg:     rgba(217, 119, 6, 0.08);
    --color-error:          #dc2626;
    --color-error-hover:    #b91c1c;
    --color-error-bg:       rgba(220, 38, 38, 0.08);
    --chart-1: #0e8a93;
    --chart-2: #6366f1;
    --chart-3: #ea580c;
    --chart-4: #16a34a;
    --chart-5: #db2777;
    --chart-6: #ca8a04;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
  }
}

/* ========================================
   LAYOUT — Dashboard Shell
   ======================================== */

html, body { height: 100%; overflow: hidden; margin: 0; }

.dashboard {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 56px 1fr;
  height: 100dvh;
}

/* Sidebar */
.sidebar {
  grid-row: 1 / -1;
  background: var(--color-surface);
  border-right: 1px solid var(--color-divider);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 20;
}

.sidebar-logo {
  padding: var(--space-5) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  min-height: 56px;
}

.sidebar-logo svg { flex-shrink: 0; }

.sidebar-logo-text {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
}

.sidebar-logo-sub {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 400;
}

.sidebar-nav {
  padding: var(--space-3) var(--space-3);
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.sidebar-section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-4) var(--space-3) var(--space-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  cursor: pointer;
  transition: all var(--transition-interactive);
}

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

.nav-item.active {
  background: var(--color-primary-highlight);
  color: var(--color-primary);
  font-weight: 600;
}

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

.sidebar-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--color-divider);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* Header */
.header {
  grid-column: 2;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.header-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
}

.header-breadcrumb {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.header-date {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.theme-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: all var(--transition-interactive);
}

.theme-toggle:hover {
  background: var(--color-surface-dynamic);
  color: var(--color-text);
}

/* Main content */
.main {
  grid-column: 2;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

/* ========================================
   COMPONENTS
   ======================================== */

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  transition: border-color var(--transition-interactive), box-shadow var(--transition-interactive);
}

.kpi-card:hover {
  border-color: var(--color-border);
  box-shadow: var(--shadow-md);
}

.kpi-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
  font-variant-numeric: tabular-nums lining-nums;
  line-height: 1;
}

.kpi-delta {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 500;
}

.kpi-delta.up { color: var(--color-success); }
.kpi-delta.down { color: var(--color-error); }
.kpi-delta.flat { color: var(--color-text-faint); }

.kpi-delta svg { width: 14px; height: 14px; }

/* Section Cards */
.section-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-divider);
}

.section-title {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--color-text);
}

.section-body {
  padding: var(--space-5);
}

/* Chart containers */
.chart-container {
  position: relative;
  width: 100%;
  height: 280px;
}

.chart-container-sm {
  height: 200px;
}

/* Two-column grid */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-6);
}

/* Tables */
.data-table {
  width: 100%;
  font-size: var(--text-sm);
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-weight: 600;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--color-surface-offset);
  border-bottom: 1px solid var(--color-divider);
}

.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  color: var(--color-text);
  font-variant-numeric: tabular-nums lining-nums;
}

.data-table tbody tr {
  transition: background var(--transition-interactive);
}

.data-table tbody tr:hover {
  background: var(--color-primary-glow);
}

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

/* ── Client Table (fixed layout, no wrap) ── */
.client-table {
  table-layout: fixed;
}
.client-table th,
.client-table td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Column Resize Handle ───────────────── */
.col-resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: col-resize;
  background: transparent;
  transition: background 0.15s;
  z-index: 2;
}
.col-resize-handle:hover,
.col-resize-handle:active {
  background: var(--color-primary);
}

/* ── Settings Gear Button ───────────────── */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover,
.btn-icon.active {
  background: var(--color-primary-glow);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* ── Column Settings Panel ──────────────── */
.col-settings-panel {
  border-top: 1px solid var(--color-divider);
  border-bottom: 1px solid var(--color-divider);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-offset);
  animation: dropIn 0.15s ease;
}
.col-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}
.col-settings-reset {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: none;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.col-settings-reset:hover {
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.col-settings-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}
.col-settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 180px;
}

/* Toggle switch */
.col-toggle {
  position: relative;
  display: inline-flex;
  width: 32px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
}
.col-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}
.col-toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--color-divider);
  border-radius: 999px;
  transition: background 0.2s;
}
.col-toggle-slider::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-text-muted);
  transition: transform 0.2s, background 0.2s;
}
.col-toggle input:checked + .col-toggle-slider {
  background: var(--color-primary);
}
.col-toggle input:checked + .col-toggle-slider::before {
  transform: translateX(14px);
  background: var(--color-bg);
}

/* Column name input */
.col-settings-name {
  width: 110px;
  padding: 3px 6px;
  font-size: var(--text-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  transition: border-color 0.15s;
}
.col-settings-name:focus {
  outline: none;
  border-color: var(--color-primary);
}
.col-settings-hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  opacity: 0.6;
}

/* Add Column Section */
.col-settings-add-section {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-divider);
}
.btn-add-column {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  color: var(--color-primary);
  background: none;
  border: 1px dashed var(--color-primary);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-add-column:hover {
  background: color-mix(in srgb, var(--color-primary) 10%, transparent);
}
.col-add-form {
  animation: dropIn 0.15s ease;
}
.col-add-form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.col-add-form-row input,
.col-add-form-row select {
  padding: 6px 10px;
  font-size: var(--text-sm);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  transition: border-color 0.15s;
}
.col-add-form-row input:focus,
.col-add-form-row select:focus {
  outline: none;
  border-color: var(--color-primary);
}
.col-add-name {
  flex: 1;
  min-width: 160px;
}
.col-add-type {
  width: 110px;
}
.col-add-form-actions {
  display: flex;
  gap: 8px;
}
.col-add-save {
  font-size: var(--text-sm);
  padding: 6px 16px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.15s;
}
.col-add-save:hover {
  opacity: 0.85;
}
.col-add-save:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.col-add-cancel {
  font-size: var(--text-sm);
  padding: 6px 12px;
  background: none;
  color: var(--color-text-muted);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.col-add-cancel:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

/* Custom column indicator in settings grid */
.col-settings-row .col-custom-badge {
  font-size: 9px;
  background: color-mix(in srgb, var(--color-primary) 15%, transparent);
  color: var(--color-primary);
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* ── Client Search ───────────────────── */
.client-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.client-search-icon {
  position: absolute;
  left: 10px;
  color: var(--color-text-muted);
  pointer-events: none;
}
.client-search {
  padding: 6px 10px 6px 30px;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  width: 200px;
  transition: border-color 0.2s, width 0.3s;
}
.client-search:focus {
  outline: none;
  border-color: var(--color-primary);
  width: 260px;
}
.client-search::placeholder {
  color: var(--color-text-muted);
}

/* ── Sortable Table Headers ────────────── */
.data-table th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  white-space: nowrap;
  transition: color 0.15s;
}
.data-table th.sortable:hover {
  color: var(--color-text);
}
.sort-icon {
  display: inline-block;
  width: 12px;
  margin-left: 2px;
  font-size: 10px;
  opacity: 0.3;
  vertical-align: middle;
  transition: opacity 0.15s;
}
.sort-icon::after {
  content: "⇅";
}
th.sortable:hover .sort-icon {
  opacity: 0.6;
}
th.sort-asc .sort-icon {
  opacity: 1;
}
th.sort-asc .sort-icon::after {
  content: "▲";
}
th.sort-desc .sort-icon {
  opacity: 1;
}
th.sort-desc .sort-icon::after {
  content: "▼";
}

/* Filterable column indicator */
.data-table th.filterable {
  padding-right: var(--space-5);
}
.data-table th.filterable::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 4px solid var(--color-text-muted);
  opacity: 0.4;
  transition: opacity 0.15s;
}
.data-table th.filterable:hover::after {
  opacity: 0.8;
}
.data-table th.filterable.filter-active::after {
  border-top-color: var(--color-primary);
  opacity: 1;
}

/* ── Filter Chips Bar ──────────────────── */
.client-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 var(--space-4);
  min-height: 0;
  transition: padding 0.2s;
}
.client-filters:not(:empty) {
  padding: var(--space-2) var(--space-4) var(--space-3);
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px 10px;
  font-size: var(--text-xs);
  background: var(--color-primary-glow);
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  border-radius: 999px;
  cursor: default;
  animation: chipIn 0.2s ease;
}
@keyframes chipIn {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: scale(1); }
}
.filter-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--color-primary);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s;
}
.filter-chip-remove:hover {
  background: var(--color-primary);
  color: var(--color-bg);
}

/* ── Filter Dropdown ───────────────────── */
.filter-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  min-width: 160px;
  max-height: 260px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  z-index: 100;
  padding: 4px 0;
  animation: dropIn 0.15s ease;
}
@keyframes dropIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.filter-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: var(--text-sm);
  color: var(--color-text);
  cursor: pointer;
  transition: background 0.1s;
}
.filter-dropdown-item:hover {
  background: var(--color-primary-glow);
}
.filter-dropdown-item.active {
  color: var(--color-primary);
  font-weight: 600;
}
.filter-dropdown-item .check-mark {
  width: 14px;
  font-size: 12px;
  color: var(--color-primary);
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-error   { background: var(--color-error-bg);   color: var(--color-error); }
.badge-primary { background: var(--color-primary-glow); color: var(--color-primary); }
.badge-muted   { background: var(--color-surface-offset); color: var(--color-text-muted); }
.badge-danger  { background: var(--color-error-bg);   color: var(--color-error); }

/* KPI change indicator */
.kpi-change {
  font-size: var(--text-xs);
  font-weight: 600;
}
.kpi-change.positive { color: var(--color-success); }
.kpi-change.negative { color: var(--color-error); }

/* Content calendar */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--color-divider);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.calendar-header-cell {
  padding: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-align: center;
  background: var(--color-surface-offset);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.calendar-cell {
  background: var(--color-surface);
  padding: var(--space-2);
  min-height: 80px;
  font-size: var(--text-xs);
  position: relative;
}

.calendar-cell.outside {
  background: var(--color-surface-offset);
  opacity: 0.5;
}

.calendar-cell.today {
  background: var(--color-primary-glow);
}

.calendar-day {
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}

.calendar-event {
  padding: 2px var(--space-1);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 500;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: default;
}

.calendar-event.linkedin-personal {
  background: rgba(56, 190, 201, 0.2);
  color: var(--color-primary);
  border-left: 2px solid var(--color-primary);
}

.calendar-event.linkedin-company {
  background: rgba(129, 140, 248, 0.2);
  color: var(--chart-2);
  border-left: 2px solid var(--chart-2);
}

.calendar-event.facebook {
  background: rgba(251, 191, 36, 0.2);
  color: var(--chart-6);
  border-left: 2px solid var(--chart-6);
}

/* Pipeline stages */
.pipeline-stage {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
}

.pipeline-bar-track {
  flex: 1;
  height: 8px;
  background: var(--color-surface-offset);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.pipeline-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 600ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Quick links */
.quick-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
}

.quick-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-offset);
  border-radius: var(--radius-md);
  color: var(--color-text);
  text-decoration: none;
  font-size: var(--text-sm);
  transition: all var(--transition-interactive);
}

.quick-link:hover {
  background: var(--color-primary-glow);
  color: var(--color-primary);
}

.quick-link svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--color-text-muted); }
.quick-link:hover svg { color: var(--color-primary); }

/* Page sections (hidden by default, shown when active) */
.page-section { display: none; }
.page-section.active { display: flex; flex-direction: column; gap: var(--space-6); }

/* Skeleton loaders */
@keyframes shimmer { 0%{background-position:-200% 0} 100%{background-position:200% 0} }
.skeleton {
  background: linear-gradient(90deg,var(--color-surface-offset) 25%,var(--color-surface-dynamic) 50%,var(--color-surface-offset) 75%);
  background-size:200% 100%; animation:shimmer 1.5s ease-in-out infinite; border-radius:var(--radius-sm);
}

/* Mobile hamburger */
.mobile-menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 19;
}

/* Responsive */
@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .dashboard { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: -240px;
    top: 0;
    bottom: 0;
    width: 240px;
    transition: left 300ms cubic-bezier(0.16, 1, 0.3, 1);
  }
  .sidebar.open { left: 0; }
  .sidebar-overlay.visible { display: block; }
  .mobile-menu-btn { display: flex; }
  .header, .main { grid-column: 1; }
}

@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .main { padding: var(--space-4); gap: var(--space-4); }
  .calendar-grid { font-size: 9px; }
  .calendar-cell { min-height: 60px; padding: var(--space-1); }
}

/* Footer */
.dashboard-footer {
  padding: var(--space-6) 0;
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

.dashboard-footer a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.dashboard-footer a:hover {
  color: var(--color-primary);
}

/* Tooltip for calendar events */
.tooltip {
  position: fixed;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  color: var(--color-text);
  max-width: 300px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 150ms ease;
}

.tooltip.visible {
  opacity: 1;
}

/* SEO keyword row highlight */
.keyword-position {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.position-good { color: var(--color-success); }
.position-medium { color: var(--color-warning); }
.position-poor { color: var(--color-text-muted); }

/* ========================================
   CRUD — Add Button
   ======================================== */
.btn-add {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-primary);
  background: var(--color-primary-glow);
  border: 1px solid rgba(56, 190, 201, 0.3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-add:hover {
  background: rgba(56, 190, 201, 0.2);
  border-color: var(--color-primary);
}

/* Editable cells */
.editable-cell {
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
  border-radius: 4px;
  padding: 2px 4px;
  margin: -2px -4px;
}
.editable-cell:hover {
  background: var(--color-primary-glow);
}

/* Inline edit inputs */
.inline-edit {
  width: 100%;
  padding: 4px 8px;
  font-size: var(--text-sm);
  font-family: inherit;
  background: var(--color-surface-raised, var(--color-surface-2));
  color: var(--color-text);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-sm);
  outline: none;
  box-shadow: 0 0 0 2px var(--color-primary-glow);
}
.inline-edit:focus {
  border-color: var(--color-primary);
}

/* New row for adding records */
.new-row td {
  padding: 8px 12px !important;
}
.new-row input,
.new-row select {
  width: 100%;
  padding: 4px 8px;
  font-size: var(--text-sm);
  font-family: inherit;
  background: var(--color-surface-raised, var(--color-surface-2));
  color: var(--color-text);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-sm);
}
.new-row input:focus,
.new-row select:focus {
  border-color: var(--color-primary);
  outline: none;
  box-shadow: 0 0 0 2px var(--color-primary-glow);
}
.new-row input::placeholder { color: var(--color-text-faint); }

/* Save/Cancel buttons in new row */
.row-actions {
  display: flex;
  gap: 4px;
}
.btn-save-row {
  padding: 4px 10px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: #fff;
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
}
.btn-save-row:hover { opacity: 0.85; }
.btn-cancel-row {
  padding: 4px 10px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
}
.btn-cancel-row:hover { background: var(--color-surface-offset); }

/* Saving indicator */
.cell-saving {
  opacity: 0.5;
  pointer-events: none;
}
.cell-saved {
  animation: saved-flash 0.8s ease;
}
@keyframes saved-flash {
  0% { background: rgba(56, 190, 201, 0.3); }
  100% { background: transparent; }
}

/* ========================================
   CRUD — Toast Notifications
   ======================================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: 'Satoshi', sans-serif;
  animation: toast-in 0.3s ease;
  max-width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}
.toast-success {
  background: var(--color-success);
  color: #fff;
}
.toast-error {
  background: var(--color-error);
  color: #fff;
}
.toast-info {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-divider);
}
.toast-warn {
  background: #b45309;
  color: #fff;
}
@keyframes toast-in {
  from { transform: translateX(100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.toast-out {
  animation: toast-out 0.3s ease forwards;
}
@keyframes toast-out {
  to { transform: translateX(100px); opacity: 0; }
}

/* ── Content Detail Modal ────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}
.modal-overlay.open {
  display: flex;
}
.modal-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 640px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 48px rgba(0,0,0,0.3);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-divider);
  flex-shrink: 0;
}
.modal-header h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
}
.modal-close {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: var(--color-text); }
.modal-body { padding: var(--space-4) var(--space-5); overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.modal-tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 500;
  background: var(--color-surface-offset);
  color: var(--color-text-muted);
}
.modal-field {
  margin-bottom: var(--space-4);
}
.modal-field label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}
.modal-copy {
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--color-text);
  white-space: pre-wrap;
  padding: var(--space-3);
  background: var(--color-surface-offset);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-divider);
  max-height: 280px;
  overflow-y: auto;
}
.modal-hashtags {
  font-size: var(--text-sm);
  color: var(--color-primary);
}
.modal-notes {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-style: italic;
}
.modal-footer {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  padding: var(--space-3) var(--space-5) var(--space-4);
  border-top: 1px solid var(--color-divider);
}
.btn-modal {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity 0.15s;
}
.btn-modal:hover { opacity: 0.85; }
.btn-approve {
  background: var(--color-success);
  color: #fff;
}
.btn-needs-edit {
  background: transparent;
  border-color: var(--color-warning, #f59e0b);
  color: var(--color-warning, #f59e0b);
}
.btn-dismiss {
  background: var(--color-surface-offset);
  color: var(--color-text-muted);
}

/* Make content table rows clickable */
#contentTable tr {
  cursor: pointer;
}
#contentTable tr:hover {
  background: var(--color-surface-offset);
}

/* ── Upgraded Modal: Editing & Feedback ──── */
.btn-edit-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--color-divider);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-edit-toggle:hover { border-color: var(--color-primary); color: var(--color-primary); }
.btn-edit-toggle.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.modal-copy-edit {
  font-family: 'Satoshi', sans-serif;
  font-size: var(--text-sm);
  line-height: 1.7;
  color: var(--color-text);
  padding: var(--space-3);
  background: var(--color-surface-offset);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-primary);
  width: 100%;
  resize: vertical;
  box-sizing: border-box;
  min-height: 140px;
}
.modal-copy-edit:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px rgba(0,209,178,0.15); }

.modal-input {
  font-family: 'Satoshi', sans-serif;
  font-size: var(--text-sm);
  color: var(--color-text);
  padding: 8px var(--space-3);
  background: var(--color-surface-offset);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-primary);
  width: 100%;
  box-sizing: border-box;
}
.modal-input:focus { outline: none; box-shadow: 0 0 0 2px rgba(0,209,178,0.15); }

.modal-feedback {
  font-family: 'Satoshi', sans-serif;
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--color-text);
  padding: var(--space-3);
  background: var(--color-surface-offset);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-divider);
  width: 100%;
  resize: vertical;
  box-sizing: border-box;
  min-height: 80px;
}
.modal-feedback:focus { outline: none; border-color: var(--color-warning, #f59e0b); box-shadow: 0 0 0 2px rgba(245,158,11,0.15); }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5) var(--space-4);
  border-top: 1px solid var(--color-divider);
  flex-shrink: 0;
}
.modal-footer-left { display: flex; gap: var(--space-2); }
.modal-footer-right { display: flex; gap: var(--space-2); }

.btn-reject {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: 1px solid var(--color-error);
  color: var(--color-error);
}
.btn-reject:hover { background: var(--color-error); color: #fff; }

.btn-send-feedback {
  background: var(--color-warning, #f59e0b);
  color: #000;
}

/* Edit mode indicator */
.modal-panel.editing .modal-header { border-bottom-color: var(--color-primary); }

/* Saved flash */
.modal-saved-flash {
  display: inline-block;
  color: var(--color-success);
  font-size: var(--text-xs);
  font-weight: 600;
  margin-left: var(--space-2);
  animation: flash-fade 1.5s ease forwards;
}
@keyframes flash-fade { 0% { opacity:1; } 100% { opacity:0; } }
