:root {
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --not-started-bg: #f1f5f9;
  --not-started-fg: #64748b;
  --not-started-border: #94a3b8;
  --in-progress-bg: #eff6ff;
  --in-progress-fg: #3b82f6;
  --in-progress-border: #3b82f6;
  --done-bg: #f0fdf4;
  --done-fg: #16a34a;
  --done-border: #22c55e;
  --danger: #ef4444;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 8px -2px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 20px 40px -8px rgba(0,0,0,0.15), 0 8px 16px -4px rgba(0,0,0,0.08);
  --radius: 10px;
  --radius-sm: 6px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

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

html { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

/* ── Header ── */
header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary);
  flex-shrink: 0;
}

header h1 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.header-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  flex: 1;
  max-width: 400px;
  color: var(--text-muted);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.header-search:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
  color: var(--text-secondary);
}
.header-search input {
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  width: 100%;
}
.header-search input::placeholder { color: var(--text-muted); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  transition: background 0.12s, box-shadow 0.12s, transform 0.08s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 3px rgba(59,130,246,0.3); }
.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text-primary); }

.btn-sm { padding: 5px 11px; font-size: 12px; }

.btn-icon {
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  line-height: 0;
  transition: background 0.12s, color 0.12s;
}
.btn-icon:hover { background: var(--bg); color: var(--text-primary); }
.btn-icon.danger:hover { background: #fef2f2; color: var(--danger); }

/* ── Main ── */
main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 36px 24px 0;
}

/* ── View scroll layout ── */
#tasks-view, #notes-view, #note-editor-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#tasks-view { padding-bottom: 32px; }
#active-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#active-section .section-header { flex-shrink: 0; }
#active-section .tasks-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding-bottom: 32px;
}
#archive-section { flex-shrink: 0; }
.archive-body { max-height: 40vh; overflow-y: auto; }

/* ── Section ── */
.section { margin-bottom: 48px; }

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}
.section-header h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.badge {
  background: var(--border);
  color: var(--text-secondary);
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 8px;
  min-width: 24px;
  text-align: center;
}

/* ── Filter pills ── */
.filter-pills { display: flex; gap: 6px; margin-left: auto; }

.pill {
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 12px;
  background: var(--card-bg);
  font-family: var(--font);
  transition: all 0.12s;
}
.pill:hover { border-color: var(--primary); color: var(--primary); }
.pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── Search state ── */
.search-notice {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
  padding: 0 2px;
}
.search-notice strong { color: var(--text-secondary); }

/* ── Tasks list ── */
.tasks-list { display: flex; flex-direction: column; gap: 10px; }

/* ── Task card ── */
.task-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--not-started-border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.18s, transform 0.15s;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.task-card .task-description {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.5;
}
.task-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.task-card[data-status="in_progress"] { border-left-color: var(--in-progress-border); }
.task-card[data-status="done"] { border-left-color: var(--done-border); opacity: 0.72; background: #fafffe; }

.task-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.task-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  word-break: break-word;
}
.task-card[data-status="done"] .task-name {
  text-decoration: line-through;
  color: var(--text-secondary);
}

.task-card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.task-card:hover .task-card-actions { opacity: 1; }

/* ── Task description (card view) ── */
.task-description {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  max-height: 68px;
  overflow: hidden;
  position: relative;
  -webkit-mask-image: linear-gradient(to bottom, black 55%, transparent 100%);
  mask-image: linear-gradient(to bottom, black 55%, transparent 100%);
}

/* Rendered markdown styles */
.task-description p,
.md-preview p    { margin: 0 0 6px; line-height: 1.55; }
.task-description p:last-child,
.md-preview p:last-child { margin-bottom: 0; }
.task-description h1, .task-description h2, .task-description h3,
.md-preview h1,       .md-preview h2,       .md-preview h3 {
  font-size: 14px; font-weight: 700; margin: 8px 0 4px; color: var(--text-primary);
}
.task-description ul, .task-description ol,
.md-preview ul,       .md-preview ol {
  padding-left: 20px; margin: 4px 0;
}
.task-description ul, .md-preview ul { list-style: disc; }
.task-description ol, .md-preview ol { list-style: decimal; }
.task-description li, .md-preview li { margin-bottom: 4px; }
.task-description code, .md-preview code {
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 11px;
  padding: 1px 5px;
}
.task-description hr, .md-preview hr {
  border: none; border-top: 1px solid var(--border); margin: 8px 0;
}
.task-description a, .md-preview a {
  color: var(--primary); text-decoration: underline; text-underline-offset: 2px;
}
.task-description strong, .md-preview strong { font-weight: 700; color: var(--text-primary); }
.task-description em, .md-preview em { font-style: italic; }

