/* =========================================================
   Youtliner — app.css
   Workflowy-inspired hierarchical outliner styles
   ========================================================= */

:root {
  --bg-primary: #ffffff;
  --bg-secondary: #fafafa;
  --bg-hover: #f5f5f5;
  --text-primary: #37352f;
  --text-secondary: #787774;
  --text-muted: #b4b4b4;
  --bullet-color: #37352f;
  --bullet-light: #c4c4c4;
  --border-color: #e8e8e8;
  --tree-line: #e0e0e0;
  --accent: #2383e2;
  --danger: #e03e3e;
  --success: #0f9d58;
  --radius: 4px;
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ── App layout ── */
#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
.header {
  height: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-primary);
  gap: 8px;
  z-index: 10;
}

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

.header-center {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background 0.1s, color 0.1s;
}

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

.doc-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

/* ── Breadcrumb ── */
.breadcrumb {
  display: inline-flex;
  align-items: center;
  overflow: hidden;
  font-size: 13px;
  color: var(--text-secondary);
  gap: 0;
  max-width: 100%;
}

.breadcrumb-item {
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--radius);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
  transition: background 0.1s, color 0.1s;
}

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

.breadcrumb-home {
  font-weight: 500;
  color: var(--text-primary);
}

.breadcrumb-segment {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.breadcrumb-sep {
  color: var(--text-muted);
  padding: 0 2px;
  flex-shrink: 0;
}

.breadcrumb-current {
  color: var(--text-primary);
  font-weight: 500;
}

/* ── Main area ── */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 40px 20px 80px;
  display: flex;
  justify-content: center;
}

/* ── Youtliner wrapper ── */
.youtliner-wrapper {
  width: 100%;
  max-width: 720px;
  position: relative;
}

/* Page title (when zoomed into an item) */
.page-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 24px 0;
  padding: 4px 0;
  line-height: 1.3;
}

.page-title-content {
  outline: none;
  display: block;
}

.page-title-content:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
}

/* ── Youtliner tree ── */
.youtliner {
  font-family: var(--font-main);
  font-size: 15px;
  line-height: 1.5;
}

/* ── Outline item ── */
.outline-item {
  position: relative;
  min-height: 28px;
}

.item-row {
  display: flex;
  align-items: flex-start;
  min-height: 28px;
  padding: 2px 0;
  border-radius: var(--radius);
  position: relative;
}

.item-row:hover .collapse-btn.visible {
  opacity: 1;
}

/* ── Collapse button (triangle) ── */
.collapse-btn {
  width: 20px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
  border-radius: var(--radius);
  transition: color 0.1s, transform 0.1s;
  margin-top: 2px;
  position: absolute;
  left: -20px;
}

.collapse-btn.invisible {
  opacity: 0;
  pointer-events: none;
}

.collapse-btn.visible {
  opacity: 0;
}

.collapse-btn:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.collapse-btn.collapsed svg {
  transform: rotate(-90deg);
}

/* ── Bullet ── */
.bullet {
  width: 24px;
  height: 24px;
  min-width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
  border-radius: 50%;
  position: relative;
  transition: background 0.1s;
}

.bullet::after {
  content: '';
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bullet-color);
  transition: background 0.1s, box-shadow 0.1s;
}

.bullet:hover::after {
  background: var(--accent);
}

.bullet:hover {
  background: rgba(35, 131, 226, 0.06);
}

/* Bullet with children indicator — always shows ring */
.bullet.has-children::after,
.bullet.collapsed-with-children::after {
  box-shadow: 0 0 0 2px var(--bullet-color);
  background: transparent;
}

.bullet.has-children:hover::after,
.bullet.collapsed-with-children:hover::after {
  box-shadow: 0 0 0 2px var(--accent);
}

.bullet.collapsed-with-children::after {
  background: var(--bullet-color);
}

.completed-bullet::after {
  background: var(--text-muted) !important;
  box-shadow: none !important;
}

