@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600;700&display=swap');
@import "tailwindcss";

:root {
  /* ========================================
     UNIFIED LINEAR DESIGN TOKENS
     ======================================== */

  /* Base Colors */
  --term-bg-rgb: 10 10 10;
  --term-bg-elevated-rgb: 13 13 13;
  --term-bg-surface-rgb: 15 15 15;
  --term-bg-highlight-rgb: 21 21 21;
  --term-bg: rgb(var(--term-bg-rgb));
  --term-bg-elevated: rgb(var(--term-bg-elevated-rgb));
  --term-bg-surface: rgb(var(--term-bg-surface-rgb));
  --term-bg-highlight: rgb(var(--term-bg-highlight-rgb));

  /* Border Hierarchy */
  --term-border-subtle-rgb: 26 26 26;
  --term-border-rgb: 42 42 42;
  --term-border-focus-rgb: 88 166 255;
  --term-border-subtle: rgb(var(--term-border-subtle-rgb));
  --term-border: rgb(var(--term-border-rgb));
  --term-border-focus: rgb(var(--term-border-focus-rgb));

  /* Text Hierarchy */
  --term-text-rgb: 224 224 224;
  --term-text-muted-rgb: 136 136 136;
  --term-text-tertiary-rgb: 102 102 102;
  --term-text: rgb(var(--term-text-rgb));
  --term-text-muted: rgb(var(--term-text-muted-rgb));
  --term-text-tertiary: rgb(var(--term-text-tertiary-rgb));

  /* Component Variant Tokens */
  --term-btn-primary-bg: rgb(88 166 255);
  --term-btn-primary-hover: rgb(126 200 255);
  --term-btn-primary-text: rgb(10 10 10);
  --term-btn-secondary-bg: rgb(21 21 21);
  --term-btn-secondary-border: rgb(42 42 42);
  --term-btn-secondary-text: rgb(136 136 136);
  --term-btn-secondary-hover-border: rgb(88 166 255);
  --term-btn-secondary-hover-text: rgb(224 224 224);

  /* Card Variants */
  --term-card-default-bg: rgb(10 10 10);
  --term-card-elevated-bg: rgb(15 15 15);
  --term-card-bordered-border: rgb(42 42 42);

  /* ========================================
     SEMANTIC COLORS (Terminal-aligned)
     ======================================== */
  --semantic-positive-rgb: 158 230 179;
  --semantic-negative-rgb: 255 180 180;
  --semantic-neutral-rgb: 136 136 136;
  --semantic-info-rgb: 88 166 255;
  --semantic-warning-rgb: 231 187 98;
  --semantic-positive: rgb(var(--semantic-positive-rgb));
  --semantic-negative: rgb(var(--semantic-negative-rgb));
  --semantic-neutral: rgb(var(--semantic-neutral-rgb));
  --semantic-info: rgb(var(--semantic-info-rgb));
  --semantic-warning: rgb(var(--semantic-warning-rgb));

  /* ========================================
     LEGACY ALIASES (for backward compatibility)
     ======================================== */
  --bg-base: var(--term-bg);
  --bg-elevated: var(--term-bg-elevated);
  --bg-surface: var(--term-bg-surface);
  --bg-highlight: var(--term-bg-highlight);
  --bg-primary: var(--term-bg);
  --bg-secondary: var(--term-bg-elevated);
  --bg-tertiary: var(--term-bg-highlight);

  --border-subtle: var(--term-border-subtle);
  --border-default: var(--term-border);
  --border-strong: var(--term-border-focus);
  --border-color: var(--term-border);

  --text-primary: var(--term-text);
  --text-secondary: var(--term-text-muted);
  --text-tertiary: var(--term-text-tertiary);
  --text-muted: var(--term-text-tertiary);

  --accent-green: var(--semantic-positive);
  --accent-red: var(--semantic-negative);
  --accent-blue: var(--semantic-info);

  /* ========================================
     RESEARCH TOKENS
     ======================================== */
  --research-bg: var(--term-bg);
  --research-surface: var(--term-bg-elevated);
  --research-panel: var(--term-bg-surface);
  --research-text-strong: var(--term-text);
  --research-text-muted: var(--term-text-muted);
  --research-accent-thesis: rgb(138 185 247);
  --research-accent-risk: rgb(255 143 158);
  --research-accent-catalyst: rgb(158 230 179);
  --research-accent-evidence: rgb(127 192 255);
  --research-accent-ghost: rgb(196 178 255);
  --research-grid: rgba(88, 166, 255, 0.06);

  /* Settings-derived semantic surfaces */
  --term-status-info-rgb: 15 31 49;
  --term-status-info-border-rgb: 29 76 125;
  --term-status-info-strong-rgb: 141 195 255;
  --term-status-success-rgb: 16 36 23;
  --term-status-success-border-rgb: 33 79 49;
  --term-status-error-rgb: 33 19 19;
  --term-status-error-border-rgb: 92 43 43;
  --term-status-warning-rgb: 29 23 12;
  --term-status-warning-border-rgb: 61 52 32;
  --term-status-info: rgb(var(--term-status-info-rgb));
  --term-status-info-border: rgb(var(--term-status-info-border-rgb));
  --term-status-info-strong: rgb(var(--term-status-info-strong-rgb));
  --term-status-success: rgb(var(--term-status-success-rgb));
  --term-status-success-border: rgb(var(--term-status-success-border-rgb));
  --term-status-error: rgb(var(--term-status-error-rgb));
  --term-status-error-border: rgb(var(--term-status-error-border-rgb));
  --term-status-warning: rgb(var(--term-status-warning-rgb));
  --term-status-warning-border: rgb(var(--term-status-warning-border-rgb));

  /* ========================================
     TYPOGRAPHY SCALE
     ======================================== */
  --font-mono: 'IBM Plex Mono', 'JetBrains Mono', 'SF Mono', 'Monaco', 'Inconsolata', monospace;

  /* Display */
  --text-display-2xl: 36px; /* text-4xl */
  --text-display-xl: 30px;  /* text-3xl */

  /* ========================================
     TERMINAL SPACING SYSTEM (4px grid)
     ======================================== */
  --term-xs: 4px;   /* 0.25rem */
  --term-sm: 8px;   /* 0.5rem */
  --term-md: 12px;  /* 0.75rem */
  --term-lg: 16px;  /* 1rem */
  --term-xl: 20px;  /* 1.25rem */
  --term-2xl: 24px; /* 1.5rem */

  /* Section spacing */
  --section-vertical-lg: 6rem;
  --section-vertical-md: 4rem;
  --section-vertical-sm: 2rem;

  /* Element spacing */
  --element-gap-lg: 1.5rem;
  --element-gap-md: 1rem;
  --element-gap-sm: 0.5rem;

  /* Padding */
  --padding-none: 0;
  --padding-sm: 0.5rem;
  --padding-md: 1rem;
  --padding-lg: 1.5rem;
}

