/* CSS Custom Properties for Theme */
:root {
  /* Light mode colors */
  --bg-primary: #ffffff;
  --bg-secondary: #fafbfc;
  --bg-tertiary: #f4f5f7;
  --bg-elevated: #ffffff;
  --text-primary: #172b4d;
  --text-secondary: #5e6c84;
  --text-muted: #8993a4;
  --border-primary: #dfe1e6;
  --border-secondary: #f4f5f7;
  --accent-primary: #0052cc;
  --accent-secondary: #172b4d;
  --success: #36b37e;
  --warning: #ffab00;
  --error: #de350b;
  --info: #00a3f7;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(9, 30, 66, 0.04);
  --shadow: 0 2px 4px rgba(9, 30, 66, 0.08);
  --shadow-md: 0 4px 8px rgba(9, 30, 66, 0.12), 0 2px 4px rgba(9, 30, 66, 0.08);
  --shadow-lg: 0 8px 16px rgba(9, 30, 66, 0.16), 0 4px 8px rgba(9, 30, 66, 0.12);
  --shadow-xl: 0 12px 24px rgba(9, 30, 66, 0.2), 0 8px 16px rgba(9, 30, 66, 0.16);
  
  /* Border radius */
  --radius-sm: 4px;
  --radius: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  
  /* Typography */
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
}

[data-theme="dark"] {
  /* Dark mode colors */
  --bg-primary: #121212;
  --bg-secondary: #1e1e1e;
  --bg-tertiary: #2d2d2d;
  --bg-elevated: #1e1e1e;
  --text-primary: #ffffff;
  --text-secondary: #b3b3b3;
  --text-muted: #8c8c8c;
  --border-primary: #333333;
  --border-secondary: #2d2d2d;
  --accent-primary: #4c9aff;
  --accent-secondary: #ffffff;
  --success: #57d9a3;
  --warning: #ffcc02;
  --error: #ff5630;
  --info: #00b8d9;
  
  /* Dark shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.32);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.32);
  --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.48), 0 4px 8px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 12px 24px rgba(0, 0, 0, 0.56), 0 8px 16px rgba(0, 0, 0, 0.48);
}

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-feature-settings: 'rlig' 1, 'calt' 1, 'ss01' 1;
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.5;
  font-size: var(--font-size-base);
  transition: background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
}

/* Header Styles */
.header {
  background-color: var(--bg-elevated);
  border-bottom: 1px solid var(--border-primary);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
  height: 64px;
}

.header-left {
  display: flex;
  align-items: center;
  min-width: 0;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  text-decoration: none;
  color: inherit;
  transition: opacity 0.2s ease;
}

.logo:hover {
  opacity: 0.8;
}

.logo-img {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
}

.logo-text {
  font-weight: 600;
  font-size: var(--font-size-lg);
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  max-width: 600px;
  margin: 0 var(--space-xl);
}

.document-title {
  flex: 1;
  max-width: 400px;
}

.title-input {
  width: 100%;
  background: transparent;
  border: none;
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  padding: var(--space-sm);
  border-radius: var(--radius);
  transition: background-color 0.2s ease;
}

.title-input:hover,
.title-input:focus {
  background-color: var(--bg-tertiary);
  outline: none;
}

.title-input::placeholder {
  color: var(--text-secondary);
  font-weight: 500;
}

.header-right {
  display: flex;
  gap: var(--space-xs);
  flex-shrink: 0;
}

.action-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: var(--space-sm);
  cursor: pointer;
  font-size: var(--font-size-lg);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  position: relative;
  overflow: hidden;
}

.action-btn:hover {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.action-btn:active {
  transform: translateY(0);
}

.action-btn:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Lucide Icon Styles */
.action-btn i,
.quick-action-btn i,
.insight-icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  flex-shrink: 0;
}

.action-btn i {
  transition: transform 0.2s ease;
}

.action-btn:hover i {
  transform: scale(1.1);
}

/* Theme icon specific styling */
.theme-icon {
  transition: transform 0.3s ease;
}

