/* ==========================================================================
   Session Rail - Horizontal Carousel
   ========================================================================== */

/* Wraps the rail + session views so we can swap the rail position without
   touching the rail or view components themselves. Four positions:
     rail-top    — rail above messages (default)
     rail-bottom — rail under everything (below the input bar)
     rail-left   — rail down the left side
     rail-right  — rail down the right side
   The DOM is `.dashboard-body > .session-rail-container > .session-rail`
   (with `.session-views-container` as the rail-container's sibling). For
   left/right we make the rail-container the column-sized flex item; for
   top/bottom we flip the dashboard-body's main axis (column / column-reverse). */
.dashboard-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.dashboard-body.rail-top    { flex-direction: column; }
.dashboard-body.rail-bottom { flex-direction: column-reverse; }
.dashboard-body.rail-left   { flex-direction: row; }
.dashboard-body.rail-right  { flex-direction: row-reverse; }

.session-rail {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg-darker);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

/* In bottom-position mode the rail sits under the views/input so the
   horizontal divider line lives on its top edge instead of its bottom. */
.dashboard-body.rail-bottom .session-rail {
    border-bottom: none;
    border-top: 1px solid var(--border);
}

/* Vertical positions (left/right): the rail becomes a 240px-wide column.
   The actual direct child of `.dashboard-body` is `.session-rail-container`
   (which wraps the rail plus the floating dropdown and dialogs), so the
   column-sized box is applied to that wrapper. The inner `.session-rail` is
   then styled via a descendant combinator to switch its flex direction and
   scrolling axis.

   `!important` on the rail's flex-direction and overflow keeps the column
   direction sticky against the base rule's `overflow-x: auto`, which on
   some browser cascades has shadowed the override. */
