/* ==========================================================================
   Session View - Main Terminal Area
   ========================================================================== */

/* Container holds all session views stacked */
.session-views-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Wrapper controls visibility of each session view */
.session-view-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.session-view-wrapper.hidden {
    display: none;
}

.session-view-wrapper.focused {
    /* Focused session is visible */
}

.session-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0; /* Prevent flex child from overflowing parent on rotation */
}

.session-view-body {
    --surface-basis: 50%;

    flex: 1;
    display: flex;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

.session-view-chat {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.session-view-body.has-surface .session-view-chat {
    flex: 1 1 calc(100% - var(--surface-basis));
}

.session-view-body.fullscreen .session-view-chat {
    display: none;
}

.session-view-body.surface-collapsed .session-view-chat {
    flex-basis: auto;
}

.session-surface-resize-handle {
    flex: 0 0 0.45rem;
    cursor: col-resize;
    position: relative;
    background: transparent;
}

.session-surface-resize-handle::before {
    content: "";
    position: absolute;
    inset: 0.5rem 0.18rem;
    border-radius: 999px;
    background: rgba(86, 95, 137, 0.55);
}

.session-surface-resize-handle:hover::before {
    background: rgba(122, 162, 247, 0.85);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.session-view-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--border);
}

.session-view-header .session-name {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
}

.session-view-header .session-hostname {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-secondary);
}

.session-view-header .session-path {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: monospace;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-view-header .session-model {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-family: monospace;
    padding: 0.2rem 0.45rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: rgba(187, 154, 247, 0.08);
    white-space: nowrap;
}

.session-view-header .session-launcher-version {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-family: monospace;
    padding: 0.2rem 0.45rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: rgba(122, 162, 247, 0.08);
    white-space: nowrap;
}

/* Header actions (Fork…) — a button, but it sits in the chip row, so it takes
   the same chip geometry as `.session-launcher-version` / `.forward-chip`
   rather than the browser default. Without this it rendered as a raw
   system-styled button: light background, square corners, wrong font. */
.session-view-header .session-header-action {
    font-size: 0.78rem;
    font-family: inherit;
    color: var(--text-secondary);
    padding: 0.2rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: rgba(187, 154, 247, 0.1);
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.session-view-header .session-header-action:hover {
    color: var(--text-primary);
    border-color: var(--accent);
    background: rgba(187, 154, 247, 0.18);
}

.session-view-header .session-header-action:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Port-forward chips (docs/PORT_FORWARDING.md) */
.session-view-header .session-forwards {
    display: inline-flex;
    gap: 0.35rem;
    align-items: center;
    flex-wrap: wrap;
}

.session-view-header .forward-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.78rem;
    font-family: monospace;
    padding: 0.15rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: rgba(125, 207, 255, 0.1);
    white-space: nowrap;
}

.session-view-header .forward-chip-open {
    appearance: none;
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    color: var(--text-teal, #7dcfff);
    text-decoration: none;
    cursor: pointer;
}

.session-view-header .forward-chip-open:hover {
    text-decoration: underline;
}

/* Live port health from the proxy's background probe, conveyed by color
   alone: a subtle breathing green while the port is live, flat red when the
   last probe was refused. */
.session-view-header .forward-chip.is-up {
    border-color: rgba(158, 206, 106, 0.6);
    background: rgba(158, 206, 106, 0.12);
    animation: forward-chip-breathe 2.8s ease-in-out infinite;
}

.session-view-header .forward-chip.is-up .forward-chip-open {
    color: var(--success, #9ece6a);
}

@keyframes forward-chip-breathe {
    0%,
    100% {
        background: rgba(158, 206, 106, 0.08);
        box-shadow: 0 0 0 rgba(158, 206, 106, 0);
    }

    50% {
        background: rgba(158, 206, 106, 0.22);
        box-shadow: 0 0 6px rgba(158, 206, 106, 0.35);
    }
}

@media (prefers-reduced-motion: reduce) {
    .session-view-header .forward-chip.is-up {
        animation: none;
    }
}

.session-view-header .forward-chip.is-down {
    border-color: rgba(247, 118, 142, 0.6);
    background: rgba(247, 118, 142, 0.12);
}

.session-view-header .forward-chip.is-down .forward-chip-open {
    color: var(--error, #f7768e);
}

.session-view-header .forward-chip-revoke {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    line-height: 1;
    font-size: 0.95rem;
}

.session-view-header .forward-chip-revoke:hover {
    color: var(--error);
}

.session-forward-surface {
    flex: 0 0 var(--surface-basis);
    position: relative;
    min-width: min(28rem, 50vw);
    max-width: 70%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-darker);
    border-left: 1px solid rgba(122, 162, 247, 0.45);
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.22);
}

.session-forward-surface.collapsed {
    flex-basis: 3rem;
    min-width: 3rem;
    max-width: 3rem;
}

.session-forward-surface.fullscreen {
    flex: 1 1 100%;
    min-width: 0;
    max-width: none;
    border-left: 0;
    box-shadow: none;
}

.session-forward-toolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.4rem;
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.18);
}