/* ── Task footer ── */
.task-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

/* ── Stakeholder chips (card) ── */
.sh-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }

.sh-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  padding: 2px 9px 2px 3px;
  background: #f8fafc;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.sh-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

/* ── Status badge ── */
.status-badge {
  border-radius: 20px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 3px 11px;
  text-transform: uppercase;
  border: 1px solid transparent;
  font-family: var(--font);
  transition: opacity 0.12s, transform 0.08s;
  flex-shrink: 0;
}
.status-badge:hover { opacity: 0.78; transform: scale(0.97); }
.status-badge:disabled { cursor: default; }
.status-badge:disabled:hover { opacity: 1; transform: none; }

.status-badge[data-status="not_started"] { background: var(--not-started-bg); color: var(--not-started-fg); border-color: #cbd5e1; }
.status-badge[data-status="in_progress"] { background: var(--in-progress-bg); color: var(--in-progress-fg); border-color: #bfdbfe; }
.status-badge[data-status="done"]        { background: var(--done-bg);        color: var(--done-fg);        border-color: #bbf7d0; }

/* ── Priority pills (modal) ── */
.priority-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.priority-pill {
  padding: 5px 14px; border-radius: 20px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  border: 1.5px solid var(--border);
  background: transparent; color: var(--text-secondary);
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.priority-pill:hover { border-color: var(--primary); color: var(--primary); }
.priority-pill.active[data-value=""]       { background: var(--bg-secondary); border-color: var(--border); color: var(--text-secondary); }
.priority-pill.active[data-value="low"]    { background: #dbeafe; border-color: #93c5fd; color: #1d4ed8; }
.priority-pill.active[data-value="medium"] { background: #fef3c7; border-color: #fcd34d; color: #92400e; }
.priority-pill.active[data-value="high"]   { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.modal.view-mode .priority-pill:not(.active) { display: none; }
.modal.view-mode .priority-pill.active { pointer-events: none; }
.modal.view-mode .priority-pill.active[data-value=""] { display: none; }

/* ── Priority badge (card) ── */
.priority-badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 700; letter-spacing: .02em;
  border: 1px solid transparent;
}
.priority-badge.priority-low    { background: #dbeafe; color: #1d4ed8; border-color: #93c5fd; }
.priority-badge.priority-medium { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.priority-badge.priority-high   { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }

/* ── Asset chips ── */
.linked-assets { display: flex; flex-wrap: wrap; gap: 6px; }

.asset-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--primary);
  font-size: 12px;
  font-weight: 500;
  max-width: 220px;
  overflow: hidden;
  padding: 3px 9px;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.asset-chip:hover { background: #eff6ff; border-color: #bfdbfe; }
.asset-chip .chip-domain { color: var(--text-muted); font-size: 10px; font-weight: 400; }

/* ── Unarchive button ── */
.btn-unarchive {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  padding: 3px 10px;
  transition: all 0.12s;
}
.btn-unarchive:hover { border-color: var(--primary); color: var(--primary); background: #eff6ff; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 52px 24px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 36px; margin-bottom: 10px; }
.empty-state p { font-size: 14px; }
.gilbert-empty { text-align: center; padding: 48px 24px 32px; }
.gilbert-empty svg { display: block; margin: 0 auto 18px; filter: drop-shadow(0 8px 24px rgba(124,58,237,.18)); }
.gilbert-msg { font-size: 18px; font-weight: 700; color: var(--text-primary); margin: 0 0 6px; }
.gilbert-sub { font-size: 13px; color: var(--text-muted); margin: 0; }

/* ── Archive section ── */
.archive-header {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 14px 0;
  border-top: 1px solid var(--border);
  user-select: none;
  color: var(--text-secondary);
}
.archive-header:hover h2 { color: var(--text-primary); }
.archive-header h2 {
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.archive-toggle-icon { font-size: 14px; margin-left: auto; transition: transform 0.2s; display: inline-block; }
.archive-toggle-icon.open { transform: rotate(180deg); }

.archive-body { display: none; padding-top: 14px; }
.archive-body.open { display: block; }

/* ── Modal ── */
.modal-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.45);
  inset: 0;
  padding: 24px;
  position: fixed;
  z-index: 100;
  backdrop-filter: blur(3px);
  animation: fadeIn 0.15s ease;
}
.modal-overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--card-bg);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  max-height: 96vh;
  overflow-y: auto;
  padding: 28px 36px;
  width: 100%;
  max-width: 1100px;
  animation: slideUp 0.18s ease;
}
.modal-header-actions { display: flex; align-items: center; gap: 8px; }
.modal.view-mode { cursor: pointer; }
.modal.view-mode .form-control,
.modal.view-mode .task-desc-editor,
.modal.view-mode select { pointer-events: none; background: transparent !important; border-color: transparent !important; box-shadow: none; resize: none; color: var(--text-primary); }
.modal.view-mode .task-desc-editor { padding: 0; min-height: unset; }
.modal.view-mode #md-toolbar,
.modal.view-mode .asap-row,
.modal.view-mode .add-row-btn,
.modal.view-mode #customer-input-wrap,
.modal.view-mode #modal-form-actions,
.modal.view-mode #link-note-input { display: none !important; }
.modal.view-mode label { color: var(--text-muted); font-size: 11px; }
.modal.view-mode #modal-close { display: none; }
.modal.view-mode .link-chip-remove { display: none; }
@keyframes slideUp {
  from { transform: translateY(14px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: -28px;
  margin: -28px -36px 26px;
  padding: 28px 36px 18px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  z-index: 2;
}
.modal-header h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }

/* Note modal */
.note-modal { display: flex; flex-direction: column; min-height: 82vh; }
.note-modal-title-field {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
/* Tags row — never compress, more breathing room */
.note-modal #note-modal-tag-field { flex-shrink: 0; margin-top: 14px; min-height: 40px; }
.note-modal #note-modal-tag-field .tag-chip { font-size: 15px; padding: 6px 8px 6px 13px; }

/* Toolbar row — never compress, wraps buttons, no visible border */
.note-modal .note-toolbar-row {
  flex-shrink: 0;
  margin-top: 14px;
  border: none;
  border-radius: 0;
  padding: 0;
  background: transparent;
}
/* Strip the inner md-toolbar's own border/bg */
.note-modal .note-toolbar-row .md-toolbar {
  border: none;
  background: transparent;
  border-radius: 0;
  padding: 0;
  flex-wrap: wrap;
  gap: 4px;
}
.note-modal .note-toolbar-row .md-btn { font-size: 15px; padding: 6px 10px; }
.note-modal .note-toolbar-row .md-btn strong,
.note-modal .note-toolbar-row .md-btn em,
.note-modal .note-toolbar-row .md-btn u { font-size: 15px; }
.md-font-select {
  font-size: 14px;
  font-family: var(--font);
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--card-bg);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
}
.md-font-select:hover { border-color: var(--text-muted); }

.note-modal-editor {
  flex: 1;
  min-height: 200px;
  border: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
  padding: 14px 16px;
  margin-top: 0;
}
.note-modal.view-mode { cursor: pointer; }
.note-modal.view-mode .note-toolbar-row { display: none !important; }
.note-modal.view-mode .note-modal-editor { border-radius: 10px; margin-top: 12px; }
.note-modal.view-mode #note-modal-tag-wrap { display: none !important; }
.note-modal.view-mode #note-modal-tag-field { border-color: transparent; background: transparent; padding-left: 0; }
.note-modal.view-mode #note-modal-tag-field .tag-chip-remove { display: none; }
.note-modal.view-mode .note-modal-editor { pointer-events: none; }
.note-modal-editor ul, .note-modal-editor ol { padding-left: 1.5em; margin: 0.3em 0; }
.note-modal-editor ul { list-style: disc; }
.note-modal-editor ol { list-style: decimal; }
.note-modal-editor li { margin: 0.1em 0; }
.note-modal.view-mode #note-modal-close,
.note-modal.view-mode #note-modal-delete-btn { display: none !important; }
.note-modal.view-mode #note-modal-form-actions { display: none !important; }
.note-modal.view-mode .note-modal-title-field { pointer-events: none; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 26px;
  line-height: 1;
  padding: 0 4px;
  transition: color 0.12s;
}
.modal-close:hover { color: var(--text-primary); }

/* ── Form ── */
.form-group { margin-bottom: 22px; }

.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.required { color: var(--danger); }

.form-control {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 12px;
  width: 100%;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.form-control:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
.form-control.error { border-color: var(--danger); }

textarea.form-control { min-height: 110px; resize: vertical; line-height: 1.6; font-size: 13px; }

/* ── Task description WYSIWYG editor ── */
.task-desc-editor {
  width: 100%;
  min-height: 120px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  padding: 10px 12px;
  color: var(--text-primary);
  outline: none;
  cursor: text;
  word-break: break-word;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.task-desc-editor:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
.task-desc-editor p { margin: 0 0 0.5em; }
.task-desc-editor p:last-child { margin-bottom: 0; }
.task-desc-editor strong, .task-desc-editor b { font-weight: 700; }
.task-desc-editor em, .task-desc-editor i { font-style: italic; }
.task-desc-editor s, .task-desc-editor del { text-decoration: line-through; opacity: 0.6; }
.task-desc-editor h2 { font-size: 15px; font-weight: 700; margin: 6px 0 4px; }
.task-desc-editor ul, .task-desc-editor ol { padding-left: 1.5em; margin: 0.3em 0; }
.task-desc-editor ul { list-style: disc; }
.task-desc-editor ol { list-style: decimal; }
.task-desc-editor li { margin: 0.1em 0; }
.task-desc-editor code {
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 0.87em;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}
.task-desc-editor .note-checklist { list-style: none; padding-left: 0; }
.task-desc-editor .note-cl-item {
  display: flex; align-items: flex-start; gap: 7px; margin-bottom: 3px;
}
.task-desc-editor .note-cl-item input[type="checkbox"] {
  flex-shrink: 0; margin-top: 3px; accent-color: var(--primary);
  width: 14px; height: 14px; cursor: pointer;
}
.task-desc-editor pre { background: #1e293b; color: #e2e8f0; border-radius: 6px; padding: 10px 14px; margin: 6px 0; overflow-x: auto; font-size: 12.5px; }
.task-desc-editor pre code { background: none; border: none; color: inherit; padding: 0; font-size: inherit; }
.task-desc-editor table { border-collapse: collapse; width: 100%; margin: 6px 0; font-size: 13px; }
.task-desc-editor th, .task-desc-editor td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.task-desc-editor th { background: var(--bg); font-weight: 600; }
.task-desc-editor a { color: var(--primary); text-decoration: underline; }
.note-modal-editor a { color: var(--primary); text-decoration: underline; }
.note-editor a { color: var(--primary); text-decoration: underline; }

.field-error { color: var(--danger); font-size: 12px; margin-top: 5px; display: none; }
.field-error.visible { display: block; }

/* ── Markdown toolbar ── */
.desc-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}
.desc-label-row label { margin-bottom: 0; }

.desc-tabs { display: flex; gap: 2px; }

.desc-tab {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: all 0.12s;
}
.desc-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.desc-tab:not(.active):hover { border-color: var(--primary); color: var(--primary); }

.md-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  padding: 5px 8px;
  transition: opacity 0.15s;
}

.md-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font);
  font-size: 12px;
  padding: 4px 8px;
  line-height: 1;
  transition: background 0.1s, border-color 0.1s;
  white-space: nowrap;
}
.md-btn:hover { background: var(--card-bg); border-color: var(--border); color: var(--text-primary); }
.md-btn strong { font-size: 13px; }
.md-btn em { font-style: italic; font-size: 13px; }

.md-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

.md-toolbar ~ textarea,
.md-toolbar ~ .md-preview {
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

/* ── Markdown preview (in modal) ── */
.md-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  min-height: 110px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}
.md-preview.hidden { display: none; }
.md-preview.empty { color: var(--text-muted); font-style: italic; }

/* ── Stakeholder / Asset form rows ── */
.form-row-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  padding: 12px;
  position: relative;
}

.form-row-grid {
  display: grid;
  gap: 8px;
}
.form-row-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row-grid.cols-1 { grid-template-columns: 1fr; }

.form-row-item .remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
}

.row-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
  display: block;
}

.add-row-btn { margin-top: 4px; }

/* ── Form actions ── */
.form-actions {
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 28px;
  padding-top: 22px;
}
#modal-form-actions, #note-modal-form-actions {
  position: sticky;
  bottom: -28px;
  margin: 28px -36px -28px;
  padding: 18px 36px 28px;
  background: var(--card-bg);
  z-index: 2;
}

/* ── Card clickable ── */
.task-card { cursor: pointer; }
.task-card .btn-icon,
.task-card .status-badge,
.task-card .asset-chip,
.task-card a { cursor: auto; }
.task-card .btn-icon { cursor: pointer; }

/* ── Status picker ── */
.status-picker {
  position: fixed;
  z-index: 300;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  min-width: 155px;
}
.status-picker.hidden { display: none; }

.sp-opt {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}
.sp-opt:hover { background: var(--bg); color: var(--text-primary); }
.sp-opt.current { font-weight: 600; }
.sp-opt[data-status="not_started"].current { color: var(--not-started-fg); }
.sp-opt[data-status="in_progress"].current { color: var(--in-progress-fg); }
.sp-opt[data-status="done"].current        { color: var(--done-fg); }

.sp-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sp-dot[data-status="not_started"] { background: var(--not-started-border); }
.sp-dot[data-status="in_progress"] { background: var(--in-progress-border); }
.sp-dot[data-status="done"]        { background: var(--done-border); }

.sp-check {
  margin-left: auto;
  color: var(--primary);
  font-size: 14px;
  display: none;
}
.sp-opt.current .sp-check { display: block; }

/* ── Detail panel ── */
.detail-bg {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.2);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s;
}
.detail-bg.open { opacity: 1; pointer-events: all; }

.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 480px;
  max-width: 100vw;
  height: 100vh;
  background: var(--card-bg);
  border-left: 1px solid var(--border);
  box-shadow: -6px 0 32px rgba(0,0,0,0.10);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.26s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.detail-panel.open { transform: translateX(0); }

.dp-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 12px;
}
.dp-hdr-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.dp-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 40px;
}

