:root {
  --bg: #ffffff;
  --card: #ffffff;
  --card-gradient: linear-gradient(165deg, #ffffff 0%, #f2f3f7 65%, #e9ebf1 100%);
  --card-soft: #f6f7fa;
  --border: #eaecf1;
  --text: #1b1e27;
  --text-muted: #8a90a2;
  --text-faint: #b3b8c5;
  --purple: #5b4fe0;
  --purple-hover: #4a3fce;
  --green: #1fae63;
  --yellow-bg: #fdf1cf;
  --yellow-border: #f3dd9c;
  --gold: #f0a83c;
  --red: #e35555;
  --red-bg: #fde3e3;
  --red-text: #c23b3b;
  --orange-bg: #fdedd3;
  --orange-text: #b8791b;
  --blue-bg: #e2e9fe;
  --blue-text: #3757d6;
  --purple-bg: #ece4fd;
  --purple-text: #7c3aed;
  --green-bg: #dff5e5;
  --green-text: #1f9254;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 4px rgba(40, 45, 65, 0.05), 0 20px 40px -12px rgba(40, 45, 65, 0.18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

.page.two-col {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 28px;
  max-width: 100%;
  margin: 0 auto;
  padding: 28px 40px;
  align-items: start;
}

.left-col {
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 28px;
  max-height: calc(100vh - 56px);
  overflow-y: auto;
}

.right-col { min-width: 0; }

@media (max-width: 900px) {
  .page.two-col { grid-template-columns: 1fr; padding: 16px; }
  .left-col { position: static; max-height: none; overflow-y: visible; }
}

.card {
  background: var(--card-gradient);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

/* Page header */
.page-header {
  padding: 22px 24px;
}
.header-eyebrow {
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--purple);
  margin-bottom: 6px;
}
.header-title {
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--text);
  text-wrap: balance;
}
.header-subtitle {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.header-stats { color: var(--text-muted); font-size: 13px; }
.round-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; cursor: pointer;
}

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--purple);
  flex-shrink: 0;
}

.add-input {
  flex: 1;
  min-width: 180px;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  padding: 8px 6px;
  color: var(--text);
}
.add-input::placeholder { color: var(--text-faint); }

/* Search */
.search-row {
  padding: 6px 16px;
}
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 4px;
  font-size: 14px;
  opacity: .6;
  pointer-events: none;
}
.search-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  padding: 10px 6px 10px 28px;
  color: var(--text);
}
.search-input::placeholder { color: var(--text-faint); }
.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 32px rgba(20, 24, 40, 0.14);
  max-height: 340px;
  overflow-y: auto;
  z-index: 50;
}
.search-results.hidden { display: none; }
.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover, .search-result-item.active-result {
  background: var(--card-soft);
}
.search-result-title { font-weight: 500; flex: 1; }
.search-result-path {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}
.search-empty {
  padding: 16px 14px;
  color: var(--text-faint);
  font-size: 13px;
  text-align: center;
}
.sop-row.flash-highlight {
  animation: flash-row 1.1s ease;
}
@keyframes flash-row {
  0%, 100% { box-shadow: none; }
  20% { box-shadow: 0 0 0 3px var(--purple); }
}

.star-btn, .star-toggle {
  border: none;
  background: transparent;
  font-size: 18px;
  color: var(--text-faint);
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
}
.star-toggle { font-size: 15px; }
.star-btn.active, .star-toggle.active { color: var(--gold); }

.btn-primary {
  background: var(--purple);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 18px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
}
.btn-primary:hover { background: var(--purple-hover); }

.dot-lg { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.count-muted { color: var(--text-muted); font-size: 12.5px; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 16px;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
}
.icon-btn:hover { color: var(--red); background: var(--red-bg); }

/* Tree (left nav) */
.tree-card { padding: 18px; }
.tree-header { margin-bottom: 12px; }
.tree-container { display: flex; flex-direction: column; gap: 16px; }
.tree-category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.tree-cat-name {
  font-weight: 700;
  font-size: 14px;
  outline: none;
  border-radius: 6px;
  padding: 2px 4px;
  margin: -2px -4px;
  flex: 1;
}
.tree-cat-name:focus { background: var(--card-soft); }
.tree-category-header .count-muted { margin-left: -2px; }
.tree-subheadlines {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-left: 16px;
}
.tree-sub-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  border-left: 2px solid transparent;
}
.tree-sub-item:hover { background: var(--card-soft); }
.tree-sub-item.active {
  background: var(--card-soft);
  border-left-color: var(--purple);
  font-weight: 600;
}
.tree-sub-name { flex: 1; }

/* Detail panel (right) */
.detail-card { padding: 26px 30px; }
.detail-breadcrumb {
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 8px;
}
.crumb-sep { color: var(--text-faint); }
.detail-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.detail-title {
  font-size: 22px;
  font-weight: 700;
  outline: none;
  border-radius: 6px;
  padding: 2px 6px;
  margin: -2px -6px;
  flex: 1;
}
.detail-title:focus { background: var(--card-soft); }

.sop-rows { display: flex; flex-direction: column; gap: 8px; }

