:root {
  --bg-dark: #000000;
  --bg-card: rgba(12, 12, 12, 0.85);
  --accent: #2563eb;
  --accent-glow: rgba(37, 99, 235, 0.5);
  --neon-cyan: #00f2ff;
  --neon-magenta: #ff00ff;
  --text-primary: #ffffff;
  --text-secondary: #888888;
  --border-glass: rgba(255, 255, 255, 0.05);
  --border-luminous: rgba(0, 242, 255, 0.2);
  --card-shadow: 0 10px 40px -10px rgba(0, 0, 0, 1);
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* Animations */
@keyframes glow-pulse {
  0% { box-shadow: 0 0 5px var(--border-luminous); }
  50% { box-shadow: 0 0 15px var(--border-luminous); }
  100% { box-shadow: 0 0 5px var(--border-luminous); }
}

@keyframes scanline {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(100vh); }
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-primary);
  font-family: var(--font-main);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

body::after {
  content: "";
  position: fixed;
  top: 0; left: 0; width: 100%; height: 2px;
  background: rgba(0, 242, 255, 0.03);
  z-index: 1000;
  animation: scanline 8s linear infinite;
  pointer-events: none;
}

.grid-background {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background-image: 
    linear-gradient(rgba(37, 99, 235, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 99, 235, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  z-index: -1;
}

.container { max-width: 1400px; margin: 0 auto; padding: 2rem; position: relative; }

/* Dashboard Cards Enhancements */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border: 1px solid var(--border-glass);
  border-radius: 1.25rem;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.glass-card:hover {
  border-color: var(--border-luminous);
  transform: translateY(-4px);
  box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 1), 0 0 15px rgba(0, 242, 255, 0.1);
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h2 { font-size: 1rem; font-weight: 600; display: flex; align-items: center; gap: 0.75rem; color: var(--text-secondary); }
.card-header h2 i { color: var(--neon-cyan); }

/* Form Elements */
.form-content { padding: 1.5rem; display: flex; flex-direction: column; gap: 1.25rem; }
.input-group { display: flex; flex-direction: column; gap: 0.5rem; flex: 1; min-width: 0; }
.input-group label { font-size: 0.75rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; }
.input-group input, .input-group select, .input-group textarea {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-glass);
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  color: #fff;
  font-family: inherit;
  transition: all 0.3s ease;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.input-group input:focus, .input-group select:focus, .input-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.form-row { 
    display: flex; 
    gap: 1.25rem; 
    width: 100%;
}
.form-row > * {
    flex: 1;
    min-width: 0;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #1e40af);
  color: white;
  border: none;
  padding: 1rem;
  border-radius: 0.5rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  transition: all 0.3s ease;
  margin-top: 0.5rem;
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 20px -10px var(--accent-glow); }

.action-row {
  display: flex;
  gap: 1rem;
  align-items: stretch;
}

.action-row > button {
  flex: 1;
}

.btn-secondary {
  background: linear-gradient(135deg, rgba(0, 242, 255, 0.14), rgba(255, 0, 255, 0.14));
  color: var(--text-primary);
  border: 1px solid rgba(0, 242, 255, 0.2);
  padding: 1rem;
  border-radius: 0.5rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  transition: all 0.3s ease;
  margin-top: 0.5rem;
}

.btn-secondary:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 20px -10px rgba(0, 242, 255, 0.25);
  border-color: rgba(0, 242, 255, 0.45);
}

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

.btn-icon { background: transparent; border: none; color: var(--text-secondary); cursor: pointer; padding: 0.5rem; border-radius: 0.4rem; transition: all 0.2s; }
.btn-icon:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.btn-icon.primary { color: var(--neon-cyan); }

/* Operation Logs */
.log-viewer {
  height: 250px;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.4);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  overflow-y: auto;
  border-radius: 0 0 1rem 1rem;
}

