/* ==============  THEME VARIABLES  ============== */
:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --radius: 6px;
  --radius-lg: 10px;
  --transition: 0.15s ease;
}

body.theme-light {
  --bg: #f8fafc;
  --panel: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --hover: #f1f5f9;
  --soft-bg: #f1f5f9;
  --soft-hover: #e2e8f0;
  --active-bg: #0f172a;
  --active-text: #ffffff;
  --primary-bg: #0f172a;
  --primary-text: #ffffff;
  --primary-hover: #1e293b;
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --input-focus: #0f172a;
  --danger: #dc2626;
  --success: #16a34a;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.15);
}

body.theme-dark {
  --bg: #09090b;
  --panel: #18181b;
  --border: #27272a;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --text-subtle: #71717a;
  --hover: #27272a;
  --soft-bg: #27272a;
  --soft-hover: #3f3f46;
  --active-bg: #fafafa;
  --active-text: #18181b;
  --primary-bg: #fafafa;
  --primary-text: #18181b;
  --primary-hover: #ffffff;
  --input-bg: #27272a;
  --input-border: #3f3f46;
  --input-focus: #71717a;
  --danger: #ef4444;
  --success: #22c55e;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, 0.6);
}

body.theme-green {
  --bg: #0a1410;
  --panel: #0f1d17;
  --border: #1f3a2d;
  --text: #c6f2d5;
  --text-muted: #6ba57f;
  --text-subtle: #4a7a5a;
  --hover: #152821;
  --soft-bg: #152821;
  --soft-hover: #1f3a2d;
  --active-bg: #22c55e;
  --active-text: #0a1410;
  --primary-bg: #22c55e;
  --primary-text: #0a1410;
  --primary-hover: #16a34a;
  --input-bg: #0f1d17;
  --input-border: #1f3a2d;
  --input-focus: #22c55e;
  --danger: #f87171;
  --success: #4ade80;
  --shadow: 0 4px 20px rgba(0, 30, 15, 0.4);
  --shadow-lg: 0 10px 40px rgba(0, 50, 20, 0.5);
}

/* Synthwave sunset — warm purple/pink/orange on deep violet */
body.theme-sunset {
  --bg: #1a0b2e;
  --panel: #261245;
  --border: #4a1e6b;
  --text: #fce7f3;
  --text-muted: #e4a3d1;
  --text-subtle: #b373a8;
  --hover: #321a58;
  --soft-bg: #2d1551;
  --soft-hover: #4a1e6b;
  --active-bg: #f97316;
  --active-text: #1a0b2e;
  --primary-bg: #ec4899;
  --primary-text: #ffffff;
  --primary-hover: #f472b6;
  --input-bg: #1a0b2e;
  --input-border: #6b2d8f;
  --input-focus: #ec4899;
  --danger: #f87171;
  --success: #4ade80;
  --shadow: 0 4px 28px rgba(236, 72, 153, 0.25);
  --shadow-lg: 0 10px 48px rgba(236, 72, 153, 0.35);
}

/* Matrix/terminal aesthetic — bright green-on-black with monospace everywhere */
body.theme-hacker {
  --bg: #000000;
  --panel: #050a05;
  --border: #003d15;
  --text: #00ff41;
  --text-muted: #00b52e;
  --text-subtle: #007a1d;
  --hover: #001a08;
  --soft-bg: #001a08;
  --soft-hover: #002a12;
  --active-bg: #00ff41;
  --active-text: #000000;
  --primary-bg: #00ff41;
  --primary-text: #000000;
  --primary-hover: #5fff7a;
  --input-bg: #000000;
  --input-border: #003d15;
  --input-focus: #00ff41;
  --danger: #ff0040;
  --success: #00ff41;
  --shadow: 0 0 18px rgba(0, 255, 65, 0.18);
  --shadow-lg: 0 0 36px rgba(0, 255, 65, 0.35);
}
body.theme-hacker {
  font-family: var(--font-mono);
}
body.theme-hacker .editor-textarea,
body.theme-hacker input,
body.theme-hacker textarea,
body.theme-hacker pre,
body.theme-hacker code {
  font-family: var(--font-mono);
}
body.theme-hacker .editor-textarea::selection,
body.theme-hacker input::selection,
body.theme-hacker textarea::selection {
  background: #00ff41;
  color: #000000;
}
/* Subtle green glow on borders of the main panels */
body.theme-hacker .app-header,
body.theme-hacker .sidebar,
body.theme-hacker .editor-area,
body.theme-hacker .chat-window,
body.theme-hacker .ai-chat-window,
body.theme-hacker .modal-box {
  box-shadow: 0 0 12px rgba(0, 255, 65, 0.08);
}