.dp-title {
  font-size: 21px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
  margin-bottom: 6px;
  word-break: break-word;
}
.dp-title.done { text-decoration: line-through; color: var(--text-secondary); }

.dp-dates {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.dp-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.dp-description {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 8px;
}
.dp-description p             { margin-bottom: 8px; }
.dp-description p:last-child  { margin-bottom: 0; }
.dp-description h1, .dp-description h2, .dp-description h3 {
  font-size: 14px; font-weight: 700; margin: 14px 0 5px; color: var(--text-primary);
}
.dp-description ul, .dp-description ol { padding-left: 20px; margin: 6px 0; }
.dp-description ul { list-style: disc; }
.dp-description ol { list-style: decimal; }
.dp-description li  { margin-bottom: 4px; }
.dp-description code {
  background: #f1f5f9; border: 1px solid var(--border);
  border-radius: 3px; font-family: 'SF Mono', Menlo, monospace;
  font-size: 12px; padding: 1px 5px;
}
.dp-description hr  { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.dp-description a   { color: var(--primary); text-decoration: underline; text-underline-offset: 2px; }
.dp-description strong { font-weight: 700; color: var(--text-primary); }
.dp-description em  { font-style: italic; }

.dp-section { margin-top: 20px; }
.dp-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.dp-asset-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  margin-bottom: 6px;
  text-decoration: none;
  color: var(--text-primary);
  font-size: 13px;
  transition: background 0.12s;
}
.dp-asset-row:hover { background: #eff6ff; border-color: #bfdbfe; }
.dp-asset-row .dp-asset-domain { color: var(--text-muted); font-size: 11px; margin-left: auto; }

/* ── Due date chip ── */
.due-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  flex-shrink: 0;
}
.due-chip.due-future {
  background: #f8fafc;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.due-chip.due-week {
  background: #fff7ed;
  color: #c2410c;
  border: 1px solid #fed7aa;
}
.due-chip.due-today {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fde68a;
}
.due-chip.overdue {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}
.due-chip.asap {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fbbf24;
  font-weight: 700;
}

/* ── Customer tag input (form) ── */
.tag-input-field {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  min-height: 42px;
  cursor: text;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.tag-input-field:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 4px;
  color: #0369a1;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 4px 3px 9px;
  white-space: nowrap;
}
.tag-chip-remove {
  background: none;
  border: none;
  color: #7dd3fc;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 3px;
  font-family: var(--font);
  transition: color 0.1s;
}
.tag-chip-remove:hover { color: #0369a1; }
.tag-input {
  background: none;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-primary);
  min-width: 140px;
  width: 100%;
  padding: 3px 0;
}
.tag-input::placeholder { color: var(--text-muted); }

/* Customer chips on cards / detail panel */
.customer-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}
.customer-chip {
  display: inline-flex;
  align-items: center;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 4px;
  color: #0369a1;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  letter-spacing: 0.01em;
}

