/* ============================================================
   6D Studios — Design System Base
   Shared across all apps. Import before app-specific styles.
   ============================================================ */

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Design Tokens (Dark Mode — Default) ───────────────────── */
:root {
  /* Backgrounds */
  --bg-page: #1A1D24;
  --bg-surface: #21252D;
  --bg-row: #272B35;
  --bg-row-alt: #272B35;
  --bg-row-hover: #2E3340;
  --bg-row-selected: #2A3344;
  --bg-header: #0D0F14;

  /* Borders */
  --border-color: #353A45;

  /* Text */
  --text-primary: #E0E2E6;
  --text-secondary: #A0A4AE;  /* FIXED: was #8E919A, improved contrast 4.8:1 */
  --text-tertiary: #6E7278;
  --text-uppercase: #A0A4AE;

  /* Accent — Sage Green */
  --accent: #7C9A82;
  --accent-hover: #6B8A71;
  --accent-dim: rgba(124, 154, 130, 0.15);
  --accent-glow: rgba(124, 154, 130, 0.25);

  /* Semantic Colors */
  --danger: #C85A5A;
  --danger-bg: rgba(200, 90, 90, 0.15);
  --success: #66B89A;
  --success-bg: rgba(102, 184, 154, 0.15);
  --warning: #D4A24C;
  --warning-bg: rgba(212, 162, 76, 0.15);
  --blue: #6B8FD4;
  --blue-bg: rgba(107, 143, 212, 0.15);
  --coral: #D88AAE;
  --coral-bg: rgba(216, 138, 174, 0.15);
  --gold: #D4A24C;
  --gold-bg: rgba(212, 162, 76, 0.15);

  /* Spacing Scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;
  --space-3xl: 48px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.15);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.25);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.35);

  /* Transitions */
  --transition-fast: 120ms ease;
  --transition: 180ms ease;
  --transition-slow: 320ms cubic-bezier(0.22, 0.61, 0.36, 1);

  /* Typography Scale */
  --font-family: 'Figtree', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --fs-xs: 11px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 16px;
  --fs-lg: 20px;
  --fs-xl: 24px;
  --fs-2xl: 32px;
  --fw-normal: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;
  --lh-tight: 1.2;
  --lh-normal: 1.5;
  --lh-relaxed: 1.6;

  /* Topbar */
  --topbar: #0D0F14;
  --topbar-height: 56px;
}

/* ── Light Mode Tokens ─────────────────────────────────────── */
[data-theme="light"] {
  --bg-page: #F5F5F3;
  --bg-surface: #FFFFFF;
  --bg-row: #F0F0EB;
  --bg-row-alt: #F0F0EB;
  --bg-row-hover: #E8E8E3;
  --bg-row-selected: #E0E0DB;
  --bg-header: #FFFFFF;

  --border-color: #D8D8D3;

  --text-primary: #1A1D24;
  --text-secondary: #5A5E6A;
  --text-tertiary: #8E919A;
  --text-uppercase: #5A5E6A;

  --accent: #5A7F62;
  --accent-hover: #4A6F52;
  --accent-dim: rgba(90, 127, 98, 0.12);
  --accent-glow: rgba(90, 127, 98, 0.2);

  --danger: #C85A5A;
  --danger-bg: rgba(200, 90, 90, 0.1);
  --success: #4A8F72;
  --success-bg: rgba(74, 143, 114, 0.1);
  --warning: #B8862B;
  --warning-bg: rgba(184, 134, 43, 0.1);
  --blue: #4A6FB8;
  --blue-bg: rgba(74, 111, 184, 0.1);
  --coral: #C06A8A;
  --coral-bg: rgba(192, 106, 138, 0.1);
  --gold: #7B6BA4;
  --gold-bg: rgba(123, 107, 164, 0.1);

  --topbar: #FFFFFF;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.1);
  --shadow-lg: 0 16px 48px rgba(0,0,0,0.14);
}

/* ── Typography ────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Figtree:wght@400;500;600;700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;600&display=swap');

body {
  font-family: var(--font-family);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  background: var(--bg-page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Semantic Type Classes */
.text-xs { font-size: var(--fs-xs); }
.text-sm { font-size: var(--fs-sm); }
.text-base { font-size: var(--fs-base); }
.text-md { font-size: var(--fs-md); }
.text-lg { font-size: var(--fs-lg); }
.text-xl { font-size: var(--fs-xl); }
.text-2xl { font-size: var(--fs-2xl); }

/* Data text — use Inter */
.data-text, .stat-number, .budget-cell, .cell.number {
  font-family: 'Inter', system-ui, sans-serif;
}

/* Code/mono text */
code, .mono, .code-text {
  font-family: var(--font-mono);
}

