/*
 * Frism "Obsidian" Design System
 * A dark-theme design system inspired by modern code editors
 */

/* ===========================
   1. CSS CUSTOM PROPERTIES
   =========================== */
:root {
  /* === Background Colors === */
  --bg-app: #0a0a0f;
  --bg-panel: #12121a;
  --bg-code: #0d0d12;
  --bg-sidebar: #0f0f14;
  --bg-header: #111118;
  --bg-hover: rgba(255, 255, 255, 0.05);
  --bg-active: rgba(255, 255, 255, 0.08);
  --bg-input: #1a1a24;
  --bg-tooltip: #252533;

  /* === Text Colors === */
  --text-primary: #e8e8ec;
  --text-secondary: #8b8b9a;
  --text-muted: #5a5a6a;
  --text-placeholder: #4a4a5a;
  --text-tertiary: #4a4a5a;

  /* === Accent Colors === */
  --accent-primary: #6366f1; /* Indigo - main brand */
  --accent-primary-hover: #818cf8;
  --accent-secondary: #a855f7; /* Purple - AI features */
  --accent-success: #22c55e; /* Green - success states */
  --accent-warning: #f59e0b; /* Amber - warnings */
  --accent-error: #ef4444; /* Red - errors */
  --accent-info: #3b82f6; /* Blue - info */

  /* === Border Colors === */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-focus: var(--accent-primary);

  /* === Shadows === */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
  --shadow-glow-ai: 0 0 20px rgba(168, 85, 247, 0.2);

  /* === Typography === */
  --font-sans:
    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  --font-serif: "Noto Serif SC", "Georgia", serif;

  --text-xs: 0.75rem; /* 12px */
  --text-sm: 0.875rem; /* 14px */
  --text-base: 1rem; /* 16px */
  --text-lg: 1.125rem; /* 18px */
  --text-xl: 1.25rem; /* 20px */
  --text-2xl: 1.5rem; /* 24px */

  /* === Spacing === */
  --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 */

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

  /* === Transitions === */
  --transition-fast: 150ms ease;
  --transition-normal: 200ms ease;
  --transition-slow: 300ms ease;

  /* === Z-Index Scale === */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal: 300;
  --z-toast: 400;
}

/* ===========================
   2. BASE RESET
   =========================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow: hidden;
}

/* ===========================
   3. SCROLLBAR STYLING
   =========================== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* ===========================
   4. TYPOGRAPHY UTILITIES
   =========================== */
.text-xs {
  font-size: var(--text-xs);
}
.text-sm {
  font-size: var(--text-sm);
}
.text-base {
  font-size: var(--text-base);
}
.text-lg {
  font-size: var(--text-lg);
}
.text-xl {
  font-size: var(--text-xl);
}
.text-2xl {
  font-size: var(--text-2xl);
}

.font-mono {
  font-family: var(--font-mono);
}
.font-serif {
  font-family: var(--font-serif);
}

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

/* ===========================
   5. LAYOUT COMPONENTS
   =========================== */

/* Main App Container */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 var(--space-4);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: 600;
  color: var(--text-primary);
}

.app-logo-icon {
  width: 28px;
  height: 28px;
  background: linear-gradient(
    135deg,
    var(--accent-primary),
    var(--accent-secondary)
  );
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-sm);
}

/* Main Content Area */
.app-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 220px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-section {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-title {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}

/* File Tree */
.file-tree {
  padding: var(--space-2);
}

.file-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.file-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.file-item.active {
  background: var(--bg-active);
  color: var(--text-primary);
}

.file-item-icon {
  width: 16px;
  height: 16px;
  opacity: 0.6;
}

/* Editor Panel */
.editor-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-code);
  overflow: hidden;
}

.editor-tabs {
  display: flex;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 var(--space-2);
  gap: var(--space-1);
}

.editor-tab {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
}

.editor-tab:hover {
  color: var(--text-secondary);
}

.editor-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent-primary);
}

.editor-tab-close {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: all var(--transition-fast);
}

.editor-tab:hover .editor-tab-close {
  opacity: 0.5;
}

.editor-tab-close:hover {
  opacity: 1 !important;
  background: var(--bg-hover);
}

.editor-content {
  flex: 1;
  overflow: hidden;
}

/* Preview Panel */
.preview-panel {
  width: 50%;
  background: var(--bg-panel);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-subtle);
}

.preview-content {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: var(--space-4);
  background: #1a1a24;
}

