/* === BuJo — Layout & Typography === */

:root {
  --sidebar-width: 200px;
  --status-height: 28px;
  --rapid-log-height: 52px;
  --bg: #1a1a2e;
  --bg-surface: #16213e;
  --bg-sidebar: #0f1626;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #e94560;
  --border: #2a2a4a;
  --selected: rgba(233, 69, 96, 0.15);
  --hover: rgba(255, 255, 255, 0.04);
  --font: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8f8fa;
    --bg-surface: #ffffff;
    --bg-sidebar: #f0f0f4;
    --text: #1a1a2e;
    --text-muted: #666;
    --accent: #d63050;
    --border: #ddd;
    --selected: rgba(214, 48, 80, 0.1);
    --hover: rgba(0, 0, 0, 0.04);
  }
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  overflow: hidden;
}

/* === App Grid: sidebar + main === */

#app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: calc(100vh - var(--status-height));
}

/* === Sidebar === */

#sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Scrollable region: logs/collections. Takes all remaining height and
   scrolls internally; the sync section below never scrolls with it. */
#sidebar-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Sync section: footer pinned at the sidebar bottom. Locked to the
   #rapid-log input row height via the shared variable; min-height so the
   transient fallback note can extend it without clipping. */
#sync-section {
  flex-shrink: 0;
  min-height: var(--rapid-log-height);
  box-sizing: border-box;
  border-top: 1px solid var(--border);
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#sync-section sl-button {
  flex: 1;
  min-width: 0;
}

/* Last successful sync, muted next to the 'End sync' button. */
.sync-timestamp {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Sticky sign-in fallback (transient, not a third persistent state). */
.sync-fallback {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 0;
}

.sync-fallback-buttons {
  display: flex;
  gap: 6px;
}

.sync-fallback-buttons sl-button {
  flex: 1;
  min-width: 0;
}

.sync-note {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

.sidebar-header {
  padding: 4px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-top: 8px;
  flex-shrink: 0;
}

.sidebar-header:first-child { margin-top: 0; }

.sidebar-item {
  padding: 4px 12px 4px 20px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  border-radius: 4px;
  margin: 0 4px;
  flex-shrink: 0;
}

.sidebar-item:hover { background: var(--hover); }
.sidebar-item.active::before {
  content: '•';
  position: absolute;
  left: 6px;
  color: var(--accent);
  font-weight: bold;
}
.sidebar-item.active { position: relative; }
.sidebar-item.focused { outline: 1px solid var(--accent); outline-offset: -1px; }

.sidebar-item { display: flex; align-items: center; justify-content: space-between; }

.sidebar-item-delete {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
}

.sidebar-item:hover .sidebar-item-delete,
.sidebar-item.focused .sidebar-item-delete { display: inline; }
.sidebar-item-delete:hover { color: var(--accent); }
.sidebar-item-delete:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }

/* Sidebar bucket links (time-frame placeholders) — fade with age */
.sidebar-item-bucket { opacity: var(--bucket-opacity, 0.7); }
.sidebar-item-bucket:hover, .sidebar-item-bucket.active { opacity: 1; }

/* === Main Area === */

main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#view {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
}

/* === Date Headers === */

.date-header {
  font-size: 12px;
  color: var(--text-muted);
  padding: 12px 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}

.date-header:first-child { padding-top: 0; }

/* === Entries === */

.entry {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  min-height: 28px;
  line-height: 1.5;
}

.entry:hover { background: var(--hover); }
.entry.selected {
  background: var(--selected);
  border-left: 2px solid var(--accent);
  padding-left: 6px;
}

/* Signifier symbol */
.entry-sig {
  flex-shrink: 0;
  width: 16px;
  text-align: center;
  color: var(--accent);
  font-weight: bold;
}

.entry-body { flex: 1; }

/* Day number prefix in future log entries */
.entry-day {
  flex-shrink: 0;
  width: 20px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Done: strikethrough + muted */
.entry.done .entry-body {
  text-decoration: line-through;
  color: var(--text-muted);
}

/* Migrated / Scheduled: muted */
.entry.migrated .entry-body,
.entry.scheduled .entry-body {
  color: var(--text-muted);
  font-style: italic;
  text-decoration: line-through;
}

/* Migration target label (e.g. "→ April 2026") */
.entry-migration-target {
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
  flex-shrink: 0;
  cursor: pointer;
  text-decoration: none;
  border-radius: 2px;
}

.entry-migration-target:hover {
  text-decoration: underline;
  color: var(--accent);
}

.entry-migration-target:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
  color: var(--accent);
}

/* Time emphasis in event entries */
.entry-time {
  color: var(--text);
  display: inline-flex;
  align-items: center;
}