/* ── Loading Spinner ───────────────────────────────────────── */
.loading-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-page, #1A1D24);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
.loading-overlay.hidden {
  opacity: 0; visibility: hidden; pointer-events: none;
}
.spinner-container {
  display: flex; flex-direction: column; align-items: center; gap: 20px;
}
.spinner-ring {
  width: 72px; height: 72px; border-radius: 50%;
  border: 3px solid var(--accent-dim);
  border-top-color: var(--accent);
  animation: spin6d 1s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  display: flex; align-items: center; justify-content: center;
}
.spinner-logo {
  font-family: 'Figtree', sans-serif;
  font-weight: 700; font-size: 22px; color: var(--accent);
  letter-spacing: -0.5px;
  animation: pulse6d 1.5s ease-in-out infinite;
}
.spinner-text {
  font-family: 'Inter', sans-serif;
  font-size: 13px; color: var(--text-tertiary);
  letter-spacing: 1px;
}
@keyframes spin6d { to { transform: rotate(360deg); } }
@keyframes pulse6d { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 48px; right: 0;
  height: var(--topbar-height);
  background: var(--topbar);
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  z-index: 100;
  transition: left 0.25s cubic-bezier(0.22,0.61,0.36,1);
}
body.sixd-nav-open .topbar { left: 180px; }
[data-theme="light"] .topbar {
  background: #FFFFFF; color: #1A1D24;
  border-bottom: 1px solid #D8D8D3;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex-shrink: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.logo-circle {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: var(--fw-bold); font-size: var(--fs-base); color: #fff;
  letter-spacing: -0.5px; flex-shrink: 0;
  transition: transform 0.15s ease;
}
.logo-circle:hover { transform: scale(1.06); }
.topbar .logo-circle { display: none; }

.topbar-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.topbar-brand-name {
  font-size: var(--fs-md); font-weight: var(--fw-bold); font-family: var(--font-family);
  color: var(--text-primary); line-height: var(--lh-tight);
}
.topbar-brand-name .studio { color: #5A7F62; }

.version-badge {
  font-size: var(--fs-xs); color: var(--text-tertiary); font-weight: 400; opacity: 0.6;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 8px 16px; border-radius: 8px;
  font-weight: 600; font-size: var(--fs-sm);
  cursor: pointer; font-family: var(--font-family);
  transition: all 0.15s ease;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-secondary {
  background: var(--bg-row); color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 8px 16px; border-radius: 8px;
  font-weight: 500; font-size: var(--fs-sm);
  cursor: pointer; font-family: var(--font-family);
  transition: all var(--transition);
}
.btn-secondary:hover { background: var(--bg-row-hover); border-color: var(--accent); }

.btn-icon {
  background: none; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); color: var(--text-secondary);
  width: 36px; height: 36px; display: flex; align-items: center;
  justify-content: center; cursor: pointer;
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--bg-row-hover); color: var(--text-primary); border-color: var(--accent); }

.btn-signout {
  background: none; border: 1px solid var(--border-color);
  color: var(--text-secondary); padding: 6px 14px;
  border-radius: 8px; font-size: var(--fs-sm);
  font-weight: 500; cursor: pointer;
  font-family: var(--font-family);
  transition: all 0.15s ease;
}
.btn-signout:hover { border-color: var(--danger); color: var(--danger); }

.theme-toggle-btn {
  background: none; border: none; border-radius: 8px;
  padding: 7px 12px; cursor: pointer; font-size: var(--fs-md); line-height: 1;
  transition: all 0.2s; display: flex; align-items: center; outline: none;
  color: var(--text-secondary);
}
.theme-toggle-btn:hover { background: rgba(255,255,255,0.1); }
.theme-toggle-btn:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
[data-theme="light"] .theme-toggle-btn { color: #1A1D24; }
[data-theme="light"] .theme-toggle-btn:hover { background: rgba(26,29,36,0.08); }

/* Topbar app-name and studio label */
.topbar .app-name {
  font-size: var(--fs-md); font-weight: var(--fw-bold);
  color: #fff; line-height: var(--lh-tight);
}
[data-theme="light"] .topbar .app-name { color: var(--text-primary); }
.topbar .studio {
  font-size: var(--fs-md); font-weight: var(--fw-bold);
  color: var(--accent); line-height: var(--lh-tight);
}

/* ── Forms ─────────────────────────────────────────────────── */
.form-label {
  display: block; font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  color: var(--text-secondary); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 14px;
  background: var(--bg-row); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-family: var(--font-family); font-size: var(--fs-base);
  transition: border-color 0.2s, background 0.2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-tertiary); }

