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

:root {
  --bg-base: #0d1117;
  --bg-surface: #161b22;
  --bg-elevated: #1c2128;
  --bg-hover: #21262d;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --orange: #f0883e;
  --green: #3fb950;
  --red: #f85149;
  --purple: #bc8cff;
  --radius: 8px;
  --radius-sm: 4px;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Top Bar ─── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  min-height: 48px;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.logo {
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  white-space: nowrap;
}

.presentation-select {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.85rem;
  font-family: inherit;
  max-width: 300px;
  cursor: pointer;
}
.presentation-select:focus {
  outline: none;
  border-color: var(--accent);
}

.nav-btn, .tool-btn {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s;
}
.nav-btn:hover:not(:disabled), .tool-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--accent);
}
.nav-btn:disabled, .tool-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* Night 2: Save button styles */
.save-btn {
  font-weight: 600;
}
.save-btn.unsaved {
  background: var(--orange);
  border-color: var(--orange);
  color: #0d1117;
  animation: pulse 2s ease-in-out infinite;
}
.save-btn.unsaved:hover:not(:disabled) {
  background: #ff9f5e;
  border-color: #ff9f5e;
}

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

.slide-counter {
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  min-width: 50px;
  text-align: center;
}

/* ─── Main Layout ─── */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-height: 36px;
}

.slide-title {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 300px;
}

.badge {
  background: var(--bg-hover);
  color: var(--text-secondary);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
}

/* ─── Preview Panel ─── */
.preview-panel {
  flex: 3;
  border-right: 1px solid var(--border);
}

.preview-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #1a1a2e;
}

.preview-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: white;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 8px;
}
.empty-icon { font-size: 3rem; }
.empty-state p { font-size: 0.9rem; }
.empty-hint { font-size: 0.8rem; }
.empty-state code {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}

/* ─── Editor Panel ─── */
.editor-panel {
  flex: 2;
  min-width: 320px;
}

.editor-fields {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.edit-group {
  margin-bottom: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.edit-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-elevated);
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  user-select: none;
}
.edit-group-header:hover {
  background: var(--bg-hover);
}

.type-icon {
  font-size: 0.9rem;
}

.edit-field {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}

.edit-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.edit-tag {
  background: var(--bg-hover);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Consolas', monospace;
  font-size: 0.68rem;
}

.edit-input {
  width: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1.5;
  resize: vertical;
  min-height: 36px;
  transition: border-color 0.15s;
}
.edit-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.15);
}

.edit-input.modified {
  border-color: var(--orange);
  box-shadow: 0 0 0 2px rgba(240, 136, 62, 0.15);
}

/* ─── Slide Overview Modal ─── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
}

.modal-content {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90vw;
  max-width: 1200px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.close-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.slide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 20px;
  overflow-y: auto;
}

.slide-thumb {
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.slide-thumb:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.slide-thumb.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}

.slide-thumb-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--accent);
}
.slide-thumb-info {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ─── Responsive ─── */
@media (max-width: 900px) {
  .main-layout {
    flex-direction: column;
  }
  .preview-panel {
    flex: 1;
    border-right: none;
    border-bottom: 1px solid var(--border);
    min-height: 40vh;
  }
  .editor-panel {
    flex: 1;
    min-width: auto;
  }
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
  }
}

/* ─── Night 3: AI Tools ─── */
.ai-tools {
  border-top: 2px solid var(--border);
  background: var(--bg-elevated);
  padding: 16px;
  max-height: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-tools.hidden {
  display: none;
}

.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.ai-header span {
  font-weight: 600;
  color: var(--purple);
}
.close-ai-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.15s;
}
.close-ai-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.ai-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.ai-btn {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
  flex: 1;
  min-width: 120px;
}
.ai-btn:hover {
  background: var(--bg-hover);
  border-color: var(--purple);
  color: var(--purple);
}
.ai-btn:active {
  transform: scale(0.98);
}

.ai-result {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--text-primary);
  max-height: 200px;
  overflow-y: auto;
}
.ai-result.hidden {
  display: none;
}
.ai-result.loading {
  color: var(--text-secondary);
  font-style: italic;
}
.ai-result.error {
  border-color: var(--red);
  color: var(--red);
}
.ai-result.success {
  border-color: var(--green);
}

.ai-toggle-btn.active {
  background: var(--purple);
  border-color: var(--purple);
  color: #0d1117;
}

.ai-apply-btn {
  background: var(--green);
  color: #0d1117;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  margin-top: 8px;
  transition: all 0.15s;
}
.ai-apply-btn:hover {
  background: #56d364;
  transform: translateY(-1px);
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-base);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
