/* ═══════════════════════════════════════════════════════════════
   CLOTO NAV — Sidebar Rail + Contextual Top Bar
   ═══════════════════════════════════════════════════════════════ */

/* ══════════════════════════════════════════════════════════════
   SIDEBAR RAIL (48px, fixed left)
   ══════════════════════════════════════════════════════════════ */

.cloto-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--cloto-glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--cloto-glass-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-8) 0;
  z-index: var(--cloto-z-header);
  transition: transform var(--duration-normal) var(--ease-spring),
              opacity var(--duration-normal) var(--ease-spring);
}

.cloto-sidebar-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cloto-text-40);
  background: transparent;
  border: none;
  cursor: pointer;
  margin-bottom: var(--space-4);
  transition: all var(--duration-fast) var(--ease-spring);
  position: relative;
}

.cloto-sidebar-btn:hover {
  color: var(--cloto-text-70);
  background: var(--cloto-teal-a6);
}

.cloto-sidebar-btn.active {
  color: var(--cloto-teal);
  background: var(--cloto-teal-a10);
}

.cloto-sidebar-btn svg {
  display: block;
  pointer-events: none;
}

/* Tooltip on hover */
.cloto-sidebar-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--cloto-text-100);
  background: var(--cloto-surface);
  border: 1px solid var(--cloto-glass-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-fast) var(--ease-default);
  z-index: 10;
}

.cloto-sidebar-btn:hover::after {
  opacity: 1;
}

/* Spacer between top and bottom groups */
.cloto-sidebar-spacer {
  flex: 1;
}

/* Save status dot in sidebar */
.cloto-sidebar-save-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: transparent;
  margin-bottom: var(--space-4);
  transition: background var(--duration-slow) var(--ease-default),
              box-shadow var(--duration-slow) var(--ease-default);
}

.cloto-sidebar-save-dot.is-saving {
  background: var(--cloto-gold);
  box-shadow: var(--shadow-glow-gold);
  animation: cloto-save-pulse 0.8s ease-in-out infinite;
}

.cloto-sidebar-save-dot.is-flash {
  background: var(--cloto-success);
  box-shadow: 0 0 6px var(--cloto-success-a50);
  animation: cloto-dot-flash 1.5s var(--ease-default) forwards;
}

/* ── Light theme ── */
body.fd-light .cloto-sidebar {
  background: var(--cloto-white-a85);
  border-right-color: var(--cloto-surface-a8);
}

body.fd-light .cloto-sidebar-btn {
  color: #8a8a96;
}

body.fd-light .cloto-sidebar-btn:hover {
  color: #3a3c48;
  background: var(--cloto-teal-a6);
}

body.fd-light .cloto-sidebar-btn.active {
  color: var(--cloto-teal);
  background: var(--cloto-teal-a10);
}

body.fd-light .cloto-sidebar-btn::after {
  background: #ffffff;
  border-color: var(--cloto-surface-a8);
  color: #2a2c38;
}

/* Theme toggle in sidebar — show correct icon per theme */
.cloto-sidebar-btn[data-section="theme"] .fd-theme-icon--light { display: block; }
.cloto-sidebar-btn[data-section="theme"] .fd-theme-icon--dark  { display: none; }
body.fd-light .cloto-sidebar-btn[data-section="theme"] .fd-theme-icon--light { display: none; }
body.fd-light .cloto-sidebar-btn[data-section="theme"] .fd-theme-icon--dark  { display: block; }

/* ══════════════════════════════════════════════════════════════
   ZEN MODE — Sidebar auto-hide
   ══════════════════════════════════════════════════════════════ */

body.cloto-zen-active .cloto-sidebar {
  transform: translateX(calc(-1 * var(--sidebar-width)));
  opacity: 0;
  pointer-events: none;
}

body.cloto-zen-active .cloto-sidebar.cloto-sidebar-peek {
  transform: translateX(0);
  opacity: 0.85;
  pointer-events: auto;
}

body.cloto-zen-active .cloto-main {
  margin-left: 0;
}

/* Zen: topbar becomes transparent, minimal */
.cloto-topbar--immersive {
  background: transparent;
  border-bottom-color: transparent;
  opacity: 0.4;
  transition: opacity var(--duration-normal) var(--ease-spring);
}

.cloto-topbar--immersive:hover {
  opacity: 1;
}

/* Hover trigger zone (invisible, catches mouse on left edge) */
.cloto-sidebar-trigger {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 8px;
  z-index: calc(var(--cloto-z-header) + 1);
}

body.cloto-zen-active .cloto-sidebar-trigger {
  display: block;
}

/* ══════════════════════════════════════════════════════════════
   TOP BAR (36px, contextual)
   ══════════════════════════════════════════════════════════════ */

.cloto-topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-16);
  background: var(--cloto-glass-bg);
  border-bottom: 1px solid var(--cloto-glass-border);
  font-size: var(--cloto-fs-sm);
  color: var(--cloto-text-40);
  flex-shrink: 0;
  z-index: 1;
}

.cloto-topbar__left,
.cloto-topbar__center,
.cloto-topbar__right {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  min-width: 0;
}