.sop-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.sop-row.starred {
  background: var(--yellow-bg);
  border-color: var(--yellow-border);
}
.sop-row-main {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.type-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }
.sop-title {
  flex: 1;
  outline: none;
  font-weight: 500;
  border-radius: 6px;
  padding: 2px 4px;
  margin: -2px -4px;
  cursor: text;
}
.sop-title:focus { background: rgba(0,0,0,.05); }

.badge {
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-writing { background: var(--blue-bg); color: var(--blue-text); }
.badge-video { background: var(--purple-bg); color: var(--purple-text); }
.badge-photo { background: var(--green-bg); color: var(--green-text); }

.sop-badges { display: flex; align-items: center; gap: 4px; }
.badge-icon {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}
.badge-empty { font-size: 11px; color: var(--text-faint); font-weight: 500; white-space: nowrap; }

.expand-caret {
  color: var(--text-faint);
  font-size: 11px;
  transition: transform .15s ease;
  width: 14px;
  text-align: center;
}
.sop-row.expanded .expand-caret { transform: rotate(90deg); }

.sop-content-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  display: none;
}
.sop-row.expanded .sop-content-panel { display: block; }

.content-block {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px dashed var(--border);
  border-radius: 8px;
  transition: opacity .15s ease, box-shadow .1s ease;
}
.content-block:last-of-type { margin-bottom: 0; }
.content-block.dragging { opacity: .35; }
.content-block.drag-over-top { box-shadow: inset 0 2px 0 var(--purple); }
.content-block.drag-over-bottom { box-shadow: inset 0 -2px 0 var(--purple); }
.block-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}
.block-header .icon-btn { margin-left: auto; }
.drag-handle {
  cursor: grab;
  color: var(--text-faint);
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}
.drag-handle:active { cursor: grabbing; }
.block-empty {
  color: var(--text-faint);
  font-size: 12.5px;
  padding: 2px 0 12px;
}
.add-block-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.add-block-btn {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.add-block-btn:hover { border-color: var(--purple); color: var(--purple); }

.writing-textarea {
  width: 100%;
  min-height: 110px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13.5px;
  resize: vertical;
  outline: none;
  background: var(--card);
  color: var(--text);
}
.writing-textarea:focus { border-color: var(--purple); }

.loom-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
  margin-bottom: 10px;
  background: var(--card);
  color: var(--text);
}
.loom-input:focus { border-color: var(--purple); }

.loom-embed-wrap {
  position: relative;
  padding-top: 56.25%;
  border-radius: 10px;
  overflow: hidden;
  background: #10121a;
  margin-bottom: 10px;
}
.loom-embed-wrap iframe {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none;
}

.video-watch-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--card-soft);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
  font-size: 13.5px;
  text-decoration: none;
}
.video-watch-link:hover { border-color: var(--purple); color: var(--purple); }
.video-watch-icon { color: var(--purple); }
.video-watch-arrow { color: var(--text-faint); margin-left: 2px; }
.loom-empty {
  color: var(--text-faint);
  font-size: 12.5px;
  padding: 14px 0 2px;
}

.photo-panel { }
.photo-upload-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.photo-thumb-wrap {
  max-width: 320px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: zoom-in;
}
.photo-thumb-wrap img { display: block; width: 100%; max-height: 260px; object-fit: cover; }
.file-btn {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12.5px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
}
.photo-empty { color: var(--text-faint); font-size: 12.5px; }

.add-sop-inline-btn, .add-subheadline-btn {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 2px;
}
.add-sop-inline-btn:hover, .add-subheadline-btn:hover { border-color: var(--purple); color: var(--purple); }
.add-subheadline-btn { margin-top: 4px; }

.empty-state {
  color: var(--text-faint);
  font-size: 13px;
  padding: 30px 10px;
  text-align: center;
}

.sidebar-title { font-weight: 700; font-size: 16px; }
.sidebar-sub { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.add-inline { display: flex; gap: 8px; margin-bottom: 14px; }
.add-inline .add-input {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  padding: 9px 12px;
}

/* Inline add forms */
.inline-add-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.add-input-inline {
  border: 1px solid var(--purple);
  background: var(--card);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  flex: 1;
  min-width: 140px;
}
.add-select-inline {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
}
.btn-sm {
  padding: 7px 14px;
  font-size: 12.5px;
  border-radius: 8px;
}

/* Confirm modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 30, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: #ffffff;
  border-radius: var(--radius-md);
  box-shadow: 0 24px 48px rgba(20, 24, 40, 0.25);
  padding: 24px;
  width: 100%;
  max-width: 380px;
}
.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}
.modal-message {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.5;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 16px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
}
.btn-secondary:hover { background: var(--card-soft); }
.btn-danger {
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
}
.btn-danger:hover { background: var(--red-text); }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(10,12,20,.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
  cursor: zoom-out;
}
.lightbox.hidden { display: none; }
.lightbox img { max-width: 90vw; max-height: 90vh; border-radius: 8px; }

@media (prefers-reduced-motion: reduce) {
  .expand-caret, .sop-row.flash-highlight { transition: none; animation: none; }
}