/* ==============  BASE  ============== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  transition: background var(--transition), color var(--transition);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.hidden { display: none !important; }

.icon { width: 20px; height: 20px; flex-shrink: 0; }
.icon-sm { width: 16px; height: 16px; flex-shrink: 0; }
.icon-xs { width: 11px; height: 11px; flex-shrink: 0; }

/* Visibility toggle in create-section modal */
.visibility-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}
.radio-option {
  display: flex;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.radio-option:hover { background: var(--hover); }
.radio-option input[type="radio"] {
  margin: 3px 0 0 0;
  flex-shrink: 0;
  accent-color: var(--primary-bg);
}
.radio-option:has(input:checked) {
  border-color: var(--primary-bg);
  background: var(--hover);
}
.radio-title {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 2px;
}
.radio-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
}

/* Username edit button in chat */
.chat-username-btn {
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background var(--transition), color var(--transition);
  font-family: inherit;
}
.chat-username-btn:hover {
  background: var(--hover);
  color: var(--text);
}
.chat-username-btn #chat-username {
  font-weight: 600;
}

/* ==============  HEADER  ============== */
.app-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 12px; }
.sync-status { font-size: 12px; color: var(--text-muted); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.icon-btn:hover { background: var(--hover); }

/* Theme toggle icons — only one is visible based on active theme */
.theme-icon { display: none; }
body.theme-light .theme-icon-light { display: block; }
body.theme-dark .theme-icon-dark { display: block; }
body.theme-green .theme-icon-green { display: block; color: #4ade80; }
body.theme-hacker .theme-icon-hacker { display: block; color: #00ff41; }
body.theme-sunset .theme-icon-sunset { display: block; color: #f97316; }

.icon-btn-sm {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius);
  font-size: 16px;
  line-height: 1;
  transition: color var(--transition);
}
.icon-btn-sm:hover { color: var(--text); }

/* ==============  LAYOUT  ============== */
.main-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* ==============  SIDEBAR  ============== */
.sidebar {
  width: 280px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-block {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-block.flex-grow { flex: 1; min-height: 0; }
.scroll-y { overflow-y: auto; }

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.section-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 6px 8px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--transition);
  margin-bottom: 2px;
}
.section-btn:hover { background: var(--hover); }
.section-btn.active {
  background: var(--active-bg);
  color: var(--active-text);
}
.section-btn .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.section-row {
  display: flex;
  align-items: stretch;
  gap: 4px;
  margin-bottom: 2px;
}
.section-row .section-btn { margin-bottom: 0; flex: 1; }
.section-lock-btn {
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 0 8px;
  border-radius: var(--radius);
}
.section-lock-btn:hover { color: var(--text); background: var(--hover); }

.section-wrapper { margin-bottom: 2px; }
.section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition);
}
.section-header:hover { background: var(--hover); }
.section-header.active { background: var(--hover); }
.section-header .section-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.section-header .section-count {
  font-size: 11px;
  color: var(--text-subtle);
  background: var(--soft-bg);
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.chevron {
  width: 12px;
  height: 12px;
  color: var(--text-muted);
  transition: transform var(--transition);
  flex-shrink: 0;
}
.chevron.expanded { transform: rotate(90deg); }
.chevron-spacer { width: 12px; height: 12px; flex-shrink: 0; }

.section-header-btn {
  background: transparent;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  padding: 2px 5px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  opacity: 0;
  transition: opacity var(--transition), color var(--transition), background var(--transition);
}
.section-header:hover .section-header-btn { opacity: 1; }
.section-header-btn:hover { color: var(--text); background: var(--soft-hover); }
.section-header-btn.danger:hover { color: var(--danger); }

.section-notes-nested {
  list-style: none;
  padding: 0;
  margin: 2px 0 4px 0;
}
.section-note-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 28px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.section-note-item:hover { background: var(--hover); color: var(--text); }
.section-note-item.active {
  background: var(--active-bg);
  color: var(--active-text);
}
.section-note-item .note-title-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.section-empty-hint {
  font-size: 12px;
  color: var(--text-subtle);
  padding: 4px 8px 6px 28px;
  font-style: italic;
}
.editor-section-label {
  font-size: 12px;
  color: var(--text-muted);
  padding: 2px 8px;
  background: var(--soft-bg);
  border-radius: 10px;
}
.modal-box-search {
  width: min(640px, 95vw);
  padding: 0;
  overflow: hidden;
}
.search-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.search-input-row .icon-sm { color: var(--text-muted); flex-shrink: 0; }
#search-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  outline: none;
  font-family: inherit;
}
.search-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--soft-bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.search-results {
  max-height: 50vh;
  overflow-y: auto;
}
.search-result {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result.active { background: var(--hover); }
.search-result-icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--soft-bg);
  color: var(--text-muted);
}
.search-result-body { flex: 1; min-width: 0; }
.search-result-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-result-meta {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}
.search-result-type {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--text-subtle);
  align-self: flex-start;
  padding: 2px 6px;
  background: var(--soft-bg);
  border-radius: 4px;
  flex-shrink: 0;
}
.search-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: dropFadeIn 0.1s ease;
}
@keyframes dropFadeIn { from { opacity: 0; } to { opacity: 1; } }
.drop-overlay-inner {
  background: var(--panel);
  border: 2px dashed var(--primary-bg);
  color: var(--text);
  border-radius: var(--radius-lg);
  padding: 48px 64px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.drop-overlay-title {
  font-size: 22px;
  font-weight: 700;
  margin: 12px 0 4px 0;
}
.drop-overlay-sub {
  font-size: 14px;
  color: var(--text-muted);
}

.files-scope-label {
  font-size: 11px;
  color: var(--text-subtle);
  background: var(--soft-bg);
  padding: 2px 8px;
  border-radius: 10px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==============  UPLOAD  ============== */
.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
}
.upload-btn {
  background: var(--soft-bg);
  border: none;
  color: var(--text);
  padding: 10px 4px;
  border-radius: var(--radius);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: background var(--transition);
}
.upload-btn:hover { background: var(--soft-hover); }

.upload-progress { margin-top: 8px; }
.progress-bar {
  height: 4px;
  background: var(--soft-bg);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--active-bg);
  width: 0%;
  transition: width 0.2s ease;
}
.progress-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: center;
}