/* ── Due input group (ASAP toggle + date picker) ── */
.due-input-group {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.due-input-group .form-control { flex: 1; }

.asap-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 10px 13px;
  white-space: nowrap;
  transition: all 0.12s;
  flex-shrink: 0;
}
.asap-btn:hover {
  border-color: #f59e0b;
  color: #b45309;
  background: #fffbeb;
}
.asap-btn.active {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #92400e;
  box-shadow: 0 0 0 2px rgba(251,191,36,0.25);
}

/* ── Stakeholder autocomplete ── */
.sh-autocomplete {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.sh-ac-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-secondary);
  text-align: left;
  transition: background 0.1s;
}
.sh-ac-opt:hover { background: var(--bg); color: var(--text-primary); }
.sh-ac-name { flex: 1; font-weight: 500; }
.sh-ac-email { font-size: 11px; color: var(--text-muted); }

/* Style the native date input to match the rest of the form */
input[type="date"].form-control {
  appearance: none;
  -webkit-appearance: none;
  color-scheme: light;
}
input[type="date"].form-control::-webkit-calendar-picker-indicator {
  opacity: 0.5;
  cursor: pointer;
}
input[type="date"].form-control::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}

/* Due date in detail panel */
.dp-due {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
}

/* ── Note auto-save status ── */
.note-save-status {
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 4px;
  min-width: 60px;
  text-align: right;
  transition: color 0.2s;
}
.note-save-status.saving { color: var(--text-muted); }
.note-save-status.saved  { color: #16a34a; }
.note-save-status.error  { color: var(--danger); }

/* ── Linked notes / tasks ── */
.linked-notes-chips, .linked-tasks-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.link-note-chip, .link-task-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-secondary);
  color: var(--text-primary); transition: background 0.12s;
}
.link-note-chip:hover { background: var(--accent-light, #ede9fe); border-color: var(--accent); }
.link-task-chip:hover { background: var(--accent-light, #ede9fe); border-color: var(--accent); }
.link-chip-remove { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 14px; line-height: 1; padding: 0 0 0 2px; }
.link-chip-remove:hover { color: var(--danger); }
.link-note-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow-lg); z-index: 50;
  max-height: 200px; overflow-y: auto;
}
.link-note-opt {
  padding: 8px 12px; cursor: pointer; font-size: 13px; color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}
.link-note-opt:last-child { border-bottom: none; }
.link-note-opt:hover { background: var(--bg-secondary); }
.linked-tasks-section { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 14px; }
.linked-section-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-secondary); margin-bottom: 8px; }
.note-modal.view-mode .linked-tasks-section { border-top: none; padding-top: 0; }

