/* Catppuccin Theme & Modern Layout */
:root {
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
    'Noto Sans', Helvetica, Arial, sans-serif;
  --radius: 8px;
  --transition-speed: 0.2s;

  /* Light Theme - matching landing page */
  --bg: #fafafa;
  --bg-base: #ffffff;
  --bg-mantle: #f5f5f5;
  --bg-crust: #eff1f5;
  --text: #0a0a0a;
  --text-text: #3b3f58;
  --text-subtext: #6c6f85;
  --text-muted: rgba(10, 10, 10, 0.65);
  --border: rgba(0, 0, 0, 0.1);
  --border-overlay: rgba(0, 0, 0, 0.15);
  --border-hover: rgba(0, 0, 0, 0.2);
  --accent: #8b5cf6;
  --accent-blue: #1e66f5;
  --accent-lavender: #7287fd;
  --accent-primary: #8b5cf6;
  --accent-secondary: #7c3aed;
  --accent-gradient: linear-gradient(
    135deg,
    var(--accent) 0%,
    var(--accent-secondary) 100%
  );
  --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-strong: 0 16px 40px rgba(0, 0, 0, 0.12);
  --glass-bg: rgba(255, 255, 255, 0.8);
  --glass-border: rgba(0, 0, 0, 0.1);
  --shadow-color: rgba(0, 0, 0, 0.1);
}

body.dark-theme {
  /* Dark Theme - matching landing page */
  --bg: #0a0a0a;
  --bg-base: #1e1e2e;
  --bg-mantle: #181825;
  --bg-crust: #11111b;
  --text: #fafafa;
  --text-text: #cdd6f4;
  --text-subtext: #a6adc8;
  --text-muted: rgba(250, 250, 250, 0.65);
  --border: rgba(255, 255, 255, 0.1);
  --border-overlay: rgba(255, 255, 255, 0.15);
  --border-hover: rgba(255, 255, 255, 0.2);
  --accent: #8b5cf6;
  --accent-blue: #89b4fa;
  --accent-lavender: #cba6f7;
  --accent-primary: #8b5cf6;
  --accent-secondary: #7c3aed;
  --accent-gradient: linear-gradient(
    135deg,
    var(--accent) 0%,
    var(--accent-secondary) 100%
  );
  --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.3);
  --shadow-strong: 0 16px 40px rgba(0, 0, 0, 0.4);
  --glass-bg: rgba(24, 24, 37, 0.75);
  --glass-border: rgba(255, 255, 255, 0.1);
  --shadow-color: rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden; /* Prevent body scrolling */
  font-family: var(--font-family);
  background: radial-gradient(
      ellipse 80% 50% at 50% 0%,
      rgba(139, 92, 246, 0.08),
      transparent
    ),
    var(--bg);
  color: var(--text);
}

/* Main Layout */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 16px;
  gap: 16px;
}

.workspace-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
}

.workspace-title h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-text);
}

.workspace-title p {
  margin: 4px 0 0;
  color: var(--text-subtext);
  max-width: 640px;
  font-size: 13px;
}

.workspace-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-btn {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-text);
  backdrop-filter: blur(12px);
  transition: all var(--transition-speed) ease;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 6px var(--shadow-color);
}

.action-btn i {
  font-size: 18px;
  line-height: 1;
}

.action-btn:hover {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--accent-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
}

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

#generate-btn {
  background: var(--accent-gradient);
  color: #ffffff;
  border: none;
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

#generate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.btn-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 110px; /* Fixed width to prevent button shift */
}

.btn-loading {
  display: none; /* Hidden by default */
  align-items: center;
  justify-content: center;
  min-width: 110px; /* Same width as btn-text */
}

.loader-container {
  --uib-size: 18px;
  --uib-color: #ffffff;
  --uib-speed: 1s;
  --uib-stroke: 2px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--uib-size);
  width: var(--uib-size);
}

.loader-line {
  position: absolute;
  top: 0;
  left: calc(50% - var(--uib-stroke) / 2);
  display: flex;
  align-items: flex-start;
  height: 100%;
  width: var(--uib-stroke);
}