/* ── Cards ─────────────────────────────────────────────────── */
.card, .kanban-card, .deal-card, .grid-card, .kpi-card, .stat-card, .chart-card, .clause-card, .template-card, .update-card {
  border-radius: var(--radius-md);
}
.card {
  background: var(--bg-surface); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: var(--space-xl);
  transition: all 0.2s;
}
.card:hover {
  border-color: var(--accent); transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* ── Table Headers (standardized) ─────────────────────────── */
th { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-tertiary); }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5); z-index: 500;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--bg-surface); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: var(--space-xl);
  box-shadow: var(--shadow-lg); max-width: 560px; width: 90%;
  max-height: 80vh; overflow-y: auto;
}
.modal-title {
  font-size: var(--fs-lg); font-weight: var(--fw-bold); margin-bottom: var(--space-lg);
  color: var(--text-primary);
}

/* ── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-surface); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 10px 20px;
  box-shadow: var(--shadow-md); z-index: 9000;
  font-size: var(--fs-sm); color: var(--text-primary);
  animation: toastIn 0.3s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }

/* ── Theme Toggle ──────────────────────────────────────────── */
.theme-toggle {
  background: none; border: none; border-radius: 8px;
  padding: 7px 12px; cursor: pointer; font-size: var(--fs-md); line-height: 1;
  transition: all 0.2s; display: flex; align-items: center; outline: none;
  color: var(--text-secondary);
}
.theme-toggle:hover { background: rgba(255,255,255,0.1); }
.theme-toggle:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
[data-theme="light"] .theme-toggle { color: #1A1D24; }
[data-theme="light"] .theme-toggle:hover { background: rgba(26,29,36,0.08); }

/* ── Accessibility ─────────────────────────────────────────── */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 48px 24px;
  color: var(--text-secondary);
}
.empty-state-icon {
  font-size: 40px; margin-bottom: 12px; opacity: 0.3;
}
.empty-state-title {
  font-size: var(--fs-md); font-weight: var(--fw-semibold); margin-bottom: 6px;
  color: var(--text-primary);
}
.empty-state-text {
  font-size: var(--fs-sm); margin-bottom: 16px; max-width: 360px; margin-inline: auto;
}
.empty-state-cta {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--accent); font-weight: var(--fw-semibold); font-size: var(--fs-sm);
  text-decoration: none; cursor: pointer;
  transition: opacity 0.15s;
}
.empty-state-cta:hover { opacity: 0.8; }

/* ── Empty State — Enhancements ───────────────────────────── */

/* Compact empty state for inline use (kanban columns, table groups) */
.empty-state.compact {
  padding: 20px 12px;
}
.empty-state.compact .empty-state-icon {
  font-size: 24px;
  margin-bottom: 8px;
}
.empty-state.compact .empty-state-title {
  font-size: var(--fs-sm);
}
.empty-state.compact .empty-state-text {
  font-size: var(--fs-xs);
}

/* KPI card empty accent text */
.hero-card .stat[style*="color:var(--accent)"] {
  font-weight: 500;
}

/* ── Mobile Responsive ─────────────────────────────────────── */

/* Hamburger button — hidden by default, shown on mobile */
.sixd-mobile-hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.sixd-mobile-hamburger:hover { background: var(--bg-row-hover); }
.sixd-mobile-hamburger svg {
  width: 20px; height: 20px;
  stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* Mobile nav backdrop */
.sixd-nav-backdrop {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 250;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sixd-nav-backdrop.visible { display: block; }

/* Tablet: ≤ 768px */
@media (max-width: 768px) {
  /* Hide the fixed sidebar */
  .sixd-nav { display: none !important; }

  /* Remove body margin that the sidebar creates */
  body { margin-left: 0 !important; }
  body.sixd-nav-open { margin-left: 0 !important; }

  /* Topbar: reset left offset */
  .topbar { left: 0 !important; padding: 0 12px; }
  body.sixd-nav-open .topbar { left: 0 !important; }

  /* Show hamburger */
  .sixd-mobile-hamburger { display: flex; }

  /* Mobile nav overlay */
  .sixd-nav.sixd-mobile-nav {
    display: flex !important;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 240px;
    max-width: 80vw;
    z-index: 300;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sixd-nav.sixd-mobile-nav.expanded {
    width: 240px;
  }
  .sixd-nav.sixd-mobile-nav .nav-label {
    opacity: 1; width: auto;
  }
  .sixd-nav.sixd-mobile-nav.mobile-open {
    transform: translateX(0);
  }

  /* Modal: full-width on mobile */
  .modal { max-width: 100% !important; width: calc(100% - 24px) !important; }

  /* Toast: fit to screen */
  .toast { max-width: calc(100vw - 32px); }
}

/* Small mobile: ≤ 480px */
@media (max-width: 480px) {
  .topbar { font-size: 13px; min-height: 44px; }
  .topbar-right { gap: 4px; }
  .topbar-brand-name { font-size: var(--fs-sm); }
  .version-badge { display: none; }

  /* Cards: tighter padding */
  .card { padding: var(--space-lg); }

  /* Forms: larger touch targets */
  .form-input, .form-select, .form-textarea { min-height: 40px; font-size: 16px !important; }
  .btn-primary, .btn-secondary { min-height: 40px; }
}