.surface-icon-button {
    appearance: none;
    flex: 0 0 auto;
    width: 1.6rem;
    height: 1.6rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
}

.surface-icon-button:hover {
    color: var(--text-primary);
    border-color: var(--border);
    background: rgba(122, 162, 247, 0.08);
}

.surface-close-button:hover {
    color: var(--error);
    border-color: rgba(247, 118, 142, 0.45);
    background: rgba(247, 118, 142, 0.08);
}

.surface-status {
    flex: 0 0 auto;
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 999px;
    background: var(--text-muted);
    opacity: 0.7;
}

.surface-status.is-up {
    background: var(--success, #9ece6a);
    opacity: 1;
}

.surface-status.is-down {
    background: var(--error, #f7768e);
    opacity: 1;
}

.session-forward-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
    font: 0.8rem var(--font-mono, monospace);
}

.session-forward-visit {
    flex: 0 0 auto;
    color: var(--text-teal, #7dcfff);
    font-size: 0.8rem;
    text-decoration: none;
    white-space: nowrap;
}

.session-forward-visit:hover {
    text-decoration: underline;
}

.session-forward-frame {
    flex: 1 1 auto;
    display: block;
    width: 100%;
    min-height: 0;
    border: 0;
    background: #fff;
}

.session-forward-surface.collapsed .surface-status,
.session-forward-surface.collapsed .session-forward-title,
.session-forward-surface.collapsed .surface-mode-button,
.session-forward-surface.collapsed .session-forward-visit,
.session-forward-surface.collapsed .surface-close-button {
    display: none;
}

.session-forward-surface.collapsed .session-forward-frame {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.session-view-header .status {
    font-size: 0.8rem;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
}

.session-view-header .status.connected {
    background: rgba(158, 206, 106, 0.2);
    color: var(--success);
}

.session-view-header .status.disconnected {
    background: rgba(247, 118, 142, 0.2);
    color: var(--error);
}

.session-view-header .session-cost {
    font-size: 0.85rem;
    font-family: monospace;
    color: var(--success);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    background: rgba(158, 206, 106, 0.1);
    transition: background 0.3s ease;
}

.session-view-header .session-cost.flash {
    animation: cost-flash 0.5s ease-out, cost-shake 0.4s ease-in-out;
}

@keyframes cost-flash {
    0% {
        background: rgba(158, 206, 106, 0.6);
    }
    100% {
        background: rgba(158, 206, 106, 0.1);
    }
}

@keyframes cost-shake {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    15% { transform: translateX(-2px) rotate(-2deg); }
    30% { transform: translateX(2px) rotate(2deg); }
    45% { transform: translateX(-2px) rotate(-1deg); }
    60% { transform: translateX(2px) rotate(1deg); }
    75% { transform: translateX(-1px) rotate(-0.5deg); }
    90% { transform: translateX(1px) rotate(0.5deg); }
}

.session-view-scroll-area {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
    min-height: 0;
    overscroll-behavior: contain;
}

.session-view-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 0.75rem 0 0.75rem;
    min-width: 0; /* Allow flex child to shrink below content size */
    overscroll-behavior: contain; /* Prevent iOS rubber-banding from escaping this container */
}

/* Floating "Jump to live" pill shown when the user has scrolled up.
   Clicking it re-arms auto-tailing and snaps the messages view to bottom. */
.jump-to-live-pill {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    padding: 0.4rem 0.9rem;
    background: var(--accent);
    color: var(--bg-dark);
    border: none;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    transition: transform 0.12s ease, background 0.12s ease;
}

.jump-to-live-pill:hover {
    background: var(--accent-hover);
    transform: translateX(-50%) translateY(-1px);
}

.jump-to-live-pill:active {
    transform: translateX(-50%) translateY(0);
}
.fork-lineage-card {
    margin: 0.75rem 1rem;
    padding: 0.65rem 0.8rem;
    border: 1px solid rgba(122, 162, 247, 0.35);
    border-radius: 8px;
    background: rgba(122, 162, 247, 0.08);
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.fork-lineage-card a {
    color: var(--accent-blue);
}