/* ── Item content (contenteditable) ── */
.item-content {
  flex: 1;
  outline: none;
  padding: 3px 4px;
  min-height: 24px;
  color: var(--text-primary);
  line-height: 1.5;
  word-break: break-word;
  border-radius: var(--radius);
  transition: background 0.1s;
}

.item-content:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

.item-content:focus {
  background: rgba(35, 131, 226, 0.03);
}

/* Completed item */
.completed .item-content {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* ── Children container ── */
.children {
  padding-left: 32px;
  position: relative;
}

.children::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--tree-line);
}

.children.collapsed {
  display: none;
}

/* ── Add item button ── */
.add-item-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  padding: 6px 12px;
  color: var(--text-muted);
  font-size: 14px;
  border-radius: var(--radius);
  transition: color 0.1s, background 0.1s;
}

.add-item-btn:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

/* ── Empty state ── */
.empty-state {
  padding: 40px 0;
  text-align: center;
  color: var(--text-secondary);
  font-size: 15px;
}

.empty-state kbd {
  display: inline-block;
  padding: 1px 6px;
  font-size: 12px;
  font-family: var(--font-main);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  color: var(--text-primary);
}

/* ── Sync indicator ── */
.sync-indicator {
  position: fixed;
  top: 50px;
  right: 16px;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 100;
  opacity: 0.85;
}

.sync-indicator.syncing {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.sync-indicator.error {
  background: #fff5f5;
  color: var(--danger);
  border: 1px solid #fca5a5;
}

.sync-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.sync-indicator.syncing .sync-dot {
  animation: pulse 1.2s ease-in-out infinite;
}

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

/* ── Loading ── */
.youtliner-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 0;
  color: var(--text-secondary);
  gap: 16px;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  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); }
}

/* ── No document state ── */
.no-document {
  text-align: center;
  padding: 80px 0;
  color: var(--text-secondary);
}

/* ── Drag and drop indicators ── */
.outline-item.drag-over-top > .item-row::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
  pointer-events: none;
}

.outline-item.drag-over-bottom > .item-row::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
  pointer-events: none;
}

.outline-item.drag-over-child > .item-row {
  background: rgba(35, 131, 226, 0.06);
  border-radius: var(--radius);
}

/* Dragged item */
.outline-item[draggable="true"]:active {
  opacity: 0.7;
}

/* ── Auth page ── */
.auth-page {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  padding: 16px;
}

.auth-loading {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
}

.auth-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.auth-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 6px;
  text-align: center;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0 0 28px;
  text-align: center;
}

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

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.auth-input {
  font-family: var(--font-main);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 8px 12px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(35, 131, 226, 0.12);
}

.auth-input::placeholder {
  color: var(--text-muted);
}

.auth-error {
  font-size: 13px;
  color: var(--danger);
  margin: 0;
  padding: 8px 12px;
  background: #fff5f5;
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
}

.auth-btn {
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  padding: 9px 16px;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 4px;
}

.auth-btn:hover:not(:disabled) {
  opacity: 0.88;
}

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

.auth-toggle {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  margin: 20px 0 0;
}

.auth-toggle-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.auth-toggle-link:hover {
  text-decoration: underline;
}

/* ── Header sync indicator ── */
.sync-indicator-header {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-right: 4px;
  white-space: nowrap;
}

.sync-indicator-header .sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sync-indicator-header .sync-label {
  color: var(--text-secondary);
}