.loader-line::before {
  content: '';
  height: 22%;
  width: 100%;
  border-radius: calc(var(--uib-stroke) / 2);
  background-color: var(--uib-color);
  animation: pulse calc(var(--uib-speed)) ease-in-out infinite;
  transition: background-color 0.3s ease;
  transform-origin: center bottom;
}

.loader-line:nth-child(1) {
  transform: rotate(calc(360deg / -12 * 1));
}
.loader-line:nth-child(1)::before {
  animation-delay: calc(var(--uib-speed) / -12 * 1);
}

.loader-line:nth-child(2) {
  transform: rotate(calc(360deg / -12 * 2));
}
.loader-line:nth-child(2)::before {
  animation-delay: calc(var(--uib-speed) / -12 * 2);
}

.loader-line:nth-child(3) {
  transform: rotate(calc(360deg / -12 * 3));
}
.loader-line:nth-child(3)::before {
  animation-delay: calc(var(--uib-speed) / -12 * 3);
}

.loader-line:nth-child(4) {
  transform: rotate(calc(360deg / -12 * 4));
}
.loader-line:nth-child(4)::before {
  animation-delay: calc(var(--uib-speed) / -12 * 4);
}

.loader-line:nth-child(5) {
  transform: rotate(calc(360deg / -12 * 5));
}
.loader-line:nth-child(5)::before {
  animation-delay: calc(var(--uib-speed) / -12 * 5);
}

.loader-line:nth-child(6) {
  transform: rotate(calc(360deg / -12 * 6));
}
.loader-line:nth-child(6)::before {
  animation-delay: calc(var(--uib-speed) / -12 * 6);
}

.loader-line:nth-child(7) {
  transform: rotate(calc(360deg / -12 * 7));
}
.loader-line:nth-child(7)::before {
  animation-delay: calc(var(--uib-speed) / -12 * 7);
}

.loader-line:nth-child(8) {
  transform: rotate(calc(360deg / -12 * 8));
}
.loader-line:nth-child(8)::before {
  animation-delay: calc(var(--uib-speed) / -12 * 8);
}

.loader-line:nth-child(9) {
  transform: rotate(calc(360deg / -12 * 9));
}
.loader-line:nth-child(9)::before {
  animation-delay: calc(var(--uib-speed) / -12 * 9);
}

.loader-line:nth-child(10) {
  transform: rotate(calc(360deg / -12 * 10));
}
.loader-line:nth-child(10)::before {
  animation-delay: calc(var(--uib-speed) / -12 * 10);
}

.loader-line:nth-child(11) {
  transform: rotate(calc(360deg / -12 * 11));
}
.loader-line:nth-child(11)::before {
  animation-delay: calc(var(--uib-speed) / -12 * 11);
}

.loader-line:nth-child(12) {
  transform: rotate(calc(360deg / -12 * 12));
}
.loader-line:nth-child(12)::before {
  animation-delay: calc(var(--uib-speed) / -12 * 12);
}

@keyframes pulse {
  0%,
  80%,
  100% {
    transform: scaleY(0.75);
    opacity: 0;
  }
  20% {
    transform: scaleY(1);
    opacity: 1;
  }
}

.btn-loading i {
  animation: spin 1s linear infinite;
}

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

.workspace-tip {
  white-space: nowrap;
}

.main-content {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
  padding: 10px;
  gap: 2px;
  border-radius: 12px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}

.editor-section,
.preview-section {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-base);
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3),
    inset 0 -1px 0 rgba(17, 17, 27, 0.05);
  border: 1px solid rgba(140, 140, 160, 0.15);
  overflow-y: auto; /* Enable independent scrolling */
  transition: transform var(--transition-speed) ease,
    box-shadow var(--transition-speed) ease;
}

.preview-section {
  border-left: none;
  background: #ffffff !important; /* Always white for PDF preview */
}

.resizer {
  flex: 0 0 12px;
  cursor: col-resize;
  background: transparent;
  z-index: 10;
  position: relative;
  user-select: none;
  touch-action: none;
}

.resizer::before,
.resizer::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 999px;
  transition: opacity var(--transition-speed) ease,
    background var(--transition-speed) ease;
}

