/* ─── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1116;
  --bg-alt:    #181a21;
  --bg-hover:  #1e2030;
  --text:      #e0e0e6;
  --text-dim:  #888899;
  --text-faint:#555566;
  --accent:    #7c6ef0;
  --accent-dim:#4a3f8e;
  --border:    #252837;
  --green:     #5cb85c;
  --orange:    #f0a050;
  --radius:    8px;
  --sidebar-w: 280px;
}

html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  overflow: hidden;
}

/* ─── Layout ──────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
}

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

#content {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 3rem;
}

/* ─── Sidebar ─────────────────────────────────────────────── */
.sidebar-header {
  padding: 1.25rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.stats {
  display: block;
  font-size: 0.75rem;
  color: var(--text-faint);
  margin-top: 0.15rem;
}

.search-box {
  padding: 0.75rem 1rem;
}

.search-box input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.nav-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-faint);
  padding: 0.5rem 1rem 0.25rem;
}

#pages, #tags {
  list-style: none;
}

#pages li a, #tags li a {
  display: block;
  padding: 0.35rem 1rem;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.1s ease;
}

#pages li a:hover, #tags li a:hover {
  background: var(--bg-hover);
  color: var(--text);
}

#pages li a.active {
  color: var(--accent);
  font-weight: 500;
}

#tags li a {
  display: flex;
  justify-content: space-between;
}

#tags li a .tag-count {
  color: var(--text-faint);
  font-size: 0.75rem;
}

/* ─── Page View ───────────────────────────────────────────── */
.page-view {
  max-width: 720px;
  margin: 0 auto;
}

.page-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.page-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.page-tag {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  background: var(--accent-dim);
  border-radius: 4px;
  color: var(--text);
}

.page-properties {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
}

/* ─── Blocks ──────────────────────────────────────────────── */
.blocks {
  list-style: none;
}

.block {
  padding: 0.3rem 0;
  color: var(--text);
}

/* Indentation by level */
.block-level-0 { margin-left: 0; }
.block-level-1 { margin-left: 1.5rem; }
.block-level-2 { margin-left: 3rem; }
.block-level-3 { margin-left: 4.5rem; }
.block-level-4 { margin-left: 6rem; }

/* Deep-link highlight */
.block-highlight {
  background: rgba(99, 102, 241, 0.12);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.4), 0 0 20px rgba(99, 102, 241, 0.15);
  border-radius: 8px;
  scroll-margin-top: 80px;
  scroll-margin-bottom: 80px;
  padding: 0.5rem;
  margin: 0.25rem -0.5rem;
  transition: background 0.2s, box-shadow 0.2s;
}

.block-bullet {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.block-bullet::before {
  content: '•';
  color: var(--text-faint);
  font-size: 1.2rem;
  line-height: 1;
  margin-top: 0.15rem;
  flex-shrink: 0;
}

.block-content {
  flex: 1;
}

.block-content code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85em;
  background: var(--bg-alt);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
}

/* Page links [[link]] */
.page-ref {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}

.page-ref:hover {
  text-decoration: underline;
}

/* Tags #tag */
.inline-tag {
  color: var(--orange);
  font-size: 0.85em;
  cursor: pointer;
  text-decoration: none;
}
.inline-tag:hover {
  text-decoration: underline;
}

/* Linked References (tag pages) */
.linked-references {
  margin-top: 2rem;
}
.linked-refs-header {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.linked-ref {
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  background: var(--bg-alt);
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: border-color 0.15s;
}
.linked-ref:hover {
  border-color: var(--accent);
}
.linked-ref-page {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 0.35rem;
  cursor: pointer;
}
.linked-ref-page:hover {
  text-decoration: underline;
}
.linked-ref-content {
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.5;
}

/* TODO states */
.todo-TODO { color: var(--orange); font-weight: 500; }
.todo-DONE { color: var(--green); text-decoration: line-through; }
.todo-DOING { color: var(--accent); font-weight: 500; }

/* ─── Inline Components ─────────────────────────────────────── */
.component {
  margin: 0.5rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* Event Card */
.component-event {
  background: var(--bg-alt);
}

.component-event.event-past {
  opacity: 0.55;
}

.event-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--bg-hover);
}

.event-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.event-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.event-badge-upcoming {
  background: var(--accent);
  color: white;
}

