/* ── Shared styles — loaded by all pages ──────────────────────── */

/* ── CSS Custom Properties / Theme Variables ─────────────────── */

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

:root {
  --bg: #0a0a0a;
  --surface: #161616;
  --surface-hover: #1e1e1e;
  --border: #2a2a2a;
  --text: #e5e5e5;
  --text-dim: #888;
  --accent: #3b82f6;
  --accent-dim: #1e3a5f;
  --user-bubble: #1a3a5c;
  --assistant-bubble: #1a1a1a;
  --code-bg: rgba(255,255,255,0.08);
  --pre-bg: rgba(0,0,0,0.4);
  --table-header: rgba(255,255,255,0.05);
  --radius: 16px;
  --safe-bottom: 0px;
  --safe-top: 0px;
}

[data-theme="light"] {
  --bg: #f0ece6;
  --surface: #e6e1da;
  --surface-hover: #ddd8d0;
  --border: #ccc7bf;
  --text: #2c2c2c;
  --text-dim: #777;
  --accent: #2563eb;
  --accent-dim: #bfdbfe;
  --user-bubble: #d0dff5;
  --assistant-bubble: #e8e4dd;
  --code-bg: rgba(0,0,0,0.06);
  --pre-bg: rgba(0,0,0,0.05);
  --table-header: rgba(0,0,0,0.04);
}

/* Universal hidden utility — toggled by JS on any element */
.hidden { display: none !important; }

/* ── Reset / Base Styles ─────────────────────────────────────── */

html, body {
  height: 100dvh;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout Wrapper ──────────────────────────────────────────── */

#layout {
  display: flex;
  height: 100dvh;
  height: 100%;
  overflow: hidden;
  position: relative;
}

/* ── Header ──────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

#notif-btn, #mobile-menu-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#mobile-menu-btn {
  display: none;
}

#notif-btn:hover, #mobile-menu-btn:hover {
  background: var(--surface-hover);
}

/* ── Files Shared Styles ─────────────────────────────────────── */

.files-dropdown-header {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.files-list {
  overflow-y: auto;
  padding: 4px;
}

.files-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 20px 14px;
}

.files-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  overflow: hidden;
}

.files-item:hover {
  background: var(--surface-hover);
}

.files-item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
}

.files-item-path {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
  text-align: left;
}

.files-item-icon {
  color: var(--text-dim);
  flex-shrink: 0;
}

/* ── Shared Keyframes ────────────────────────────────────────── */

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

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

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes checkPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ── Icon Rail ───────────────────────────────────────────────── */

.icon-rail {
  display: flex;
  flex-direction: column;
  width: 52px;
  min-width: 52px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  height: 100%;
  padding: 8px 0;
  flex-shrink: 0;
  z-index: 12;
}

.rail-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
}

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

.rail-middle {
  flex: 1;
}

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

.rail-btn {
  position: relative;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  color: var(--text-dim);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.rail-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.rail-btn.active {
  color: var(--accent);
  background: var(--accent-dim);
}

.rail-btn.active::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.rail-initial {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.rail-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: #ef4444;
  color: white;
  font-size: 9px;
  font-weight: 700;
  min-width: 14px;
  height: 14px;
  line-height: 14px;
  text-align: center;
  border-radius: 7px;
  padding: 0 3px;
  pointer-events: none;
}

/* Rail tooltips */
.rail-btn[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 100;
  pointer-events: none;
}

/* Rail dropdowns */
.rail-dropdown {
  position: fixed;
  left: 52px;
  min-width: 180px;
  max-height: 360px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  overflow: hidden;
  z-index: 50;
  animation: fadeIn 0.1s ease;
}

.rail-dropdown-header {
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.rail-dropdown-option {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  padding: 9px 14px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.rail-dropdown-option:hover {
  background: var(--surface-hover);
}

.rail-dropdown-option.active {
  color: var(--accent);
}

/* ── Mobile Sidebar ──────────────────────────────────────────── */

.mobile-sidebar-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 119;
}

.mobile-sidebar-backdrop.visible {
  display: block;
}

.mobile-sidebar {
  position: fixed;
  top: 0;
  left: -300px;
  width: 300px;
  height: 100%;
  background: var(--bg);
  border-right: 1px solid var(--border);
  z-index: 120;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: left 0.25s ease;
}

.mobile-sidebar.open {
  left: 0;
}

.mobile-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.mobile-sidebar-title {
  font-size: 18px;
  font-weight: 600;
}

.mobile-sidebar-close {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-size: 14px;
  padding: 11px 16px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.mobile-sidebar-item:hover {
  background: var(--surface-hover);
}

.mobile-sidebar-item.active {
  color: var(--accent);
  font-weight: 600;
}

.mobile-sidebar-item.mob-primary {
  background: var(--accent);
  color: white;
  margin: 8px 12px;
  width: calc(100% - 24px);
  border-radius: 10px;
  justify-content: center;
  font-weight: 600;
}

.mobile-sidebar-item.mob-primary:hover {
  opacity: 0.9;
  background: var(--accent);
}

.mobile-sidebar-item svg, .mobile-sidebar-item .rail-initial {
  color: var(--text-dim);
  flex-shrink: 0;
}

.mobile-sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 12px;
}

.mobile-sidebar-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 16px 4px;
}

.mobile-session-list {
  max-height: 200px;
  overflow-y: auto;
  padding: 0 8px;
}

.mobile-sidebar-spacer {
  flex: 1;
}

.mobile-only {
  display: none;
}

/* ── Settings Page ───────────────────────────────────────────── */

.settings-page {
  position: absolute;
  top: 0;
  left: 53px;
  right: 0;
  bottom: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings-page.hidden {
  display: none;
}

.settings-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.settings-page-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.settings-page-close:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.settings-page-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  max-width: 640px;
}

.settings-page-section {
  margin-bottom: 32px;
}

.settings-page-section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 4px 0;
}

