/* ========================================
   CSS VARIABLES & THEME TOKENS
   ======================================== */
:root {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color-scheme: dark;
  --transition-base: 0.3s ease;
}

* {
  box-sizing: border-box;
}

/* Dark Theme (Default) - Purple/Violet Palette */
body {
  --bg-base: #0a0514;
  --bg-card: rgba(15, 8, 25, 0.9);
  --bg-card-solid: rgba(20, 12, 35, 0.92);
  --glass-strong: linear-gradient(135deg, rgba(20, 10, 35, 0.78), rgba(18, 10, 32, 0.55));
  --glass-soft: rgba(15, 8, 25, 0.85);
  --field-bg: rgba(18, 10, 32, 0.6);
  --field-border: rgba(168, 148, 200, 0.3);
  --field-border-focus: rgba(167, 139, 250, 0.7);
  --ghost-border: rgba(168, 148, 200, 0.35);
  --ghost-hover: rgba(167, 139, 250, 0.5);
  --text-main: #f5f3ff;
  --text-muted: #ddd6fe;
  --accent: #a78bfa;
  --accent-strong: #8b5cf6;
  --border: rgba(167, 139, 250, 0.22);
  --shadow: 0 24px 60px rgba(10, 5, 20, 0.55);
  --glow-1: rgba(139, 92, 246, 0.4);
  --glow-2: rgba(167, 139, 250, 0.35);
  --glow-3: rgba(217, 70, 239, 0.28);
  --log-bg: rgba(12, 6, 22, 0.85);
  --log-text: #e9d5ff;
  --cost-chart-base: rgba(8, 4, 16, 0.8);
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 40px 24px 80px;
  background: radial-gradient(circle at 20% -10%, var(--glow-1), transparent 45%),
              radial-gradient(circle at 80% -20%, var(--glow-2), transparent 50%),
              radial-gradient(circle at 50% 120%, var(--glow-3), transparent 55%),
              var(--bg-base);
  color: var(--text-main);
  transition: background 0.7s ease, color 0.4s ease;
}

/* Light Theme - Lavender/Purple Tones */
body[data-theme="light"] {
  color-scheme: light;
  --bg-base: linear-gradient(180deg, #faf5ff 0%, #fefcff 65%);
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-solid: rgba(255, 255, 255, 0.96);
  --glass-strong: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(243, 232, 255, 0.9));
  --glass-soft: rgba(255, 255, 255, 0.92);
  --field-bg: rgba(255, 255, 255, 0.95);
  --field-border: rgba(139, 92, 246, 0.3);
  --field-border-focus: rgba(124, 58, 237, 0.6);
  --ghost-border: rgba(139, 92, 246, 0.4);
  --ghost-hover: rgba(124, 58, 237, 0.55);
  --text-main: #2e1065;
  --text-muted: #5b21b6;
  --accent: #7c3aed;
  --accent-strong: #6d28d9;
  --border: rgba(139, 92, 246, 0.3);
  --shadow: 0 24px 50px rgba(88, 28, 135, 0.18);
  --glow-1: rgba(139, 92, 246, 0.35);
  --glow-2: rgba(167, 139, 250, 0.24);
  --glow-3: rgba(217, 70, 239, 0.24);
  --log-bg: rgba(255, 255, 255, 0.96);
  --log-text: #3b0764;
  --cost-chart-base: rgba(255, 255, 255, 0.92);
}

/* ========================================
   BASE STYLES
   ======================================== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body.modal-open {
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

.background-glow {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 10% 20%, var(--glow-1), transparent 62%),
              radial-gradient(circle at 90% 10%, var(--glow-2), transparent 58%),
              radial-gradient(circle at 50% 120%, var(--glow-3), transparent 60%);
  filter: blur(80px);
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.4s ease, filter 0.4s ease;
}

body.app-busy .background-glow {
  opacity: 0.7;
  filter: blur(95px);
}

body.modal-open .background-glow {
  opacity: 0.65;
  filter: blur(110px);
}

/* ========================================
   LAYOUT
   ======================================== */
