/* ============================================
   Design Tokens
   ============================================ */

:root {
  /* Colors — matched to WorkFlowy default theme */
  --color-text:          #2A3135;
  --color-text-muted:    #4B5155;
  --color-text-faint:    #868C90;
  --color-text-dark:     #2A3135;
  --color-text-medium:   #4B5155;
  --color-bg:            #fff;
  --color-bg-subtle:     #F3F4F4;
  --color-bg-faint:      #F3F4F4;
  --color-bg-header:     #fff;
  --color-border:        #DCE0E2;
  --color-border-light:  #ECEEF0;
  --color-border-input:  #DCE0E2;
  --color-accent:        #49BAF2;
  --color-accent-bg:     #C1E1F2;
  --color-error:         #dc2626;
  --color-error-bg:      #fef2f2;
  --color-error-border:  #fecaca;
  --color-success-bg:    #f0fdf4;
  --color-success-border:#bbf7d0;
  --color-success-text:  #166534;
  --color-btn-primary:   #333;
  --color-hover-bg:      transparent;
  --color-bullet:        #2A3135;
  --color-bullet-parent: #868C90;

  /* Typography — matched to live WorkFlowy computed styles */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
  --font-family-content: "Helvetica Neue", Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
  --font-size-base: 16px;
  --font-size-sm:   0.875rem;
  --font-size-xs:   0.8rem;
  --line-height:    20px; /* WF .content live computed: 20px */
  --note-font-size: 13px;

  /* Layout */
  --content-max-width: 900px;

  /* Transitions */
  --transition-fast: 150ms ease;

  /* Spacing */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-6:  24px;
  --space-8:  32px;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  /* Z-index */
  --z-sticky:  10;
  --z-toolbar: 1000;
}

/* ============================================
   Global Reset
   ============================================ */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-family);
  line-height: 16px; /* WF body live computed: 16px; content elements override to 20px */
  color: var(--color-text);
  background: var(--color-bg);
}

/* ============================================
   Shared Components
   ============================================ */

.alert-error {
  background: var(--color-error-bg);
  border: 1px solid var(--color-error-border);
  color: var(--color-error);
  padding: 0.75rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  font-size: var(--font-size-sm);
  text-align: center;
}

/* ============================================
   Login Page
   ============================================ */

.login-page {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-family);
  background: var(--color-bg);
}

.login-card {
  background: white;
  padding: 2rem;
  border: 1px solid #eee;
  width: 100%;
  max-width: 360px;
}

.login-title {
  margin: 0 0 1.5rem;
  font-size: 1.25rem;
  font-weight: 500;
  text-align: center;
  color: var(--color-text);
}

.login-form-group {
  margin-bottom: 1rem;
}

.login-form-group--last {
  margin-bottom: 1.5rem;
}

.login-label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: var(--font-size-sm);
  color: var(--color-text-medium);
}

.login-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  box-sizing: border-box;
  transition: border-color 0.2s;
}

.login-input:focus {
  border-color: var(--color-accent);
  outline: none;
}

.login-btn {
  width: 100%;
  padding: 0.625rem;
  background: var(--color-btn-primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
}

/* ============================================
   Search Page
   ============================================ */

.search-bar {
  position: sticky;
  top: 0;
  background: white;
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--color-border-light);
  z-index: var(--z-sticky);
}