/* ==============  FILES  ============== */
.files-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius);
  font-size: 13px;
  transition: background var(--transition);
}
.file-item:hover { background: var(--hover); }
.file-info { flex: 1; min-width: 0; }
.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-size { font-size: 10px; color: var(--text-subtle); }
.file-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}
.file-item:hover .file-actions { opacity: 1; }
.file-actions button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius);
  transition: color var(--transition);
}
.file-actions button:hover { color: var(--text); }
.file-actions .delete-btn:hover { color: var(--danger); }

.empty-text {
  font-size: 12px;
  color: var(--text-subtle);
  font-style: italic;
}

/* ==============  EDITOR  ============== */
.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.editor-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.editor-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.editor-title { font-weight: 500; }
.editor-private-tag { font-size: 12px; color: var(--text-subtle); }
.danger-text-btn {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: var(--radius);
}
.danger-text-btn:hover { background: var(--hover); }

.editor-textarea {
  flex: 1;
  width: 100%;
  padding: 16px;
  border: none;
  outline: none;
  resize: none;
  background: var(--panel);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
}
.editor-footer {
  padding: 6px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* ==============  SECTION NOTES LIST VIEW  ============== */
.section-notes-view,
.editor-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.section-notes-view.hidden,
.editor-view.hidden { display: none; }

.section-view-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.notes-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
}
.note-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.note-card:hover {
  background: var(--hover);
  border-color: var(--text-subtle);
}
.note-card-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 4px;
  word-break: break-word;
}
.note-card-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
}
.notes-list .empty-text {
  text-align: center;
  padding: 32px;
}

