/* ── RESET & BASE ───────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
* { -webkit-tap-highlight-color: transparent; }

/* ── DESIGN TOKENS — Light (default) ───────────────── */
:root {
  --bg:          #F5F5F7;
  --bg2:         #FFFFFF;
  --bg3:         #F2F2F7;
  --border:      rgba(0,0,0,0.10);
  --text:        #1D1D1F;
  --text-dim:    #6E6E73;
  --accent:      #007AFF;
  --success:     #34C759;
  --danger:      #FF3B30;
  --warning:     #FF9F0A;

  --sidebar-w:   220px;
  --header-h:    44px;
  --tabs-h:      56px;
  --radius:      12px;
  --radius-sm:   8px;
  --radius-pill: 16px;
}

/* ── Dark Mode ──────────────────────────────────────── */
body.dark {
  --bg:          #0F0F10;
  --bg2:         #1C1C1E;
  --bg3:         #222224;
  --border:      rgba(255,255,255,0.10);
  --text:        #F5F5F7;
  --text-dim:    rgba(235,235,245,0.76);
  --accent:      #0A84FF;
}

/* ── GLOBAL ─────────────────────────────────────────── */
html { height: 100%; height: -webkit-fill-available; }

body {
  height: 100%;
  min-height: -webkit-fill-available;
  overflow: hidden;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}

/* ── THEME TOGGLE ICONS ─────────────────────────────── */
body:not(.dark) .icon-sun { display: none; }
body.dark .icon-moon { display: none; }
body:not(.dark) .icon-moon { display: block; }
body.dark .icon-sun { display: block; }

/* ── LOGIN ──────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 44px 36px;
  max-width: 360px;
  width: 90%;
  text-align: center;
  box-shadow: 0 2px 24px rgba(0,0,0,0.06), 0 0 0 1px var(--border);
}

.login-brand {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.login-mascot {
  width: 116px;
  height: 116px;
  object-fit: contain;
  animation: mascot-drop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes mascot-drop {
  from { opacity: 0; transform: translateY(-16px) scale(0.85); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-align: center;
  margin-bottom: 4px;
}

.login-sub {
  color: var(--text-dim);
  margin-bottom: 28px;
  font-size: 0.875rem;
}

.login-card input {
  display: block;
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  margin-bottom: 10px;
  outline: none;
  transition: border-color 0.15s;
}

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

.login-card button {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 2px;
}

.login-card button:hover { opacity: 0.88; }

.error-msg {
  color: var(--danger);
  margin-top: 10px;
  font-size: 0.84rem;
}

/* ── APP SHELL ──────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--bg);
}

/* ── MOBILE HEADER (hidden on desktop) ─────────────── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
}

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

.app-title {
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

/* Status dot */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot.online     { background: var(--success); box-shadow: 0 0 0 2px rgba(52,199,89,0.25); }
.status-dot.offline    { background: var(--danger); }
.status-dot.connecting { background: var(--warning); animation: pulse 1s ease-in-out infinite; }

/* ── SEARCH BAR ─────────────────────────────────────── */
#search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}

#search-input:focus { border-color: var(--accent); }

/* ── MAIN LAYOUT ────────────────────────────────────── */
#layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

/* ── SIDEBAR ────────────────────────────────────────── */
#files-sidebar {
  width: var(--sidebar-w);
  min-width: 160px;
  max-width: 480px;
  background: var(--bg3);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.22s ease, opacity 0.22s ease;
  position: relative;
}

#files-sidebar.collapsed {
  width: 0 !important;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
  border-right: none;
}

/* Resize handle */
#sidebar-resize-handle {
  position: absolute;
  top: 0; right: -4px; bottom: 0;
  width: 8px;
  cursor: col-resize;
  z-index: 10;
}
#sidebar-resize-handle:hover,
#sidebar-resize-handle.dragging {
  background: var(--accent);
  opacity: 0.3;
}
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  overscroll-behavior: contain;
}