.sync-saved .sync-dot    { background: #4caf50; }
.sync-saving .sync-dot   { background: #ff9800; animation: pulse 1s ease-in-out infinite; }
.sync-error .sync-dot    { background: #f44336; }
.sync-offline .sync-dot  { background: #9e9e9e; }

/* ── Logout button ── */
.logout-btn {
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 4px 10px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}

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

/* ── Mobile responsive ── */
@media (max-width: 768px) {
  .main {
    padding: 20px 12px 60px;
  }

  .youtliner-wrapper {
    max-width: 100%;
  }

  .header {
    padding: 0 8px;
  }

  .doc-title {
    max-width: 180px;
  }

  .breadcrumb-item {
    max-width: 100px;
  }

  .page-title {
    font-size: 22px;
  }

  .collapse-btn {
    left: -16px;
  }
}

@media (max-width: 480px) {
  .header-btn {
    width: 28px;
    height: 28px;
  }

  .youtliner {
    font-size: 14px;
  }
}

/* ── Item Notes ── */
.item-note-area {
  padding-left: 24px;
  margin-top: 2px;
  margin-bottom: 4px;
}

.item-note {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
  outline: none;
  min-height: 20px;
}

.item-note:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
}

.item-note-preview {
  font-size: 12px;
  color: var(--text-muted);
  padding-left: 24px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
  cursor: pointer;
}

/* ── Inline code ── */
.item-content code, .item-note code {
  background: var(--bg-secondary);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 0.9em;
  color: #e01e5a;
}

/* ── Links in content ── */
.item-content a {
  color: var(--accent);
  text-decoration: underline;
}

/* ── Mobile Formatting Toolbar ── */
.mobile-toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 8px;
  z-index: 100;
}

.toolbar-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-primary);
}

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

.toolbar-sep {
  width: 1px;
  height: 24px;
  background: var(--border-color);
  margin: 0 4px;
}

/* Show mobile toolbar only on small screens */
@media (min-width: 769px) {
  .mobile-toolbar { display: none; }
}

/* ── Main layout (sidebar + content) ── */
.main-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: 0;
  left: -280px;
  width: 280px;
  height: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  transition: left 0.2s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.sidebar-visible {
  left: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.sidebar-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
  padding: 0 4px;
}

.sidebar-close:hover {
  color: var(--text-primary);
}

.sidebar-new-btn {
  margin: 12px 16px;
  padding: 8px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-family: var(--font-main);
  font-weight: 500;
  text-align: center;
}

.sidebar-new-btn:hover {
  opacity: 0.88;
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
}

.sidebar-item {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  cursor: pointer;
  gap: 4px;
}

.sidebar-item:hover {
  background: var(--bg-hover);
}

.sidebar-item.active {
  background: rgba(35, 131, 226, 0.1);
}

.sidebar-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.sidebar-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 2px;
  opacity: 0;
  flex-shrink: 0;
}

.sidebar-item:hover .sidebar-delete-btn {
  opacity: 1;
}

.sidebar-delete-btn:hover {
  color: var(--danger);
}

.sidebar-edit-input {
  flex: 1;
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 4px 8px;
  outline: none;
  font-family: var(--font-main);
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 49;
}

/* ── Hamburger menu button ── */
.menu-btn {
  display: none;
}

/* ── Desktop: sidebar fixed, content offset ── */
@media (min-width: 769px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 240px;
    height: 100%;
    z-index: 50;
    border-right: 1px solid var(--border-color);
  }

  .sidebar-close {
    display: none;
  }

  .sidebar-overlay {
    display: none;
  }

  .app {
    margin-left: 240px;
  }
}

/* Mobile: hamburger visible, sidebar overlays */
@media (max-width: 768px) {
  .menu-btn {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
  }

  .sidebar-visible {
    left: 0;
  }
}

/* ── Search Modal ── */
.search-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}

.search-modal {
  width: 90%;
  max-width: 600px;
  background: var(--bg-primary);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.search-input {
  width: 100%;
  padding: 16px 20px;
  border: none;
  border-bottom: 1px solid var(--border-color);
  font-family: var(--font-main);
  font-size: 16px;
  outline: none;
  color: var(--text-primary);
  background: var(--bg-primary);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-results {
  max-height: 400px;
  overflow-y: auto;
}

.search-result {
  padding: 12px 20px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
}

.search-result:hover {
  background: var(--bg-hover);
}

.search-result:last-child {
  border-bottom: none;
}

.search-result-doc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  font-weight: 500;
}

.search-result-content {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.4;
}

.search-result-content mark {
  background: #fff3b0;
  color: var(--text-primary);
  border-radius: 2px;
  padding: 0 1px;
}

.search-empty,
.search-loading {
  padding: 24px 20px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}
