/* ─────────────────────────────────────────────────────────────────
   Lock-In chrome — top nav + left rail.

   Static layout:  the rail is a permanent column (no slide animation,
   no overlay). When .collapsed is set the rail is hidden via
   `display:none` and the body's left padding is removed — this is a
   layout change, not a transition, so it never feels animated.

   Default state: the rail is OPEN.
   ────────────────────────────────────────────────────────────────── */


:root {
  --top-nav-h: 40px;
  --rail-w: 232px;
}

body {
  /* Reserve top-nav height + rail width — sidebar is permanent. */
  padding-top: var(--top-nav-h);
  padding-left: var(--rail-w);
}

/* If we ever render without the sidebar (e.g. onboarding), reclaim the space. */
body:not(:has(.main-sidebar)) { padding-left: 0; }


/* ── Top navigation ─────────────────────────────────────────── */

.top-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--top-nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-3, 12px);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  font-size: 13px;
  transition: right 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

/* When AI panel is open, push the top-nav so its right-side actions stay visible
   beside the panel — the panel covers from y=0 down, but the nav still owns the
   strip to its left. */
body.ai-right-sidebar-open .top-nav {
  right: var(--ai-right-sidebar-width);
  border-right: 1px solid var(--border);
}

.top-nav__group {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.top-nav__brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  margin: 0 4px 0 2px;
  border-radius: 4px;
  transition: background 120ms ease;
}

.top-nav__brand:hover { background: var(--surface-2); }
.top-nav__brand img { display: block; }

.top-nav__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: background 120ms ease, color 120ms ease;
  position: relative;
}

.top-nav__icon:hover { background: var(--surface-2); color: var(--text); }
.top-nav__icon .fas, .top-nav__icon .fab { font-size: 13px; }

.top-nav__icon.is-active { background: var(--surface-2); color: var(--text); }


/* Pill buttons (Focus / AI) — visible label + icon, sits between page actions and the icon strip. */

.top-nav__pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--text);
  cursor: pointer;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.top-nav__pill:hover { background: var(--surface-2); }
.top-nav__pill .fas, .top-nav__pill .fab { font-size: 11px; }

.top-nav__pill--focus {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.top-nav__pill--focus:hover { filter: brightness(1.08); background: var(--primary); }

.top-nav__pill--ai {
  background: var(--bg);
}

.top-nav__links {
  display: flex;
  align-items: center;
  gap: 0;
  margin-left: 6px;
}

.top-nav__link {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 4px;
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease;
}

.top-nav__link:hover { color: var(--text); background: var(--surface-2); }

.top-nav__link.is-active {
  color: var(--text-strong);
  background: var(--surface-2);
}

.top-nav__page-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
  min-height: 26px;
}

.top-nav__page-actions:empty {
  display: none;
  margin: 0;
  padding: 0;
  border: 0;
}

.top-nav__avatar {
  width: 26px; height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  transition: filter 120ms ease;
}

.top-nav__avatar:hover { filter: brightness(1.1); }
.top-nav__avatar.is-active { box-shadow: 0 0 0 2px var(--primary-bg); }


/* Notification badge tweak — keep position relative to new icon */
.top-nav .notification-bell-container { position: relative; }
.top-nav .notification-badge {
  position: absolute;
  top: 2px; right: 2px;
  min-width: 14px; height: 14px;
  padding: 0 3px;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  font-size: 9px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}


/* ── Left rail (.main-sidebar reuse, new layout) ─────────────── */

.main-sidebar {
  position: fixed;
  top: var(--top-nav-h);
  left: 0;
  bottom: 0;
  width: var(--rail-w) !important;
  background: var(--surface);
  /* No border-right — surface vs bg already gives visual separation. */
  border-right: 0 !important;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  z-index: 900;
  padding: 0 !important;
  height: auto !important;
  /* Hard-disable all animation/transition on the rail and its children. */
  transition: none !important;
  animation: none !important;
  transform: none !important;
}

.main-sidebar,
.main-sidebar *,
.main-sidebar *::before,
.main-sidebar *::after {
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease, filter 120ms ease !important;
  animation: none !important;
}

/* Hidden state is layout-only (no transform, no opacity fade). */
.main-sidebar.collapsed {
  display: none !important;
  width: 0 !important;
}

.main-sidebar * { box-sizing: border-box; }


/* ── Rail sections ───────────────────────────────────────────── */

.rail-section {
  padding: 8px 12px;
}

.rail-section + .rail-section {
  /* No hard divider between sections — keep it airy. */
  padding-top: 4px;
}

.rail-section__head {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-subtle);
  margin-bottom: 6px;
  letter-spacing: 0;
  text-transform: none;
  padding: 2px 4px;
}


/* ── Lock-in launcher (top of rail) ──────────────────────────── */

.rail-focus {
  padding: 10px 12px 4px;
}

.rail-focus__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 32px;
  padding: 0 12px;
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.rail-focus__btn:hover { filter: brightness(1.08); }
.rail-focus__btn .fas { font-size: 11px; }


/* ── Mini calendar ───────────────────────────────────────────── */

