/* Art direction: Marketing analytics dashboard → professional, data-driven, confident
   Palette: Deep slate/charcoal base with emerald accent — growth, money, performance
   Typography: General Sans (body) + General Sans (display via weight) — clean, modern, functional
   Density: balanced — spacious KPIs, dense tables */

/* ===== TYPE SCALE ===== */
:root {
  --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 (4px base) ===== */
  --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;
  --space-20: 5rem;
  --space-24: 6rem;
  --space-32: 8rem;

  /* ===== 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);

  /* ===== FONTS ===== */
  --font-body: 'General Sans', 'Inter', sans-serif;
  --font-display: 'General Sans', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', 'Menlo', monospace;

  /* ===== CONTENT WIDTHS ===== */
  --content-narrow: 640px;
  --content-default: 960px;
  --content-wide: 1200px;
  --content-full: 100%;
}

/* ===== LIGHT MODE (custom — dark slate + emerald accent) ===== */
:root, [data-theme="light"] {
  --color-bg:             #f5f6f8;
  --color-surface:        #ffffff;
  --color-surface-2:      #f9fafb;
  --color-surface-offset: #eef0f4;
  --color-surface-offset-2: #e4e7ed;
  --color-surface-dynamic: #dde1e8;
  --color-divider:        #d1d5dc;
  --color-border:         #c4c9d2;

  --color-text:           #1a1d26;
  --color-text-muted:     #6b7280;
  --color-text-faint:     #9ca3af;
  --color-text-inverse:   #f9fafb;

  --color-primary:        #059669;
  --color-primary-hover:  #047857;
  --color-primary-active: #065f46;
  --color-primary-highlight: #d1fae5;

  --color-warning:        #d97706;
  --color-warning-hover:  #b45309;
  --color-warning-active: #92400e;
  --color-warning-highlight: #fef3c7;

  --color-error:          #dc2626;
  --color-error-hover:    #b91c1c;
  --color-error-active:   #991b1b;
  --color-error-highlight: #fee2e2;

  --color-success:        #059669;
  --color-success-hover:  #047857;
  --color-success-active: #065f46;
  --color-success-highlight: #d1fae5;

  --color-blue:           #2563eb;
  --color-blue-hover:     #1d4ed8;
  --color-blue-highlight: #dbeafe;

  --color-purple:         #7c3aed;
  --color-purple-hover:   #6d28d9;
  --color-purple-highlight: #ede9fe;

  --color-orange:         #ea580c;
  --color-orange-hover:   #c2410c;
  --color-orange-highlight: #ffedd5;

  --color-gold:           #ca8a04;
  --color-gold-hover:     #a16207;
  --color-gold-highlight: #fef9c3;

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

  --sidebar-bg: #1a1d26;
  --sidebar-text: #e5e7eb;
  --sidebar-text-muted: #9ca3af;
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-active: rgba(5,150,105,0.2);
  --sidebar-border: rgba(255,255,255,0.08);
}