.settings-page-section-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 16px 0;
  line-height: 1.4;
}

.settings-section {
  margin-bottom: 16px;
}

.settings-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.settings-key-row {
  display: flex;
  gap: 6px;
}

.settings-input {
  flex: 1;
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

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

.settings-input::placeholder {
  color: var(--text-dim);
}

.settings-toggle-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.settings-toggle-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.settings-status {
  font-size: 12px;
  margin-top: 6px;
  min-height: 18px;
}

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

.settings-status-none {
  color: var(--text-dim);
}

.settings-status-err {
  color: #ef4444;
}

.settings-save-btn {
  font-size: 14px;
  font-weight: 600;
  padding: 8px 24px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s;
  font-family: inherit;
}

.settings-save-btn:hover:not(:disabled) {
  opacity: 0.9;
}

.settings-save-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Settings — Summary Prompts ──────────────────────────────── */

.settings-prompts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-prompt-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.settings-prompt-item-view {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  gap: 12px;
}

.settings-prompt-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.settings-prompt-item-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-prompt-default {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-dim);
  background: var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
}

.settings-prompt-item-preview {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-prompt-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.settings-prompt-edit-btn,
.settings-prompt-delete-btn,
.settings-prompt-delete-cancel-btn {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}

.settings-prompt-edit-btn:hover,
.settings-prompt-delete-cancel-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.settings-prompt-delete-btn:hover {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.3);
}

.settings-prompt-delete-btn.confirming {
  color: #ef4444;
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* Inline edit form */
.settings-prompt-item-edit {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-prompt-label-input {
  font-size: 13px;
}

.settings-prompt-text-input {
  font-size: 13px;
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
  padding: 10px 12px;
}

.settings-prompt-edit-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.settings-prompt-save-edit-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s;
}

.settings-prompt-save-edit-btn:hover {
  opacity: 0.9;
}

.settings-prompt-cancel-edit-btn {
  font-size: 12px;
  font-weight: 500;
  padding: 5px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s;
}

.settings-prompt-cancel-edit-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* Add prompt button */
.settings-add-prompt-btn {
  width: 100%;
  font-size: 13px;
  font-weight: 500;
  padding: 8px;
  margin-top: 8px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.settings-add-prompt-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Restore defaults link */
.settings-restore-link {
  display: block;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  text-decoration: underline;
  margin-top: 8px;
  cursor: pointer;
  transition: color 0.15s;
}

.settings-restore-link:hover {
  color: var(--accent);
}

/* ── Sync Button States ──────────────────────────────────────── */

#rail-sync.syncing svg {
  animation: spin 1s linear infinite;
}

#rail-sync.sync-ok {
  color: #22c55e;
}

#rail-sync.sync-err {
  color: #ef4444;
}

/* ── System Notices ──────────────────────────────────────────── */

.system-notice {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 8px;
  margin: 8px 0;
}

/* ── Toast Notification ──────────────────────────────────────── */

