/* ========================================================================== */
/* DESIGN LOOKBOOK — UNIFIED SHELL THEME & COMPONENT SYSTEM (SSOT)           */
/* Adhering strictly to root DESIGN.md specification (Modules 1 - 8)          */
/* ========================================================================== */

:root {
  /* 1. Base Color Scale (Light: Warm Paper) */
  --bg: #faf9f6;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f4f3ee;
  --bg-subtle: #edebe4;
  --border: #e2dfd7;
  --border-strong: #1a1a18;
  --border-subtle: #eceae3;
  --text: #181816;
  --text-muted: #66645d;
  --text-dim: #949187;
  --accent: #181816;
  --accent-contrast: #ffffff;
  --accent-warm: #c34e18;
  --accent-blue: #0969da;
  --accent-teal: #086d70;
  --accent-amber: #8a5b08;
  --accent-danger: #b3261e;
  --mono-bg: #f2f0ea;

  /* 2. Metrics & Radii */
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-subtle: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-float: 0 12px 32px -8px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);

  /* 3. Typography Stacks */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Newsreader", "Charter", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --container: 1280px;

  /* 4. Cross-Surface Compatibility Aliases */
  --shell-bg: var(--bg);
  --shell-panel: var(--bg-surface);
  --shell-panel-2: var(--bg-surface-elevated);
  --shell-line: var(--border);
  --shell-text: var(--text);
  --shell-dim: var(--text-muted);
  --shell-accent: var(--accent-blue);
  --shell-ok: var(--accent-teal);
  --tab-active-bg: var(--accent-blue);
  --tab-active-text: #ffffff;
  --tab-active-border: var(--accent-blue);

  color-scheme: light;
}

html[class~="dark"], html[data-mode="dark"] {
  /* 1. Base Color Scale (Dark: Deep Ink) */
  --bg: #0c0d10;
  --bg-surface: #14151a;
  --bg-surface-elevated: #1c1e24;
  --bg-subtle: #181920;
  --border: #262832;
  --border-strong: #dedfd5;
  --border-subtle: #1e2029;
  --text: #f4f4f2;
  --text-muted: #9597a1;
  --text-dim: #5c5f6c;
  --accent: #f4f4f2;
  --accent-contrast: #0c0d10;
  --accent-warm: #e86326;
  --accent-blue: #58a6ff;
  --accent-teal: #14b8a6;
  --accent-amber: #e5a03c;
  --accent-danger: #f2776b;
  --mono-bg: #161820;

  /* 2. Metrics & Radii */
  --shadow-subtle: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-float: 0 16px 40px -8px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);

  /* 4. Cross-Surface Compatibility Aliases */
  --shell-bg: var(--bg);
  --shell-panel: var(--bg-surface);
  --shell-panel-2: var(--bg-surface-elevated);
  --shell-line: var(--border);
  --shell-text: var(--text);
  --shell-dim: var(--text-muted);
  --shell-accent: var(--accent-blue);
  --shell-ok: var(--accent-teal);
  --tab-active-bg: #1f6feb;
  --tab-active-text: #ffffff;
  --tab-active-border: #388bfd;

  color-scheme: dark;
}

/* Global Accessibility Ring conforming to DESIGN.md Module 4 */
:where(a[href], button, input, select, textarea, summary, [tabindex]:not([tabindex="-1"])):focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
  border-radius: inherit;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ========================================================================== */
/* 5. UNIFIED BUTTON SYSTEM (DESIGN.md Module 4 SSOT)                         */
/* ========================================================================== */

.dl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  box-sizing: border-box;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.dl-btn:hover {
  background: var(--bg-surface-elevated);
  border-color: var(--border-strong);
  color: var(--text);
}

.dl-btn:active {
  transform: scale(0.98);
}

/* High-emphasis Primary Button (Dark Invert) */
.dl-btn-primary {
  background: var(--text);
  color: var(--bg) !important;
  border-color: var(--text);
  font-weight: 700;
  box-shadow: var(--shadow-subtle);
}

.dl-btn-primary:hover {
  background: color-mix(in srgb, var(--text) 90%, var(--bg));
  border-color: var(--text);
  color: var(--bg) !important;
  opacity: 0.95;
}

/* CTA Conversion Button (Terracotta / Warm Accent) */
.dl-btn-cta {
  background: var(--accent-warm);
  color: #ffffff !important;
  border-color: var(--accent-warm);
  font-weight: 700;
  box-shadow: 0 1px 3px color-mix(in srgb, var(--accent-warm) 35%, transparent);
}