/* ── Utility ── */
.hidden { display: none !important; }

/* ── App nav tabs ── */
.app-nav {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 0 24px;
  position: sticky;
  top: 49px; /* header height */
  z-index: 9;
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  padding: 14px 2px;
  margin-right: 26px;
  transition: color 0.12s, border-color 0.12s;
}
.nav-tab:hover { color: var(--text-secondary); }
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ── Notes layout ── */
.notes-top-row {
  display: flex;
  align-items: stretch;
  gap: 24px;
  flex: 1;
  min-height: 0;
}
.notes-main-col {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.notes-cal-wrap {
  flex-shrink: 0;
  align-self: flex-start;
  width: 270px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 20px;
}

/* Calendar widget */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.cal-month-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: .01em;
}
.cal-month-clickable {
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 6px;
}
.cal-month-clickable:hover { background: var(--bg); color: var(--primary); }
.cal-year-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  margin-top: 6px;
}
.cal-month-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  margin-top: 6px;
}
.cal-pick-item {
  padding: 7px 4px;
  text-align: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-primary);
}
.cal-pick-item:hover { background: var(--bg); }
.cal-pick-item.current { color: var(--primary); font-weight: 700; background: rgba(99,102,241,.08); }
.cal-nav {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 15px;
  line-height: 1;
}
.cal-nav:hover { background: var(--bg); color: var(--text-primary); }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
}
.cal-dow {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  text-align: center;
  padding: 2px 0 5px;
}
.cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  border-radius: 50%;
  color: var(--text-muted);
  user-select: none;
  cursor: default;
}
.cal-day.has-note {
  color: var(--text-primary);
  font-weight: 600;
  cursor: pointer;
}
.cal-day.has-note:hover { background: var(--bg); }
.cal-day.range-start, .cal-day.range-end {
  background: var(--primary) !important;
  color: #fff !important;
  border-radius: 50%;
}
.cal-day.in-range {
  background: rgba(99, 102, 241, 0.13);
  color: var(--text-primary);
  border-radius: 0;
}
.cal-day.has-note.in-range { font-weight: 700; }
.cal-day.today { text-decoration: underline; text-underline-offset: 2px; }
.cal-clear {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 5px 8px;
  font-size: 11px;
  text-align: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1.4;
}
.cal-clear:hover { background: var(--bg); }
.cal-today-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 5px 8px;
  font-size: 11px;
  text-align: center;
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-weight: 600;
  border-radius: var(--radius-sm);
}
.cal-today-btn:hover { background: var(--bg); }