.note-title-input {
  background: var(--panel);
  color: var(--text);
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  outline: none;
}
.note-title-input:focus {
  border-bottom-color: var(--accent, #3b82f6);
}

#note-back-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: var(--radius);
}
#note-back-btn:hover {
  background: var(--hover);
  color: var(--text);
}

/* ==============  CHAT  ============== */
.chat-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 40;
}
.chat-toggle {
  background: #2563eb;
  color: #ffffff;
  border: none;
  border-radius: 28px;
  height: 56px;
  padding: 0 20px 0 16px;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(37, 99, 235, 0.5);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  position: relative;
  transition: transform var(--transition), box-shadow var(--transition);
  animation: chatPulse 2.4s ease-in-out infinite;
}
.chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 32px rgba(37, 99, 235, 0.6);
  animation: none;
}
.chat-toggle .icon { width: 22px; height: 22px; }
.chat-toggle-label { white-space: nowrap; }

@keyframes chatPulse {
  0%, 100% { box-shadow: 0 6px 24px rgba(37, 99, 235, 0.5); }
  50% { box-shadow: 0 6px 24px rgba(37, 99, 235, 0.5), 0 0 0 8px rgba(37, 99, 235, 0.15); }
}

body.theme-dark .chat-toggle {
  background: #3b82f6;
  box-shadow: 0 6px 24px rgba(59, 130, 246, 0.5);
}
body.theme-dark .chat-toggle:hover {
  box-shadow: 0 10px 32px rgba(59, 130, 246, 0.6);
}
body.theme-dark @keyframes chatPulse {
  0%, 100% { box-shadow: 0 6px 24px rgba(59, 130, 246, 0.5); }
  50% { box-shadow: 0 6px 24px rgba(59, 130, 246, 0.5), 0 0 0 8px rgba(59, 130, 246, 0.2); }
}

body.theme-green .chat-toggle {
  background: #22c55e;
  color: #0a1410;
  box-shadow: 0 6px 24px rgba(34, 197, 94, 0.5);
}
body.theme-green .chat-toggle:hover {
  box-shadow: 0 10px 32px rgba(34, 197, 94, 0.65);
}
body.theme-green @keyframes chatPulse {
  0%, 100% { box-shadow: 0 6px 24px rgba(34, 197, 94, 0.5); }
  50% { box-shadow: 0 6px 24px rgba(34, 197, 94, 0.5), 0 0 0 8px rgba(34, 197, 94, 0.25); }
}

/* ==============  AI CHAT (Gemini, bottom-left)  ============== */
.ai-chat-container {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 40;
}
.ai-chat-toggle {
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  color: #ffffff;
  border: none;
  border-radius: 28px;
  height: 56px;
  padding: 0 20px 0 16px;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(139, 92, 246, 0.5);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  position: relative;
  transition: transform var(--transition), box-shadow var(--transition);
}
.ai-chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 32px rgba(139, 92, 246, 0.65);
}
.ai-chat-toggle .icon { width: 22px; height: 22px; }