.rail-mini-cal {
  padding: 12px;
}

.mc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.mc-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.mc-nav { display: flex; gap: 2px; }

.mc-nav__btn {
  width: 22px; height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.mc-nav__btn:hover { background: var(--surface-2); color: var(--text); }
.mc-nav__btn .fas { font-size: 11px; }

.mc-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.mc-dow {
  text-align: center;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-subtle);
  padding: 4px 0 2px;
  text-transform: uppercase;
}

.mc-day {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 24px;
  background: transparent;
  border: 0;
  border-radius: 4px;
  font-size: 11.5px;
  color: var(--text);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
  font-feature-settings: "tnum" on;
}

.mc-day:hover { background: var(--surface-2); }
.mc-day--off { color: var(--text-subtle); }

.mc-day--today {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.mc-day--selected:not(.mc-day--today) {
  background: var(--surface-2);
  color: var(--text-strong);
  outline: 1px solid var(--border-2);
  outline-offset: -1px;
}


/* ── Quick add row — Notion-density with microinteractions ─────────── */

.rail-quick-add { padding: 6px 12px 10px; }

.rail-quick-add__form {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 10px;
  background: var(--bg);
  /* Stronger border so the input reads as an actionable control on every
     page. Light: dark-grey hairline; dark: near-white hairline (set in the
     overrides below). */
  border: 1.5px solid rgba(15, 23, 42, 0.42);
  border-radius: 6px;
  transition:
    border-color 180ms cubic-bezier(0.16, 1, 0.3, 1),
    background   180ms cubic-bezier(0.16, 1, 0.3, 1),
    box-shadow   180ms cubic-bezier(0.16, 1, 0.3, 1);
}

.rail-quick-add__form:hover {
  border-color: rgba(15, 23, 42, 0.62);
  background: var(--surface);
}

.rail-quick-add__form:focus-within {
  border-color: var(--primary, rgba(15, 23, 42, 0.78));
  background: var(--surface);
}

/* Dark mode: white-ish border so the input is just as visible against
   the dark sidebar background. */
body.dark-mode .rail-quick-add__form,
[data-theme="dark"] .rail-quick-add__form {
  border-color: rgba(255, 255, 255, 0.55);
}
body.dark-mode .rail-quick-add__form:hover,
[data-theme="dark"] .rail-quick-add__form:hover {
  border-color: rgba(255, 255, 255, 0.78);
}
body.dark-mode .rail-quick-add__form:focus-within,
[data-theme="dark"] .rail-quick-add__form:focus-within {
  border-color: #ffffff;
}

.rail-quick-add__icon {
  font-size: 11px;
  color: var(--text-subtle);
  transition: color 160ms ease;
}

.rail-quick-add__form:focus-within .rail-quick-add__icon {
  color: var(--text-muted);
}

.rail-quick-add__input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  box-shadow: none;
  font: inherit;
  font-size: 12.5px;
  color: var(--text);
  min-width: 0;
  transition: opacity 150ms ease;
}
.rail-quick-add__input:focus,
.rail-quick-add__input:focus-visible {
  outline: 0 !important;
  box-shadow: none !important;
  border: 0 !important;
}
.rail-quick-add__input:disabled { opacity: 0.5; }
.rail-quick-add__input::placeholder { color: var(--text-subtle); }

/* Minimalist feedback — just a brief border-color cue. The new task
   landing in the list IS the confirmation; this is just a soft echo. */
.rail-quick-add__form[data-state="ok"] {
  border-color: var(--primary);
}
.rail-quick-add__form[data-state="error"] {
  border-color: var(--danger);
  animation: railQuickAddShake 0.32s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes railQuickAddShake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-3px); }
  40%, 60% { transform: translateX(3px); }
}


/* ── Tools (only secondary buttons here now) ──────────────────── */

.rail-tools {
  padding: 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rail-tool {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 28px;
  padding: 0 8px;
  background: transparent;
  border: 0;
  border-radius: 4px;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  text-align: left;
  transition: background 120ms ease;
}

.rail-tool:hover { background: var(--surface-2); }

.rail-tool__icon {
  font-size: 12px;
  color: var(--text-muted);
  width: 14px;
  text-align: center;
}

.rail-tool__label { flex: 1; }


/* ── Today's compact list ────────────────────────────────────── */

.rail-today { padding: 8px 12px; }

.rail-today__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  padding: 2px 4px;
}

.rail-today__heading {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-subtle);
}

.rail-today__toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 18px;
  padding: 0 6px;
  background: transparent;
  border: 0;
  border-radius: 3px;
  color: var(--text-subtle);
  cursor: pointer;
  font-size: 10px;
  font-weight: 500;
  font-feature-settings: "tnum" on;
}

.rail-today__toggle:hover { background: var(--surface-2); color: var(--text-muted); }
.rail-today__toggle .fas { font-size: 10px; }
.rail-today__toggle[aria-pressed="true"] { color: var(--primary); }
.rail-today__toggle[aria-pressed="true"]:hover { background: var(--primary-bg); }

.rail-today__toggle-count:empty { display: none; }


