/* ==========================================================================
   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 */
}

@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-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;
}

/* 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 a {
    color: var(--text-teal, #7dcfff);
    text-decoration: none;
}

.session-view-header .forward-chip a: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 a {
    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 a {
    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);
}

/* Inline preview overlay for the session's forward (opened from the chip).
   left/top/width come from inline style (draggable by the title bar,
   resizable by the corner grip); max-width keeps phones sane. */
.forward-preview {
    position: fixed;
    z-index: 900;
    max-width: calc(100vw - 1rem);
    display: flex;
    flex-direction: column;
    background: var(--bg-darker);

    /* Accent edge: the default --border blends into the dark page behind a
       floating window; the accent line keeps the panel readable as a
       distinct surface. */
    border: 1px solid rgba(122, 162, 247, 0.55);
    border-radius: 10px;
    box-shadow:
        0 0 0 1px rgba(122, 162, 247, 0.15),
        0 12px 32px rgba(0, 0, 0, 0.55);
    overflow: hidden;

    /* Genie in: expand out of the launching chip (transform-origin is set
       inline to the chip's position). */
    animation: forward-preview-in 0.18s ease-out;
}

/* Genie out: collapse back into the chip; unmount happens on animationend
   (with a timer fallback for reduced-motion, where this never plays). */
.forward-preview.closing {
    animation: forward-preview-out 0.16s ease-in forwards;
    pointer-events: none;
}

@keyframes forward-preview-in {
    from {
        transform: scale(0.05);
        opacity: 0.25;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes forward-preview-out {
    from {
        transform: scale(1);
        opacity: 1;
    }

    to {
        transform: scale(0.05);
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .forward-preview,
    .forward-preview.closing {
        animation: none;
    }
}

.forward-preview-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid var(--border);
}

.forward-preview-title {
    flex: 1;
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: move;

    /* Prevent text-selection/scroll gestures from hijacking the drag. */
    user-select: none;
    touch-action: none;
}

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

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

.forward-preview-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.95rem;
    padding: 0 0.2rem;
    line-height: 1;
}

.forward-preview-close:hover {
    color: var(--error);
}

/* Kept mounted while collapsed (inline height 0) so the embedded app keeps
   state; height otherwise comes from inline style (resizable). */
.forward-preview-frame {
    display: block;
    width: 100%;
    border: 0;
    background: #fff;
}

/* During drag/resize the iframe must not swallow pointer events. */
.forward-preview-frame.interacting {
    pointer-events: none;
}

.forward-preview-grip {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    touch-action: none;

    /* Two diagonal ticks, echoing the platform resize affordance. */
    background: linear-gradient(
        135deg,
        transparent 55%,
        var(--text-secondary) 55%,
        var(--text-secondary) 62%,
        transparent 62%,
        transparent 75%,
        var(--text-secondary) 75%,
        var(--text-secondary) 82%,
        transparent 82%
    );
    opacity: 0.7;
}

.forward-preview-grip:hover {
    opacity: 1;
}

.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);
}