.app-shell {
  position: relative;
  z-index: 1;
  width: min(1200px, 100%);
  display: flex;
  flex-direction: column;
  gap: 32px;
  transition: transform 0.3s ease, filter 0.35s ease;
  filter: none;
}

body.app-busy .app-shell {
  transform: translateY(-2px);
}

body.modal-open .app-shell {
  filter: blur(6px);
  transform: translateY(6px) scale(0.992);
}

body.modal-open .app-top-bar__actions > * {
  pointer-events: none;
  opacity: 0.75;
  transform: scale(0.96);
}

.main-grid {
  display: grid;
  gap: 28px;
  max-width: 100%;
  min-width: 0;
}

/* ========================================
   TOP BAR
   ======================================== */
.app-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 26px;
  border-radius: 28px;
  border: 1px solid rgba(167, 139, 250, 0.3);
  background: linear-gradient(140deg, rgba(15, 10, 30, 0.92), rgba(12, 8, 25, 0.68));
  box-shadow: 0 26px 60px rgba(8, 4, 20, 0.45);
  backdrop-filter: blur(14px);
  flex-wrap: wrap;
}

body[data-theme="light"] .app-top-bar {
  border-color: rgba(139, 92, 246, 0.32);
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.86), rgba(250, 245, 255, 0.78));
  box-shadow: 0 26px 58px rgba(88, 28, 135, 0.18);
}

.app-top-bar__cluster {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.app-top-bar__logo {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.3), rgba(139, 92, 246, 0.5));
  border: 1px solid rgba(167, 139, 250, 0.45);
  overflow: hidden;
  display: grid;
  place-items: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

body[data-theme="light"] .app-top-bar__logo {
  border-color: rgba(139, 92, 246, 0.4);
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.25), rgba(139, 92, 246, 0.35));
}

.app-top-bar__spark {
  position: absolute;
  width: 120%;
  height: 120%;
  background: radial-gradient(circle at 30% 30%, rgba(196, 181, 253, 0.65), transparent 55%);
  filter: blur(6px);
  opacity: 0.85;
  transform: rotate(18deg);
}

body[data-theme="light"] .app-top-bar__spark {
  background: radial-gradient(circle at 30% 30%, rgba(139, 92, 246, 0.55), transparent 55%);
}

.app-top-bar__spark--secondary {
  background: radial-gradient(circle at 70% 70%, rgba(167, 139, 250, 0.75), transparent 60%);
  opacity: 0.7;
  transform: rotate(-28deg);
}

body[data-theme="light"] .app-top-bar__spark--secondary {
  background: radial-gradient(circle at 70% 70%, rgba(124, 58, 237, 0.6), transparent 60%);
}

.app-top-bar__copy {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.app-top-bar__title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-main);
  margin: 0;
  line-height: 1.2;
}

.app-top-bar__subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  max-width: 460px;
  line-height: 1.4;
  text-transform: none;
  margin: 0;
}

body[data-theme="light"] .app-top-bar__subtitle {
  color: rgba(91, 33, 182, 0.9);
}

.app-top-bar__actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.app-top-bar__settings {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 22px;
  border-radius: 999px;
  border: 1px solid rgba(167, 139, 250, 0.35);
  background: linear-gradient(135deg, rgba(15, 10, 35, 0.85), rgba(18, 12, 40, 0.7));
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.94rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.25s ease, border-color 0.25s ease, background 0.25s ease;
  box-shadow: 0 22px 46px rgba(8, 4, 20, 0.44);
  backdrop-filter: blur(14px);
}

body[data-theme="light"] .app-top-bar__settings {
  border-color: rgba(139, 92, 246, 0.45);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(237, 233, 254, 0.82));
  box-shadow: 0 22px 44px rgba(88, 28, 135, 0.16);
}