/* Botón expand (visible solo cuando sidebar colapsado) */
.sidebar-expand-btn {
  display: none;
  position: absolute;
  top: 50%;
  left: 8px;
  transform: translateY(-50%);
  width: 24px;
  height: 48px;
  border-radius: 0 8px 8px 0;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-left: none;
  cursor: pointer;
  color: var(--text-dim);
  align-items: center;
  justify-content: center;
  z-index: 5;
  transition: background 0.12s, color 0.12s;
}
.sidebar-expand-btn:not(.hidden) { display: flex; }
.sidebar-expand-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
}

#status-dot-desktop { margin-left: 6px; }

.sidebar-search-row {
  padding: 0 10px 10px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Compact icon buttons for floating tools (terminal, QC) */
.sidebar-tool-btn {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg3);
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.sidebar-tool-btn:hover { background: var(--border); color: var(--text); }

.sidebar-action-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--border);
  color: var(--text-dim);
  font-size: 0.82rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.sidebar-action-btn:hover {
  background: var(--border);
  color: var(--text);
}

.sidebar-section-label {
  padding: 4px 16px 6px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── SELECTION TOOLBAR ───────────────────────────────── */
.selection-toolbar {
  position: fixed;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18), 0 2px 6px rgba(0,0,0,0.1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: toolbar-pop 0.12s cubic-bezier(0.34,1.56,0.64,1);
  pointer-events: all;
}
.selection-toolbar.hidden { display: none; }

@keyframes toolbar-pop {
  from { opacity: 0; transform: scale(0.88) translateY(4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.selection-toolbar button {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 7px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s;
}
.selection-toolbar button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.selection-toolbar button + button {
  border-left: 1px solid var(--border);
  border-radius: 0;
  padding-left: 9px;
}
.selection-toolbar button:last-child {
  border-radius: 0 7px 7px 0;
}
.selection-toolbar button:first-child {
  border-radius: 7px 0 0 7px;
}

/* ── CHAT HEADER ─────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
  min-height: 36px;
}
.chat-ws-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}
.chat-ws-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}
.chat-header-spacer { flex: 1; }
.chat-header-action {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-dim);
  transition: background 0.12s, color 0.12s;
}
.chat-header-action:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ── MSG TIMESTAMP (hover) ────────────────────────────── */
.msg-time {
  font-size: 0.68rem;
  color: var(--text-dim);
  opacity: 0;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.msg-row:hover .msg-time { opacity: 1; }

/* ── NOTES PANEL ─────────────────────────────────────── */
.notes-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px 8px 6px;
}
.note-item {
  border-radius: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  transition: background 0.12s;
}
.note-item:hover { background: var(--bg3, var(--bg2)); }
.note-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}
.note-item-badge {
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.badge-note { background: #e8f4fd; color: #2980b9; }
.badge-action { background: #fef9e7; color: #b7860a; }
.dark .badge-note { background: rgba(52,152,219,0.18); color: #5dade2; }
.dark .badge-action { background: rgba(212,160,23,0.12); color: #f0c040; }
.note-item-time { font-size: 0.65rem; color: var(--text-dim); }
.note-item-title {
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.4;
}
.note-item-title:hover { color: var(--accent); }
.note-item-editor {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.note-edit-title {
  width: 100%;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.82rem;
  box-sizing: border-box;
}
.note-edit-content {
  width: 100%;
  min-height: 64px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
  resize: vertical;
  box-sizing: border-box;
  font-family: inherit;
}
.note-edit-actions { display: flex; gap: 6px; justify-content: flex-end; }
.note-save-btn {
  padding: 4px 12px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
}
.note-cancel-btn {
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bg2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.78rem;
}

/* ── DIR PICKER ──────────────────────────────────────── */
.ws-path-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.ws-path-row input { flex: 1; }
.ws-browse-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
.ws-browse-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.dir-picker {
  position: relative;
  z-index: 200;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 220px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  margin-top: 4px;
}
.dir-picker-breadcrumb {
  padding: 7px 10px;
  font-size: 0.7rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow-x: auto;
  flex-shrink: 0;
}
.dir-crumb { cursor: pointer; color: var(--accent); }
.dir-crumb:hover { text-decoration: underline; }
.dir-sep { margin: 0 2px; opacity: 0.35; }
.dir-picker-list { overflow-y: auto; flex: 1; padding: 4px; }
.dir-picker-item {
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.83rem;
  color: var(--text);
  user-select: none;
}
.dir-picker-item:hover { background: var(--accent-soft); }
.dir-picker-select {
  display: block;
  width: 100%;
  padding: 6px 10px;
  margin-bottom: 4px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: left;
}
.dir-picker-select:hover { background: var(--accent); color: #fff; }
.dir-picker-loading, .dir-picker-empty {
  padding: 12px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.dir-picker-error {
  padding: 8px 12px;
  color: #e74c3c;
  font-size: 0.78rem;
}

/* ── SIDEBAR PANELS ─────────────────────────────────── */
.sidebar-panel {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.sidebar-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 4px;
}

.panel-toggle {
  cursor: pointer;
  user-select: none;
}
.panel-toggle:hover .sidebar-panel-title {
  color: var(--text);
}

.panel-chevron {
  transition: transform 0.18s ease;
  flex-shrink: 0;
  opacity: 0.6;
}
.sidebar-panel.collapsed .panel-chevron {
  transform: rotate(-90deg);
}

.panel-body {
  overflow: hidden;
  transition: max-height 0.22s ease, opacity 0.18s ease;
  max-height: 800px;
  opacity: 1;
  padding-bottom: 6px;
}
.sidebar-panel.collapsed .panel-body {
  max-height: 0;
  opacity: 0;
  padding-bottom: 0;
}

.sidebar-panel-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar-panel-action {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.sidebar-panel-action:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

/* ── WORKSPACE MODAL ────────────────────────────────── */
.ws-modal-content {
  width: 420px;
}

.ws-modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 18px;
}

.ws-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.ws-field input[type="text"] {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s;
}
.ws-field input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.ws-field-hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-weight: 400;
}

.ws-color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ws-color-row input[type="color"] {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  cursor: pointer;
  background: none;
}

.ws-color-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.ws-color-preset {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}
.ws-color-preset:hover { transform: scale(1.2); border-color: var(--text-primary); }

.ws-modal-error {
  font-size: 0.82rem;
  color: #FF3B30;
  padding: 8px 10px;
  background: rgba(255,59,48,0.08);
  border-radius: 8px;
  margin: 0;
}

.ws-modal-submit {
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.ws-modal-submit:hover { opacity: 0.88; }
.ws-modal-submit:disabled { opacity: 0.5; cursor: default; }

/* ── WORKSPACE LIST ─────────────────────────────────── */
.workspace-list {
  display: flex;
  flex-direction: column;
  padding: 0 8px 4px;
  gap: 1px;
}

.workspace-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.84rem;
  color: var(--text-secondary);
  transition: background 0.12s, color 0.12s;
  position: relative;
  user-select: none;
}
.workspace-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.workspace-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

.ws-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ws-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Botón cerrar sesión — visible solo en hover del item */
.ws-close-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 0.72rem;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.1s, color 0.1s;
}
.workspace-item:hover .ws-close-btn { display: flex; align-items: center; }
.ws-close-btn:hover { background: var(--danger); color: #fff; }

/* Indicador de actividad en workspace no activo */
.ws-busy-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: ws-pulse 1s ease-in-out infinite alternate;
  flex-shrink: 0;
}
@keyframes ws-pulse { from { opacity: 0.4; } to { opacity: 1; } }

.ws-add-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  font-size: 0.78rem;
  cursor: pointer;
  width: 100%;
  margin-top: 2px;
  transition: border-color 0.15s, color 0.15s;
}
.ws-add-btn:hover { border-color: var(--accent); color: var(--accent); }

.ws-badge {
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  margin-left: auto;
}

.ws-name-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.ws-preview {
  font-size: 0.7rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-style: italic;
  font-weight: 400;
}

.workspace-item.archived { opacity: 0.65; }
.workspace-item.archived:hover { opacity: 1; }
.workspace-item.archived.active { opacity: 1; }

.ws-archive-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 0.72rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  margin-top: 4px;
}
.ws-archive-toggle:hover { color: var(--text-secondary); }
.ws-archive-toggle svg { transition: transform 0.15s; }
.ws-archive-toggle.open svg { transform: rotate(90deg); }

.ws-archive-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* Banner modo lectura */
.readonly-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* ── FOLDER TABS ────────────────────────────────────── */
.folder-tabs {
  display: flex;
  flex-direction: column;
  padding: 0 8px;
  gap: 1px;
}

.folder-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 0.84rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}

.folder-tab:hover {
  background: rgba(0,0,0,0.04);
  color: var(--text);
}

body.dark .folder-tab:hover {
  background: rgba(255,255,255,0.06);
}

.folder-tab.active {
  background: var(--bg2);
  color: var(--text);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

/* ── FILES LIST ─────────────────────────────────────── */
.files-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  margin-top: 8px;
}

.files-list::-webkit-scrollbar { width: 4px; }
.files-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.file-item {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
  margin-bottom: 1px;
}

.file-item:hover { background: var(--bg2); }

.file-item-name {
  font-size: 0.82rem;
  font-weight: 500;
  word-break: break-all;
  color: var(--text);
}

.file-item-meta {
  font-size: 0.73rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.file-item-actions {
  display: none;
  gap: 4px;
  margin-top: 6px;
}

.file-item:hover .file-item-actions { display: flex; }

.file-item-actions button {
  font-size: 0.73rem;
  padding: 2px 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg2);
  cursor: pointer;
  color: var(--text-dim);
  font-family: inherit;
  transition: background 0.12s, color 0.12s;
}

.file-item-actions button:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.dir-item .file-item-name { color: var(--text); }

/* ── SIDEBAR FOOTER ─────────────────────────────────── */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.sidebar-icon-btn:hover {
  background: var(--border);
  color: var(--text);
}

/* ── CHAT MAIN ──────────────────────────────────────── */
#chat-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg2);
}

#chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 16px 20px;
  display: block;
}

#chat::-webkit-scrollbar { width: 4px; }
#chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── MESSAGE BUBBLES ────────────────────────────────── */
.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  margin-bottom: 6px;
}

.msg-row.user     { align-items: flex-end; }
.msg-row.assistant { align-items: flex-start; }

.bubble {
  line-height: 1.55;
  font-size: 0.925rem;
  word-break: break-word;
  position: relative;
}

/* User bubble: right-aligned, subtle bg */
.bubble.user {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 18px 18px 5px 18px;
  background: var(--bg3);
  color: var(--text);
}

body.dark .bubble.user {
  background: var(--accent);
  color: #fff;
}

/* Assistant bubble: left-aligned, NO background */
.bubble.assistant {
  max-width: 80%;
  padding: 4px 0;
  background: none;
  color: var(--text);
}

.bubble-meta {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 3px;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 0 2px;
}

.channel-badge {
  font-size: 0.67rem;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--border);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.bubble-actions {
  display: none;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.msg-row.actions-open .bubble-actions { display: flex; }

.bubble-actions button {
  font-size: 0.73rem;
  padding: 3px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, color 0.12s;
}

.bubble-actions button:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.act-nova-note:hover  { background: var(--success) !important; border-color: var(--success) !important; }
.act-nova-action:hover { background: var(--warning) !important; border-color: var(--warning) !important; }

/* Markdown inside bubbles */
.bubble p { margin-bottom: 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 6px 0 6px 20px; }
.bubble li { margin-bottom: 3px; }
.bubble strong { font-weight: 600; }
.bubble em { font-style: italic; }
.bubble a { color: var(--accent); text-decoration: underline; }
.bubble h1, .bubble h2, .bubble h3 { margin: 14px 0 6px; font-weight: 600; }
.bubble table { border-collapse: collapse; font-size: 0.85rem; margin: 8px 0; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 5px 10px; }
.bubble th { background: var(--bg3); }

.bubble pre {
  background: #1a1a2e;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 8px 0;
  position: relative;
}

.bubble code {
  font-family: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  font-size: 0.82rem;
}

.bubble p code {
  background: var(--bg3);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.83rem;
  border: 1px solid var(--border);
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 10px;
  font-size: 0.72rem;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  font-family: inherit;
}

.bubble pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: rgba(255,255,255,0.18) !important; }

.continue-btn {
  align-self: flex-start;
  margin: 4px 0 8px 0;
  padding: 4px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
}

.continue-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── EMPTY STATE ────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px 20px;
  text-align: center;
  min-height: 60vh;
}

.empty-mascot {
  width: 120px;
  height: 120px;
  object-fit: contain;
  margin-bottom: 20px;
  animation: mascot-drop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.empty-title {
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.empty-sub {
  font-size: 0.875rem;
  color: var(--text-dim);
}

/* ── TYPING INDICATOR (inside #chat scroll area) ────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0 10px;
  color: var(--text-dim);
  font-size: 0.85rem;
  align-self: flex-start;
}

.typing-mascot {
  width: 48px;
  height: 48px;
  object-fit: contain;
  animation: mascot-think 0.7s ease-in-out infinite alternate;
}

@keyframes mascot-think {
  from { transform: translateY(0) scale(1); }
  to   { transform: translateY(-6px) scale(1.05); }
}

.typing-label {
  font-size: 0.82rem;
  color: var(--text-dim);
  font-style: italic;
}

.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-dots span {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── INPUT BAR ──────────────────────────────────────── */
#input-bar {
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg2);
  flex-shrink: 0;
}

.input-pill {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  border: 1px solid var(--border);
  background: var(--bg3);
  border-radius: var(--radius-pill);
  padding: 8px;
  max-width: 760px;
  margin: 0 auto;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-pill:focus-within {
  border-color: rgba(0,122,255,0.35);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.08);
}

body.dark .input-pill:focus-within {
  border-color: rgba(10,132,255,0.4);
  box-shadow: 0 0 0 3px rgba(10,132,255,0.1);
}

.input-wrap {
  flex: 1;
  position: relative;
}

#message-input {
  width: 100%;
  padding: 6px 8px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.925rem;
  font-family: inherit;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
  line-height: 1.5;
  outline: none;
}

#message-input::placeholder { color: var(--text-dim); }

.pill-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}