/* PDF Preview Container */
.pdf-container {
  background: white;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

/* PDF.js Text Layer - enables text selection and copy */
.textLayer {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  opacity: 0.25;
  line-height: 1;
  -webkit-text-size-adjust: none;
  -moz-text-size-adjust: none;
  text-size-adjust: none;
}

.textLayer > span {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}

.textLayer ::selection {
  background: rgba(0, 0, 255, 0.3);
}

.textLayer ::-moz-selection {
  background: rgba(0, 0, 255, 0.3);
}

.textLayer .endOfContent {
  display: block;
  position: absolute;
  left: 0;
  top: 100%;
  right: 0;
  bottom: 0;
  z-index: -1;
  cursor: default;
  user-select: none;
}

/* ===========================
   6. AI CHAT BAR
   =========================== */
.ai-chat-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-panel);
  border-top: 1px solid var(--border-subtle);
}

.ai-chat-input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-2) var(--space-4);
  transition: all var(--transition-fast);
}

.ai-chat-input-wrapper:focus-within {
  border-color: var(--accent-secondary);
  box-shadow: var(--shadow-glow-ai);
}

.ai-chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: var(--text-sm);
}

.ai-chat-input::placeholder {
  color: var(--text-placeholder);
}

.ai-chat-actions {
  display: flex;
  gap: var(--space-1);
}

.ai-chat-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.ai-chat-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.ai-chat-btn.primary {
  background: var(--accent-secondary);
  color: white;
}

.ai-chat-btn.primary:hover {
  background: var(--accent-primary);
}

/* ===========================
   7. BUTTON COMPONENTS
   =========================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

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

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--bg-active);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-md);
}

/* ===========================
   8. FORM COMPONENTS
   =========================== */
.input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  transition: all var(--transition-fast);
}

.input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

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

/* ===========================
   9. UTILITY CLASSES
   =========================== */
.flex {
  display: flex;
}
.flex-col {
  flex-direction: column;
}
.items-center {
  align-items: center;
}
.justify-between {
  justify-content: space-between;
}
.justify-center {
  justify-content: center;
}
.gap-1 {
  gap: var(--space-1);
}
.gap-2 {
  gap: var(--space-2);
}
.gap-3 {
  gap: var(--space-3);
}
.gap-4 {
  gap: var(--space-4);
}
.flex-1 {
  flex: 1;
}
.shrink-0 {
  flex-shrink: 0;
}

.p-2 {
  padding: var(--space-2);
}
.p-3 {
  padding: var(--space-3);
}
.p-4 {
  padding: var(--space-4);
}
.px-4 {
  padding-left: var(--space-4);
  padding-right: var(--space-4);
}
.py-2 {
  padding-top: var(--space-2);
  padding-bottom: var(--space-2);
}

.rounded {
  border-radius: var(--radius-md);
}
.rounded-lg {
  border-radius: var(--radius-lg);
}
.rounded-full {
  border-radius: var(--radius-full);
}

.hidden {
  display: none !important;
}
.overflow-hidden {
  overflow: hidden;
}
.overflow-auto {
  overflow: auto;
}

.cursor-pointer {
  cursor: pointer;
}
.select-none {
  user-select: none;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===========================
   10. ANIMATIONS
   =========================== */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

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

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

.animate-fade {
  animation: fadeIn var(--transition-normal);
}
.animate-slide-up {
  animation: slideUp var(--transition-normal);
}
.animate-pulse {
  animation: pulse 2s infinite;
}

/* ===========================
   11. RESIZABLE PANELS
   =========================== */
.gutter {
  background: var(--bg-panel);
  position: relative;
}

.gutter:hover {
  background: var(--accent-primary);
}

.gutter-horizontal {
  width: 4px;
  cursor: col-resize;
}

.gutter-vertical {
  height: 4px;
  cursor: row-resize;
}

/* ===========================
   12. DOCUMENT OUTLINE
   =========================== */
.outline-list {
  padding: var(--space-2);
}

.outline-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.outline-item:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.outline-item.active {
  color: var(--text-primary);
  background: var(--bg-active);
}

.outline-item.level-2 {
  padding-left: calc(var(--space-4) + var(--space-2));
}

.outline-item.level-3 {
  padding-left: calc(var(--space-6) + var(--space-2));
}

/* ===========================
   13. LOADING STATES
   =========================== */
.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-input) 25%,
    var(--bg-hover) 50%,
    var(--bg-input) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ===========================
   14. RESPONSIVE DESIGN
   =========================== */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .preview-panel {
    display: none;
  }

  .preview-panel.mobile-active {
    display: flex;
    position: fixed;
    inset: 0;
    width: 100%;
    z-index: var(--z-modal);
  }
}