body.theme-green .ai-chat-toggle {
  background: linear-gradient(135deg, #10b981 0%, #22c55e 100%);
  color: #0a1410;
  box-shadow: 0 6px 24px rgba(16, 185, 129, 0.5);
}

.ai-chat-window {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 340px;
  height: 460px;
  min-width: 280px;
  min-height: 300px;
  max-width: 95vw;
  max-height: 95vh;
  display: flex;
  flex-direction: column;
  position: fixed;
  bottom: 80px;
  left: 16px;
  z-index: 50;
  resize: both;
  overflow: hidden;
}
.ai-chat-window .chat-header {
  cursor: move;
  touch-action: none;
  user-select: none;
}
.ai-chat-window.dragging { user-select: none; box-shadow: 0 20px 60px rgba(0,0,0,0.45); }
.ai-model-label {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  color: white;
  margin-left: 4px;
}
body.theme-green .ai-model-label {
  background: linear-gradient(135deg, #10b981 0%, #22c55e 100%);
  color: #0a1410;
}

.ai-provider-select {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 6px;
  border-radius: 4px;
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  color: white;
  border: none;
  margin-left: 4px;
  cursor: pointer;
  outline: none;
  text-transform: none;
}
.ai-provider-select option { color: var(--text); background: var(--panel); }
body.theme-green .ai-provider-select { background: linear-gradient(135deg, #10b981 0%, #22c55e 100%); color: #0a1410; }
body.theme-hacker .ai-provider-select { background: #00ff41; color: #000; }

/* AI chat message bubbles */
.ai-msg {
  display: flex;
  max-width: 85%;
}
.ai-msg-bubble {
  padding: 8px 12px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.4;
}
.ai-msg.user { align-self: flex-end; }
.ai-msg.user .ai-msg-bubble {
  background: var(--primary-bg);
  color: var(--primary-text);
}
.ai-msg.model { align-self: flex-start; }
.ai-msg.model .ai-msg-bubble {
  background: var(--soft-bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.ai-msg-label {
  font-size: 10px;
  font-weight: 600;
  opacity: 0.6;
  margin-bottom: 3px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.ai-typing {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: var(--soft-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  align-self: flex-start;
  max-width: fit-content;
}
.ai-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: aiTyping 1.4s ease-in-out infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes aiTyping {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}
.ai-error {
  font-size: 12px;
  color: var(--danger);
  font-style: italic;
  padding: 8px 12px;
  text-align: center;
}

.ai-pending-card {
  align-self: flex-start;
  max-width: 85%;
  background: var(--soft-bg);
  border: 1px solid var(--border);
  border-left: 3px solid #8b5cf6;
  border-radius: var(--radius);
  padding: 8px 10px;
  margin: 4px 0;
  font-size: 12px;
}
.ai-pending-head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 6px;
}
.ai-pending-action {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #8b5cf6;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ai-pending-summary { color: var(--text); font-weight: 500; }
.ai-pending-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.ai-pending-body {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  margin: 4px 0 8px 0;
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
}
.ai-pending-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.btn-approve, .btn-reject {
  flex: 1;
  padding: 6px 10px;
  font-size: 12px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  transition: filter var(--transition);
}
.btn-approve { background: var(--success); color: white; }
.btn-reject { background: var(--soft-hover); color: var(--text); }
.btn-approve:hover, .btn-reject:hover { filter: brightness(1.1); }

.ai-diff {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  margin: 4px 0 8px 0;
  max-height: 200px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-diff-line { display: block; padding: 0 4px; border-radius: 2px; }
.ai-diff-add { background: rgba(22, 163, 74, 0.15); color: var(--success); }
.ai-diff-remove { background: rgba(220, 38, 38, 0.15); color: var(--danger); text-decoration: line-through; text-decoration-thickness: 1px; }
.ai-diff-context { color: var(--text-muted); }

/* Editor header actions */
.editor-header-actions { display: flex; gap: 6px; align-items: center; }
#history-btn { padding: 4px 10px; font-size: 12px; background: var(--soft-bg); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; color: var(--text); }
#history-btn:hover { background: var(--soft-hover); }

/* History modal */
.modal-box-wide { width: min(760px, 95vw); }
.history-layout { display: grid; grid-template-columns: 220px 1fr; gap: 12px; min-height: 300px; max-height: 55vh; }
.history-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--soft-bg); }
.history-list li {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 12px;
  transition: background var(--transition);
}
.history-list li:last-child { border-bottom: none; }
.history-list li:hover { background: var(--hover); }
.history-list li.active { background: var(--active-bg); color: var(--active-text); }
.history-list .v-time { font-weight: 600; display: block; }
.history-list .v-meta { color: var(--text-muted); font-size: 11px; }
.history-list li.active .v-meta { color: var(--active-text); opacity: 0.8; }
.history-preview {
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--panel);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.history-empty { color: var(--text-muted); font-style: italic; font-size: 12px; }

/* Responsive: on small screens, stack AI chat on mobile */
@media (max-width: 768px) {
  .ai-chat-window { width: calc(100vw - 32px); }
}

.chat-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border: 2px solid var(--bg);
}

.chat-window {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 320px;
  height: 400px;
  display: flex;
  flex-direction: column;
}
.chat-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  min-width: 0;
}
.chat-actions { display: flex; gap: 2px; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-empty {
  text-align: center;
  color: var(--text-subtle);
  font-size: 12px;
  font-style: italic;
  margin-top: 16px;
}
.chat-msg {
  display: flex;
  max-width: 75%;
}
.chat-msg-bubble {
  padding: 6px 10px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-msg.me {
  align-self: flex-end;
}
.chat-msg.me .chat-msg-bubble {
  background: var(--primary-bg);
  color: var(--primary-text);
}
.chat-msg.other { align-self: flex-start; }
.chat-msg.other .chat-msg-bubble {
  background: var(--soft-bg);
  color: var(--text);
}
.chat-msg-user {
  font-size: 10px;
  font-weight: 600;
  opacity: 0.7;
  margin-bottom: 2px;
}
.chat-msg-time {
  font-size: 9px;
  opacity: 0.6;
  text-align: right;
  margin-top: 2px;
}
.chat-input-row {
  padding: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 4px;
}
.chat-input-row input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.chat-input-row input:focus { border-color: var(--input-focus); }
.send-btn {
  background: var(--primary-bg);
  color: var(--primary-text);
  border: none;
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
}
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.send-btn:not(:disabled):hover { background: var(--primary-hover); }

/* ==============  NOTIFICATIONS  ============== */
.notifications {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.notification {
  pointer-events: auto;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  color: white;
  font-size: 14px;
  font-weight: 500;
  max-width: 320px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 0.2s ease-out;
}
.notification.success { background: var(--success); }
.notification.error { background: var(--danger); }
.notification button {
  background: transparent;
  border: none;
  color: white;
  opacity: 0.7;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0;
}
.notification button:hover { opacity: 1; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ==============  MODALS  ============== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}
.modal-box {
  position: relative;
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-head h3, .modal-box > h3 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-box label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-top: 12px;
}
.modal-box label:first-of-type { margin-top: 0; }
.modal-box input[type="text"],
.modal-box input[type="password"] {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: var(--font);
}
.modal-box input:focus { border-color: var(--input-focus); }
.hint {
  font-size: 11px;
  color: var(--text-subtle);
  margin: 6px 0 0 0;
}
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}
.btn-primary, .btn-secondary, .btn-danger {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  border: none;
  transition: background var(--transition), opacity var(--transition);
  font-family: inherit;
}
.btn-primary {
  background: var(--primary-bg);
  color: var(--primary-text);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--input-border);
}
.btn-secondary:hover { background: var(--hover); }
.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { opacity: 0.9; }

/* ==============  IMAGE PREVIEW  ============== */
.image-preview {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  flex-direction: column;
}
.image-preview img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius);
}
.image-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: none;
  font-size: 20px;
  cursor: pointer;
}
.image-close:hover { background: rgba(255, 255, 255, 0.4); }
.image-caption {
  color: white;
  margin-top: 12px;
  font-size: 14px;
}

/* ==============  RESPONSIVE  ============== */
@media (max-width: 768px) {
  .main-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .chat-window { width: calc(100vw - 32px); }
}