.pill-icon-btn:hover {
  background: var(--border);
  color: var(--text);
}

#mic-btn.recording {
  color: var(--danger);
  animation: pulse 0.8s ease-in-out infinite;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s;
}

.send-btn:hover { opacity: 0.88; }
.send-btn:active { transform: scale(0.94); }
.send-btn:disabled { background: var(--bg3); cursor: default; opacity: 1; }

/* Slash popup */
.slash-popup {
  position: absolute;
  bottom: calc(100% + 6px);
  left: -8px;
  right: -8px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

body.dark .slash-popup {
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.slash-item {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  gap: 10px;
  align-items: center;
  transition: background 0.1s;
}

.slash-item:hover,
.slash-item.selected {
  background: var(--accent);
  color: #fff;
}

.slash-item code { opacity: 0.8; font-family: 'JetBrains Mono', monospace; }

/* ── ICON BUTTONS (generic) ─────────────────────────── */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--border);
  color: var(--text);
}

/* ── MODALS ─────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  cursor: pointer;
}

.modal-content {
  position: relative;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 18px;
  max-width: 92vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  width: 680px;
}

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

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

.modal-body {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

.modal-body img { max-width: 100%; border-radius: 10px; }
.modal-body iframe { width: 100%; height: 70vh; border: none; border-radius: 10px; }
.modal-body pre { background: var(--bg3); padding: 12px; border-radius: 10px; overflow: auto; font-size: 0.82rem; }

.settings-content { max-width: 420px; width: 100%; }
.settings-body { padding: 8px 0; display: flex; flex-direction: column; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child { border-bottom: none; }
.setting-row a { color: var(--accent); text-decoration: none; }
.setting-row a:hover { text-decoration: underline; }
.setting-row code { font-family: 'JetBrains Mono', monospace; font-size: 0.78rem; color: var(--text-dim); word-break: break-all; }

/* Toggle switch */
.toggle { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--border); border-radius: 22px; cursor: pointer; transition: background 0.2s; }
.slider::before { content: ''; position: absolute; height: 16px; width: 16px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: transform 0.2s; }
.toggle input:checked + .slider { background: var(--success); }
.toggle input:checked + .slider::before { transform: translateX(18px); }

