/* style.css — Mobile-first responsive layout for tmux-helper */

/* ── CSS Variables ── */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-card: #161b22;
  --border: #30363d;
  --text-primary: #c9d1d9;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --danger: #f85149;
  --danger-hover: #ff7b72;
  --success: #56d364;
  --warning: #d29922;
  --font-mono: 'Cascadia Code', 'Fira Code', 'SF Mono', 'Menlo', 'Consolas', monospace;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --sidebar-width: 250px;
  --header-height: 44px;
  --toolbar-height: 48px;
}

/* ── Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Ensure [hidden] always wins over author display rules */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  font-family: var(--font-ui);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-text-size-adjust: 100%;
  /* Prevent pull-to-refresh and overscroll bounce */
  overscroll-behavior: none;
  -webkit-overflow-scrolling: auto;
  touch-action: pan-x pan-y;
}

/* ── Buttons ── */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--border); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary { background: var(--bg-secondary); }
.btn-block { display: block; width: 100%; }

.btn-sm {
  padding: 4px 12px;
  font-size: 13px;
  border-radius: 4px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
}
.btn-sm:hover { color: var(--text-primary); border-color: var(--text-primary); }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  line-height: 1;
}
.btn-icon:hover { color: var(--text-primary); }

.btn-delete {
  color: var(--text-muted);
  font-size: 16px;
}
.btn-delete:hover { color: var(--danger); }

/* ── Login Page ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 32px 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.login-title {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  font-family: var(--font-mono);
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.error-msg {
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--danger);
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.3);
  border-radius: 6px;
}

#login-btn {
  margin-top: 8px;
}

/* ── Dashboard Layout ── */
.dashboard-page {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* JS overrides height/top when mobile keyboard appears */
}

/* Header */
.header {
  display: flex;
  align-items: center;
  height: var(--header-height);
  padding: 0 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-title {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  margin-left: 8px;
  flex: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.font-size-label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 20px;
  text-align: center;
}

/* Main layout */
.main-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  /* Mobile: hidden by default */
  position: fixed;
  top: var(--header-height);
  left: calc(-1 * var(--sidebar-width));
  bottom: 0;
  z-index: 10;
  transition: left 0.2s ease;
}
.sidebar.open {
  left: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.session-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}