.search-bar-inner {
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.search-input {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(26,115,232,0.2);
}

.search-nav {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.search-nav a {
  color: var(--color-accent);
  text-decoration: none;
}

.search-nav a:hover {
  text-decoration: underline;
}

.results-container {
  max-width: 680px;
  margin: 0 auto;
  padding: 1rem 2rem;
}

.result-item {
  background: white;
  border: none;
  border-bottom: 1px solid var(--color-border-light);
  border-radius: 0;
  padding: var(--space-3) var(--space-2);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.result-item:hover {
  background-color: var(--color-hover-bg);
}

.result-item a {
  text-decoration: none;
  color: inherit;
  display: block;
}

.result-breadcrumb {
  font-size: var(--font-size-xs);
  color: var(--color-text-faint);
  margin-bottom: 0.375rem;
}

.result-content {
  font-size: 0.95rem;
  line-height: var(--line-height);
}

.result-content mark {
  background: #fff3b0;
  padding: 0 2px;
  border-radius: 2px;
}

.tag-pill {
  display: inline-block;
  background: var(--color-accent-bg);
  color: var(--color-accent);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: var(--font-size-xs);
  margin-right: 4px;
  margin-top: 0.375rem;
}

.result-meta {
  margin-top: 0.375rem;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-faint);
}

.empty-state p {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.empty-state small {
  font-size: 0.85rem;
}

.pagination {
  display: none;
  justify-content: center;
  gap: 1rem;
  padding: 1rem 0;
}

.pagination button {
  padding: 0.5rem 1rem;
  border: 1px solid #ccc;
  border-radius: var(--radius-sm);
  background: white;
  cursor: pointer;
  font-size: var(--font-size-sm);
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination button:not(:disabled):hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.search-status {
  text-align: center;
  padding: 0.5rem;
  color: var(--color-text-faint);
  font-size: 0.85rem;
}

.spinner {
  display: none;
  text-align: center;
  padding: 2rem;
  color: var(--color-text-faint);
}

/* ============================================
   Settings Page
   ============================================ */

.settings-page {
  margin: 0;
  font-family: var(--font-family);
  background: var(--color-bg-subtle);
  padding: 2rem;
}

.settings-container {
  max-width: 640px;
  margin: 0 auto;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.settings-title {
  margin: 0;
  font-size: 1.5rem;
  color: var(--color-text-dark);
}

.settings-nav-link {
  color: var(--color-text-medium);
  text-decoration: none;
  margin-right: 1rem;
  font-size: var(--font-size-sm);
}

.settings-logout-form {
  display: inline;
}

.settings-logout-btn {
  background: none;
  border: none;
  color: var(--color-text-medium);
  cursor: pointer;
  font-size: var(--font-size-sm);
  text-decoration: underline;
}

.settings-new-key-banner {
  background: var(--color-success-bg);
  border: 1px solid var(--color-success-border);
  padding: 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
}

.settings-new-key-label {
  margin: 0 0 0.5rem;
  font-weight: 600;
  color: var(--color-success-text);
  font-size: var(--font-size-sm);
}

.settings-new-key-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.settings-new-key-code {
  background: #dcfce7;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  word-break: break-all;
  flex: 1;
}

.settings-copy-btn {
  padding: 0.5rem 0.75rem;
  background: var(--color-btn-primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--font-size-sm);
  white-space: nowrap;
}

.settings-card {
  background: white;
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  margin-bottom: 1.5rem;
}

.settings-card-title {
  margin: 0 0 1rem;
  font-size: 1rem;
  color: var(--color-text-dark);
}

.settings-create-form {
  display: flex;
  gap: 0.5rem;
}

.settings-create-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border-input);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
}

.settings-create-btn {
  padding: 0.5rem 1rem;
  background: var(--color-btn-primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--font-size-sm);
  white-space: nowrap;
}

.settings-table-card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  overflow: hidden;
}

.settings-empty {
  padding: 2rem;
  text-align: center;
  color: var(--color-text-faint);
  margin: 0;
  font-size: var(--font-size-sm);
}

.settings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.settings-table thead tr {
  border-bottom: 1px solid var(--color-border-light);
  text-align: left;
}

.settings-table th {
  padding: 0.75rem 0.5rem;
  font-weight: 600;
  color: var(--color-text-medium);
}

.settings-table th:first-child {
  padding-left: 1rem;
}

.settings-table tbody tr {
  border-bottom: 1px solid var(--color-bg-subtle);
}

.settings-table td {
  padding: 0.625rem 0.5rem;
  color: var(--color-text-faint);
}

.settings-table td:first-child {
  padding-left: 1rem;
  color: var(--color-text-dark);
}

.settings-table td.key-preview {
  font-family: monospace;
}

.settings-delete-form {
  margin: 0;
}

.settings-delete-btn {
  background: none;
  border: none;
  color: var(--color-error);
  cursor: pointer;
  font-size: 0.8125rem;
  text-decoration: underline;
}

/* ============================================
   Outliner Client Component
   ============================================ */

/* Global overrides (migrated from globalStyles useEffect injection) */
body {
  overflow-x: hidden;
}

@media (max-width: 768px) {
  .outliner-node-row {
    --indent-size: 12px !important;
  }
  .outliner-textarea {
    font-size: 16px !important;
  }
  .outliner-breadcrumb {
    font-size: 11px !important;
  }
  .drag-handle {
    display: none;
  }
  .outliner-zoom-heading {
    font-size: 22px !important; /* mobile: proportional reduction from 27px desktop */
    padding: var(--space-1) 0 !important;
  }
}

/* Node row — WF live: padding 0, padding-top 4px is on .content not row */
.outliner-node-row {
  display: flex;
  align-items: flex-start;
  padding: 0;
  min-height: 24px;
  position: relative;
  border-radius: 3px;
}

/* Expand/collapse triangle — always visible for nodes with children */
.outliner-triangle {
  width: 16px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  user-select: none;
  transition: transform var(--transition-fast);
}

.outliner-triangle--expanded {
  transform: rotate(90deg);
}

.outliner-triangle-icon {
  display: block;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 4.5px 0 4.5px 6.5px;
  border-color: transparent transparent transparent var(--color-bullet);
}

/* Spacer (when no triangle) */
.outliner-spacer {
  width: 16px;
  height: 24px;
  flex-shrink: 0;
}

/* Drag handle */
.drag-handle {
  width: 16px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0;
  cursor: grab;
  color: var(--color-text-faint);
  transition: opacity var(--transition-fast);
}

.outliner-node-row:hover .drag-handle {
  opacity: 1;
}

.drag-handle:active {
  cursor: grabbing;
}

/* SortableJS ghost — semi-transparent placeholder at drop position */
.sortable-ghost {
  opacity: 0.4;
  background: var(--color-hover-bg);
}

/* SortableJS drag — element following cursor */
.sortable-drag {
  opacity: 0.85;
  background: var(--color-bg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

/* Drop indicator — blue line on ghost top edge */
.sortable-ghost::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-accent);
  border-radius: 1px;
}

/* Bullet */
.outliner-bullet {
  width: 18px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
  cursor: default;
}

.outliner-bullet--has-children {
  cursor: pointer;
}

.outliner-bullet-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-bullet);
}