/* ── TOAST ──────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 18px;
  font-size: 0.85rem;
  color: var(--text);
  animation: toastIn 0.2s ease;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  white-space: nowrap;
}

body.dark .toast { box-shadow: 0 4px 16px rgba(0,0,0,0.5); }
.toast-error   { border-color: var(--danger); color: var(--danger); }
.toast-success { border-color: var(--success); color: var(--success); }

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

/* ── MOBILE BOTTOM TABS ─────────────────────────────── */
#mobile-tabs {
  display: none;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom, 0px));
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.mobile-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.65rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s;
  padding: 0 2px;
}

.mobile-tab.active { color: var(--accent); }
.mobile-tab svg { flex-shrink: 0; }
.mobile-ws-info {
  display: flex;
  align-items: center;
  gap: 7px;
}
.mobile-ws-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #007AFF;
  flex-shrink: 0;
}
.mobile-ws-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.expand-ws-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #007AFF;
  flex-shrink: 0;
  margin-bottom: 3px;
}

/* ── MISC ───────────────────────────────────────────── */
.hidden { display: none !important; }
.loading-msg { color: var(--text-dim); font-size: 0.85rem; text-align: center; padding: 16px; }
.drag-over { outline: 2px dashed var(--accent) !important; outline-offset: -2px; background: rgba(0,122,255,0.03) !important; }

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