/* Icon color inheritance */
i[data-lucide] {
  color: inherit;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  padding: var(--space-xl) var(--space-lg);
}

.content-wrapper {
  display: flex;
  gap: var(--space-xl);
  width: 100%;
}

.editor-container {
  flex: 1;
  min-width: 0;
  background-color: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Editor.js Styles */
#editor {
  min-height: 500px;
  padding: var(--space-2xl);
}

/* Editor.js Dark Mode Customization */
[data-theme="dark"] .codex-editor {
  color: var(--text-primary);
}

[data-theme="dark"] .codex-editor__redactor {
  color: var(--text-primary);
}

[data-theme="dark"] .ce-block__content {
  color: var(--text-primary);
}

[data-theme="dark"] .ce-paragraph {
  color: var(--text-primary);
}

[data-theme="dark"] .ce-header {
  color: var(--text-primary);
}

[data-theme="dark"] .ce-toolbar__content {
  background: var(--bg-elevated);
  border-color: var(--border-primary);
}

[data-theme="dark"] .ce-toolbar__actions {
  background: var(--bg-elevated);
  border-color: var(--border-primary);
}

[data-theme="dark"] .ce-popover {
  background: var(--bg-elevated);
  border-color: var(--border-primary);
  color: var(--text-primary);
}

[data-theme="dark"] .ce-popover__item {
  color: var(--text-primary);
}

[data-theme="dark"] .ce-popover__item:hover {
  background-color: var(--bg-tertiary);
}

[data-theme="dark"] .ce-toolbox {
  background: var(--bg-elevated);
  border-color: var(--border-primary);
}

[data-theme="dark"] .ce-toolbox__button {
  color: var(--text-primary);
}

[data-theme="dark"] .ce-toolbox__button:hover {
  background-color: var(--bg-tertiary);
}

[data-theme="dark"] .ce-inline-toolbar {
  background: var(--bg-elevated);
  border-color: var(--border-primary);
}

[data-theme="dark"] .ce-inline-tool {
  color: var(--text-primary);
}

[data-theme="dark"] .ce-inline-tool:hover {
  background-color: var(--bg-tertiary);
}

/* Enhanced Analytics Sidebar */
.analytics-sidebar {
  width: 350px;
  background-color: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  height: fit-content;
  position: sticky;
  top: 96px;
  box-shadow: var(--shadow);
  flex-shrink: 0;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.analytics-header h3 {
  margin-bottom: var(--space-lg);
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

/* Stats Sections */
.stats-section {
  margin-bottom: var(--space-xl);
}

.stats-section h4 {
  margin-bottom: var(--space-md);
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Basic Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.stat-item {
  text-align: center;
  padding: var(--space-md);
  background-color: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-secondary);
  transition: all 0.2s ease;
}

.stat-item:hover {
  border-color: var(--border-primary);
  transform: translateY(-1px);
}

.stat-label {
  display: block;
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.stat-value {
  display: block;
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

/* Stats List for Structure */
.stats-list {
  background-color: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-secondary);
  overflow: hidden;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-secondary);
}

.stat-row:last-child {
  border-bottom: none;
}

.stat-row .stat-label {
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  margin: 0;
}

.stat-row .stat-value {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--accent-primary);
}

/* Quality Metric Cards */
.metric-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.metric-card {
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  border: 1px solid var(--border-secondary);
  transition: all 0.2s ease;
}

.metric-card:hover {
  border-color: var(--border-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}

.metric-label {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.metric-value {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--accent-primary);
}

.metric-description {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  font-style: italic;
}

/* Document Insights */
.insights-list {
  background-color: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-secondary);
  padding: var(--space-md);
}

.insight-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.insight-item:last-child {
  margin-bottom: 0;
}

.insight-icon {
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--accent-primary);
}

.insight-text {
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  line-height: 1.4;
}

/* Quick Action Buttons */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.quick-action-btn {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-md);
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-secondary);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.quick-action-btn:hover {
  background-color: var(--bg-tertiary);
  border-color: var(--border-primary);
  transform: translateY(-1px);
}

.quick-action-btn:active {
  transform: translateY(0);
}