.session-empty {
  padding: 16px 8px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.session-item {
  display: flex;
  align-items: center;
  padding: 0;
  margin-bottom: 2px;
  border-radius: 6px;
  transition: background 0.1s;
}
.session-item:hover { background: var(--bg-tertiary); }
.session-item.active { background: var(--bg-tertiary); border-left: 2px solid var(--accent); }

.session-info {
  display: flex;
  align-items: center;
  flex: 1;
  padding: 8px 10px;
  cursor: pointer;
  min-width: 0;
}

.session-name {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-badge {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 8px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--border);
}

/* Terminal area */
.terminal-area {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.terminal-container {
  flex: 1;
  padding: 4px;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.terminal-container .xterm {
  height: 100%;
}

.terminal-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 14px;
}

/* Mobile toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  height: var(--toolbar-height);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  scrollbar-width: none;
}
.toolbar::-webkit-scrollbar {
  display: none;
}

.toolbar-btn {
  min-width: 44px;
  min-height: 36px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: var(--font-mono);
  font-weight: 600;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  touch-action: pan-x;
  -webkit-user-select: none;
  user-select: none;
  transition: background 0.1s, color 0.1s;
  flex-shrink: 0;
  white-space: nowrap;
}
.toolbar-btn:active { background: var(--border); }
.toolbar-btn.active {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
}

/* Keyboard toggle button — larger, distinct style */
.keyboard-toggle-btn {
  font-size: 18px;
  min-width: 48px;
  padding: 6px 12px;
}

/* Prefix button (C-b) — highlighted accent */
.prefix-btn {
  background: var(--accent) !important;
  color: #fff !important;
  font-weight: 700;
  font-size: 12px;
  min-width: 42px;
}

/* ── Toolbar edit mode ── */
.toolbar-btn.editing {
  position: relative;
  overflow: visible;
}
.toolbar-delete-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  background: var(--danger);
  color: #fff;
  border-radius: 50%;
  font-size: 11px;
  line-height: 20px;
  text-align: center;
  z-index: 2;
  pointer-events: auto;
}
.toolbar-btn-label {
  pointer-events: none;
}
.toolbar-settings-btn {
  font-size: 16px;
  margin-left: auto;
}
.toolbar-add-btn {
  font-size: 18px;
  color: var(--accent) !important;
  border-style: dashed !important;
  border-color: var(--accent) !important;
}
.toolbar-reset-btn {
  font-size: 16px;
  color: var(--text-muted) !important;
}

/* Form elements (toolbar modal) */
.form-select {
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  font-family: var(--font-mono);
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}
.form-select:focus {
  border-color: var(--accent);
}
.radio-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

/* ── Mouse mode / Keyboard mode ── */

/* Mouse mode: prevent keyboard from appearing on touch */
.terminal-container.mouse-mode .xterm-helper-textarea {
  pointer-events: none;
  opacity: 0;
  position: absolute;
  top: -9999px;
}

/* Mouse mode: show a subtle cursor indicator */
.terminal-container.mouse-mode {
  cursor: default;
}

/* Keyboard mode: normal xterm behavior */
.terminal-container.keyboard-mode .xterm-helper-textarea {
  pointer-events: auto;
}

.terminal-container.keyboard-mode {
  cursor: text;
}

/* ── Desktop (>= 768px) ── */
@media (min-width: 768px) {
  #sidebar-toggle {
    display: none;
  }

  .sidebar {
    position: static;
    left: 0;
  }

  .toolbar {
    display: none !important;
  }
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Server section (Phase 6) ── */
.server-section {
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.server-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 6px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.server-list {
  list-style: none;
  padding: 0 8px 4px;
  max-height: 140px;
  overflow-y: auto;
}

.server-item {
  display: flex;
  align-items: center;
  padding: 0;
  margin-bottom: 2px;
  border-radius: 6px;
  transition: background 0.1s;
}
.server-item:hover { background: var(--bg-tertiary); }
.server-item.active { background: var(--bg-tertiary); border-left: 2px solid var(--accent); }

.server-info {
  display: flex;
  align-items: center;
  flex: 1;
  padding: 6px 10px;
  cursor: pointer;
  min-width: 0;
}

.server-name {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.server-badge {
  font-size: 10px;
  color: var(--text-muted);
  margin-left: 8px;
  flex-shrink: 0;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
}

.server-badge-local {
  color: var(--success);
  border-color: var(--success);
  background: rgba(86, 211, 100, 0.1);
}

.btn-edit {
  color: var(--text-muted);
  font-size: 14px;
}
.btn-edit:hover { color: var(--accent); }

/* ── Server Modal ── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}

.modal-card .form-group {
  margin-bottom: 12px;
}

.modal-card .form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.modal-card .form-group input {
  width: 100%;
  padding: 7px 10px;
  font-size: 13px;
  font-family: var(--font-mono);
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  transition: border-color 0.15s;
}

.modal-card .form-group input:focus {
  border-color: var(--accent);
}

.modal-card .form-group input:read-only {
  opacity: 0.5;
  cursor: not-allowed;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-group-half {
  flex: 1;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  gap: 8px;
}

.modal-actions-right {
  display: flex;
  gap: 8px;
}

.success-msg {
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--success);
  background: rgba(86, 211, 100, 0.1);
  border: 1px solid rgba(86, 211, 100, 0.3);
  border-radius: 6px;
}

/* ── Favorites section ── */
.favorites-section {
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.favorites-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 4px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.favorites-list {
  list-style: none;
  padding: 0 8px 4px;
  max-height: 120px;
  overflow-y: auto;
}

.fav-item {
  display: flex;
  align-items: center;
  padding: 0;
  margin-bottom: 2px;
  border-radius: 6px;
  transition: background 0.1s;
}
.fav-item:hover { background: var(--bg-tertiary); }

.fav-info {
  display: flex;
  align-items: center;
  flex: 1;
  padding: 5px 10px;
  cursor: pointer;
  min-width: 0;
  gap: 6px;
}

.fav-server-tag {
  font-size: 10px;
  color: var(--accent);
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(88, 166, 255, 0.1);
  border: 1px solid rgba(88, 166, 255, 0.3);
  flex-shrink: 0;
  white-space: nowrap;
}

.fav-name {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Star toggle button in session list */
.btn-fav {
  color: var(--text-muted);
  font-size: 16px;
  padding: 4px 6px;
}
.btn-fav:hover { color: var(--warning); }
.btn-fav.is-fav { color: var(--warning); }

/* ── File Browser (Phase 8F) ── */

.files-page {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Navigation tabs */
.nav-tab {
  text-decoration: none;
  color: var(--text-secondary);
}
.nav-tab:hover { color: var(--text-primary); }
.nav-tab-active {
  color: var(--accent) !important;
  border-color: var(--accent) !important;
  font-weight: 600;
}

/* Files area */
.files-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 10px 16px 6px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.breadcrumb-segment {
  color: var(--accent);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
}
.breadcrumb-segment:hover {
  background: var(--bg-tertiary);
  color: var(--accent-hover);
}
.breadcrumb-sep { color: var(--text-muted); }

/* Files action bar */
.files-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 8px;
  flex-shrink: 0;
}
.btn-bookmark {
  color: var(--text-muted);
  font-size: 18px;
  margin-left: auto;
}
.btn-bookmark:hover { color: var(--warning); }
.btn-bookmark.is-bookmarked { color: var(--warning); }

/* File list */
.file-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 12px;
  position: relative;
}
.file-list-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  color: var(--text-muted);
  font-size: 14px;
}

/* File item */
.file-item {
  display: flex;
  align-items: center;
  border-radius: 6px;
  transition: background 0.1s;
  margin-bottom: 1px;
}
.file-item:hover { background: var(--bg-tertiary); }

.file-item-main {
  display: flex;
  align-items: center;
  flex: 1;
  padding: 7px 10px;
  cursor: pointer;
  min-width: 0;
  gap: 8px;
}

.file-icon {
  flex-shrink: 0;
  font-size: 16px;
  width: 24px;
  text-align: center;
}
.file-name {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}
.file-size {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-muted);
  min-width: 60px;
  text-align: right;
  font-family: var(--font-mono);
}
.file-date {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-muted);
  min-width: 70px;
  text-align: right;
}

.file-item-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-right: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.file-item:hover .file-item-actions { opacity: 1; }

.btn-file-action {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
  text-decoration: none;
  border-radius: 4px;
}
.btn-file-action:hover { color: var(--text-primary); background: var(--bg-secondary); }
.btn-file-delete:hover { color: var(--danger); }

.file-item-parent { opacity: 0.7; }
.file-item-parent:hover { opacity: 1; }

/* Upload dropzone */
.upload-dropzone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(88, 166, 255, 0.08);
  border: 2px dashed var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
  z-index: 5;
  pointer-events: none;
}