/* Drop zone */
#chat-main.drop-active { outline: 2px dashed var(--accent); outline-offset: -4px; }

/* ── DESKTOP LAYOUT (≥768px) ────────────────────────── */
@media (min-width: 768px) {
  /* Hide mobile-only elements */
  #header { display: none; }
  #mobile-tabs { display: none !important; }

  /* Show sidebar always */
  #files-sidebar {
    display: flex !important;
    transform: none !important;
  }

  #sidebar-close { display: none; }

  #chat { padding: 20px 28px; }
  .bubble.user { max-width: 60%; }
  .bubble.assistant { max-width: 75%; }

  /* Wider modal on desktop */
  .modal-content { width: 680px; }
}

/* ── MOBILE LAYOUT (<768px) ─────────────────────────── */
@media (max-width: 767px) {
  /* Prevenir zoom en inputs (iOS) */
  input, textarea, select { font-size: max(16px, 1em) !important; }

  #mobile-tabs { display: flex; }

  /* Sidebar hidden by default on mobile */
  #files-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(var(--sidebar-w), 85vw);
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,0.18);
  }

  #files-sidebar.mobile-shown { transform: translateX(0); }

  #sidebar-close { display: flex; }

  #chat-main.mobile-hidden { display: none; }

  /* Toast above bottom tabs */
  #toast-container { bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom, 0px)); }

  /* Input pill más compacto en mobile */
  .input-pill { border-radius: 20px; }

  /* Tap feedback en botones */
  button:active, .file-item:active { transform: scale(0.97); transition: transform 0.1s; }
  .mobile-tab:active { transform: scale(0.88) !important; }
  .send-btn:active  { transform: scale(0.90) !important; }

  /* Mensajes más anchos en mobile */
  .bubble.user      { max-width: 85%; }
  .bubble.assistant { max-width: 95%; }

  /* Chat padding más ajustado */
  #chat { padding: 12px 14px; }
}