@theme inline {
  --color-term-bg: var(--term-bg);
  --color-term-elevated: var(--term-bg-elevated);
  --color-term-surface: var(--term-bg-surface);
  --color-term-highlight: var(--term-bg-highlight);
  --color-term-border: var(--term-border);
  --color-term-border-subtle: var(--term-border-subtle);
  --color-term-border-focus: var(--term-border-focus);
  --color-term-text: var(--term-text);
  --color-term-text-muted: var(--term-text-muted);
  --color-term-text-tertiary: var(--term-text-tertiary);
  --color-info: var(--semantic-info);
  --color-positive: var(--semantic-positive);
  --color-negative: var(--semantic-negative);
  --color-warning: var(--semantic-warning);
  --color-neutral: var(--semantic-neutral);
  --color-research-bg: var(--research-bg);
  --color-research-surface: var(--research-surface);
  --color-research-panel: var(--research-panel);
  --color-research-text-strong: var(--research-text-strong);
  --color-research-text-muted: var(--research-text-muted);
  --spacing-term-xs: var(--term-xs);
  --spacing-term-sm: var(--term-sm);
  --spacing-term-md: var(--term-md);
  --spacing-term-lg: var(--term-lg);
  --spacing-term-xl: var(--term-xl);
  --spacing-term-2xl: var(--term-2xl);
  --radius-md: 0px;
  --radius-lg: 0px;
  --radius-xl: 0px;
  --radius-2xl: 0px;
  --radius-3xl: 0px;
}