.log-entry { margin-bottom: 0.5rem; border-left: 2px solid var(--accent); padding-left: 0.75rem; }
.log-entry.loading { border-color: var(--neon-cyan); }
.log-entry.success { border-color: #10b981; }
.log-entry.error { border-color: #ef4444; }

/* Dynamic Section Stacking */
.section-results {
  grid-column: span 2;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.bento-meta, .bento-context, .bento-draft, .bento-analysis {
  width: 100%;
}

/* Metadata Grid */
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; padding: 1.5rem; }
.meta-item { display: flex; flex-direction: column; gap: 0.25rem; }
.meta-item .label { font-size: 0.7rem; color: var(--text-secondary); text-transform: uppercase; }
.meta-item .value { font-size: 0.9rem; font-weight: 600; color: var(--neon-cyan); }

/* Context and Analysis Areas */
.code-viewer, .analysis-result-container {
  height: 450px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid var(--border-glass);
}

#context-output {
  width: 100%;
  height: 100%;
  padding: 1.25rem;
  background: transparent;
  border: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-primary);
}

#draft-output {
  width: 100%;
  height: 100%;
  padding: 1.25rem;
  background:
    linear-gradient(180deg, rgba(0, 242, 255, 0.04), transparent 12%),
    rgba(0, 0, 0, 0.2);
  border: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
  color: #d7fbff;
}

.draft-viewer {
  position: relative;
}

.card-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.draft-status {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(0, 242, 255, 0.15);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--neon-cyan);
  background: rgba(0, 242, 255, 0.08);
}

.draft-status.append,
.draft-status.replace,
.draft-status.finalize {
  animation: glow-pulse 1.5s ease;
}

.draft-status.replace {
  color: #ffd166;
  border-color: rgba(255, 209, 102, 0.3);
  background: rgba(255, 209, 102, 0.1);
}

.draft-status.finalize {
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.1);
}

#analysis-output {
  width: 100%;
  height: 100%;
  padding: 1.5rem;
  overflow-y: auto;
  line-height: 1.7;
  color: var(--text-primary);
  font-size: 0.95rem;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  color: var(--neon-cyan);
  margin-top: 1.5rem;
  margin-bottom: 1rem;
  font-weight: 700;
  border-bottom: 1px solid rgba(0, 242, 255, 0.1);
  padding-bottom: 0.5rem;
}

.markdown-body p { margin-bottom: 1rem; }
.markdown-body strong { color: var(--neon-magenta); font-weight: 700; }
.markdown-body code {
  background: rgba(255, 255, 255, 0.1);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--neon-cyan);
}

.markdown-body pre {
  background: #0d1117;
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  margin: 1.5rem 0;
  border: 1px solid var(--border-glass);
}

.markdown-body pre code { background: transparent; padding: 0; color: #e6edf3; }

.markdown-body ul, .markdown-body ol {
  margin-left: 1.5rem;
  margin-bottom: 1rem;
}

.markdown-body li { margin-bottom: 0.5rem; }

.placeholder-text {
  color: var(--text-secondary);
  font-style: italic;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

/* Export Dropdown */
.export-dropdown {
  position: relative;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: all 0.3s ease;
}

.export-dropdown.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.btn-export {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border: none;
  padding: 0.4rem 0.85rem;
  border-radius: 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-export:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.export-chevron {
  font-size: 0.6rem;
  transition: transform 0.2s ease;
}

.export-menu.open + .export-chevron,
.export-menu.open ~ .export-chevron { transform: rotate(180deg); }

.export-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  z-index: 50;
  min-width: 220px;
  background: rgba(16, 18, 27, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: 0.75rem;
  padding: 0.5rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px) scale(0.95);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.export-menu.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.export-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  padding: 0.65rem 0.85rem;
  border-radius: 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.export-option:hover {
  background: rgba(37, 99, 235, 0.15);
  color: var(--neon-cyan);
}

.export-option i {
  font-size: 0.9rem;
  width: 1.2rem;
  text-align: center;
  color: var(--text-secondary);
  transition: color 0.15s;
}

.export-option:hover i { color: var(--neon-cyan); }

/* Button success state for copy */
.btn-icon.success { color: #10b981 !important; }

/* Title with icon layout */
.title-with-icon { display: flex; align-items: center; gap: 0.75rem; }

/* Footer */
.footer { text-align: center; padding: 3rem; color: var(--text-secondary); font-size: 0.8rem; border-top: 1px solid var(--border-glass); margin-top: 4rem; }

/* Responsive adjustments */
@media (max-width: 1250px) {
  .dashboard { grid-template-columns: 1fr; max-width: 800px; margin: 0 auto; }
  .section-results { grid-column: span 1; }
  .form-row { flex-direction: column; gap: 1.25rem; }
  .action-row { flex-direction: column; }
  .export-menu { right: auto; left: 0; }
}