/* ── TAREAS AUTÓNOMAS ─────────────────────────────────────── */
.worker-status-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 10px; margin: 5px 8px 2px;
  background: var(--surface2); border-radius: 20px;
  font-size: 0.72rem; color: var(--text-dim);
}
.worker-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
  background: #666;
}
.worker-dot.alive {
  background: #34c759;
  box-shadow: 0 0 6px #34c75966;
  animation: pulse-dot 2s ease-in-out infinite;
}
.worker-dot.dead { background: #ff3b30; }
@keyframes pulse-dot {
  0%,100% { box-shadow: 0 0 4px #34c75944; }
  50%      { box-shadow: 0 0 10px #34c75999; }
}
.tasks-list { display: flex; flex-direction: column; gap: 4px; padding: 2px 8px 8px; }
.task-item {
  padding: 8px 10px; border-radius: 8px;
  background: var(--surface2);
  border-left: 3px solid transparent;
  font-size: 0.78rem;
}
.task-pending  { border-left-color: #ff9500; }
.task-running  { border-left-color: #007aff; animation: task-pulse 1.5s ease-in-out infinite; }
.task-done     { border-left-color: #34c759; }
.task-error    { border-left-color: #ff3b30; }
.task-cancelled{ border-left-color: #8e8e93; opacity: .6; }
@keyframes task-pulse {
  0%,100% { background: var(--surface2); }
  50%      { background: color-mix(in srgb, var(--surface2) 85%, #007aff 15%); }
}
.task-item-header { display: flex; align-items: flex-start; gap: 6px; margin-bottom: 3px; }
.task-status-icon { flex-shrink: 0; }
.task-prompt-preview { color: var(--text); line-height: 1.35; }
.task-item-meta {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.68rem; color: var(--text-dim);
}
.task-when { flex: 1; }
.task-cancel-btn, .task-detail-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); font-size: 0.75rem; padding: 2px 5px;
  border-radius: 4px; transition: background 0.12s;
}
.task-cancel-btn:hover { background: rgba(255,59,48,.15); color: #ff3b30; }
.task-detail-btn:hover { background: var(--surface3); }
.task-error-msg { font-size: 0.67rem; color: #ff3b30; margin-top: 3px; }
.tasks-empty { text-align: center; padding: 14px; color: var(--text-dim); font-size: 0.78rem; }

/* Modal de nueva tarea */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.55); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal-card {
  background: var(--surface); border-radius: 14px;
  width: 100%; max-width: 440px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 0.9rem; font-weight: 600; color: var(--text); }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); font-size: 1rem; padding: 2px 6px;
  border-radius: 4px; transition: background 0.12s;
}
.modal-close:hover { background: var(--surface2); }
.modal-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--border);
}
.field-label { font-size: 0.75rem; font-weight: 600; color: var(--text-dim); display: block; }
.field-input {
  width: 100%; padding: 7px 10px; border-radius: 8px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); font-size: 0.82rem; outline: none;
  transition: border-color 0.15s;
}
.field-input:focus { border-color: var(--accent); }
.task-prompt-input {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); font-size: 0.82rem; outline: none;
  resize: vertical; font-family: inherit;
  transition: border-color 0.15s;
}
.task-prompt-input:focus { border-color: var(--accent); }
.field-hint { font-size: 0.68rem; color: var(--text-dim); }
.task-type-tabs { display: flex; gap: 4px; }
.type-tab {
  flex: 1; padding: 5px 4px; border: 1px solid var(--border);
  background: var(--surface2); border-radius: 6px;
  font-size: 0.74rem; cursor: pointer; color: var(--text-dim);
  transition: all 0.15s;
}
.type-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.type-fields { display: flex; flex-direction: column; gap: 4px; }
.type-fields.hidden { display: none; }
.timer-row { display: flex; gap: 6px; }
.timer-num { width: 70px; flex-shrink: 0; }
.timer-unit { flex: 1; }
.btn-primary {
  padding: 7px 18px; border-radius: 8px;
  background: var(--accent); color: #fff; border: none;
  font-size: 0.82rem; font-weight: 600; cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-secondary {
  padding: 7px 14px; border-radius: 8px;
  background: var(--surface2); color: var(--text-dim);
  border: 1px solid var(--border); font-size: 0.82rem;
  cursor: pointer; transition: background 0.12s;
}
.btn-secondary:hover { background: var(--surface3); }

/* ── TERMINAL FLOATING WINDOW ──────────────────────────────── */
.term-window {
  position: fixed;
  z-index: 900;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 80px rgba(0,0,0,0.7), 0 4px 20px rgba(0,0,0,0.5);
  overflow: hidden;
  min-width: 340px;
  min-height: 220px;
  /* default size/position set by JS */
}
.term-window.hidden {
  display: none;
}

/* Titlebar — drag handle */
.term-titlebar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 10px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  cursor: move;
  user-select: none;
  -webkit-user-select: none;
}

.term-shell-tabs {
  display: flex;
  gap: 4px;
}
.term-shell-tab {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: none;
  color: #666;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.12s;
}
.term-shell-tab:hover  { background: var(--bg3); color: var(--text-dim); }
.term-shell-tab.active { background: var(--bg3); border-color: var(--border); color: var(--text); }

.term-status {
  font-size: 0.68rem;
  color: var(--text-dim);
  font-family: "JetBrains Mono", monospace;
  margin-left: 4px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.term-close-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.12s, background 0.12s;
  flex-shrink: 0;
}
.term-close-btn:hover { background: var(--bg3); color: var(--danger); }

/* Terminal content */
.term-container {
  flex: 1;
  overflow: hidden;
  padding: 6px 8px 4px;
  position: relative;
}
.term-session-container { height: 100%; }
.term-container .xterm  { height: 100%; }
.term-container .xterm-viewport { overflow-y: auto !important; }

/* ── Floating chips (minimized state) ───────────────────────── */
/* Shared chip base */
.float-chip {
  position: fixed;
  right: 18px;
  z-index: 910;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px 5px 8px;
  border-radius: 8px;
  font-size: 0.72rem;
  font-family: "JetBrains Mono", monospace;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
  transition: background 0.12s, color 0.12s, transform 0.1s;
  white-space: nowrap;
  border: 1px solid var(--border);
}
.float-chip.hidden { display: none; }

/* Terminal chip — above input area */
.term-chip {
  bottom: 72px;
  background: var(--bg2);
  color: var(--text-dim);
}
.term-chip:hover { background: var(--bg3); color: var(--text); transform: translateY(-1px); }

/* QuickCapture chip — above terminal chip */
.qc-chip {
  bottom: 112px;
  background: var(--bg2);
  color: var(--text-dim);
}
.qc-chip:hover { background: var(--bg3); color: var(--text); transform: translateY(-1px); }

/* Recover previous note button */
.qc-recover-btn {
  position: absolute;
  bottom: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.72rem;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 5px;
  opacity: 0.8;
  transition: opacity 0.12s, background 0.12s;
}
.qc-recover-btn:hover { opacity: 1; background: var(--bg3); }
.qc-recover-btn.hidden { display: none; }

/* ── QuickCapture floating window ───────────────────────────── */
.qc-window {
  position: fixed;
  z-index: 895;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 16px 60px rgba(0,0,0,0.25), 0 4px 16px rgba(0,0,0,0.12);
  overflow: hidden;
  min-width: 260px;
  min-height: 140px;
}
.qc-window.hidden { display: none; }

.qc-titlebar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 8px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  cursor: move;
  user-select: none;
  -webkit-user-select: none;
}
.qc-title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--text-dim);
  flex: 1;
  pointer-events: none;
}
.qc-header-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: 4px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  font-size: 0.72rem;
  transition: background 0.1s, color 0.1s;
  flex-shrink: 0;
}
.qc-header-btn:hover { background: var(--bg2); color: var(--text); }
.qc-header-btn.danger:hover { color: var(--danger); }