.cloto-topbar__left {
  flex: 1;
}

.cloto-topbar__center {
  flex: 0 1 auto;
  justify-content: center;
}

.cloto-topbar__right {
  flex: 1;
  justify-content: flex-end;
  flex-shrink: 0;
}

.cloto-topbar__title {
  font-weight: 500;
  color: var(--cloto-text-70);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cloto-topbar__subtitle {
  color: var(--cloto-text-40);
  font-size: var(--cloto-fs-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cloto-topbar__spectator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-6);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--cloto-gold);
  background: var(--cloto-gold-a10);
  border: 1px solid var(--cloto-gold-a20);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.cloto-topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-6);
  font-size: var(--cloto-fs-xs);
  font-weight: 500;
  color: var(--cloto-text-40);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-spring);
  white-space: nowrap;
}

.cloto-topbar-btn:hover {
  color: var(--cloto-text-70);
  background: var(--cloto-teal-a6);
  border-color: var(--cloto-glass-border);
}

.cloto-topbar-btn svg {
  display: block;
  flex-shrink: 0;
}


/* ── Light theme topbar ── */
body.fd-light .cloto-topbar {
  background: var(--cloto-white-a85);
  border-bottom-color: var(--cloto-surface-a6);
  color: #6a6a76;
}

body.fd-light .cloto-topbar__title {
  color: #2a2c38;
}

body.fd-light .cloto-topbar-btn {
  color: #6a6a76;
}

body.fd-light .cloto-topbar-btn:hover {
  color: #2a2c38;
  background: var(--cloto-teal-a6);
}

/* ══════════════════════════════════════════════════════════════
   MAIN WRAPPER (margin-left for sidebar)
   ══════════════════════════════════════════════════════════════ */

.cloto-main {
  margin-left: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  transition: margin-left var(--duration-normal) var(--ease-spring);
}

.cloto-content {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  position: relative;
}

/* Section roots: hidden by default, shown with .is-active */
.cloto-content > [id$="-root"] {
  display: none;
  flex: 1 1 0;
  min-height: 0;
  overflow: auto;
}

.cloto-content > [id$="-root"].is-active {
  display: flex;
  flex-direction: column;
}

/* Outline root: no scroll here — grid children handle their own scroll */
#fbw-outline-root.is-active {
  overflow: hidden;
}

/* Splash root: full-viewport overlay when active
   z-index between header (300) and modal (500) so prompts appear on top */
#fbw-splash-root.is-active {
  position: fixed;
  inset: 0;
  z-index: var(--cloto-z-drawer);
  overflow: auto;
  background: var(--cloto-void);
}

/* Roots that need flex column layout when active */
#fbw-outline-root.is-active,
#fbw-settings-root.is-active,
#fbw-wizard-root.is-active,
#fbw-zen-root.is-active {
  display: flex;
  flex-direction: column;
}

/* Wizard + outline + zen roots: no overflow on root — children scroll internally */
#fbw-wizard-root.is-active,
#fbw-outline-root.is-active,
#fbw-zen-root.is-active {
  overflow: hidden;
}

/* Zen: remove padding/gap from content area for full immersion */
body.cloto-zen-active .cloto-content {
  padding: 0;
  gap: 0;
}

/* Draft root: placeholder only, never competes for flex space */
#fbw-draft-root.is-active {
  flex: none;
}

/* ══════════════════════════════════════════════════════════════
   ADJUSTMENTS — Existing content adapts to new wrapper
   ══════════════════════════════════════════════════════════════ */

/* Outline container fills content area via flex */
#fbw-outline-root > .fbw-outline-container {
  flex: 1 1 0;
  min-height: 0;
}

/* Characters/Locations fill content */
.cloto-main #fbw-characters-root,
.cloto-main #fbw-locations-root {
  padding: var(--space-8);
}

/* Settings fills content */
.cloto-main #fbw-settings-root {
  padding: 0;
}

/* ══════════════════════════════════════════════════════════════
   MOBILE — Bottom tab bar (< 768px)
   ══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  .cloto-sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: var(--sidebar-width);
    flex-direction: row;
    justify-content: space-around;
    padding: 0;
    border-right: none;
    border-top: 1px solid var(--cloto-glass-border);
    z-index: var(--cloto-z-header);
  }

  .cloto-sidebar-btn {
    margin-bottom: 0;
  }

  .cloto-sidebar-spacer {
    display: none;
  }

  /* Hide bottom group items that don't fit on mobile — settings conditioned by JS, project via menu */
  .cloto-sidebar-bottom .cloto-sidebar-btn[data-section="project"] {
    display: none;
  }

  .cloto-sidebar-btn::after {
    display: none;
  }

  .cloto-sidebar-save-dot {
    display: none;
  }

  .cloto-main {
    margin-left: 0;
    margin-bottom: var(--sidebar-width);
    height: calc(100vh - var(--sidebar-width));
    height: calc(100dvh - var(--sidebar-width));
  }

  .cloto-topbar {
    padding: 0 var(--space-8);
  }

  /* Zen mode on mobile — sidebar stays hidden */
  body.cloto-zen-active .cloto-sidebar {
    transform: translateY(var(--sidebar-width));
  }

  body.cloto-zen-active .cloto-main {
    margin-bottom: 0;
  }

  body.cloto-zen-active .cloto-sidebar-trigger {
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: 8px;
  }

  /* V2 mobile: hide sidebar entirely (not bottom tab bar) */
  body:has(.fbw-outline-v2) .cloto-sidebar {
    display: none;
  }
  body:has(.fbw-outline-v2) .cloto-main {
    margin-left: 0;
    margin-bottom: 0;
    height: 100vh;
    height: 100dvh;
  }
}