/* ── Notes list grid ── */
.notes-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding-bottom: 32px;
}

.note-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left: 4px solid #6366f1;
  border-radius: var(--radius);
  padding: 14px 18px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.18s, transform 0.15s;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow: hidden;
  flex-shrink: 0;
}
.note-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.note-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.note-card-actions { display: flex; gap: 2px; flex-shrink: 0; opacity: 0; transition: opacity 0.15s; }
.note-card:hover .note-card-actions { opacity: 1; }

.note-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-card-excerpt {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.note-card-date {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Note editor ── */
.note-editor-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.note-editor-topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 28px;
}

.note-delete-btn { color: var(--danger) !important; }
.note-delete-btn:hover { background: #fef2f2 !important; border-color: #fecaca !important; }

.note-title-input {
  display: block;
  width: 100%;
  background: none;
  border: none;
  border-bottom: 2px solid var(--border);
  border-radius: 0;
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  padding: 4px 0 10px;
  margin-bottom: 12px;
  outline: none;
  font-family: var(--font);
  letter-spacing: -0.02em;
  transition: border-color 0.15s;
}
.note-title-input:focus { border-bottom-color: var(--primary); }
.note-title-input::placeholder { color: var(--text-muted); font-weight: 400; }

.note-tags-field {
  margin-bottom: 0;
  border-color: transparent;
  background: transparent;
  padding: 2px 0;
  min-height: 0;
  box-shadow: none !important;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.note-tags-field:focus-within { border-color: transparent; border-bottom-color: var(--primary); }
.note-tags-field .tag-input { font-size: 12px; }
.note-tags-field .tag-input::placeholder { font-size: 12px; }

.note-toolbar-row {
  display: flex;
  align-items: center;
  margin-top: 18px;
  margin-bottom: 0;
}

.note-md-toolbar {
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  flex: 1;
}

/* ── Checklist (task markdown) ── */
.cl-list {
  list-style: none !important;
  padding-left: 2px !important;
  margin: 4px 0;
}
.cl-item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin-bottom: 4px;
  line-height: 1.5;
}
.cl-item input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 3px;
  accent-color: var(--primary);
  width: 14px;
  height: 14px;
  cursor: pointer;
}
.cl-item input[type="checkbox"]:disabled { cursor: default; opacity: 0.65; }
.cl-text { flex: 1; }
.cl-done { text-decoration: line-through; color: var(--text-muted); }

/* ── Checklist (note WYSIWYG editor) ── */
.note-editor .note-checklist {
  list-style: none;
  padding-left: 0;
  margin: 6px 0;
}
.note-editor .note-cl-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 5px;
  min-height: 1.5em;
}
.note-editor .note-cl-item input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 4px;
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* ── Note WYSIWYG editor ── */
.note-editor {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 200px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.75;
  padding: 16px 18px;
  color: var(--text-primary);
  outline: none;
  cursor: text;
  transition: border-color 0.12s, box-shadow 0.12s;
  word-break: break-word;
}
.note-editor:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.08);
}