.quick-action-btn i {
  color: var(--text-secondary);
  transition: color 0.2s ease;
}

.quick-action-btn:hover i {
  color: var(--accent-primary);
}

/* Footer */
.footer {
  background-color: var(--bg-elevated);
  border-top: 1px solid var(--border-primary);
  padding: var(--space-xl) var(--space-lg);
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
}

.footer a {
  color: var(--accent-secondary);
  text-decoration: none;
  transition: all 0.2s ease;
  font-weight: 500;
}

.footer a:hover {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.footer i {
  vertical-align: middle;
  margin: 0 0.25rem;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

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

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-primary);
  border-top: 3px solid var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 1024px) {
  .content-wrapper {
    flex-direction: column;
  }
  
  .analytics-sidebar {
    width: 100%;
    position: static;
    order: 2;
    max-height: none;
  }
  
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-sm);
  }
  
  .stat-item {
    padding: var(--space-sm);
  }
  
  .stat-value {
    font-size: var(--font-size-lg);
  }
}

@media (max-width: 768px) {
  .header-main {
    padding: 0 var(--space-md);
    height: 56px;
  }
  
  .logo-text {
    display: none;
  }
  
  .header-center {
    margin: 0 var(--space-md);
  }
  
  .main-content {
    padding: var(--space-lg) var(--space-md);
  }
  
  .content-wrapper {
    gap: var(--space-lg);
  }
  
  #editor {
    padding: var(--space-lg);
  }
  
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
  }
  
  .analytics-sidebar {
    padding: var(--space-lg);
  }
  
  .action-btn {
    width: 36px;
    height: 36px;
  }
  
  .action-btn i {
    width: 16px;
    height: 16px;
  }
}

@media (max-width: 480px) {
  .header-main {
    padding: 0 var(--space-sm);
  }
  
  .header-right {
    gap: 2px;
  }
  
  .header-center {
    margin: 0 var(--space-sm);
  }
  
  .title-input {
    font-size: var(--font-size-base);
  }
  
  .main-content {
    padding: var(--space-md) var(--space-sm);
  }
  
  .analytics-sidebar {
    padding: var(--space-md);
    width: calc(100% + var(--space-md));
    margin: 0 calc(-1 * var(--space-sm));
  }
  
  .stats-grid {
    gap: var(--space-sm);
  }
  
  .stat-item {
    padding: var(--space-sm);
  }
  
  .stat-value {
    font-size: var(--font-size-base);
  }
  
  #editor {
    padding: var(--space-md);
  }
  
  .action-btn {
    width: 32px;
    height: 32px;
    padding: var(--space-xs);
  }
  
  .action-btn i {
    width: 14px;
    height: 14px;
  }
}

/* Hidden states */
.editor-container.hidden {
  display: none;
}

/* Focus ring improvements */
button:focus-visible,
.action-btn:focus-visible,
.quick-action-btn:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

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

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

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

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

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Custom scrollbar for analytics sidebar */
.analytics-sidebar::-webkit-scrollbar {
  width: 6px;
}

.analytics-sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.analytics-sidebar::-webkit-scrollbar-thumb {
  background: var(--border-primary);
  border-radius: var(--radius-sm);
}

/* Animation for metric cards */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.metric-card {
  animation: fadeInUp 0.3s ease;
}

/* Pulse animation for updated values */
@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.stat-value.updated {
  animation: pulse 0.3s ease;
}

/* Icon hover effects */
@keyframes iconBounce {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

.action-btn:hover i {
  animation: iconBounce 0.3s ease;
}

/* Notification icon alignment */
.notification-icon {
  margin-right: 0.5rem;
  flex-shrink: 0;
}

/* Loading state icons */
.loading-icon {
  animation: spin 1s linear infinite;
}

/* Success state icons */
.success-icon {
  color: var(--success);
}

/* Error state icons */
.error-icon {
  color: var(--error);
}

/* Warning state icons */
.warning-icon {
  color: var(--warning);
}

/* Info state icons */
.info-icon {
  color: var(--info);
}
