/**
 * Griffin Bowen Design System
 * A unified design language for professional legal applications
 *
 * Usage: Include this file FIRST, before other stylesheets
 * <link rel="stylesheet" href="design-system.css">
 */

/* ==========================================================================
   1. DESIGN TOKENS (CSS Custom Properties)
   ========================================================================== */

:root {
  /* ---- Color Palette ---- */

  /* Neutral Scale */
  --color-charcoal: #1a1d21;
  --color-charcoal-light: #2d3138;
  --color-slate: #4a5160;
  --color-stone: #6b7280;
  --color-silver: #9ca3af;
  --color-ivory: #faf9f7;
  --color-cream: #f5f3f0;
  --color-warm-white: #fffefb;
  --color-white: #ffffff;

  /* Brand Accents */
  --color-brass: #b8860b;
  --color-brass-light: #d4a84b;
  --color-brass-dark: #8b6508;
  --color-brass-muted: rgba(184, 134, 11, 0.12);

  /* Semantic Colors */
  --color-sage: #5c6b5e;
  --color-sage-muted: rgba(92, 107, 94, 0.08);
  --color-navy: #1e3a5f;
  --color-navy-muted: rgba(30, 58, 95, 0.06);

  /* Status Colors */
  --color-success: #059669;
  --color-success-light: #d1fae5;
  --color-warning: #d97706;
  --color-warning-light: #fef3c7;
  --color-danger: #dc2626;
  --color-danger-light: #fee2e2;
  --color-info: #2563eb;
  --color-info-light: #dbeafe;

  /* ---- Typography ---- */
  --font-display: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Monaco', 'Consolas', monospace;

  /* Font Sizes */
  --text-xs: 0.6875rem;    /* 11px */
  --text-sm: 0.75rem;      /* 12px */
  --text-base: 0.875rem;   /* 14px */
  --text-md: 1rem;         /* 16px */
  --text-lg: 1.125rem;     /* 18px */
  --text-xl: 1.25rem;      /* 20px */
  --text-2xl: 1.5rem;      /* 24px */
  --text-3xl: 1.875rem;    /* 30px */
  --text-4xl: 2.5rem;      /* 40px */

  /* Font Weights */
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Line Heights */
  --leading-tight: 1.1;
  --leading-snug: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  /* Letter Spacing */
  --tracking-tight: -0.02em;
  --tracking-normal: 0;
  --tracking-wide: 0.01em;
  --tracking-wider: 0.05em;
  --tracking-widest: 0.15em;

  /* ---- Spacing ---- */
  --space-0: 0;
  --space-1: 0.25rem;      /* 4px */
  --space-2: 0.5rem;       /* 8px */
  --space-3: 0.75rem;      /* 12px */
  --space-4: 1rem;         /* 16px */
  --space-5: 1.25rem;      /* 20px */
  --space-6: 1.5rem;       /* 24px */
  --space-8: 2rem;         /* 32px */
  --space-10: 2.5rem;      /* 40px */
  --space-12: 3rem;        /* 48px */
  --space-14: 3.5rem;      /* 56px */
  --space-16: 4rem;        /* 64px */
  --space-20: 5rem;        /* 80px */

  /* ---- Shadows ---- */
  --shadow-subtle: 0 1px 2px rgba(26, 29, 33, 0.04);
  --shadow-sm: 0 1px 3px rgba(26, 29, 33, 0.08);
  --shadow-card: 0 2px 8px rgba(26, 29, 33, 0.06), 0 1px 2px rgba(26, 29, 33, 0.04);
  --shadow-md: 0 4px 12px rgba(26, 29, 33, 0.08);
  --shadow-elevated: 0 8px 24px rgba(26, 29, 33, 0.1), 0 2px 6px rgba(26, 29, 33, 0.06);
  --shadow-lg: 0 12px 40px rgba(26, 29, 33, 0.12);
  --shadow-brass-glow: 0 4px 20px rgba(184, 134, 11, 0.15);

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

  /* ---- Transitions ---- */
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;
  --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);

  /* ---- Z-Index Scale ---- */
  --z-base: 0;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-header: 500;
  --z-sidebar: 600;
  --z-overlay: 800;
  --z-modal: 900;
  --z-toast: 1000;

  /* ---- Borders ---- */
  --border-subtle: 1px solid rgba(26, 29, 33, 0.08);
  --border-light: 1px solid rgba(26, 29, 33, 0.12);
  --border-medium: 1px solid rgba(26, 29, 33, 0.2);

  /* ---- Layout ---- */
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 0px;
  --header-height: 64px;
  --max-content-width: 1400px;
}