/* ══════════════════════════════════════════════════════════════
   SECTION TRANSITION (fade on switch)
   ══════════════════════════════════════════════════════════════ */

.cloto-content > [id$="-root"] {
  opacity: 0;
  transition: opacity 150ms ease;
}

.cloto-content > [id$="-root"].is-active {
  opacity: 1;
}

/* ══════════════════════════════════════════════════════════════
   SIDEBAR NOTIFICATION BADGES
   ══════════════════════════════════════════════════════════════ */

.cloto-sidebar-btn .cloto-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  pointer-events: none;
}

.cloto-badge--info {
  background: var(--cloto-teal);
  box-shadow: 0 0 4px var(--cloto-teal-a50);
}

.cloto-badge--warning {
  background: var(--cloto-warning);
  box-shadow: 0 0 4px rgba(251, 191, 36, 0.5);
}

.cloto-badge--active {
  background: var(--cloto-gold);
  box-shadow: 0 0 4px rgba(212, 168, 83, 0.5);
  animation: cloto-badge-pulse 1.5s ease-in-out infinite;
}

@keyframes cloto-badge-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.3); }
}

/* ══════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ══════════════════════════════════════════════════════════════ */

.cloto-toast-container {
  position: fixed;
  bottom: var(--space-12);
  right: var(--space-12);
  z-index: var(--cloto-z-toast, 10000);
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-4);
  pointer-events: none;
}

.cloto-toast {
  padding: var(--space-4) var(--space-10);
  font-size: var(--cloto-fs-sm);
  font-weight: 500;
  border-radius: var(--radius-md);
  background: var(--cloto-surface);
  border: 1px solid var(--cloto-glass-border);
  color: var(--cloto-text-100);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms ease, transform 200ms ease;
}

.cloto-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.cloto-toast--success {
  border-color: rgba(74, 222, 128, 0.3);
  color: var(--cloto-success);
}

.cloto-toast--error {
  border-color: rgba(248, 113, 113, 0.3);
  color: var(--cloto-danger);
}

.cloto-toast--info {
  border-color: var(--cloto-teal-a20);
}

/* ══════════════════════════════════════════════════════════════
   THEME CROSS-FADE TRANSITION
   ══════════════════════════════════════════════════════════════ */

.cloto-theme-transition .cloto-sidebar,
.cloto-theme-transition .cloto-topbar {
  transition: background 1s var(--ease-default),
              border-color 1s var(--ease-default),
              color 1s var(--ease-default);
}

/* ══════════════════════════════════════════════════════════════
   WIZARD CARD BREADCRUMB (topbar center)
   ══════════════════════════════════════════════════════════════ */

.wiz-card-breadcrumb {
  font-size: var(--cloto-fs-xs);
  color: var(--cloto-text-40);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
  letter-spacing: 0.01em;
}

/* ══════════════════════════════════════════════════════════════
   LAYOUT V2 — Topbar hidden, kanban gets its own header
   ══════════════════════════════════════════════════════════════ */

/* Hide global topbar when V2 layout is active */
body:has(.fbw-outline-v2) .cloto-topbar {
  display: none;
}

/* Kanban header (replaces topbar for kanban zone) */
.fbw-v2-kanban-header {
  flex-shrink: 0;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  border-bottom: 1px solid var(--cloto-glass-border);
  font-size: var(--cloto-fs-sm);
  color: var(--cloto-text-40);
}

.fbw-v2-kanban-header__title {
  font-weight: 500;
  color: var(--cloto-text-70);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fbw-v2-kanban-header__badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-5);
  font-size: var(--cloto-fs-2xs);
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--cloto-gold);
  background: var(--cloto-gold-a10);
  border: 1px solid var(--cloto-gold-a20);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

body.fd-light .fbw-v2-kanban-header {
  border-bottom-color: var(--cloto-surface-a6);
}

/* ══════════════════════════════════════════════════════════════
   LAYOUT V2 — Responsive breakpoints
   ══════════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
  .fbw-outline-v2 {
    grid-template-columns: 250px 1fr;
  }
  .fbw-outline-v2 .fbw-col {
    flex: 0 0 180px;
    width: 180px;
  }
}

@media (max-width: 768px) {
  .fbw-outline-v2 {
    grid-template-columns: 1fr;
    transition: none;
  }
  .fbw-outline-v2 .fbw-v2-kanban {
    display: none;
  }
}