.toast {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  z-index: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.2s ease;
  max-width: calc(100vw - 32px);
  text-align: center;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.success { border-color: #22c55e; color: #22c55e; }
.toast.error { border-color: #ef4444; color: #ef4444; }
.toast.info { border-color: var(--accent); color: var(--accent); }

/* ── Push Notification Prompt ────────────────────────────────── */

#push-prompt {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 1000;
  animation: slideUp 0.3s ease;
}

.push-prompt-content {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.push-prompt-content span {
  color: var(--text);
  font-size: 14px;
}

.push-prompt-actions {
  display: flex;
  gap: 8px;
}

#push-enable {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

#push-enable:hover {
  opacity: 0.9;
}

#push-dismiss {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

#push-dismiss:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

/* ── Notification Inbox ──────────────────────────────────────── */

.notif-panel {
  position: fixed;
  top: 0;
  right: -320px;
  width: 320px;
  height: 100%;
  background: var(--bg);
  border-left: 1px solid var(--border);
  z-index: 110;
  transition: right 0.25s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.notif-panel.open {
  right: 0;
}

.notif-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 105;
}

.notif-backdrop.visible {
  display: block;
}

.notif-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.notif-panel-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.notif-read-all-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}

.notif-read-all-btn:hover {
  color: var(--accent);
  background: var(--accent-dim);
}

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

.notif-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 16px;
  font-size: 14px;
}

.notif-item {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.notif-item:hover {
  background: var(--surface-hover);
}

.notif-unread {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
}

.notif-read {
  opacity: 0.6;
  border-left: 3px solid transparent;
}

.notif-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.notif-emoji {
  font-size: 14px;
}

.notif-time {
  font-size: 11px;
  color: var(--text-dim);
}

.notif-desc {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
}

.notif-read .notif-desc {
  color: var(--text-dim);
}

.notif-section-label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 16px 4px;
}

.notif-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

#notif-btn {
  position: relative;
}

/* Mobile: notification panel as overlay */
@media (max-width: 899px) {
  .notif-panel {
    width: 300px;
    right: -300px;
  }

  #layout.notif-open .notif-panel {
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
  }
}

/* ── Lists Panel ─────────────────────────────────────────────── */

.lists-panel {
  display: flex;
  flex-direction: column;
  width: 0;
  min-width: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  height: 100%;
  overflow: hidden;
  transition: width 0.25s ease, min-width 0.25s ease;
}

#layout.lists-open .lists-panel {
  width: 33vw;
  min-width: 320px;
  max-width: 480px;
}

.lists-backdrop {
  display: none;
}

.lists-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

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

.lists-panel-title {
  font-size: 16px;
  font-weight: 600;
}

.lists-back-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border-radius: 6px;
  transition: color 0.15s;
}

.lists-back-btn:hover {
  color: var(--text);
}

.lists-add-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.15s;
}

.lists-add-btn:hover {
  color: var(--text);
}

#lists-close {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#lists-close:hover {
  background: var(--surface-hover);
}

.lists-overview {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.lists-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 32px 16px;
}

/* List cards */
.list-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.list-card:hover {
  background: var(--surface-hover);
  border-color: var(--text-dim);
}

.list-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.list-card-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.list-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-card-pin {
  font-size: 12px;
  flex-shrink: 0;
}

.list-card-progress {
  display: flex;
  align-items: center;
  gap: 8px;
}

.list-card-progress-bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.list-card-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.list-card-progress-text {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* List detail view */
.lists-detail {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.list-detail-header {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.list-detail-title {
  background: none;
  border: none;
  border-bottom: 2px solid var(--accent);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  padding: 4px 0;
  outline: none;
  font-family: inherit;
  width: 100%;
}

.list-detail-colors {
  display: flex;
  gap: 6px;
}

.list-color-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  padding: 0;
}

.list-color-dot:hover {
  transform: scale(1.15);
}

.list-color-dot.active {
  border-color: var(--text);
}

.list-detail-actions {
  display: flex;
  gap: 8px;
}

.list-action-btn {
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.list-action-btn:hover {
  background: var(--surface-hover);
}

.list-action-btn.list-delete {
  color: #ef4444;
  border-color: rgba(239,68,68,0.3);
}

.list-action-btn.list-delete:hover {
  background: rgba(239,68,68,0.1);
}

/* List items */
.list-detail-items {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  border-radius: 6px;
  transition: opacity 0.2s;
}

.list-item.done {
  opacity: 0.5;
}

.list-item.done .list-item-text {
  text-decoration: line-through;
}

/* List section headers */
.list-section-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  padding: 12px 4px 4px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}

.list-section-header:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 4px;
}

.list-section-header.bold-header {
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
}

.list-section-empty {
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 4px 4px 28px;
  font-style: italic;
}

.list-item-bullet {
  width: 20px;
  flex-shrink: 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 16px;
}

/* Custom checkbox */
.list-item-check {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
}

.list-item-check input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.list-item-checkmark {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}

.list-item-check input:checked + .list-item-checkmark {
  background: var(--accent);
  border-color: var(--accent);
}

.list-item-check input:checked + .list-item-checkmark::after {
  content: "";
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  margin-top: -2px;
}

.list-item-checkmark.check-pop {
  animation: checkPop 0.25s ease;
}

.list-item-text {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  min-width: 0;
  word-break: break-word;
  cursor: text;
}

.list-item-edit-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--text-dim);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 0 0 1px;
  outline: none;
}

