/* ============================================================
   whenframework.com - Base Design System
   Design principles from FRAMEWORK-SA-001:
   - Cognitive clarity over decoration
   - Authority through restraint
   - Typography as primary design element
   - Dark mode as default
   ============================================================ */

/* --- Design Tokens (CSS Custom Properties) --- */
:root {
  /* Base spacing unit: 8px */
  --u1: 8px;
  --u2: 16px;
  --u3: 24px;
  --u4: 32px;
  --u5: 40px;
  --u6: 48px;
  --u8: 64px;
  --u10: 80px;
  --u12: 96px;
  --u16: 128px;

  /* Typography scale (fluid) */
  --text-xs: clamp(0.75rem, 0.7rem + 0.2vw, 0.8125rem);
  --text-sm: clamp(0.8125rem, 0.775rem + 0.2vw, 0.875rem);
  --text-base: clamp(0.9375rem, 0.9rem + 0.2vw, 1rem);
  --text-lg: clamp(1.0625rem, 1rem + 0.3vw, 1.125rem);
  --text-xl: clamp(1.25rem, 1.15rem + 0.5vw, 1.5rem);
  --text-2xl: clamp(1.5rem, 1.3rem + 1vw, 2rem);
  --text-3xl: clamp(1.875rem, 1.5rem + 1.5vw, 2.5rem);
  --text-4xl: clamp(2.25rem, 1.8rem + 2vw, 3rem);

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

  /* Font weights */
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Line heights */
  --leading-tight: 1.2;
  --leading-normal: 1.6;
  --leading-relaxed: 1.75;

  /* Letter spacing */
  --tracking-tight: -0.02em;
  --tracking-normal: 0;
  --tracking-wide: 0.02em;
  --tracking-caps: 0.08em;

  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Shadows (dark mode optimized: darker, more diffuse) */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.5);

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;

  /* Layout */
  --max-width: 1120px;
  --max-width-narrow: 640px;
  --sidebar-width: 280px;
}

/* --- Dark Theme (Default) --- */
[data-theme="platform"],
[data-theme=""],
:root {
  --bg-primary: #0d0d14;
  --bg-secondary: #13131f;
  --bg-tertiary: #1a1a2e;
  --bg-elevated: #21213a;
  --bg-hover: #2a2a45;

  --text-primary: #e8e8f0;
  --text-secondary: #a0a0b8;
  --text-tertiary: #6b6b88;
  --text-inverse: #0d0d14;

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);

  --accent-primary: #6366f1;
  --accent-primary-hover: #818cf8;
  --accent-primary-muted: rgba(99, 102, 241, 0.15);

  --success: #22c55e;
  --success-muted: rgba(34, 197, 94, 0.15);
  --error: #ef4444;
  --error-muted: rgba(239, 68, 68, 0.15);
  --warning: #eab308;
  --info: #3b82f6;
  --info-muted: rgba(59, 130, 246, 0.15);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  min-height: 100vh;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out);
}

a:hover {
  color: var(--accent-primary-hover);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input {
  font-family: inherit;
  font-size: inherit;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }

p {
  line-height: var(--leading-normal);
  color: var(--text-secondary);
}

/* --- Layout --- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--u2) var(--u3);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: var(--u1);
  color: var(--text-primary);
  font-weight: var(--weight-semibold);
  font-size: var(--text-lg);
  text-decoration: none;
}

.logo-mark {
  width: 28px;
  height: 28px;
  background: var(--accent-primary);
  border-radius: var(--radius-sm);
  display: block;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: var(--u3);
}

.nav-link {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: color var(--duration-fast) var(--ease-out);
}

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

.nav-user {
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.nav-logout-form {
  display: inline;
}

.nav-logout {
  padding: 0;
}

.main-content {
  min-height: calc(100vh - 140px);
}

.site-footer {
  border-top: 1px solid var(--border-subtle);
  padding: var(--u4) var(--u3);
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  text-align: center;
}

.footer-copy {
  color: var(--text-tertiary);
  font-size: var(--text-xs);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--u1);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-md);
  transition: all var(--duration-fast) var(--ease-out);
  white-space: nowrap;
  text-decoration: none;
}

.btn-sm {
  padding: 6px var(--u2);
  font-size: var(--text-sm);
}

.btn-md,
.btn {
  padding: var(--u1) var(--u3);
  font-size: var(--text-base);
}

.btn-lg {
  padding: var(--u2) var(--u4);
  font-size: var(--text-lg);
}

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
  color: #fff;
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-full {
  width: 100%;
}

/* --- Forms --- */
.form-group {
  margin-bottom: var(--u3);
}

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  margin-bottom: var(--u1);
}

.form-input {
  width: 100%;
  padding: 10px var(--u2);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-base);
  transition: border-color var(--duration-fast) var(--ease-out);
}

.form-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-muted);
}

.form-hint {
  display: block;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* --- Alerts --- */
.alert {
  padding: var(--u2);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin-bottom: var(--u3);
}

.alert-error {
  background: var(--error-muted);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert-success {
  background: var(--success-muted);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.alert-info {
  background: var(--info-muted);
  color: var(--info);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .header-inner {
    padding: var(--u2);
  }

  .header-nav {
    gap: var(--u2);
  }

  .nav-user {
    display: none;
  }
}