/* Paragraph spacing */
.note-editor p { margin: 0 0 0.7em; }
.note-editor p:last-child { margin-bottom: 0; }
.note-editor div { margin: 0 0 0.2em; }
.note-editor br:only-child { display: block; }

/* Inline text formatting */
.note-editor strong, .note-editor b { font-weight: 700; }
.note-editor em, .note-editor i { font-style: italic; }
.note-editor s, .note-editor del, .note-editor strike {
  text-decoration: line-through;
  opacity: 0.6;
}

/* Lists — with proper indentation */
.note-editor ul,
.note-editor ol {
  padding-left: 1.6em;
  margin: 0.3em 0 0.7em;
}
.note-editor ul { list-style: disc; }
.note-editor ol { list-style: decimal; }
.note-editor li { margin: 0.15em 0; }

/* Inline code */
.note-editor code {
  font-family: 'SF Mono', Menlo, 'Courier New', monospace;
  font-size: 0.87em;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  color: #0f172a;
}

/* Code blocks — override inline code styles inside pre */
.note-editor pre {
  background: #1e293b;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 10px 0;
  padding: 14px 16px;
  white-space: pre;
}
.note-editor pre code {
  background: none;
  border: none;
  color: #e2e8f0;
  font-size: 13px;
  padding: 0;
}

