:root {
  --bg-primary: #0b0f17;
  --bg-secondary: #131926;
  --bg-tertiary: #1c2436;
  --border-color: #232d42;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #10b981;
  --accent-hover: #059669;
  --tag-char-bg: rgba(148, 163, 184, 0.14);
  --tag-char-text: #cbd5e1;
  --tag-opp-bg: rgba(245, 158, 11, 0.15);
  --tag-opp-text: #fbbf24;
  --danger: #f43f5e;
  --radius-sm: 6px;
  --radius-md: 8px;
  --sidebar-width: 260px;
  --sidebar-collapsed: 52px;
  --video-dock-width: 360px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 13.5px;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* ============================================================================
   Minimal Sign-In Screen
   ============================================================================ */
.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.auth-brand {
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.auth-brand span {
  color: var(--accent);
}

.auth-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: -8px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-error {
  font-size: 12px;
  line-height: 1.45;
  color: #fda4af;
  background: rgba(244, 63, 94, 0.12);
  border: 1px solid rgba(244, 63, 94, 0.35);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.auth-submit {
  width: 100%;
  padding: 8px 12px;
  margin-top: 4px;
}

/* ============================================================================
   App Shell & Minimal Top Bar
   ============================================================================ */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

header {
  height: 50px;
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  flex-shrink: 0;
  z-index: 30;
}

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

.brand {
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  white-space: nowrap;
}

.brand span {
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-ghost.active {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  color: #042f2e;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

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

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.search-bar {
  flex: 1;
  max-width: 360px;
}

.search-bar input {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  color: var(--text-primary);
  font-size: 12.5px;
  outline: none;
}

.search-bar input:focus {
  border-color: var(--text-muted);
}

/* ============================================================================
   Workspace & Collapsible Left Sidebar
   ============================================================================ */
.workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 50px 0 0 0;
  background: rgba(5, 8, 15, 0.62);
  z-index: 20;
}

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

aside.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.2s ease, transform 0.25s ease;
  flex-shrink: 0;
  z-index: 25;
}

aside.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

aside.sidebar.collapsed .hide-on-collapse {
  display: none !important;
}

.sidebar-section {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border-color);
}

aside.sidebar.collapsed .sidebar-section {
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tiny-link {
  color: var(--text-secondary);
  background: none;
  border: none;
  font-size: 11px;
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 4px;
}

.tiny-link:hover {
  color: var(--accent);
  background: var(--bg-tertiary);
}

.opp-row {
  display: flex;
  gap: 4px;
  align-items: center;
}

select.sidebar-select {
  flex: 1;
  width: 100%;
  min-width: 0;
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 500;
  outline: none;
  cursor: pointer;
}

select.sidebar-select:focus {
  border-color: var(--accent);
}

.icon-action {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 4px;
  font-size: 11.5px;
  line-height: 1;
}

.icon-action:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.icon-action.del:hover {
  color: var(--danger);
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0.45;
  transition: opacity 0.15s;
}

.match-item:hover .item-actions,
.cat-header:hover .item-actions,
.subcat-item:hover .item-actions {
  opacity: 1;
}

.match-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
}

.sidebar-empty-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  padding: 6px 8px;
}

.match-item {
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.match-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.match-item.active {
  background: var(--bg-tertiary);
  color: var(--accent);
  font-weight: 500;
}

.match-item-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* Categories Tree */
.cat-group {
  margin-bottom: 4px;
}

.cat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
}

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

.cat-header.active {
  color: var(--accent);
  background: rgba(16, 185, 129, 0.08);
}

.cat-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.cat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.cat-header.active .cat-dot {
  background: var(--accent);
}

.subcat-list {
  padding-left: 16px;
  margin-top: 2px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.subcat-item {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
}

.subcat-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.subcat-item.active {
  color: var(--accent);
  font-weight: 500;
  background: rgba(16, 185, 129, 0.08);
}

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

.subcat-add {
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 8px;
  cursor: pointer;
}

.subcat-add:hover {
  color: var(--accent);
}

/* ============================================================================
   Main Notes-First Dashboard
   ============================================================================ */
main.notes-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px 24px;
  gap: 16px;
  min-width: 0;
}

.context-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.context-title h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.context-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.filter-pills {
  display: flex;
  gap: 6px;
}

.pill {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 11.5px;
  cursor: pointer;
  transition: all 0.15s;
}

.pill:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.pill.active {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
  font-weight: 600;
}

/* Quick Note Form */
.quick-note-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
}

