:root {
  --bg-main: #0b0f19;
  --bg-surface: #111827;
  --bg-card: #1f2937;
  --border-color: #374151;
  --border-focus: #3b82f6;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #38bdf8;
  --success: #10b981;
  --warning: #f59e0b;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --header-height: 58px;
  --toolbar-height: 48px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* App Header */
.app-header {
  height: var(--header-height);
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 16px;
  z-index: 10;
}

.header-left, .header-center, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.brand-title {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.brand-title .accent {
  color: var(--accent);
}

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 9999px;
  border: 1px solid rgba(56, 189, 248, 0.25);
  margin-left: 6px;
}

.doc-title-input {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--text-main);
  font-size: 0.88rem;
  width: 190px;
  transition: all 0.2s ease;
}

.doc-title-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Quick Tools */
.quick-inserts {
  display: flex;
  gap: 6px;
}

.tool-btn {
  background: rgba(31, 41, 55, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.tool-btn:hover {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: #4b5563;
}

.select-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.select-btn:focus {
  outline: none;
  border-color: var(--primary);
}

/* Header Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: #2d3748;
  border-color: #4a5568;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.6);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Toolbar */
.config-toolbar {
  height: var(--toolbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 20px;
  font-size: 0.82rem;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.group-label {
  color: var(--text-muted);
  font-weight: 500;
}

.config-select {
  background: var(--bg-main);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 0.8rem;
  cursor: pointer;
}

.config-select:focus {
  outline: none;
  border-color: var(--primary);
}

.toggle-switch-group {
  display: flex;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 2px;
}

.toggle-pill {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.toggle-pill.active {
  background: var(--primary);
  color: white;
  font-weight: 600;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text-muted);
}

.checkbox-label input {
  accent-color: var(--primary);
  cursor: pointer;
}

.checkbox-label:hover {
  color: var(--text-main);
}

.export-tools {
  margin-left: auto;
  display: flex;
  gap: 12px;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  transition: color 0.15s;
}

.btn-text:hover {
  color: var(--accent);
}

/* Workspace (Split Pane) */
.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.editor-pane {
  flex: 1;
  min-width: 320px;
  border-right: 1px solid var(--border-color);
}

.preview-pane {
  flex: 1.1;
  min-width: 320px;
  background: #090d16;
}

.pane-header {
  height: 38px;
  background: #141c2e;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.pane-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text-main);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.editor-dot {
  background-color: #38bdf8;
}

.preview-dot {
  background-color: #10b981;
}

.pane-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-text {
  font-size: 0.75rem;
  color: #6b7280;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
}

.icon-btn:hover {
  color: #ef4444;
}

.status-indicator {
  font-size: 0.75rem;
  color: #10b981;
}

/* Editor Body */
.editor-body {
  flex: 1;
  position: relative;
  display: flex;
}

.editor-body textarea {
  width: 100%;
  height: 100%;
  background: #0b0f19;
  color: #e5e7eb;
  border: none;
  padding: 16px 20px;
  font-family: var(--font-mono);
  font-size: 0.88rem;
  line-height: 1.65;
  resize: none;
  outline: none;
}

/* Drag and Drop Zone */
.drop-overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(37, 99, 235, 0.9);
  backdrop-filter: blur(4px);
  z-index: 20;
  align-items: center;
  justify-content: center;
  color: white;
  pointer-events: none;
}

.drop-overlay.active {
  display: flex;
}

.drop-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 1.1rem;
}

/* Preview Body */
.preview-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  justify-content: center;
}

.paper-sheet {
  background-color: #ffffff;
  color: #24292f;
  width: 100%;
  max-width: 850px;
  min-height: 1050px;
  padding: 48px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  transition: all 0.2s ease;
}

/* Splitter */
.splitter {
  width: 5px;
  background: var(--border-color);
  cursor: col-resize;
  transition: background 0.15s;
}

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

/* Flowchart in Preview */
.mermaid {
  display: flex;
  justify-content: center;
  margin: 20px 0;
  overflow-x: auto;
}

.mermaid svg {
  max-width: 100% !important;
  height: auto !important;
}

/* Page Break styling */
.page-break {
  page-break-after: always;
  break-after: page;
  border-top: 2px dashed #9ca3af;
  margin: 30px 0;
  position: relative;
}

.page-break::after {
  content: '✂ Page Break';
  position: absolute;
  top: -10px;
  right: 10px;
  background: #e5e7eb;
  color: #4b5563;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 4px;
}

@media print {
  .page-break::after {
    display: none;
  }
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  width: 90%;
  max-width: 620px;
  padding: 24px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 {
  font-size: 1.15rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.modal-body h4 {
  margin: 16px 0 6px;
  font-size: 0.9rem;
  color: var(--accent);
}

.code-box {
  background: #090d16;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #93c5fd;
  overflow-x: auto;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: white;
  border: 1px solid #334155;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  font-size: 0.85rem;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.25s ease;
  z-index: 1000;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* Responsiveness */
@media (max-width: 900px) {
  .workspace {
    flex-direction: column;
  }
  .splitter {
    display: none;
  }
  .editor-pane, .preview-pane {
    flex: 1;
    min-height: 50vh;
  }
  .quick-inserts {
    display: none;
  }
}