.dashboard-body.rail-left  > .session-rail-container,
.dashboard-body.rail-right > .session-rail-container {
    width: 200px;
    min-width: 200px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.dashboard-body.rail-left  > .session-rail-container { border-right: 1px solid var(--border); }
.dashboard-body.rail-right > .session-rail-container { border-left:  1px solid var(--border); }

.dashboard-body.rail-left .session-rail,
.dashboard-body.rail-right .session-rail {
    flex: 1;
    flex-direction: column !important;
    align-items: stretch;
    gap: 0.35rem;
    padding: 0.75rem 0.5rem;
    border-bottom: none;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    width: auto;
    min-height: 0;
}

.dashboard-body.rail-left .session-pill,
.dashboard-body.rail-right .session-pill {
    /* Same 200px width as horizontal mode — set by the base `.session-pill`
       rule above. We only need to allow per-pill text wrapping here. */
    white-space: normal;
}

/* Flip the active/inactive divider so it reads horizontally inside the
   vertical column rather than vertically across it. */
.dashboard-body.rail-left .session-rail-divider,
.dashboard-body.rail-right .session-rail-divider {
    flex-direction: row;
    align-self: stretch;
    width: 100%;
    justify-content: center;
    padding: 0.25rem 0;
}

.dashboard-body.rail-left .session-rail-divider .divider-line,
.dashboard-body.rail-right .session-rail-divider .divider-line {
    width: auto;
    height: 1px;
    flex: 1;
    margin: 0 0.35rem;
    align-self: center;
}

/* Divider between active and inactive sessions */
.session-rail-divider {
    display: flex;
    align-items: center;
    align-self: stretch;
    gap: 0.25rem;
    padding: 0 0.25rem;
    cursor: pointer;
    flex-shrink: 0;
}

.session-rail-divider .divider-line {
    width: 1px;
    align-self: stretch;
    margin: 0.35rem 0;
    background: var(--border);
}

.session-rail-divider .divider-toggle {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.7rem;
    padding: 0.15rem 0.35rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.session-rail-divider .divider-toggle:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.session-rail-divider.collapsed .divider-toggle {
    background: rgba(0, 0, 0, 0.2);
}

.session-pill {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.55rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: 20px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    flex-shrink: 0;
    overflow: hidden;
    width: 180px;
    box-sizing: border-box;
}

/* Agent-type watermark — large logo anchored to the pill's left edge,
   clipped by the pill's overflow:hidden, behind all foreground content.
   Sized at 80% of the previous 80×80 (so 64×64); the new `left: -16px`
   keeps the icon's horizontal center at x=16 in pill coords so the visual
   centering doesn't drift across the resize. Vertical center is held by
   `top: 50%` + `translateY(-50%)`, which is size-agnostic. */
.pill-watermark {
    position: absolute;
    left: -16px;
    top: 50%;
    transform: translateY(-50%);
    width: 64px;
    height: 64px;
    pointer-events: none;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.22;
    z-index: 0;
}
.pill-watermark.claude { background-image: url('/anthropic-mark.svg'); }
.pill-watermark.codex  { background-image: url('/openai-mark.png'); }

.session-pill:hover {
    border-color: var(--accent);
    background: rgba(122, 162, 247, 0.1);
}

.session-pill.focused {
    border-color: var(--accent);
    background: rgba(122, 162, 247, 0.18);
    box-shadow: 0 0 0 2px rgba(122, 162, 247, 0.5);
}

.session-pill.awaiting {
    border-color: var(--error);
}

.session-pill.focused.awaiting {
    /* Focus state dominates — keep the blue ring/background; the indicator
       glyph alone signals "still waiting". */
    border-color: var(--accent);
    background: rgba(122, 162, 247, 0.18);
}

.pill-indicator {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.session-pill.awaiting .pill-indicator {
    color: var(--error);
}

.pill-name {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.pill-folder {
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pill-hostname-row {
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
    overflow: hidden;
}

.pill-hostname {
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pill-hostname-row .pill-version-badge {
    font-size: 0.55rem;
    flex-shrink: 0;
}

.pill-branch {
    font-size: 0.7rem;
    color: var(--accent);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
    direction: rtl;
    text-align: left;
}



.pill-branch.pill-no-vcs {
    color: var(--text-muted);
    font-style: normal;
    font-size: 0.65rem;
}

.session-pill.status-disconnected .pill-branch {
    color: var(--text-secondary);
}

/* Sparkline - activity ticks at bottom of pill */
.pill-sparkline {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 5px;
    pointer-events: none;
}

.sparkline-tick {
    position: absolute;
    bottom: 0;
    width: 3px;
    height: 100%;
    opacity: 1;
    border-radius: 1px;
    transform: translateZ(0);
}

.sparkline-tick.tick-assistant { background: var(--accent); }
.sparkline-tick.tick-user { background: var(--success); }
.sparkline-tick.tick-result { background: #e0af68; }
.sparkline-tick.tick-portal { background: #7dcfff; }
.sparkline-tick.tick-error { background: var(--error); }
.sparkline-tick.tick-other { background: var(--text-secondary); }

.sparkline-range {
    position: absolute;
    bottom: 0;
    height: 100%;
    opacity: 0.5;
    border-radius: 1px;
    transform: translateZ(0);
}

.sparkline-range.tick-compaction { background: var(--text-secondary); }
.sparkline-range.tick-task { background: #bb9af7; }

.session-pill.hidden .sparkline-tick,
.session-pill.hidden .sparkline-range {
    opacity: 0.2;
}

.pill-status {
    font-size: 0.6rem;
    line-height: 1;
}

.pill-status.connected {
    color: var(--success);
}

.pill-status.disconnected {
    color: var(--text-secondary);
}

/* Disconnected session (DB status) styling */
.session-pill.status-disconnected {
    opacity: 0.6;
    background: rgba(127, 132, 156, 0.1);
    border-color: var(--text-secondary);
}

.session-pill.status-disconnected:hover {
    opacity: 0.8;
    background: rgba(127, 132, 156, 0.15);
}

.session-pill.status-disconnected.focused {
    opacity: 0.85;
    border-color: var(--text-secondary);
    box-shadow: 0 0 0 2px rgba(127, 132, 156, 0.3);
}

.session-pill.status-disconnected .pill-folder,
.session-pill.status-disconnected .pill-hostname,
.session-pill.status-disconnected .pill-name {
    color: var(--text-secondary);
}

/* Hidden session styling - more greyed out, no awaiting highlight */
.session-pill.hidden {
    opacity: 0.35;
    border-style: dashed;
    filter: grayscale(50%);
}

.session-pill.hidden:hover {
    opacity: 0.55;
    filter: grayscale(30%);
}

.session-pill.hidden.focused {
    opacity: 0.5;
    filter: grayscale(40%);
}

/* Hidden sessions should NOT show awaiting (red) highlighting */
.session-pill.hidden.awaiting {
    border-color: var(--border);
    animation: none;
    box-shadow: none;
}

.session-pill.hidden.focused.awaiting {
    border-color: var(--text-secondary);
    background: rgba(127, 132, 156, 0.15);
}

.pill-hidden-badge {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.pill-agent-badge {
    font-size: 0.6rem;
    font-weight: 600;
    padding: 0 0.3rem;
    border-radius: 3px;
    flex-shrink: 0;
}

.pill-agent-badge.codex {
    color: #0a4;
    background: rgba(0, 170, 68, 0.15);
}

.pill-agent-badge.cron {
    color: var(--accent);
    background: rgba(125, 207, 255, 0.15);
}

.pill-agent-badge.paused {
    color: #e0af68;
    background: rgba(224, 175, 104, 0.15);
}

/* Version staleness badge */
.pill-version-badge {
    font-size: 0.6rem;
    font-weight: 600;
    padding: 0 0.3rem;
    border-radius: 3px;
    flex-shrink: 0;
}

.pill-version-badge.version-current {
    color: var(--text-secondary);
    background: transparent;
    opacity: 0.5;
}

.pill-version-badge.version-patch {
    color: #e0af68;
    background: rgba(224, 175, 104, 0.15);
}

.pill-version-badge.version-minor {
    color: #ff9e64;
    background: rgba(255, 158, 100, 0.15);
}

.pill-version-badge.version-major {
    color: #f7768e;
    background: rgba(247, 118, 142, 0.15);
}

/* Token expiry warning badge */
.pill-token-warning {
    font-size: 0.75rem;
    flex-shrink: 0;
    cursor: help;
    color: #e0af68;
}

.pill-token-warning.critical {
    color: #ff9e64;
}

.pill-token-warning.expired {
    color: #f7768e;
}

/* Pill menu toggle (▼ button). Positioned above pill-name in stacking order
   so overflowing folder/branch text can't visually cover the dropdown affordance. */
.pill-menu-toggle {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.6rem;
    cursor: pointer;
    padding: 0.2rem 0.3rem;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.pill-menu-toggle:hover {
    color: var(--text-primary);
    background: rgba(122, 162, 247, 0.2);
}

/* Pill dropdown menu - fixed positioning to escape rail overflow clipping.
   Always in DOM, toggled by .open class (same pattern as send button dropdown). */
.pill-dropdown {
    position: fixed;
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 6px;
    min-width: 160px;
    display: none;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 100;
}

.pill-dropdown.open {
    display: flex;
}

.pill-menu-option {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 0.6rem 0.8rem;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.pill-menu-option:hover {
    background: rgba(122, 162, 247, 0.15);
}

.pill-menu-option.stop {
    color: var(--error);
}

.pill-menu-option.stop:hover {
    background: rgba(247, 118, 142, 0.15);
}

.pill-menu-option.stop.confirming {
    background: rgba(247, 118, 142, 0.2);
    font-weight: 600;
}

.pill-menu-option.hide.active {
    color: var(--success);
}

.pill-menu-option.hide.active:hover {
    background: rgba(158, 206, 106, 0.15);
}

.pill-menu-option.leave {
    color: #e0af68;
}

.pill-menu-option.leave:hover {
    background: rgba(224, 175, 104, 0.15);
}

.pill-menu-option.copy-id .option-hint {
    font-family: monospace;
}

.pill-menu-option.copy-id.copied {
    color: var(--success);
}

a.pill-menu-option.pr-link {
    text-decoration: none;
    color: #7aa2f7;
}

a.pill-menu-option.pr-link:hover {
    background: rgba(122, 162, 247, 0.15);
}

.pill-menu-option.disabled {
    color: var(--text-muted);
    cursor: default;
}

.pill-menu-option.disabled:hover {
    background: transparent;
}

.pill-menu-option .option-hint {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

/* Number annotation for nav mode (1-9 keys) */
.pill-number {
    display: none;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 1rem;
    font-weight: 700;
    color: var(--bg-primary);
    background: var(--accent);
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    font-family: monospace;
    align-items: center;
    justify-content: center;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.session-pill.nav-mode .pill-number {
    display: flex;
}

/* Nav mode selection highlight */
.session-pill.nav-mode.focused {
    border-color: var(--accent);
    background: rgba(122, 162, 247, 0.25);
    box-shadow: 0 0 0 3px rgba(122, 162, 247, 0.4);
}

/* ==========================================================================
   Role Badge (for shared sessions)
   ========================================================================== */

.pill-role-badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.pill-role-badge.role-editor {
    background: rgba(224, 175, 104, 0.3);
    color: #e0af68;
}

.pill-role-badge.role-viewer {
    background: rgba(127, 132, 156, 0.3);
    color: var(--text-secondary);
}

/* ==========================================================================
   Share / Leave Buttons
   ========================================================================== */

.pill-share {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.pill-share:hover {
    background: rgba(122, 162, 247, 0.2);
    color: var(--accent);
}

.pill-share:active {
    background: rgba(122, 162, 247, 0.3);
}