.rail-today__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.rail-today__item {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 8px;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 0;
  font-size: 12px;
  color: var(--text);
  min-width: 0;
  transition:
    background 140ms ease,
    opacity    220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.rail-today__item:hover {
  background: var(--surface);
}
.rail-today__item.is-completing { opacity: 0.5; }

/* Completed: hidden by default; visible when list has .show-completed. */
.rail-today__item.is-done { display: none; color: var(--text-subtle); }
.rail-today__item.is-done .rail-today__title { text-decoration: line-through; }

.rail-today__list.show-completed .rail-today__item.is-done { display: grid; }


.rail-today__check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px; height: 14px;
  background: transparent;
  border: 1px solid var(--border-2);
  border-radius: 3px;
  color: transparent;
  cursor: pointer;
  padding: 0;
  transition:
    background 200ms cubic-bezier(0.16, 1, 0.3, 1),
    border-color 200ms ease,
    color 200ms ease,
    transform 120ms cubic-bezier(0.16, 1, 0.3, 1);
}

.rail-today__check:hover {
  color: var(--primary);
  border-color: var(--primary);
}
.rail-today__check .fas { font-size: 8px; }

.rail-today__check.is-checked {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  animation: trCheckPop 0.34s cubic-bezier(0.16, 1, 0.3, 1);
}

.rail-today__title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  outline: none;
  transition: color 140ms ease;
}
.rail-today__title:focus-visible { outline: none; }


/* ── Rail footer (bug + Discord) ─────────────────────────────── */

.rail-footer {
  margin-top: auto;
  padding: 8px 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-top: 1px solid var(--border);
}

.rail-foot-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 26px;
  padding: 0 8px;
  background: transparent;
  border: 0;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
  text-align: left;
  transition: background 120ms ease, color 120ms ease;
}

.rail-foot-btn:hover { background: var(--surface-2); color: var(--text); }
.rail-foot-btn .fas, .rail-foot-btn .fab { font-size: 11px; width: 14px; text-align: center; }


/* ── Notification dropdown re-anchor (stays attached to bell) ── */

.top-nav .notification-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 1100;
}


/* ── AI sidebar — full-viewport panel ────────────────────────────
   The panel spans top: 0 → 100dvh and sits at z-index 9000 (below the
   top-nav, but the top-nav is pushed left by `right: var(--ai-right-sidebar-width)`
   when open, so they end up side-by-side rather than overlapping. */


/* ── Hide legacy floating AI launcher (we put it in the top nav) */

#floatingAiAssistant { display: none !important; }


/* ── Defensive: rail is permanent. Even if a stale class lands on the
   element (bfcache restore, legacy script), the rail stays full-width and
   the body keeps reserving its column. Belt-and-suspenders for the JS in
   base-inline.js that strips `.collapsed` on load. */

.main-sidebar.collapsed {
  width: var(--rail-w) !important;
  display: flex !important;
}

body:has(.main-sidebar.collapsed) {
  padding-left: var(--rail-w) !important;
}


/* ── Responsive: on narrow screens we still allow the rail to span the
   viewport, but we never `display:none` it. Sidebar is permanent. */

@media (max-width: 720px) {
  .main-sidebar { width: 100%; }
  .main-sidebar.collapsed { display: flex !important; width: 100%; }
  .top-nav__links .top-nav__link { padding: 0 6px; font-size: 12px; }
}


/* ── Page-scoped sub-nav (Insights / Mental / etc.) ─────────────
   Lives above the rail-footer. Rendered when a child template fills
   {% block sidebar_title %} or {% block sidebar_nav %}. */

.rail-subnav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

.rail-subnav__head {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-subtle);
  letter-spacing: 0;
  padding: 2px 4px;
  margin-bottom: 2px;
}

.rail-subnav__nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.rail-subnav .nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 28px;
  padding: 0 8px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease;
  min-width: 0;
}

.rail-subnav .nav-item:hover {
  /* May-2026 foundation pass: accent-tinted hover so the rail's hover and
     active states share a colour family (was grey, felt washed-out in
     light mode). --primary-bg is theme-aware. */
  background: var(--primary-bg);
  color: var(--primary);
}

.rail-subnav .nav-item.active {
  background: var(--primary-bg);
  color: var(--primary);
}

.rail-subnav .nav-item .fas,
.rail-subnav .nav-item .fab {
  font-size: 11px;
  width: 14px;
  text-align: center;
  color: inherit;
}

.rail-subnav .nav-item span {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail-subnav .nav-item .group-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.rail-subnav .nav-item .group-type {
  font-size: 9px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-subtle);
  flex: 0 0 auto;
}

.rail-subnav .nav-item.active .group-type { color: var(--primary); opacity: 0.85; }

/* Collapsed sidebar — sub-nav uses icon-only treatment */
.main-sidebar.collapsed .rail-subnav__head { display: none; }
.main-sidebar.collapsed .rail-subnav .nav-item { justify-content: center; padding: 0; }
.main-sidebar.collapsed .rail-subnav .nav-item span,
.main-sidebar.collapsed .rail-subnav .nav-item .group-type { display: none; }