.qc-body {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}
.qc-textarea {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.7;
  padding: 12px 14px;
  font-family: 'Lora', Georgia, serif;
}
.qc-textarea::placeholder {
  color: var(--text-dim);
  opacity: 0.5;
  font-style: italic;
  font-family: 'Lora', Georgia, serif;
}

/* Resize handles — 8 directions */
.trh {
  position: absolute;
  z-index: 10;
}
/* edges */
.trh-n  { top: 0;    left: 8px;  right: 8px; height: 6px; cursor: n-resize; }
.trh-s  { bottom: 0; left: 8px;  right: 8px; height: 6px; cursor: s-resize; }
.trh-w  { left: 0;   top: 8px; bottom: 8px; width: 6px;  cursor: w-resize; }
.trh-e  { right: 0;  top: 8px; bottom: 8px; width: 6px;  cursor: e-resize; }
/* corners */
.trh-nw { top: 0;    left: 0;   width: 12px; height: 12px; cursor: nw-resize; }
.trh-ne { top: 0;    right: 0;  width: 12px; height: 12px; cursor: ne-resize; }
.trh-sw { bottom: 0; left: 0;   width: 12px; height: 12px; cursor: sw-resize; }
.trh-se { bottom: 0; right: 0;  width: 12px; height: 12px; cursor: se-resize; }