.quick-note-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.quick-note-header h3 {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 12px;
  margin-bottom: 10px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 9px;
  color: var(--text-primary);
  font-size: 12.5px;
  outline: none;
}

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

.form-group textarea {
  resize: vertical;
  min-height: 58px;
  line-height: 1.45;
}

.form-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

/* Notes Grid */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
  padding-bottom: 24px;
}

.notes-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
}

.note-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.note-card:hover {
  border-color: #334155;
}

.note-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.note-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.timestamp-btn {
  background: var(--bg-tertiary);
  color: var(--accent);
  border: none;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.timestamp-btn:hover {
  background: rgba(16, 185, 129, 0.2);
}

.timestamp-btn.no-video {
  color: var(--text-muted);
  cursor: default;
}

.cat-label {
  font-size: 11.5px;
  color: var(--text-secondary);
  font-weight: 500;
}

.tag-badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}

.tag-Characterization {
  background: var(--tag-char-bg);
  color: var(--tag-char-text);
}

.tag-Opportunity {
  background: var(--tag-opp-bg);
  color: var(--tag-opp-text);
}

.quartet-line {
  font-size: 11.5px;
  color: var(--text-secondary);
  background: var(--bg-primary);
  padding: 5px 8px;
  border-radius: 4px;
  border-left: 2px solid var(--accent);
}

.note-body {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-primary);
  white-space: pre-line;
}

.note-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 8px;
  border-top: 1px solid rgba(35, 45, 66, 0.7);
  margin-top: auto;
  font-size: 11px;
  color: var(--text-muted);
  gap: 8px;
}

/* ============================================================================
   Right Collapsible Video Dock
   ============================================================================ */
aside.video-dock {
  width: var(--video-dock-width);
  background-color: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 12px;
  overflow-y: auto;
  flex-shrink: 0;
}

aside.video-dock.hidden {
  display: none;
}

.dock-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dock-header h2 {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.video-frame-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #05070b;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-frame-wrap iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.video-placeholder {
  text-align: center;
  padding: 16px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.yt-url-row {
  display: flex;
  gap: 6px;
}

.yt-url-row input {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
}

/* ============================================================================
   Modal, Loading Overlay & Toast
   ============================================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.78);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal h3 {
  font-size: 14.5px;
  font-weight: 600;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 23, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 60;
  color: var(--text-secondary);
  font-size: 12.5px;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 12px;
  z-index: 70;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  max-width: 320px;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.toast-error {
  border-left-color: var(--danger);
  color: #fda4af;
}

/* ============================================================================
   Mobile & Tablet Responsiveness
   ============================================================================ */
@media (max-width: 1024px) {
  :root {
    --video-dock-width: 300px;
  }
  .notes-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  body,
  .app-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-y: auto;
  }

  header {
    padding: 0 10px;
    gap: 6px;
    position: sticky;
    top: 0;
  }

  .header-left,
  .header-right {
    gap: 4px;
  }

  .btn-ghost {
    padding: 4px 7px;
    font-size: 11.5px;
  }

  .workspace {
    flex-direction: column;
    overflow: visible;
  }

  aside.sidebar {
    position: fixed;
    top: 50px;
    bottom: 0;
    left: 0;
    width: 270px;
    transform: translateX(-100%);
    box-shadow: 12px 0 32px rgba(0, 0, 0, 0.6);
  }

  aside.sidebar.mobile-open {
    transform: translateX(0);
  }

  aside.sidebar.collapsed {
    width: 270px;
  }

  aside.sidebar.collapsed .hide-on-collapse {
    display: block !important;
  }

  aside.video-dock {
    width: 100%;
    border-left: none;
    border-bottom: 1px solid var(--border-color);
    order: -1;
  }

  main.notes-area {
    overflow: visible;
    padding: 14px;
  }

  .search-bar {
    display: none;
  }

  .item-actions {
    opacity: 0.85;
  }
}