.event-badge-past {
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.event-badge-default {
  background: var(--accent-dim);
  color: var(--text);
}

.event-body {
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.event-date {
  color: var(--text);
}

.event-countdown {
  color: var(--accent);
  font-weight: 500;
}

.event-countdown-soon {
  color: var(--green);
  font-weight: 600;
}

.event-location {
  color: var(--text-dim);
}

.event-tasks {
  padding: 0.5rem 1rem 0.75rem;
  border-top: 1px solid var(--border);
}

.event-task {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0;
  font-size: 0.85rem;
  cursor: default;
}

.event-task input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: default;
}

.event-task-done span {
  color: var(--text-faint);
  text-decoration: line-through;
}

/* ─── Search Results ──────────────────────────────────────── */
.search-results {
  max-width: 720px;
  margin: 0 auto;
}

.search-result {
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: border-color 0.1s ease;
}

.search-result:hover {
  border-color: var(--accent);
}

.search-result .result-page {
  font-size: 0.75rem;
  color: var(--text-faint);
}

.search-result .result-content {
  margin-top: 0.25rem;
}

/* ─── Journal Box ─────────────────────────────────────────── */
.journal-box {
  margin-top: 2rem;
  padding: 1rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.write-toggle {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.write-pill {
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}

.write-pill:hover:not(.active):not(:disabled) {
  border-color: var(--text-dim);
  color: var(--text);
}

.write-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.write-pill:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Block type selector */
.type-selector {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.type-pill {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
}

.type-pill:hover:not(.active) {
  border-color: var(--text-dim);
  color: var(--text);
}

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

/* Schema input fields */
.write-fields {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.write-title-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.5rem;
}

.write-title-input:focus {
  outline: none;
  border-color: var(--accent);
}

#write-schema-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

#write-schema-fields.hidden {
  display: none;
}

.schema-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
  min-width: 120px;
}

/* Start + End share a row, Location takes full width */
.schema-field-start, .schema-field-end {
  flex: 1 1 45%;
}
.schema-field-location {
  flex: 1 1 100%;
}
.schema-field-status {
  flex: 0 0 auto;
  min-width: 110px;
}

.schema-label {
  font-size: 0.7rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.schema-label .required {
  color: var(--orange);
}

.schema-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.4rem;
}

.schema-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Date + time toggle group */
.date-time-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.date-time-group .schema-input {
  flex: 1;
}
.time-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 0.7rem;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.time-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.time-toggle.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(99, 102, 241, 0.1);
}

.journal-box textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.5rem;
  resize: vertical;
  min-height: 60px;
}

.journal-box textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.journal-box button {
  margin-top: 0.5rem;
  padding: 0.4rem 1rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}

.journal-box button:hover {
  background: var(--accent-dim);
}

.journal-box button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ─── Empty State ─────────────────────────────────────────── */
.empty-state {
  max-width: 400px;
  margin: 4rem auto;
  text-align: center;
  color: var(--text-dim);
}

.empty-state h2 {
  font-size: 1.2rem;
  color: var(--text);
  margin-bottom: 0.5rem;
}

/* ─── Mobile ──────────────────────────────────────────────── */
/* Default: hide hamburger toggle (desktop shows sidebar always) */
.menu-toggle { display: none; }

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    height: 100vh;
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #content {
    padding: 3rem 1.25rem 1.25rem;
    width: 100%;
  }

  /* Backdrop when sidebar is open */
  #sidebar.open ~ #content::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
  }

  .menu-toggle {
    display: block;
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 101;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: white;
    padding: 0.6rem 0.9rem;
    cursor: pointer;
    font-size: 1.4rem;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  }

  .block-level-1 { margin-left: 1rem; }
  .block-level-2 { margin-left: 2rem; }
  .block-level-3 { margin-left: 2.5rem; }
}

/* ─── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-alt);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  font-size: 0.85rem;
  z-index: 200;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: toast-in 0.25s ease;
  max-width: 90vw;
}

.toast.hidden {
  display: none;
}

.toast .toast-icon {
  color: var(--green);
  font-weight: 700;
}

.toast .toast-link {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  font-weight: 500;
}

.toast .toast-link:hover {
  text-decoration: underline;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.sidebar-footer {
  margin-top: auto;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

.github-link {
  display: inline-flex;
  align-items: center;
  color: var(--text-dim);
  transition: color 0.15s;
}

.github-link:hover {
  color: var(--text);
}