.app-top-bar__settings:hover {
  transform: translateY(-2px);
  box-shadow: 0 26px 64px rgba(8, 4, 20, 0.52);
  border-color: rgba(196, 181, 253, 0.6);
  background: linear-gradient(135deg, rgba(18, 12, 40, 0.92), rgba(22, 15, 45, 0.82));
}

body[data-theme="light"] .app-top-bar__settings:hover {
  border-color: rgba(139, 92, 246, 0.6);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(237, 233, 254, 0.9));
}

.app-top-bar__settings:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.32), 0 22px 44px rgba(8, 4, 20, 0.48);
}

.app-top-bar__settings-icon {
  display: inline-flex;
  width: 20px;
  height: 20px;
}

.app-top-bar__settings-icon svg {
  width: 100%;
  height: 100%;
  display: block;
}

.app-top-bar__settings-text {
  white-space: nowrap;
}

/* ========================================
   THEME TOGGLE
   ======================================== */
.theme-toggle {
  position: relative;
  width: 74px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(168, 148, 200, 0.35);
  background: linear-gradient(135deg, rgba(15, 10, 25, 0.85), rgba(25, 15, 40, 0.78));
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.25s ease, border-color 0.25s ease, background 0.25s ease;
  box-shadow: 0 18px 40px rgba(8, 4, 20, 0.45);
}

body[data-theme="light"] .theme-toggle {
  background: linear-gradient(135deg, rgba(250, 245, 255, 0.94), rgba(237, 233, 254, 0.92));
  border-color: rgba(139, 92, 246, 0.45);
  box-shadow: 0 18px 36px rgba(139, 92, 246, 0.28);
}

.theme-toggle:hover {
  transform: translateY(-1px);
  border-color: rgba(167, 139, 250, 0.5);
  box-shadow: 0 20px 46px rgba(8, 4, 20, 0.5);
}

.theme-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.35), 0 18px 40px rgba(8, 4, 20, 0.48);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  display: block;
  opacity: 0.6;
  transition: opacity 0.3s ease;
}

/* Dark mode - moon (first) highlighted */
.theme-toggle svg:first-of-type {
  opacity: 1;
}

.theme-toggle svg:last-of-type {
  opacity: 0.35;
}

/* Light mode - sun (last) highlighted */
body[data-theme="light"] .theme-toggle svg:first-of-type {
  opacity: 0.35;
}

body[data-theme="light"] .theme-toggle svg:last-of-type {
  opacity: 1;
}

.theme-toggle__thumb {
  position: absolute;
  inset: 4px;
  width: 32px;
  border-radius: 999px;
  background: rgba(167, 139, 250, 0.25);
  transition: transform 0.3s ease, background 0.3s ease;
  transform: translateX(0);
}

body[data-theme="light"] .theme-toggle__thumb {
  background: rgba(124, 58, 237, 0.35);
  transform: translateX(34px);
}

/* ========================================
   HERO SECTION
   ======================================== */
.hero {
  display: flex;
  flex-direction: column;
  gap: clamp(20px, 4vw, 36px);
  width: 100%;
}

.hero--jumbo {
  margin-top: 8px;
}

.hero__text {
  background: var(--glass-strong);
  border: 1px solid var(--border);
  border-radius: 32px;
  padding: clamp(28px, 4vw, 46px);
  box-shadow: var(--shadow);
  display: grid;
  gap: clamp(18px, 2.8vw, 26px);
  transition: background 0.5s ease, border-color 0.4s ease, box-shadow 0.4s ease;
}

.hero__eyebrow {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0;
}

.hero__text h1 {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-main), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero__text > p {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.75;
  color: var(--text-muted);
  max-width: 680px;
}

/* ========================================
   FILE UPLOAD
   ======================================== */
.file-upload-section {
  margin-top: 8px;
}