* {
  box-sizing: border-box;
}

/* Enforce a hard-corner component language across standard and arbitrary radius utilities. */
:where(
  [class*="rounded"],
  [class*="rounded-"],
  [class*="sm:rounded"],
  [class*="md:rounded"],
  [class*="lg:rounded"],
  [class*="xl:rounded"]
) {
  border-radius: 0 !important;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-mono);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:root[data-density='compact'] {
  --padding-md: 0.75rem;
  --padding-lg: 1rem;
}

:root[data-density='detailed'] {
  --padding-md: 1.125rem;
  --padding-lg: 1.75rem;
}

#root {
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 0;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* Utility Classes */
.font-mono {
  font-family: var(--font-mono);
}

.animate-in {
  animation: fadeIn 0.2s ease-out;
}

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

/* Delay classes for staggered animations */
.delay-75 {
  animation-delay: 75ms;
}

.delay-150 {
  animation-delay: 150ms;
}

.delay-200 {
  animation-delay: 200ms;
}

/* Line clamp for text truncation */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Selection color */
::selection {
  background-color: var(--accent-blue);
  color: var(--bg-primary);
}

/* Focus visible for accessibility */
*:focus-visible {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
}

/* Tab animations */
.tab-transition {
  transition: all 0.15s ease-in-out;
}

.research-shell {
  background-color: var(--research-bg);
  background-image: none;
}

/* TipTap rich text editor */
.research-editor .tiptap {
  min-height: inherit;
}

.research-editor .tiptap:focus {
  outline: none;
}

.research-editor .tiptap p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  color: var(--term-text-tertiary);
  pointer-events: none;
  height: 0;
}

.research-editor .tiptap h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

.research-editor .tiptap h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-top: 0.75rem;
  margin-bottom: 0.375rem;
}

.research-editor .tiptap ul {
  list-style: disc;
  padding-left: 1.5rem;
  margin: 0.5rem 0;
}

.research-editor .tiptap ol {
  list-style: decimal;
  padding-left: 1.5rem;
  margin: 0.5rem 0;
}

.research-editor .tiptap li {
  margin: 0.25rem 0;
}

.research-editor .tiptap blockquote {
  border-left: 2px solid var(--semantic-info);
  padding-left: 1rem;
  margin: 0.75rem 0;
  font-style: italic;
  color: var(--term-text-muted);
}

.research-editor .tiptap p {
  margin: 0.25rem 0;
}

.research-editor .tiptap strong {
  color: white;
  font-weight: 600;
}