.entry-time::before {
  content: "@";
  color: var(--sl-color-primary-600, #6cf);
  font-size: 0.85em;
  margin-right: 1px;
}

/* Hashtag pills */
.entry-tag {
  display: inline-flex;
  align-items: center;
  background: rgba(234, 179, 8, 0.15);
  border: 1px solid rgba(234, 179, 8, 0.4);
  border-radius: 10px;
  padding: 0 6px;
  font-size: 0.9em;
  line-height: 1.4;
  color: inherit;
  vertical-align: middle;
  margin-top: -2px;
}

.entry-tag-hash {
  font-size: 0.8em;
  color: rgb(234, 179, 8);
  opacity: 0.7;
  margin-right: 3px;
}

/* Inline links */
.entry-link {
  color: var(--sl-color-primary-600, #6cf);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.entry-link:hover {
  opacity: 0.8;
}

/* Inline edit — overlay editor layered over the row.
   The row is never removed while editing: it gets position:relative and
   its body is hidden via visibility (layout preserved, node stays mounted). */
.entry.editing { position: relative; }
.entry.editing .entry-body { visibility: hidden; }

.entry-edit-overlay {
  position: absolute;
  display: flex;
  align-items: stretch;
}

.entry-edit {
  flex: 1;
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--accent);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  outline: none;
  padding: 0;
}

/* === Rapid Log Input Bar === */

#rapid-log {
  border-top: 1px solid var(--border);
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  min-height: var(--rapid-log-height);
}

.rapid-sig {
  width: 24px;
  text-align: center;
  color: var(--accent);
  font-weight: bold;
  font-size: 16px;
  cursor: pointer;
  user-select: none;
}

.rapid-sig sl-tooltip { display: contents; }

#rapid-log sl-input {
  flex: 1;
  --sl-input-background-color: transparent;
  --sl-input-border-color: var(--border);
  --sl-input-color: var(--text);
  --sl-input-font-family: var(--font);
  --sl-input-font-size-medium: 14px;
}

/* === Status Bar === */

#status-bar {
  height: var(--status-height);
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  font-size: 11px;
  color: var(--text-muted);
}

/* === Load More Button === */

.load-more {
  display: flex;
  justify-content: center;
  padding: 12px 0;
}

.btn-text {
  background: none;
  border: none;
  color: var(--sl-color-neutral-500, #999);
  cursor: pointer;
  font: inherit;
  padding: 0.5em 1em;
  font-size: 13px;
  opacity: 0.7;
}

.btn-text:hover {
  color: var(--sl-color-neutral-300, #ccc);
  opacity: 1;
}

.btn-text:focus-visible {
  outline: 1px solid var(--sl-color-primary-600, #6cf);
  outline-offset: 2px;
}

.btn-text:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* === Empty / Start State === */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px;
  color: var(--text-muted);
  text-align: center;
}

.empty-state-splash {
  padding: 80px 48px;
  gap: 24px;
}

.empty-today-hint {
  padding: 24px 8px 32px;
  font-size: 15px;
  color: var(--text-muted);
  text-align: center;
}

.empty-state-message {
  font-size: 18px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.empty-state-shortcuts {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.empty-state-hint {
  display: flex;
  align-items: center;
  gap: 20px;
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0.6;
}

.empty-state-hint kbd {
  display: inline-block;
  min-width: 40px;
  text-align: right;
  color: var(--text);
  opacity: 1;
}

/* === New Collection Picker === */

.new-collection-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.new-collection-picker .shortcut-entry {
  font-size: 14px;
  padding: 4px 0;
}

.nc-error {
  color: var(--accent);
  font-size: 12px;
  margin-top: 6px;
  min-height: 16px;
}

/* === Shortcuts Dialog === */

.shortcuts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 24px;
}

.shortcut-group-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 12px 0 4px;
}

.shortcut-group-title:first-child { margin-top: 0; }

.shortcut-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 2px 0;
}

.shortcut-entry kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 5px;
  font-family: var(--font);
  font-size: 11px;
  text-align: center;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
}

#status-bar kbd {
  font-family: var(--font);
  font-size: 10px;
  padding: 0 3px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 2px;
}

/* === Scrollbar === */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Collection picker dialog === */

.collection-picker sl-menu-item::part(base) {
  font-family: var(--font);
  font-size: 13px;
}

/* === Responsive Sidebar === */

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 900;
  font-size: 24px;
  color: var(--text);
}

.sidebar-drawer {
  --size: var(--sidebar-width);
}

.sidebar-drawer::part(panel) {
  background: var(--bg-sidebar);
}

.sidebar-drawer::part(overlay) {
  backdrop-filter: blur(2px);
}

.sidebar-drawer::part(close-button) {
  color: var(--text-muted);
}

.sidebar-drawer #sidebar {
  border-right: none;
  height: 100%;
  /* Scrolling happens in #sidebar-content; keeps #sync-section pinned. */
  overflow: hidden;
}

@media (max-width: 768px) {
  .sidebar-toggle {
    display: block;
  }

  #app {
    grid-template-columns: 1fr;
  }

  #app > #sidebar {
    display: none;
  }

  #view {
    padding: 48px 16px 16px;
  }

  #rapid-log {
    padding: 8px 16px;
  }
}