.file-dropzone {
  position: relative;
  border: 2px dashed var(--field-border);
  border-radius: 20px;
  padding: 48px 32px;
  background: var(--field-bg);
  transition: all 0.3s ease;
  cursor: pointer;
}

.file-dropzone:hover {
  border-color: var(--field-border-focus);
  background: rgba(167, 139, 250, 0.05);
}

.file-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(167, 139, 250, 0.1);
  transform: scale(1.02);
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.dropzone-icon {
  color: var(--accent);
  opacity: 0.8;
}

.dropzone-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-main);
}

.dropzone-subtitle {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.dropzone-formats {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  opacity: 0.7;
}

.dropzone-file-info {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--bg-card);
  border-radius: 16px;
  border: 1px solid var(--border);
}

.file-info-icon {
  color: var(--accent);
  flex-shrink: 0;
}

.file-info-details {
  flex: 1;
  min-width: 0;
}

.file-info-name {
  margin: 0 0 4px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  word-break: break-word;
}

.file-info-size {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.file-info-remove {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--field-border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.file-info-remove:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: #ef4444;
  color: #ef4444;
}

/* ========================================
   PROCESSING OPTIONS
   ======================================== */
.processing-options {
  margin-top: 8px;
}

.option-group {
  display: grid;
  gap: 16px;
}

.option-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}

.option-toggle input[type="checkbox"] {
  display: none;
}

.toggle-switch {
  position: relative;
  width: 52px;
  height: 28px;
  border-radius: 999px;
  background: var(--field-bg);
  border: 2px solid var(--field-border);
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all 0.3s ease;
}

.option-toggle input[type="checkbox"]:checked + .toggle-switch {
  background: var(--accent);
  border-color: var(--accent);
}

.option-toggle input[type="checkbox"]:checked + .toggle-switch::after {
  transform: translateX(24px);
  background: white;
}

.toggle-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.tooltip {
  background: none;
  border: none;
  cursor: help;
  font-size: 1rem;
  padding: 0;
  margin: 0;
  opacity: 0.6;
  transition: opacity 0.2s;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
}

.tooltip:hover {
  opacity: 1;
}

.tooltip-popup {
  position: fixed;
  max-width: 280px;
  padding: 12px 16px;
  background: var(--bg-card-solid);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-main);
  z-index: 9999;
  pointer-events: none;
}

/* ========================================
   BUTTONS
   ======================================== */
.hero__execute {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.hero__execute-button {
  padding: 16px 36px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.25s ease;
  box-shadow: 0 12px 28px rgba(167, 139, 250, 0.35);
}

.hero__execute-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 16px 36px rgba(167, 139, 250, 0.45);
}

.hero__execute-button:active:not(:disabled) {
  transform: translateY(0);
}

.hero__execute-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========================================
   CARDS & RESULTS
   ======================================== */
.card {
  background: var(--glass-soft);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 0;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: all 0.4s ease;
  max-width: 100%;
  overflow: hidden;
}

.card--busy {
  opacity: 0.75;
  pointer-events: none;
}

.card__header {
  padding: 28px 32px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.card__header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-main);
}

.log-actions {
  display: flex;
  gap: 12px;
}

.action-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--ghost-border);
  background: var(--field-bg);
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
}

.action-chip:hover {
  border-color: var(--ghost-hover);
  background: var(--bg-card);
  transform: translateY(-1px);
}

.action-chip--ghost {
  background: transparent;
}

.action-chip--icon {
  padding: 8px 10px;
}

.action-chip__icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
}

.response-output {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  max-width: 100%;
  overflow: hidden;
}

.response-cards {
  display: grid;
  gap: 20px;
  max-width: 100%;
  min-width: 0;
}

.response-empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ========================================
   AI SUMMARY CARD
   ======================================== */
.ai-summary-card {
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.15), rgba(139, 92, 246, 0.1));
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: 20px;
  padding: 28px;
  position: relative;
  overflow: hidden;
  animation: slideUp 0.4s ease;
}