.resizer::before {
  top: 12px;
  bottom: 12px;
  width: 4px;
  background: linear-gradient(
    180deg,
    rgba(139, 92, 246, 0.3),
    rgba(124, 58, 237, 0.3)
  );
  opacity: 0.5;
}

.resizer::after {
  width: 12px;
  height: 36px;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(139, 92, 246, 0.12);
  opacity: 0;
}

.resizer:hover::before,
.resizer:focus-visible::before {
  opacity: 0.9;
  background: var(--accent-gradient);
}

.resizer:hover::after,
.resizer:focus-visible::after {
  opacity: 0.4;
}

/* Hamburger Menu - REMOVED */

/* Editor & Preview */
#md-input {
  width: 100%;
  flex: 1;
  border: none;
  padding: 24px;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 15px;
  line-height: 1.7;
  resize: none;
  outline: none;
  background: transparent;
  color: var(--text-text);
  border-radius: 10px;
  border: 1px solid rgba(140, 140, 160, 0.1);

}


#md-input::-webkit-scrollbar {
  width: 6px;
}

#md-input::-webkit-scrollbar-track {
  background: transparent;
}

#md-input::-webkit-scrollbar-thumb {
  z-index: 100;
  background: rgba(139, 92, 246, 0.45);
  border-radius: 999px;
}

#md-input::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 92, 246, 0.75);
}

#preview {
  padding: 24px 32px;
  background: #ffffff; /* Always white */
  border-radius: 10px;
  border: 1px solid rgba(140, 140, 160, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transition: box-shadow var(--transition-speed) ease,
    border-color var(--transition-speed) ease;
}

.preview-section:hover #preview {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.markdown-body {
  color: #24292f; /* Always dark text for readability */
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  color: #24292f; /* Always dark text */
}

.markdown-body code,
.markdown-body pre {
  border-radius: 10px;
}

.editor-section::-webkit-scrollbar,
.preview-section::-webkit-scrollbar {
  width: 6px;
}

.editor-section::-webkit-scrollbar-track,
.preview-section::-webkit-scrollbar-track {
  background: transparent;
}

.editor-section::-webkit-scrollbar-thumb,
.preview-section::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.45);
  border-radius: 999px;
}

.editor-section::-webkit-scrollbar-thumb:hover,
.preview-section::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 92, 246, 0.75);
}

textarea::placeholder {
  color: var(--text-subtext);
  opacity: 0.75;
}

/* Responsive & Other */
@media (max-width: 768px) {
  .app-container {
    padding: 12px;
  }
  .main-content {
    flex-direction: column;
    padding: 12px;
  }
  .workspace-header {
    padding: 12px;
    flex-direction: column;
    align-items: flex-start;
  }
  .workspace-title h1 {
    font-size: 18px;
  }
  .workspace-actions {
    width: 100%;
    justify-content: flex-end;
  }
  .action-btn {
    padding: 8px 12px;
    font-size: 13px;
  }
  .resizer {
    display: none;
  }
  .preview-section {
    border-left: none;
    border-top: 1px solid var(--border-overlay);
  }
  #md-input,
  #preview {
    padding: 20px;
  }
}

@media print {
  body {
    background: white !important;
  }
  .workspace-header,
  .resizer {
    display: none !important;
  }
  #preview {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
  }

  /* Prevent page breaks within elements - more aggressive approach */
  .markdown-body h1,
  .markdown-body h2,
  .markdown-body h3,
  .markdown-body h4,
  .markdown-body h5,
  .markdown-body h6 {
    break-after: avoid !important;
    page-break-after: avoid !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  .markdown-body p,
  .markdown-body blockquote,
  .markdown-body pre,
  .markdown-body code,
  .markdown-body li,
  .markdown-body table,
  .markdown-body ul,
  .markdown-body ol,
  .markdown-body details,
  .markdown-body .diagram {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  /* Keep headings with their following content */
  .markdown-body h1,
  .markdown-body h2,
  .markdown-body h3,
  .markdown-body h4,
  .markdown-body h5,
  .markdown-body h6 {
    margin-top: 1.5em !important;
    margin-bottom: 0.5em !important;
  }

  /* Ensure spoilers are expanded (handled by JS setting 'open' attribute) */
  details > summary {
    display: none;
  }
}