/* Tables */
.note-table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0 14px;
  font-size: 14px;
}
.note-table th,
.note-table td {
  border: 1px solid var(--border);
  padding: 7px 12px;
  text-align: left;
  min-width: 80px;
  vertical-align: top;
}
.note-table th {
  background: #f8fafc;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

/* ── Extended markdown — highlight, strikethrough, code blocks ── */
mark {
  background: #fef08a;
  color: #713f12;
  border-radius: 2px;
  padding: 0 2px;
}
del { opacity: 0.55; text-decoration: line-through; }

pre {
  background: #1e293b;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 10px 0;
  padding: 14px 16px;
}
pre code {
  background: none !important;
  border: none !important;
  color: #e2e8f0;
  font-family: 'SF Mono', 'Menlo', 'Courier New', monospace;
  font-size: 13px;
  padding: 0 !important;
  border-radius: 0 !important;
}

/* propagate mark/del into note preview & description areas */
.note-preview mark, .dp-description mark, .task-description mark { background: #fef08a; color: #713f12; border-radius: 2px; padding: 0 2px; }
.note-preview del, .dp-description del, .task-description del { opacity: 0.55; text-decoration: line-through; }
.note-preview pre, .dp-description pre { background: #1e293b; border-radius: var(--radius-sm); overflow-x: auto; margin: 10px 0; padding: 14px 16px; }
.note-preview pre code, .dp-description pre code { background: none !important; border: none !important; color: #e2e8f0; font-size: 13px; padding: 0 !important; }

/* Highlight button label */
.hl-btn-label {
  background: #fef08a;
  color: #713f12;
  border-radius: 2px;
  padding: 0 3px;
  font-size: 11px;
  font-weight: 700;
}

/* ── Link dialog ── */
.link-dialog-overlay {
  position: fixed; inset: 0; z-index: 2100;
  display: flex; align-items: center; justify-content: center;
}
.link-dialog-overlay.hidden { display: none; }
.link-dialog {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  padding: 18px 20px;
  width: 320px;
  display: flex; flex-direction: column; gap: 12px;
}
.link-dialog-field { display: flex; flex-direction: column; gap: 4px; }
.link-dialog-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-secondary); }
.link-dialog-input { padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; background: var(--bg); color: var(--text-primary); }
.link-dialog-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(99,102,241,.15); }
.link-dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

/* Link hover tooltip */
.link-tooltip {
  position: fixed;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
  font-size: 12px;
  max-width: 380px;
  pointer-events: auto;
}
.link-tooltip.hidden { display: none; }
.link-tooltip-href {
  color: var(--primary);
  text-decoration: underline;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.link-tooltip-btn {
  flex-shrink: 0;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  font-weight: 500;
}
.link-tooltip-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Sign-in gate ─────────────────────────────────────── */
/* The gate sits outside the three-view system; `body.logged-out` hides the
   whole app shell so no stale data or control is ever visible behind it. */
#login-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
#login-gate.hidden { display: none; }

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px 32px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}
.login-mark { display: flex; justify-content: center; margin-bottom: 4px; }
.login-card h1 {
  font-size: 22px;
  font-weight: 650;
  color: var(--text-primary);
  margin: 12px 0 6px;
}
.login-sub {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin: 0 0 24px;
  line-height: 1.5;
}
.login-btn {
  width: 100%;
  justify-content: center;
  gap: 10px;
  padding: 11px 16px;
  font-size: 14.5px;
  text-decoration: none;
}
.login-error {
  margin: 18px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
}
.login-error.hidden { display: none; }

/* Hide the app shell while signed out. Direct children of body only, so the
   gate itself and the toast host stay visible. */
body.logged-out > header,
body.logged-out > nav,
body.logged-out > main,
body.logged-out > aside,
body.logged-out > .modal-overlay,
body.logged-out > .link-dialog-overlay,
body.logged-out > .detail-panel { display: none !important; }

/* ── Signed-in user chip ──────────────────────────────── */
.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 4px;
  border-left: 1px solid var(--border);
  margin-left: 4px;
}
.user-menu.hidden { display: none; }
.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg);
}
.user-email {
  font-size: 12.5px;
  color: var(--text-secondary);
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 900px) { .user-email { display: none; } }

/* ── Toasts ───────────────────────────────────────────── */
#toast-host {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--text-primary);
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  max-width: 420px;
  animation: toast-in 0.18s ease-out;
}
.toast.danger { background: #b91c1c; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Import modal ─────────────────────────────────────── */
.import-modal { max-width: 520px; }
.import-intro {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.55;
  margin: 0 0 18px;
}
.import-intro code {
  font-size: 12px;
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
}
.import-modal input[type="file"] {
  font-size: 13px;
  color: var(--text-secondary);
  width: 100%;
}
.import-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}
.import-result {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12.5px;
  line-height: 1.6;
  max-height: 260px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.import-result.hidden { display: none; }
.import-result.error { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.import-result.ok { background: #f0fdf4; border-color: var(--done-border); color: #15803d; }