.ai-summary-card::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(167, 139, 250, 0.1) 0%, transparent 70%);
  animation: sparkle 8s linear infinite;
}

@keyframes sparkle {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(180deg); }
}

.ai-summary-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  position: relative;
  z-index: 1;
}

.ai-summary-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.2rem;
  animation: pulse 2s ease-in-out infinite;
}

.ai-summary-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-main);
}

.ai-summary-content {
  position: relative;
  z-index: 1;
  line-height: 1.8;
  color: var(--text-main);
  font-size: 0.98rem;
}

.ai-summary-content p {
  margin: 0 0 16px;
}

.ai-summary-content strong {
  color: var(--accent);
  font-weight: 600;
}

.ai-summary-content ul {
  margin: 12px 0;
  padding-left: 24px;
}

.ai-summary-content li {
  margin: 8px 0;
}

/* ========================================
   MARKDOWN CONTENT
   ======================================== */
.markdown-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  overflow: hidden;
  max-width: 100%;
  min-width: 0;
}

.markdown-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.markdown-card__title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-main);
}

.markdown-content {
  line-height: 1.8;
  color: var(--text-main);
  font-size: 0.95rem;
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4 {
  margin: 16px 0 8px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-main);
}

.markdown-content h1 { font-size: 1.8rem; margin-top: 20px; }
.markdown-content h2 { font-size: 1.5rem; margin-top: 18px; }
.markdown-content h3 { font-size: 1.25rem; margin-top: 16px; }
.markdown-content h4 { font-size: 1.05rem; margin-top: 14px; }

/* First heading has less top margin */
.markdown-content h1:first-child,
.markdown-content h2:first-child,
.markdown-content h3:first-child,
.markdown-content h4:first-child {
  margin-top: 0;
}

.markdown-content p {
  margin: 8px 0;
  line-height: 1.7;
}

.markdown-content ul,
.markdown-content ol {
  margin: 8px 0;
  padding-left: 28px;
}

.markdown-content li {
  margin: 4px 0;
  line-height: 1.6;
}

.markdown-content br {
  content: "";
  display: block;
  margin: 4px 0;
}

.markdown-content strong {
  font-weight: 600;
  color: var(--accent);
}

.markdown-content em {
  font-style: italic;
  color: var(--text-muted);
}

.markdown-content code {
  background: var(--field-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", Monaco, monospace;
  font-size: 0.9em;
  color: var(--accent);
}

.markdown-content pre {
  background: var(--log-bg);
  padding: 16px;
  border-radius: 12px;
  overflow-x: auto;
  border: 1px solid var(--border);
}

.markdown-content pre code {
  background: none;
  padding: 0;
  color: var(--log-text);
}

.markdown-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  overflow-x: auto;
  display: block;
}

.markdown-content th,
.markdown-content td {
  padding: 12px;
  border: 1px solid var(--border);
  text-align: left;
}

.markdown-content th {
  background: var(--field-bg);
  font-weight: 600;
}

/* ========================================
   IMAGE ANNOTATION CALLOUT
   ======================================== */
.annotation-callout {
  background: linear-gradient(135deg, rgba(217, 70, 239, 0.12), rgba(167, 139, 250, 0.08));
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 18px 22px;
  margin: 20px 0;
  position: relative;
}

.annotation-callout::before {
  content: '✨ AI Interpretation';
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 10px;
  opacity: 0.9;
}

.annotation-callout__type {
  font-weight: 700;
  color: var(--accent);
  font-size: 1.05rem;
  margin-bottom: 8px;
}

.annotation-callout__description {
  color: var(--text-main);
  line-height: 1.7;
  margin-bottom: 8px;
}

.annotation-callout__summary {
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.7;
  font-size: 0.92rem;
}

/* ========================================
   PAGE BY PAGE VIEW
   ======================================== */