.dl-btn-cta:hover {
  background: color-mix(in srgb, var(--accent-warm) 88%, #000);
  border-color: color-mix(in srgb, var(--accent-warm) 88%, #000);
  color: #ffffff !important;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--accent-warm) 30%, transparent);
}

/* Standard Secondary / Outline Button */
.dl-btn-secondary {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
}

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

/* Ghost / Borderless Button */
.dl-btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.dl-btn-ghost:hover {
  background: var(--bg-surface-elevated);
  border-color: transparent;
  color: var(--text);
}

/* Button Size Modifiers */
.dl-btn-sm {
  min-height: 30px;
  padding: 5px 10px;
  font-size: 12px;
  gap: 5px;
}

.dl-btn-md {
  min-height: 38px;
  padding: 8px 14px;
  font-size: 13px;
}

.dl-btn-lg {
  min-height: 46px;
  padding: 12px 20px;
  font-size: 15px;
  gap: 8px;
}

/* ========================================================================== */
/* 6. UNIFIED TAB SYSTEM (DESIGN.md Module 4 SSOT)                            */
/* ========================================================================== */

/* Pattern 1: Segmented View & Navigation Tabs */
.dl-tabs-segment {
  display: inline-flex;
  align-items: center;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 3px;
  box-sizing: border-box;
}

.dl-tab-seg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: all 0.15s ease;
}

.dl-tab-seg:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--bg-surface) 60%, transparent);
}

.dl-tab-seg[aria-selected="true"],
.dl-tab-seg[aria-pressed="true"],
.dl-tab-seg.active {
  background: var(--bg-surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-subtle);
  font-weight: 700;
}

/* Pattern 2: Action Console & Code Tabs */
.dl-tabs-action {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  box-sizing: border-box;
  overflow-x: auto;
  scrollbar-width: none;
}

.dl-tabs-action::-webkit-scrollbar {
  display: none;
}

.dl-tab-action {
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
  user-select: none;
  transition: all 0.15s ease;
}

.dl-tab-action:hover {
  color: var(--accent-blue);
  background: color-mix(in srgb, var(--accent-blue) 10%, var(--bg-surface));
  border-color: color-mix(in srgb, var(--accent-blue) 25%, transparent);
}

.dl-tab-action[aria-selected="true"],
.dl-tab-action.active,
.dl-tab-action.g-active {
  color: var(--tab-active-text, #ffffff) !important;
  background: var(--tab-active-bg, var(--accent-blue)) !important;
  border-color: var(--tab-active-border, var(--accent-blue)) !important;
  font-weight: 700;
  box-shadow: 0 1px 3px color-mix(in srgb, var(--accent-blue) 35%, transparent);
}

/* ========================================================================== */
/* 7. UNIFIED MODAL SYSTEM (DESIGN.md Module 7 SSOT)                          */
/* ========================================================================== */

.dl-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}

.dl-modal-backdrop.open,
.dl-modal-backdrop:not([hidden]) {
  display: flex;
}

.dl-modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  width: min(840px, calc(100vw - 32px));
  box-sizing: border-box;
}

.dl-modal-dialog.dl-modal-fullscreen {
  width: 100vw !important;
  max-width: 100vw !important;
  height: 100vh !important;
  max-height: 100vh !important;
  border-radius: 0 !important;
  border: none !important;
}

.dl-modal-header {
  min-height: 56px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface-elevated);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  box-sizing: border-box;
}

.dl-modal-title {
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0;
}

.dl-modal-body {
  flex: 1;
  min-height: 0;
  padding: 20px;
  overflow-y: auto;
  box-sizing: border-box;
}

.dl-modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: all 0.15s ease;
}

.dl-modal-close:hover {
  background: var(--bg-surface);
  border-color: var(--border);
  color: var(--text);
}

/* ========================================================================== */
/* 8. UNIFIED TYPOGRAPHY SCALE (DESIGN.md Module 8 SSOT)                      */
/* ========================================================================== */

.dl-text-xs {
  font-size: 11px !important;
  line-height: 1.4 !important;
}

.dl-text-sm {
  font-size: 12px !important;
  line-height: 1.45 !important;
}

.dl-text-base {
  font-size: 14px !important;
  line-height: 1.55 !important;
}

.dl-text-md {
  font-size: 16px !important;
  line-height: 1.5 !important;
}

.dl-text-lg {
  font-size: 18px !important;
  line-height: 1.4 !important;
}

.dl-text-xl {
  font-size: 22px !important;
  line-height: 1.3 !important;
}

.dl-text-2xl {
  font-size: 28px !important;
  line-height: 1.2 !important;
}