/* ===== DARK MODE ===== */
[data-theme="dark"] {
  --color-bg:             #111318;
  --color-surface:        #1a1d26;
  --color-surface-2:      #21242e;
  --color-surface-offset: #191c24;
  --color-surface-offset-2: #252833;
  --color-surface-dynamic: #2e3240;
  --color-divider:        #2e3240;
  --color-border:         #3b4050;

  --color-text:           #e5e7eb;
  --color-text-muted:     #9ca3af;
  --color-text-faint:     #6b7280;
  --color-text-inverse:   #1a1d26;

  --color-primary:        #34d399;
  --color-primary-hover:  #10b981;
  --color-primary-active: #059669;
  --color-primary-highlight: rgba(52,211,153,0.15);

  --color-warning:        #fbbf24;
  --color-warning-hover:  #f59e0b;
  --color-warning-active: #d97706;
  --color-warning-highlight: rgba(251,191,36,0.15);

  --color-error:          #f87171;
  --color-error-hover:    #ef4444;
  --color-error-active:   #dc2626;
  --color-error-highlight: rgba(248,113,113,0.15);

  --color-success:        #34d399;
  --color-success-hover:  #10b981;
  --color-success-active: #059669;
  --color-success-highlight: rgba(52,211,153,0.15);

  --color-blue:           #60a5fa;
  --color-blue-hover:     #3b82f6;
  --color-blue-highlight: rgba(96,165,250,0.15);

  --color-purple:         #a78bfa;
  --color-purple-hover:   #8b5cf6;
  --color-purple-highlight: rgba(167,139,250,0.15);

  --color-orange:         #fb923c;
  --color-orange-hover:   #f97316;
  --color-orange-highlight: rgba(251,146,60,0.15);

  --color-gold:           #fbbf24;
  --color-gold-hover:     #f59e0b;
  --color-gold-highlight: rgba(251,191,36,0.15);

  --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);

  --sidebar-bg: #111318;
  --sidebar-text: #e5e7eb;
  --sidebar-text-muted: #6b7280;
  --sidebar-hover: rgba(255,255,255,0.06);
  --sidebar-active: rgba(52,211,153,0.2);
  --sidebar-border: rgba(255,255,255,0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg:             #111318;
    --color-surface:        #1a1d26;
    --color-surface-2:      #21242e;
    --color-surface-offset: #191c24;
    --color-surface-offset-2: #252833;
    --color-surface-dynamic: #2e3240;
    --color-divider:        #2e3240;
    --color-border:         #3b4050;
    --color-text:           #e5e7eb;
    --color-text-muted:     #9ca3af;
    --color-text-faint:     #6b7280;
    --color-text-inverse:   #1a1d26;
    --color-primary:        #34d399;
    --color-primary-hover:  #10b981;
    --color-primary-active: #059669;
    --color-primary-highlight: rgba(52,211,153,0.15);
    --color-warning:        #fbbf24;
    --color-warning-hover:  #f59e0b;
    --color-warning-active: #d97706;
    --color-warning-highlight: rgba(251,191,36,0.15);
    --color-error:          #f87171;
    --color-error-hover:    #ef4444;
    --color-error-active:   #dc2626;
    --color-error-highlight: rgba(248,113,113,0.15);
    --color-success:        #34d399;
    --color-success-hover:  #10b981;
    --color-success-active: #059669;
    --color-success-highlight: rgba(52,211,153,0.15);
    --color-blue:           #60a5fa;
    --color-blue-hover:     #3b82f6;
    --color-blue-highlight: rgba(96,165,250,0.15);
    --color-purple:         #a78bfa;
    --color-purple-hover:   #8b5cf6;
    --color-purple-highlight: rgba(167,139,250,0.15);
    --color-orange:         #fb923c;
    --color-orange-hover:   #f97316;
    --color-orange-highlight: rgba(251,146,60,0.15);
    --color-gold:           #fbbf24;
    --color-gold-hover:     #f59e0b;
    --color-gold-highlight: rgba(251,191,36,0.15);
    --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);
    --sidebar-bg: #111318;
    --sidebar-text: #e5e7eb;
    --sidebar-text-muted: #6b7280;
    --sidebar-hover: rgba(255,255,255,0.06);
    --sidebar-active: rgba(52,211,153,0.2);
    --sidebar-border: rgba(255,255,255,0.06);
  }
}

/* ===== TABULAR NUMBERS FOR DATA ===== */
.tabnum { font-variant-numeric: tabular-nums lining-nums; }

/* Expandable forecast detail rows */
.forecast-detail-row {
  background-color: var(--color-surface-2, #f3f4f6);
  color: var(--color-text);
}
.forecast-detail-row td {
  border-top: 1px dashed var(--color-divider);
}
[data-theme="dark"] .forecast-detail-row {
  background-color: var(--color-surface-2);
}

/* ===== DAMPENING UI ===== */
.dampened-cell {
  position: relative;
  cursor: pointer;
  background-color: rgba(251, 191, 36, 0.1);
}
[data-theme="dark"] .dampened-cell {
  background-color: rgba(251, 191, 36, 0.12);
}
.dampened-cell .dampen-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  background: var(--color-warning-highlight);
  color: var(--color-warning);
  margin-left: 4px;
  vertical-align: middle;
}
[data-theme="dark"] .dampened-cell .dampen-badge {
  background: rgba(251, 191, 36, 0.2);
  color: #fbbf24;
}
.season-cell-clickable {
  cursor: pointer;
  transition: background-color var(--transition-interactive);
}
.season-cell-clickable:hover {
  background-color: var(--color-surface-offset);
}

/* Dampening popover */
.dampen-popover {
  position: fixed;
  z-index: 1000;
  width: 260px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4);
}
.dampen-popover .dampen-popover-title {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-3);
  color: var(--color-text);
}
.dampen-popover label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: var(--space-1);
}
.dampen-popover input[type="number"] {
  width: 100%;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: var(--text-sm);
  margin-bottom: var(--space-3);
}
.dampen-popover textarea {
  width: 100%;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: 12px;
  resize: vertical;
  min-height: 48px;
  margin-bottom: var(--space-3);
  font-family: var(--font-body);
}
.dampen-popover .dampen-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}
.dampen-popover .dampen-actions button {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text);
}
.dampen-popover .dampen-actions .dampen-save {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  border-color: var(--color-primary);
}
.dampen-popover .dampen-actions .dampen-save:hover {
  background: var(--color-primary-hover);
}
.dampen-popover .dampen-actions .dampen-reset {
  color: var(--color-error);
  border-color: var(--color-error);
  background: transparent;
}
.dampen-popover .dampen-error {
  color: var(--color-error);
  font-size: 11px;
  margin-bottom: var(--space-2);
  display: none;
}