.outliner-bullet-dot--parent {
  background: var(--color-bullet);
}

/* Textarea — WF .content live: font-family "Helvetica Neue", line-height 20px, padding-top 4px */
.outliner-textarea {
  resize: none;
  overflow: hidden;
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  padding: 4px 0 0 0; /* WF .content padding-top: 4px */
  width: 100%;
  font-family: var(--font-family-content);
  color: var(--color-text);
}

/* Breadcrumb bar */
.outliner-breadcrumb {
  background: var(--color-bg);
  padding: var(--space-2) var(--space-4);
  font-size: 13px;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  overflow-x: auto;
  white-space: nowrap;
  margin-bottom: 0;
  border-radius: 0;
  border-bottom: 1px solid var(--color-border-light);
}

.outliner-breadcrumb-link {
  color: var(--color-accent);
  text-decoration: none;
  cursor: pointer;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  vertical-align: bottom;
}

.outliner-breadcrumb-sep {
  color: var(--color-text-faint);
  margin: 0 2px;
}

.outliner-breadcrumb-current {
  color: var(--color-text-dark);
  font-weight: 600;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  vertical-align: bottom;
}

/* Zoom heading - shows zoomed node text as title */
.outliner-zoom-heading {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: var(--space-2);
  padding: var(--space-2) 0;
  font-size: 27px; /* matched to WorkFlowy --font-selected-name-font-size */
  font-weight: 400;
  font-family: var(--font-family-content);
  color: var(--color-text-dark);
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  overflow: hidden;
  line-height: 34px; /* matched to WorkFlowy --font-selected-name-line-height */
}

/* Mobile toolbar */
.outliner-mobile-toolbar {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  background: var(--color-bg);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 44px;
  z-index: var(--z-toolbar);
  padding-bottom: env(safe-area-inset-bottom);
}

.outliner-mobile-btn {
  border: none;
  background: transparent;
  font-size: 18px;
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  color: var(--color-text-dark);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Main app container */
.outliner-app {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--color-text);
  padding: 0 var(--space-6);
  max-width: var(--content-max-width);
  margin: 0 auto;
}