.research-editor .tiptap a {
  color: var(--semantic-info);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.research-editor .tiptap code {
  background-color: var(--term-bg-surface);
  border: 1px solid var(--term-border);
  border-radius: 0;
  padding: 0.125rem 0.25rem;
  font-size: 0.8em;
}

/* Custom width for sidebar (Tailwind w-70 equivalent) */
.w-70 {
  width: 17.5rem; /* 280px */
}

/* Typography Scale Utility Classes */
.text-display-2xl {
  font-size: var(--text-display-2xl);
  font-weight: 700;
  line-height: 1;
}

.text-display-xl {
  font-size: var(--text-display-xl);
  font-weight: 700;
  line-height: 1;
}

.text-heading-lg {
  font-size: 1.125rem; /* 18px */
  font-weight: 600;
  line-height: 1.4;
}

.text-heading-md {
  font-size: 1rem; /* 16px */
  font-weight: 500;
  line-height: 1.5;
}

.text-heading-sm {
  font-size: 0.875rem; /* 14px */
  font-weight: 500;
  line-height: 1.5;
}

.text-label-xs {
  font-size: 0.625rem; /* 10px */
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.text-label-sm {
  font-size: 0.75rem; /* 12px */
  font-weight: 400;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.text-body-sm {
  font-size: 0.875rem; /* 14px */
  line-height: 1.75;
  font-weight: 400;
}

.text-body-xs {
  font-size: 0.75rem; /* 12px */
  line-height: 1.6;
  font-weight: 400;
}

/* Spacing Utility Classes */
.space-y-section-lg > * + * {
  margin-top: var(--section-vertical-lg);
}

.space-y-section-md > * + * {
  margin-top: var(--section-vertical-md);
}

.space-y-section-sm > * + * {
  margin-top: var(--section-vertical-sm);
}

/* Responsive Breakpoints */
@media (min-width: 480px) {
  .xs\:block {
    display: block;
  }
  .xs\:inline {
    display: inline;
  }
  .xs\:flex {
    display: flex;
  }
  .xs\:inline-flex {
    display: inline-flex;
  }
  .xs\:grid {
    display: grid;
  }
  .xs\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .xs\:hidden {
    display: none;
  }
  .xs\:w-auto {
    width: auto;
  }
  .xs\:min-w-0 {
    min-width: 0;
  }
  .xs\:gap-1 {
    gap: 0.25rem;
  }
  .xs\:gap-2 {
    gap: 0.5rem;
  }
  .xs\:gap-3 {
    gap: 0.75rem;
  }
  .xs\:text-xs {
    font-size: 0.75rem;
    line-height: 1rem;
  }
  .xs\:text-sm {
    font-size: 0.875rem;
    line-height: 1.25rem;
  }
}

@media (min-width: 640px) {
  .sm\:block {
    display: block;
  }
  .sm\:inline {
    display: inline;
  }
  .sm\:flex {
    display: flex;
  }
  .sm\:inline-flex {
    display: inline-flex;
  }
  .sm\:grid {
    display: grid;
  }
  .sm\:hidden {
    display: none;
  }
  .sm\:w-70 {
    width: 17.5rem;
  }
  .sm\:w-auto {
    width: auto;
  }
  .sm\:min-w-0 {
    min-width: 0;
  }
  .sm\:flex-1 {
    flex: 1 1 0%;
  }
  .sm\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .sm\:gap-2 {
    gap: 0.5rem;
  }
  .sm\:gap-3 {
    gap: 0.75rem;
  }
  .sm\:gap-4 {
    gap: 1rem;
  }
  .sm\:p-4 {
    padding: 1rem;
  }
  .sm\:p-5 {
    padding: 1.25rem;
  }
  .sm\:px-4 {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .sm\:py-2 {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
  }
  .sm\:py-3 {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
  }
  .sm\:text-xs {
    font-size: 0.75rem;
    line-height: 1rem;
  }
  .sm\:text-sm {
    font-size: 0.875rem;
    line-height: 1.25rem;
  }
  .sm\:text-base {
    font-size: 1rem;
    line-height: 1.5rem;
  }
  .sm\:text-lg {
    font-size: 1.125rem;
    line-height: 1.75rem;
  }
}

/* Touch-friendly targets for mobile */
@media (max-width: 639px) {
  button,
  a,
  input,
  select,
  textarea {
    min-height: 44px;
  }

  /* Make touch targets more accessible */
  button[type="button"],
  button[type="submit"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Improve tap spacing */
  .space-y-1 > * + * {
    margin-top: 0.5rem;
  }

  /* Full width cards on mobile */
  .card-mobile-full {
    width: 100%;
  }

  /* Better scroll indicators */
  overflow-x-auto {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  overflow-x-auto::-webkit-scrollbar {
    display: none;
  }
}

/* Improved focus states for keyboard navigation */
@media (prefers-reduced-motion: no-preference) {
  *:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
    transition: outline-color 0.15s ease-in-out;
  }
}