/* ==========================================================================
   2. BASE RESET & DEFAULTS
   ========================================================================== */

*, *::before, *::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-charcoal);
  background-color: var(--color-ivory);
}

/* ==========================================================================
   3. TYPOGRAPHY UTILITIES
   ========================================================================== */

/* Display/Headlines - Serif */
.text-display {
  font-family: var(--font-display);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  color: var(--color-charcoal);
}

.text-display-lg {
  font-family: var(--font-display);
  font-size: var(--text-4xl);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  color: var(--color-charcoal);
}

.text-display-md {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-snug);
  color: var(--color-charcoal);
}

.text-display-sm {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
  line-height: var(--leading-snug);
  color: var(--color-charcoal);
}

/* Headings - Sans */
.text-heading {
  font-family: var(--font-body);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  color: var(--color-charcoal);
}

.text-heading-lg {
  font-size: var(--text-xl);
}

.text-heading-md {
  font-size: var(--text-lg);
}

.text-heading-sm {
  font-size: var(--text-md);
}

/* Body Text */
.text-body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-charcoal);
}

.text-body-sm {
  font-size: var(--text-sm);
}

/* Labels & Captions */
.text-label {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--color-slate);
}

.text-eyebrow {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--color-brass);
}

.text-caption {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-stone);
}

.text-muted {
  color: var(--color-stone);
}

/* ==========================================================================
   4. ANIMATIONS
   ========================================================================== */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.animate-fade-in {
  animation: fadeIn 0.3s ease-out forwards;
}

.animate-fade-in-up {
  animation: fadeInUp 0.4s ease-out forwards;
}

.animate-slide-in-left {
  animation: slideInLeft 0.3s ease-out forwards;
}

/* Staggered animation delays */
.delay-1 { animation-delay: 0.05s; }
.delay-2 { animation-delay: 0.1s; }
.delay-3 { animation-delay: 0.15s; }
.delay-4 { animation-delay: 0.2s; }
.delay-5 { animation-delay: 0.25s; }

/* ==========================================================================
   5. BUTTONS
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  line-height: 1;
  text-decoration: none;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-smooth);
  white-space: nowrap;
}

.btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(184, 134, 11, 0.2);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Primary Button - Brass */
.btn-primary {
  background: var(--color-brass);
  color: var(--color-white);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-brass-dark);
  box-shadow: var(--shadow-brass-glow);
}

/* Secondary Button - Outlined */
.btn-secondary {
  background: transparent;
  color: var(--color-charcoal);
  border: var(--border-medium);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-cream);
  border-color: var(--color-charcoal);
}

/* Ghost Button */
.btn-ghost {
  background: transparent;
  color: var(--color-slate);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(26, 29, 33, 0.05);
  color: var(--color-charcoal);
}

/* Danger Button */
.btn-danger {
  background: var(--color-danger);
  color: var(--color-white);
}

.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
}

/* Button Sizes */
.btn-sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
}

.btn-lg {
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-md);
}

/* ==========================================================================
   6. CARDS
   ========================================================================== */

.card {
  background: var(--color-warm-white);
  border: var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  transition: all var(--transition-smooth);
}

.card:hover {
  box-shadow: var(--shadow-elevated);
}

.card-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: var(--border-subtle);
}

.card-header-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--color-charcoal);
  margin: 0;
}

.card-header-subtitle {
  font-size: var(--text-sm);
  color: var(--color-stone);
  margin-top: var(--space-1);
}

.card-body {
  padding: var(--space-6);
}

.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: var(--border-subtle);
  background: var(--color-cream);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Card Variants */
.card--elevated {
  box-shadow: var(--shadow-elevated);
}

.card--flat {
  box-shadow: none;
  border: var(--border-light);
}

/* ==========================================================================
   7. FORMS
   ========================================================================== */

.form-group {
  margin-bottom: var(--space-5);
}

.form-label {
  display: block;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-charcoal);
  margin-bottom: var(--space-2);
}

.form-label-required::after {
  content: ' *';
  color: var(--color-danger);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-charcoal);
  background: var(--color-white);
  border: var(--border-light);
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--color-brass);
  box-shadow: 0 0 0 3px var(--color-brass-muted);
}

.form-input::placeholder {
  color: var(--color-silver);
}

.form-input:disabled {
  background: var(--color-cream);
  cursor: not-allowed;
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-10);
}

.form-help {
  font-size: var(--text-sm);
  color: var(--color-stone);
  margin-top: var(--space-1);
}

.form-error {
  font-size: var(--text-sm);
  color: var(--color-danger);
  margin-top: var(--space-1);
}

/* Form Row (side by side) */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}