.list-item-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
}

.list-item:hover .list-item-delete {
  opacity: 1;
}

@media (hover: none) {
  .list-item-delete {
    opacity: 0.5;
  }
}

.list-item-delete:hover {
  color: #ef4444;
}

/* Add item input */
.list-detail-add {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.list-detail-add input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  padding: 8px 10px;
  outline: none;
}

.list-detail-add input:focus {
  border-color: var(--accent);
}

.list-detail-add input::placeholder {
  color: var(--text-dim);
}

.list-detail-add button {
  background: var(--accent);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.list-detail-add button:hover {
  opacity: 0.9;
}

/* Pinned list dots in rail */
.rail-pinned-divider {
  width: 24px;
  height: 1px;
  background: var(--border);
  margin: 4px auto;
}

.rail-pinned-btn {
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  transition: background 0.15s;
}

.rail-pinned-btn:hover {
  background: var(--surface-hover);
}

.rail-pinned-dot {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* Mobile: lists panel as overlay */
@media (max-width: 899px) {
  #layout.lists-open .lists-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 110;
    width: 280px;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  }

  #layout.lists-open .lists-backdrop {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 105;
  }
}

/* ── Mobile: hide icon rail, show mobile-only ────────────────── */

@media (max-width: 899px) {
  .icon-rail {
    display: none;
  }

  .mobile-only {
    display: flex;
  }

  #mobile-menu-btn {
    display: flex;
  }

  .rail-dropdown {
    display: none !important;
  }

  /* Ensure panels respect safe areas */
  .lists-panel-header {
    padding-top: max(12px, env(safe-area-inset-top));
  }

  /* Larger touch targets for mobile */
  .list-item {
    padding: 10px 4px;
    min-height: 44px;
  }

  .list-action-btn {
    padding: 8px 14px;
    font-size: 13px;
    min-height: 36px;
  }

  .list-color-dot {
    width: 28px;
    height: 28px;
  }

  /* Lists add-item bar safe area */
  .list-detail-add {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  /* Mobile sidebar bottom safe area */
  .mobile-sidebar {
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Settings page full-screen on mobile (no rail) */
  .settings-page {
    left: 0;
  }

  .settings-page-header {
    padding-top: max(16px, env(safe-area-inset-top));
  }

  .settings-page-body {
    padding: 16px;
  }
}

/* ── Modal overlay (library/youtube shared) ──────────────────── */

#library-view ~ .lib-modal-overlay,
.lib-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lib-modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  padding: 24px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3);
}

.lib-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.lib-modal-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.lib-modal-close {
  font-size: 20px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}

.lib-modal-close:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* ── Prompt chips (used by summary & URL modals) ─────────────── */

.lib-prompt-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.lib-prompt-chip,
.lib-url-prompt-chip {
  font-size: 12px;
  font-weight: 500;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
}

.lib-prompt-chip:hover,
.lib-url-prompt-chip:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.lib-prompt-chip.active,
.lib-url-prompt-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Prompt textarea ─────────────────────────────────────────── */

.lib-prompt-textarea {
  width: 100%;
  font-size: 13px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 12px;
  box-sizing: border-box;
}

.lib-prompt-textarea:focus {
  border-color: var(--accent);
}

.lib-prompt-textarea::placeholder {
  color: var(--text-dim);
}

/* ── Generate button ─────────────────────────────────────────── */

.lib-prompt-generate {
  width: 100%;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s;
  font-family: inherit;
}

.lib-prompt-generate:hover:not(:disabled) {
  opacity: 0.9;
}

.lib-prompt-generate:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Responsive — shared modal adjustments ───────────────────── */

@media (max-width: 600px) {
  .lib-modal-overlay {
    padding: 12px;
    align-items: center;
  }

  .lib-modal {
    max-width: 100%;
    border-radius: 16px;
    max-height: 90vh;
    overflow-y: auto;
  }

  .lib-prompt-chips {
    gap: 6px;
  }

  .lib-prompt-chip,
  .lib-url-prompt-chip {
    font-size: 11px;
    padding: 5px 10px;
  }
}