/* ===== MARKETING CALENDAR ===== */
.calendar-timeline {
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-divider);
}
.calendar-events-area {
  position: relative;
  min-height: 60px;
  padding: 0 0 4px;
  overflow-x: clip;
}
.calendar-timeline-months {
  display: flex;
  height: 22px;
  border-top: 1px solid var(--color-divider);
}
.calendar-timeline-months span {
  flex: 1;
  text-align: center;
  font-size: 10px;
  color: var(--color-text-muted);
  line-height: 22px;
}
.calendar-event-block {
  position: absolute;
  height: 20px;
  border-radius: 3px;
  background: var(--color-primary);
  cursor: default;
  min-width: 4px;
}
.calendar-event-label {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 2px;
  font-size: 10px;
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  line-height: 1.2;
  pointer-events: none;
}
.calendar-event-block.disabled {
  background: var(--color-border);
  opacity: 0.5;
}
.calendar-event-block.disabled .calendar-event-label {
  color: var(--color-text-faint);
}

.calendar-empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.calendar-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-full);
}
.calendar-badge.in-lookback {
  background: var(--color-success-highlight);
  color: var(--color-success);
}
.calendar-badge.new-event {
  background: var(--color-warning-highlight);
  color: var(--color-warning);
}
#calendarTable input[type="text"],
#calendarTable input[type="date"],
#calendarTable input[type="number"] {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: 12px;
  font-family: var(--font-body);
}
#calendarTable input[type="number"] {
  width: 70px;
}
#calendarTable input[type="date"] {
  width: 130px;
}
#calendarTable input[type="text"] {
  min-width: 100px;
}
#calendarTable .cal-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 4px;
  border-radius: var(--radius-sm);
}
#calendarTable .cal-delete-btn:hover {
  color: var(--color-error);
  background: var(--color-error-highlight);
}
.forecast-event-marker {
  position: absolute;
  bottom: 0;
  height: 4px;
  border-radius: 2px;
  background: var(--color-primary);
  opacity: 0.7;
}

/* ===== SIDEBAR NAV DIVIDER & DOCS LINK ===== */
.sidebar-nav-divider {
  height: 1px;
  background: var(--sidebar-border);
  margin: var(--space-2) var(--space-4);
}
.docs-nav-link {
  opacity: 0.7;
}
.docs-nav-link span {
  color: var(--sidebar-text-muted);
}
.docs-nav-link.active {
  opacity: 1;
}
.docs-nav-link.active span {
  color: var(--sidebar-text);
}

/* ===== DOCUMENTATION PAGE ===== */
.docs-toc {
  margin-bottom: var(--space-6);
}
.docs-toc ol {
  margin: var(--space-4) 0 0;
  padding-left: var(--space-6);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-2) var(--space-8);
}
.docs-toc li {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.docs-toc a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition-interactive);
}
.docs-toc a:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}
.docs-section {
  margin-bottom: var(--space-6);
  scroll-margin-top: var(--space-8);
}
.docs-section h2 {
  margin-bottom: var(--space-4);
}
.docs-section h3 {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  margin-top: var(--space-6);
  margin-bottom: var(--space-2);
}
.docs-section p {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: 1.6;
  margin-bottom: var(--space-3);
}
.docs-formula {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: var(--color-surface-2);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  color: var(--color-text);
  overflow-x: auto;
}
.docs-example {
  background: var(--color-primary-highlight);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text);
  line-height: 1.6;
}
.docs-example strong {
  display: block;
  margin-bottom: var(--space-2);
  color: var(--color-primary-active);
}
[data-theme="dark"] .docs-example strong {
  color: var(--color-primary);
}
.docs-example ol,
.docs-example ul {
  margin: var(--space-2) 0 0;
  padding-left: var(--space-6);
}
.docs-example li {
  margin-bottom: var(--space-1);
}
.docs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}
.docs-table th {
  text-align: left;
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-2);
  border-bottom: 2px solid var(--color-divider);
  color: var(--color-text);
  white-space: nowrap;
}
.docs-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-divider);
  color: var(--color-text-muted);
  vertical-align: top;
}
.docs-table tr:last-child td {
  border-bottom: none;
}
.docs-table tr:hover td {
  background: var(--color-surface-offset);
}

/* ===== LOGIN SCREEN ===== */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}
.login-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-12) var(--space-10);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  max-width: 380px;
  width: 90%;
  text-align: center;
}
.login-logo {
  color: var(--color-accent);
  margin-bottom: var(--space-2);
}
.login-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
  margin: 0;
  letter-spacing: -0.02em;
}
.login-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0;
}
.btn-google-signin {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  margin-top: var(--space-4);
}
.btn-google-signin:hover {
  background: #f8f9fa;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.login-note {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  opacity: 0.7;
  margin: 0;
}

/* ===== SIDEBAR USER DISPLAY ===== */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  min-height: 0;
}
.sidebar-user:empty {
  display: none;
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 600;
  flex-shrink: 0;
}
.user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.btn-sign-out {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: color 0.15s;
}
.btn-sign-out:hover {
  color: var(--color-text);
}
.btn-sign-out svg {
  width: 16px;
  height: 16px;
}
