/* ================================================================
   THEME VARIABLES & RESET
   ================================================================ */
:root {
  --bg: #ffffff;
  --bg-card: #f8f9fa;
  --bg-header: #f0f1f3;
  --text: #1a1a2e;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --accent: #4361ee;
  --accent-hover: #3a56d4;
  --success: #2ec4b6;
  --error: #e63946;
  --warning: #ffc107;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Fira Mono', Menlo, Consolas, monospace;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --bg: #1a1b26;
  --bg-card: #24253a;
  --bg-header: #1e1f32;
  --text: #c0caf5;
  --text-muted: #7982a9;
  --border: #33354a;
  --accent: #7aa2f7;
  --accent-hover: #89b4fa;
  --success: #9ece6a;
  --error: #f7768e;
  --warning: #e0af68;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background 0.2s, color 0.2s;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding-top: 49px;
  padding-bottom: 31px;
}

/* ================================================================
   LAYOUT & HEADER
   ================================================================ */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
  transition: background 0.2s, border-color 0.2s;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.header-left h1 {
  flex-shrink: 0;
}

.header h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

/* ================================================================
   STUDY MANAGEMENT — dropdown, metadata bar, separators, rename
   ================================================================ */
.study-dropdown {
  position: relative;
  display: inline-block;
  min-width: 0;
  flex-shrink: 1;
  margin-right: 8px;
}

.study-dropdown-trigger {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}

#study-dropdown-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.study-dropdown-trigger:hover { border-color: var(--accent); }
.study-dropdown-trigger.open { border-color: var(--accent); background: var(--bg-card); }

.study-dropdown-trigger .dd-arrow {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.15s;
}

.study-dropdown-trigger.open .dd-arrow { transform: rotate(180deg); }

.study-dropdown-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 110;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  min-width: 300px;
  max-width: 380px;
  max-height: 420px;
  overflow-y: auto;
  animation: fadeIn 0.15s ease;
}

.study-dropdown-all {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
}

.study-dropdown-all:hover { background: var(--bg-header); }
.study-dropdown-all.selected { font-weight: 600; color: var(--accent); }

.study-dropdown-group-label {
  padding: 8px 12px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.study-dropdown-entry {
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
}

.study-dropdown-entry:hover { background: var(--bg-header); }
.study-dropdown-entry.selected { background: var(--bg-card); }

.study-dropdown-empty {
  padding: 16px 12px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

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

.study-dot.active { background: var(--success); }
.study-dot.inactive { background: transparent; border: 1px solid var(--border); }

.study-entry-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.study-entry-meta {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}

.study-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  flex-shrink: 0;
}

.study-dropdown-entry:hover .study-delete-btn { opacity: 1; }
.study-delete-btn:hover { color: var(--error); }

/* Confirm modal */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.12s ease;
}
.confirm-dialog {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  padding: 20px 24px;
  min-width: 320px;
  max-width: 400px;
  font-family: var(--font);
}
.confirm-dialog h3 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.confirm-dialog p {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}
.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.confirm-actions button {
  padding: 6px 14px;
  border-radius: 5px;
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  border: 1px solid var(--border);
  transition: background 0.15s, border-color 0.15s;
}
.confirm-cancel {
  background: var(--bg);
  color: var(--text);
}
.confirm-cancel:hover { background: var(--bg-header); }
.confirm-danger {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}
.confirm-danger:hover { opacity: 0.85; }

/* Inline card title editing */
.card-title {
  cursor: text;
}
.card-title:hover {
  text-decoration: underline;
  text-decoration-style: dashed;
  text-underline-offset: 3px;
  text-decoration-color: var(--text-muted);
}
.card-title-edit-wrap {
  display: inline-flex;
  align-items: center;
}
.card-title-edit-input {
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  padding: 1px 4px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  min-width: 120px;
}

/* Inline study name editing (metadata bar) */
.study-meta-label {
  cursor: text;
}
.study-meta-label:hover {
  text-decoration: underline;
  text-decoration-style: dashed;
  text-underline-offset: 3px;
  text-decoration-color: var(--text-muted);
}
.study-meta-edit-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  position: relative;
}
.study-meta-edit-input {
  font-size: 22px;
  font-weight: 700;
  font-family: var(--font);
  padding: 2px 6px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  min-width: 200px;
}
.study-meta-edit-input.invalid {
  border-color: var(--error);
}
.study-meta-edit-hint {
  font-size: 11px;
  color: var(--error);
  white-space: nowrap;
}

/* Study metadata bar */
.study-metadata-bar {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 24px 0;
  display: none;
  align-items: baseline;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

.study-metadata-bar.visible { display: flex; }

.study-meta-label {
  font-weight: 700;
  font-size: 22px;
  color: var(--text);
}

.study-meta-sep {
  color: var(--border);
}

/* Study separator in feed (All studies view) */
.study-separator {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 28px 0 8px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.study-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.study-separator.hidden-by-filter { display: none; }

/* ================================================================
   EXPORT DROPDOWN
   ================================================================ */
.export-dropdown {
  position: relative;
  display: inline-block;
}

.export-dropdown-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 110;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  min-width: 180px;
  animation: fadeIn 0.15s ease;
}

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

.export-dropdown-item:hover { background: var(--bg-header); }

.export-dropdown-item .export-icon {
  font-size: 13px;
  opacity: 0.6;
  width: 18px;
  text-align: center;
}

.export-dropdown-sep {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

/* Study dropdown action button (session prompt, resume) */
.study-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 3px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.study-dropdown-entry:hover .study-action-btn {
  opacity: 1;
}

.study-action-btn:hover {
  color: var(--text);
  background: var(--bg-card);
}

.header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

/* .btn has a border + larger line-height; .btn-icon does not.
   Force equal height so all navbar buttons align.
   Overridden by neo.css (32px) due to thicker borders. */
.header-actions .btn,
.header-actions .btn-icon {
  height: 28px;
  box-sizing: border-box;
}

.btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.btn:hover { background: var(--bg-header); }

.btn-icon {
  padding: 5px 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

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

/* ================================================================
   RESPONSIVE — narrow viewports
   ================================================================ */
@media (max-width: 600px) {
  .header-inner {
    padding: 0 12px;
  }

  .header-left {
    gap: 8px;
  }
}