/* Preview modal */
.preview-modal {
  position: fixed;
  top: var(--header-height);
  left: 0; right: 0; bottom: 0;
  background: var(--bg-primary);
  z-index: 30;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.preview-filename {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.preview-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.preview-content {
  flex: 1;
  overflow: auto;
  padding: 16px;
}
.preview-content pre {
  margin: 0;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}
.preview-content pre code {
  font-family: inherit;
  background: none;
  padding: 0;
}
.preview-image {
  max-width: 100%;
  max-height: 80vh;
  display: block;
  margin: 0 auto;
  border-radius: 4px;
}
.preview-video {
  width: 100%;
  max-height: 80vh;
  border-radius: 4px;
}
.preview-audio {
  width: 100%;
  margin-top: 40px;
}
.preview-pdf {
  width: 100%;
  height: 100%;
  border: none;
}

/* Markdown body */
.markdown-body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-primary);
  max-width: 860px;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  margin-top: 24px;
  margin-bottom: 12px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}
.markdown-body h1 { font-size: 28px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.markdown-body h2 { font-size: 22px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.markdown-body h3 { font-size: 18px; }
.markdown-body p { margin-bottom: 12px; }
.markdown-body ul, .markdown-body ol { padding-left: 24px; margin-bottom: 12px; }
.markdown-body li { margin-bottom: 4px; }
.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  color: var(--accent);
}
.markdown-body pre {
  margin-bottom: 16px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
  overflow-x: auto;
}
.markdown-body pre code {
  padding: 0;
  background: none;
  color: var(--text-primary);
  font-size: 13px;
}
.markdown-body blockquote {
  margin: 0 0 12px;
  padding: 8px 16px;
  border-left: 3px solid var(--accent);
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-radius: 0 6px 6px 0;
}
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}
.markdown-body th, .markdown-body td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}
.markdown-body th {
  background: var(--bg-tertiary);
  font-weight: 600;
}
.markdown-body img { max-width: 100%; border-radius: 4px; }
.markdown-body a { color: var(--accent); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* Bookmarks section */
.bookmarks-section {
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.bookmarks-header {
  display: flex;
  align-items: center;
  padding: 8px 12px 4px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}
.bookmarks-list {
  list-style: none;
  padding: 0 8px 4px;
  max-height: 140px;
  overflow-y: auto;
}
.bookmark-item {
  display: flex;
  align-items: center;
  padding: 0;
  margin-bottom: 2px;
  border-radius: 6px;
  transition: background 0.1s;
}
.bookmark-item:hover { background: var(--bg-tertiary); }
.bookmark-info {
  display: flex;
  align-items: center;
  flex: 1;
  padding: 5px 10px;
  cursor: pointer;
  min-width: 0;
  gap: 6px;
}
.bookmark-path {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
}

/* Mobile responsive — files */
@media (max-width: 768px) {
  .file-date { display: none; }
  .file-size { min-width: 50px; }
  .files-actions { flex-wrap: wrap; }
  .file-item-actions { opacity: 1; }
  .preview-content { padding: 12px; }
}

/* ── Ace Editor in preview ── */
.ace-editor-wrap {
  width: 100%;
  height: 100%;
  min-height: 400px;
}
.preview-content .ace-editor-wrap {
  border-radius: 6px;
  overflow: hidden;
}
.preview-content {
  display: flex;
  flex-direction: column;
}
.preview-actions .btn-edit {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.preview-actions .btn-edit:hover {
  background: var(--accent);
  color: #fff;
}
.preview-actions .btn-save {
  background: var(--success);
  color: #000;
  border: none;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.preview-actions .btn-save:hover {
  opacity: 0.85;
}
.preview-actions .btn-save:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.preview-actions .btn-source {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.preview-actions .btn-source:hover {
  background: var(--accent);
  color: #fff;
}

/* ══════════════════════════════════════════════════════════════════
   AI Chat Panel
   ══════════════════════════════════════════════════════════════════ */

.ai-toggle-btn {
  background: var(--accent) !important;
  color: var(--bg-primary) !important;
  border-color: var(--accent) !important;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.ai-toggle-btn:hover {
  background: var(--accent-hover) !important;
}

/* Panel container */
.ai-panel {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 420px;
  max-width: 100vw;
  height: 60vh;
  max-height: calc(100vh - var(--header-height));
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
  border-top-left-radius: 12px;
  display: flex;
  flex-direction: column;
  z-index: 50;
  transition: transform 0.25s ease, opacity 0.2s ease;
  box-shadow: -4px -4px 20px rgba(0,0,0,0.4);
}
.ai-panel-hidden {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

/* Header */
.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-panel-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ai-panel-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}
.ai-panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.ai-header-btn {
  font-size: 16px;
  padding: 4px 6px;
  color: var(--text-secondary);
}
.ai-header-btn:hover {
  color: var(--text-primary);
}

/* Model selector */
.ai-model-select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 3px 6px;
  outline: none;
}
.ai-model-select:focus {
  border-color: var(--accent);
}

/* Messages area */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Empty state */
.ai-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  gap: 6px;
}
.ai-empty-hint {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* Message bubbles */
.ai-message {
  display: flex;
}
.ai-message-user {
  justify-content: flex-end;
}
.ai-message-assistant {
  justify-content: flex-start;
}
.ai-bubble {
  max-width: 90%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}
.ai-bubble-user {
  background: var(--accent);
  color: var(--bg-primary);
  border-bottom-right-radius: 4px;
}
.ai-bubble-ai {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}
.ai-streaming {
  opacity: 0.85;
}

/* Text segments */
.ai-text {
  margin: 4px 0;
}
.ai-inline-code {
  background: rgba(110,118,129,0.2);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
}

/* Code blocks */
.ai-code-block {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 6px 0;
  overflow: hidden;
}
.ai-code {
  margin: 0;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: #c9d1d9;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.ai-code code {
  font-family: inherit;
  font-size: inherit;
}

/* Insert button */
.ai-insert-btn,
.ai-insert-all-btn {
  display: block;
  width: 100%;
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}
.ai-insert-btn:hover,
.ai-insert-all-btn:hover {
  background: rgba(88,166,255,0.1);
}
.ai-insert-btn {
  border-top: 1px solid var(--border);
}
.ai-insert-all-btn {
  background: rgba(88,166,255,0.05);
  border-radius: 6px;
  margin-top: 4px;
  text-align: center;
  padding: 8px;
}
.ai-insert-btn:disabled,
.ai-insert-all-btn:disabled {
  color: var(--success);
  cursor: default;
}

/* Action bar (copy, insert all, regenerate) */
.ai-action-bar {
  display: flex;
  gap: 2px;
  margin-top: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}
.ai-action-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.ai-action-btn:hover {
  background: rgba(110,118,129,0.2);
  color: var(--text-primary);
}
.ai-action-btn:disabled {
  color: var(--success);
  cursor: default;
}

/* Input area */
.ai-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-input {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-ui);
  padding: 8px 12px;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
}
.ai-input:focus {
  border-color: var(--accent);
}
.ai-input::placeholder {
  color: var(--text-muted);
}
.ai-send-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--bg-primary);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.ai-send-btn:hover {
  background: var(--accent-hover);
}
.ai-send-btn.ai-stop {
  background: var(--danger);
}
.ai-send-btn.ai-stop:hover {
  background: var(--danger-hover);
}

/* Mobile responsive */
@media (max-width: 768px) {
  .ai-panel {
    width: 100vw;
    height: 55vh;
    border-left: none;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
  }
}

/* ══════════════════════════════════════════════════════════════════════
   AI Settings Page
   ══════════════════════════════════════════════════════════════════════ */

.ai-settings-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px 16px;
  margin-top: var(--header-height);
}
.ai-settings-section {
  margin-bottom: 28px;
}
.ai-settings-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.ai-settings-section-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.ai-settings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-settings-empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 16px;
  text-align: center;
  background: var(--bg-secondary);
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.ai-settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.15s;
}
.ai-settings-item:hover {
  border-color: var(--accent);
}
.ai-settings-item-info {
  flex: 1;
  min-width: 0;
}
.ai-settings-item-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-settings-item-detail {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.ai-settings-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  margin-left: 12px;
}
.ai-settings-item-actions .btn-sm {
  padding: 3px 10px;
  font-size: 12px;
}
.ai-settings-item-actions .ai-delete-btn,
.ai-settings-item-actions .ai-delete-profile-btn {
  color: var(--danger);
  border-color: var(--danger);
}
.ai-settings-item-actions .ai-delete-btn:hover,
.ai-settings-item-actions .ai-delete-profile-btn:hover {
  background: var(--danger);
  color: #fff;
}
.ai-default-badge {
  color: var(--warning);
}

/* Profile modal inline row */
.form-row-inline {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-row-inline select,
.form-row-inline input {
  width: 100%;
}

/* Settings page textarea */
.ai-settings-page textarea {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-mono);
  padding: 8px 10px;
  resize: vertical;
  outline: none;
}
.ai-settings-page textarea:focus {
  border-color: var(--accent);
}