/* File Upload */
.form-file-upload {
  border: 2px dashed rgba(26, 29, 33, 0.15);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  text-align: center;
  background: var(--color-cream);
  cursor: pointer;
  transition: all var(--transition-smooth);
}

.form-file-upload:hover {
  border-color: var(--color-brass);
  background: var(--color-brass-muted);
}

.form-file-upload.dragover {
  border-color: var(--color-brass);
  background: var(--color-brass-muted);
}

/* ==========================================================================
   8. TABLES
   ========================================================================== */

.table-container {
  overflow-x: auto;
  border: var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--color-white);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.data-table th {
  background: var(--color-cream);
  font-weight: var(--weight-semibold);
  text-align: left;
  padding: var(--space-3) var(--space-4);
  color: var(--color-charcoal);
  border-bottom: var(--border-light);
  white-space: nowrap;
}

.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-subtle);
  color: var(--color-charcoal);
}

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

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

/* ==========================================================================
   9. MODALS
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 29, 33, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-smooth);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* .modal styles defined in styles.css - uses .modal as overlay, .modal-content as box */

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: var(--border-subtle);
}

.modal-title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--color-charcoal);
  margin: 0;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--color-stone);
  cursor: pointer;
  transition: all var(--transition-base);
}

.modal-close:hover {
  background: var(--color-cream);
  color: var(--color-charcoal);
}

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
  max-height: calc(90vh - 140px);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: var(--border-subtle);
  background: var(--color-cream);
}

/* ==========================================================================
   10. STATUS BADGES
   ========================================================================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-full);
}

.badge-success {
  background: var(--color-success-light);
  color: var(--color-success);
}

.badge-warning {
  background: var(--color-warning-light);
  color: var(--color-warning);
}

.badge-danger {
  background: var(--color-danger-light);
  color: var(--color-danger);
}

.badge-info {
  background: var(--color-info-light);
  color: var(--color-info);
}

.badge-neutral {
  background: var(--color-cream);
  color: var(--color-slate);
}

/* ==========================================================================
   11. LOADING STATES
   ========================================================================== */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(250, 249, 247, 0.9);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: var(--z-overlay);
}

.loading-content {
  background: var(--color-white);
  padding: var(--space-10);
  border-radius: var(--radius-lg);
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}

.loading-content h3 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  color: var(--color-charcoal);
  margin-bottom: var(--space-2);
}

.loading-content p {
  font-size: var(--text-sm);
  color: var(--color-slate);
  margin: 0;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-cream);
  border-top-color: var(--color-brass);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto var(--space-6);
}

.loading-text {
  margin-top: var(--space-4);
  font-size: var(--text-base);
  color: var(--color-slate);
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-cream) 25%,
    var(--color-ivory) 50%,
    var(--color-cream) 75%
  );
  background-size: 200% 100%;
  animation: pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

/* ==========================================================================
   12. PAGE LAYOUT COMPONENTS
   ========================================================================== */

.page-container {
  padding: var(--space-8) var(--space-10);
  max-width: var(--max-content-width);
  margin: 0 auto;
}

.page-header {
  margin-bottom: var(--space-8);
  padding-bottom: var(--space-6);
  border-bottom: var(--border-subtle);
  position: relative;
}

.page-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 80px;
  height: 2px;
  background: linear-gradient(90deg, var(--color-brass), transparent);
}

.page-eyebrow {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--color-brass);
  margin-bottom: var(--space-3);
}

.page-title {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  color: var(--color-charcoal);
  margin: 0;
}

.page-subtitle {
  font-size: var(--text-md);
  color: var(--color-stone);
  margin-top: var(--space-2);
}

/* Section within page */
.section {
  margin-bottom: var(--space-10);
}

.section-label {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-slate);
  margin-bottom: var(--space-5);
  padding-left: var(--space-1);
}

.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, rgba(26, 29, 33, 0.1), transparent 60%);
}

/* ==========================================================================
   13. UTILITY CLASSES
   ========================================================================== */

/* Flexbox */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

/* Spacing */
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

/* Text alignment */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* Visibility */
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ==========================================================================
   14. RESPONSIVE BREAKPOINTS
   ========================================================================== */

@media (max-width: 1024px) {
  :root {
    --sidebar-width: 0px;
  }

  .page-container {
    padding: var(--space-6) var(--space-5);
  }
}

@media (max-width: 768px) {
  :root {
    --text-4xl: 2rem;
    --text-3xl: 1.5rem;
  }

  .page-container {
    padding: var(--space-5) var(--space-4);
  }

  .page-title {
    font-size: var(--text-2xl);
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}