/* Header */
.outliner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0;
  padding-bottom: 0;
  height: 48px;
  border-bottom: 1px solid var(--color-border-light);
}

/* App title */
.outliner-app-title {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--color-text-dark);
}

.outliner-app-title--clickable {
  cursor: pointer;
}

/* Nav */
.outliner-nav {
  display: flex;
  gap: var(--space-3);
  font-size: 13px;
}

.outliner-nav a {
  color: var(--color-accent);
  text-decoration: none;
}

/* Empty state */
.outliner-empty {
  color: var(--color-text-faint);
  padding: 2rem;
  text-align: center;
}

/* Loading/error/not-found state screens */
.outliner-state {
  padding: 2rem;
  font-family: var(--font-family);
}

.outliner-state--loading {
  color: var(--color-text-faint);
}

.outliner-state--error {
  color: #c00;
}

.outliner-state--notfound a {
  color: var(--color-accent);
  text-decoration: none;
}

/* Login page additions for Supabase auth flow */
.login-check-email {
  margin: 0 0 12px;
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
}
.login-otp-hint {
  margin: 0 0 16px;
  color: var(--color-text-muted);
  font-size: 13px;
  line-height: 1.4;
}
.login-divider {
  text-align: center;
  margin: 16px 0;
  color: var(--color-text-muted);
  font-size: 13px;
}
.login-btn--github {
  display: block;
  text-align: center;
  text-decoration: none;
  background: #24292e;
  color: #fff;
}
.login-btn--github:hover {
  background: #1b1f23;
}
.login-back-link {
  display: block;
  text-align: center;
  margin-top: 12px;
  color: var(--color-accent);
  font-size: 14px;
}

/* ============================================
   Tiptap Editor Styles
   ============================================ */

/* Container div that Tiptap appends into */
.outliner-editor-container {
  flex: 1;
  min-width: 0;
  position: relative;
}

/* The ProseMirror contenteditable div that Tiptap creates */
.outliner-editor {
  outline: none;
  min-height: 1.5em;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  /* Match the old textarea sizing, font, and spacing */
  font-size: var(--font-size-base);
  line-height: var(--line-height);
  font-family: var(--font-family-content);
  color: var(--color-text);
  background: transparent;
  padding: 4px 0 0 0; /* Match .outliner-textarea padding-top */
  margin: 0;
  border: none;
  resize: none;
  cursor: text;
}

/* Remove Tiptap's default paragraph margin */
.outliner-editor p {
  margin: 0;
}

/* Placeholder for empty nodes */
.outliner-editor.is-editor-empty::before {
  content: attr(data-placeholder);
  color: var(--color-text-faint, #868C90);
  pointer-events: none;
  position: absolute;
  top: 4px;
  left: 0;
}

/* Also handle placeholder via container's data-placeholder */
.outliner-editor-container:has(.is-editor-empty) .outliner-editor::before {
  content: attr(data-placeholder);
}

/* Inline formatting marks */
.outliner-editor strong,
.outliner-editor b {
  font-weight: 700;
}

.outliner-editor em,
.outliner-editor i {
  font-style: italic;
}

/* Ensure .ProseMirror gets correct outline reset */
.outliner-editor-container .ProseMirror {
  outline: none;
}

/* Mobile: increase font size for readability (matches old .outliner-textarea mobile rule) */
@media (max-width: 768px) {
  .outliner-editor {
    font-size: 16px !important;
  }
}

/* Link styles in Tiptap editor */
.outliner-editor a {
  color: var(--color-accent, #49BAF2);
  text-decoration: underline;
  cursor: pointer;
}

.outliner-editor a:hover {
  text-decoration: none;
}

/* Link input overlay — shown when user presses Ctrl+K */
.outliner-link-overlay {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: min(480px, 90vw);
}

.outliner-link-input-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--color-border, #DCE0E2);
  border-radius: var(--radius-md, 6px);
  padding: 8px 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.outliner-link-input {
  flex: 1;
  border: none;
  outline: none;
  font: inherit;
  font-size: 14px;
  color: inherit;
  background: transparent;
  min-width: 0;
}

.outliner-link-remove {
  font-size: 12px;
  color: var(--color-error, #dc3545);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  white-space: nowrap;
  flex-shrink: 0;
}