.page-by-page-wrapper {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.copy-all-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.copy-all-container h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
}

.page-by-page-container {
  display: grid;
  gap: 24px;
}

.page-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  transition: border-color 0.3s ease;
}

.page-card:hover {
  border-color: var(--ghost-hover);
}

@media (min-width: 1024px) {
  .page-card--with-image {
    grid-template-columns: 1.5fr 1fr;
  }
}

.page-card__header {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-card__number {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.page-card__content {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.page-card__image-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 24px;
  align-self: start;
}

.page-card__image-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.page-card__image {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--field-bg);
}

.page-card__image img {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.page-card__image img:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 24px rgba(167, 139, 250, 0.4);
}

/* ========================================
   MODALS
   ======================================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal--active {
  display: flex;
}

.modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  animation: fadeIn 0.3s ease;
}

.modal__content {
  position: relative;
  z-index: 1;
  background: var(--glass-strong);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 32px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.6);
  animation: slideUp 0.4s ease;
}

.modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.modal__title-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.modal__title-group h2 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text-main);
}

.modal__close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  transition: background 0.2s, color 0.2s;
}

.modal__close:hover {
  background: var(--field-bg);
  color: var(--text-main);
}

.modal__lead {
  margin: 0 0 24px;
  color: var(--text-muted);
  line-height: 1.6;
  font-size: 0.95rem;
}

.modal__body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.modal__body label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-main);
}

.modal__body input[type="text"],
.modal__body input[type="password"] {
  padding: 14px 16px;
  border-radius: 12px;
  border: 2px solid var(--field-border);
  background: var(--field-bg);
  color: var(--text-main);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.modal__body input:focus {
  outline: none;
  border-color: var(--field-border-focus);
  box-shadow: 0 0 0 4px rgba(167, 139, 250, 0.15);
}

.modal__footer {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal__feedback {
  padding: 12px 16px;
  border-radius: 10px;
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
}

.modal__feedback--error {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.modal__actions {
  display: flex;
  gap: 12px;
}

.modal__primary,
.modal__secondary {
  flex: 1;
  padding: 14px 24px;
  border-radius: 12px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.modal__primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white;
  box-shadow: 0 8px 20px rgba(167, 139, 250, 0.3);
}

.modal__primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(167, 139, 250, 0.4);
}

.modal__secondary {
  background: var(--field-bg);
  color: var(--text-main);
  border: 1px solid var(--field-border);
}

.modal__secondary:hover {
  background: var(--bg-card);
  border-color: var(--ghost-hover);
}

/* Padlock Icon */
.modal__padlock {
  position: relative;
  width: 28px;
  height: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

.modal__padlock-shackle {
  position: absolute;
  top: 0;
  width: 16px;
  height: 14px;
  border: 3px solid var(--accent);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  transition: transform 0.4s ease;
}

.modal__padlock--open .modal__padlock-shackle {
  transform: translateX(8px) rotate(-15deg);
}

.modal__padlock-body {
  width: 24px;
  height: 18px;
  background: var(--accent);
  border-radius: 4px;
  position: relative;
  display: grid;
  place-items: center;
}

.modal__padlock-keyhole {
  width: 6px;
  height: 8px;
  background: var(--bg-base);
  border-radius: 50% 50% 0 0;
}

/* Request Modal */
.modal--request .modal__content {
  max-width: 360px;
  text-align: center;
  padding: 48px 32px 40px;
}

.request-loader {
  position: relative;
  width: 100px;
  height: 100px;
  margin: 0 auto 24px;
}

.request-loader__ring {
  position: absolute;
  inset: 0;
  border: 3px solid transparent;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1.2s linear infinite;
}

.request-loader__ring--accent {
  border-top-color: var(--accent-strong);
  animation-duration: 0.8s;
  animation-direction: reverse;
  inset: 10px;
}

.request-loader__text {
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
}

.request-loader__timer {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 24px;
  font-variant-numeric: tabular-nums;
}

.request-loader__cancel {
  padding: 12px 28px;
  border-radius: 10px;
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  color: var(--text-main);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.request-loader__cancel:hover {
  border-color: var(--ghost-hover);
  background: var(--bg-card);
}

/* ========================================
   FOOTER
   ======================================== */
.footer {
  margin-top: 48px;
  padding: 28px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  text-align: center;
}

.footer p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

.footer__status {
  display: flex;
  justify-content: center;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  transition: all 0.3s ease;
}

.status-pill__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #94a3b8;
  transition: background 0.3s ease;
}

.status-pill--ok .status-pill__dot {
  background: #22c55e;
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.5);
}

.status-pill--error .status-pill__dot {
  background: #ef4444;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.5);
}

.status-pill--loading .status-pill__dot {
  background: var(--accent);
  box-shadow: 0 0 12px rgba(167, 139, 250, 0.5);
  animation: pulse 1.5s ease-in-out infinite;
}

.status {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
}

.status--ok {
  color: #22c55e;
}

.status--error {
  color: #ef4444;
}

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

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

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

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

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */
@media (max-width: 768px) {
  body {
    padding: 20px 16px 60px;
  }

  .app-top-bar {
    padding: 14px 18px;
    gap: 16px;
  }

  .app-top-bar__logo {
    width: 42px;
    height: 42px;
  }

  .app-top-bar__title {
    font-size: 0.9rem;
    letter-spacing: 0.12em;
  }

  .app-top-bar__subtitle {
    font-size: 0.78rem;
    display: none;
  }

  .app-top-bar__settings-text {
    display: none;
  }

  .app-top-bar__settings {
    padding: 10px 14px;
  }

  .hero__text {
    padding: 24px 20px;
    gap: 20px;
  }

  .hero__text h1 {
    font-size: 1.6rem;
  }

  .hero__text > p {
    font-size: 0.95rem;
  }

  .file-dropzone {
    padding: 32px 20px;
  }

  .hero__execute-button {
    width: 100%;
    padding: 14px 28px;
  }

  .card__header {
    padding: 20px 18px 16px;
    flex-wrap: wrap;
  }

  .response-output {
    padding: 18px;
  }

  .markdown-card {
    padding: 20px;
  }

  .page-card {
    padding: 20px;
  }

  .page-card--with-image {
    grid-template-columns: 1fr;
  }

  .modal__content {
    padding: 24px;
    margin: 16px;
  }

  .footer {
    padding: 20px 18px;
    margin-top: 32px;
  }
}

/* ========================================
   COPY BUTTON
   ======================================== */
.copy-button {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--ghost-border);
  background: var(--field-bg);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.copy-button:hover {
  border-color: var(--ghost-hover);
  background: var(--bg-card);
  transform: translateY(-1px);
}

.copy-button--success {
  border-color: rgba(34, 197, 94, 0.5);
  color: #22c55e;
}

.copy-button__icon {
  width: 14px;
  height: 14px;
  display: inline-flex;
}

/* ========================================
   LIGHTBOX
   ======================================== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.3s ease;
}

.lightbox:not([hidden]) {
  display: flex;
}

.lightbox__overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  animation: fadeIn 0.3s ease;
  cursor: pointer;
}

.lightbox__content {
  position: relative;
  z-index: 1;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: slideUp 0.4s ease;
}

.lightbox__close {
  position: absolute;
  top: -48px;
  right: 0;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 2rem;
  cursor: pointer;
  padding: 8px 16px;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
}

.lightbox__close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.lightbox__image {
  max-width: 85vw;
  max-height: 80vh;
  width: auto;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.8);
  cursor: default;
}

@media (max-width: 768px) {
  .lightbox__close {
    top: 8px;
    right: 8px;
    width: 40px;
    height: 40px;
    font-size: 1.6rem;
  }
}
