/* Dashboard */
.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.new-session-button {
    background: var(--accent);
    border: none;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.new-session-button:hover {
    background: var(--accent-hover);
}

.new-session-button.active {
    background: var(--text-secondary);
}

/* Header buttons (Admin, Settings, Logout) */
.header-button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    text-decoration: none;
}

.header-button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.header-button.logout:hover {
    border-color: var(--error);
    color: var(--error);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    max-width: 600px;
    width: 90%;
    animation: scaleIn 0.2s ease-out;
}

/* Full-page modal overlay — used for admin and settings panels */
.full-page-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    overflow-y: auto;
    background: var(--bg-dark);
    animation: fadeIn 0.15s ease-out;
}

.modal-content .proxy-setup {
    margin: 0;
}

/* Health timer reminder */
.health-timer-overlay {
    position: fixed;
    inset: 0;
    z-index: 1300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.68);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

.health-timer-dialog {
    width: min(92vw, 460px);
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
    text-align: center;
    animation: scaleIn 0.2s ease-out;
}

.health-timer-dialog h2 {
    margin: 0 0 0.75rem;
    color: var(--text-primary);
    font-size: 1.25rem;
}

.health-timer-dialog p {
    margin: 0 0 1.25rem;
    color: var(--text-primary);
    font-size: 1rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.health-timer-confirm {
    background: var(--accent);
    border: none;
    color: #fff;
    padding: 0.6rem 1.35rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
}

.health-timer-confirm:hover {
    background: var(--accent-hover);
}

.health-timer-confirm:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Vertical list layout for sessions */
.sessions-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Legacy grid - keeping for reference but not used */
.sessions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

.session-portal {
    position: relative;
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
}

.session-portal:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
}

.terminal-preview-content {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 0.5rem;
}

.status-indicator.active {
    background: var(--success);
}

.status-indicator.inactive {
    background: var(--text-secondary);
}

.status-indicator.disconnected {
    background: var(--error);
}

.portal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.session-portal:hover .portal-overlay {
    opacity: 1;
}

.portal-hint {
    color: white;
    font-size: 1.2rem;
    font-weight: bold;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
}

.onboarding-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.onboarding-tutorial {
    width: min(1180px, 100%);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.onboarding-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 1rem;
    align-items: end;
    padding: 1.25rem 0;
    border-bottom: 1px solid var(--border);
}

.onboarding-kicker {
    margin: 0 0 0.35rem;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.onboarding-hero h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.65rem;
    line-height: 1.2;
}

.onboarding-lede {
    max-width: 760px;
    margin: 0.65rem 0 0;
    color: var(--text-secondary);
    line-height: 1.55;
}

.onboarding-primary,
.onboarding-secondary,
.onboarding-link-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.5rem;
    border-radius: 4px;
    padding: 0.55rem 0.95rem;
    font-weight: 650;
    text-decoration: none;
    cursor: pointer;
}

.onboarding-primary {
    border: 1px solid var(--accent);
    background: var(--accent);
    color: var(--bg-dark);
}

.onboarding-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.onboarding-secondary,
.onboarding-link-action {
    border: 1px solid var(--border);
    background: var(--bg-darker);
    color: var(--text-primary);
}

.onboarding-secondary:hover,
.onboarding-link-action:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.onboarding-grid {
    display: grid;
    grid-template-columns: minmax(320px, 1.15fr) minmax(280px, 0.85fr);
    gap: 1rem;
}

.onboarding-panel {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-darker);
    padding: 1rem;
}

.onboarding-install-panel {
    grid-row: span 3;
}

.onboarding-feature-panel {
    grid-column: 1 / -1;
}

.onboarding-panel-header {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}

.onboarding-step-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    background: var(--accent);
    color: var(--bg-dark);
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.onboarding-panel h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1rem;
}

.onboarding-panel p {
    margin: 0.35rem 0 0;
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.45;
}

.onboarding-install-panel .proxy-setup {
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    text-align: left;
}

.onboarding-install-panel .proxy-setup h3 {
    display: none;
}

.onboarding-install-panel .platform-selector {
    justify-content: flex-start;
}

.onboarding-install-panel .copy-command-container {
    margin: 0.35rem 0 0;
}

.onboarding-action-list {
    display: grid;
    gap: 0.85rem;
}

.onboarding-action-list .copy-command-container {
    margin: 0;
}

.onboarding-feature-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
}

.onboarding-feature {
    min-width: 0;
    padding: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-dark);
}

.onboarding-feature strong {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--text-primary);
}

.onboarding-feature span {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.45;
}

.code-block {
    background: var(--bg-darker);
    padding: 1rem;
    border-radius: 4px;
    margin-top: 1rem;
    text-align: left;
    display: inline-block;
}

/* Terminal Page */
.terminal-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.terminal-page .terminal-header {
    background: var(--bg-darker);
    border-bottom: 1px solid var(--border);
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.status.disconnected {
    color: var(--error);
}

.terminal-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.message {
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--bg-darker);
    border-radius: 4px;
    border-left: 3px solid var(--accent);
}

.message.user {
    border-left-color: var(--accent);
}

.message.assistant {
    border-left-color: var(--success);
}

.message.system {
    border-left-color: var(--error);
}

.message-role {
    font-weight: bold;
    margin-bottom: 0.5rem;
    text-transform: capitalize;
}

.message-content pre {
    font-family: 'Courier New', monospace;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.input-form {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--bg-darker);
    border-top: 1px solid var(--border);
}

.message-input {
    flex: 1;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: 4px;
    font-size: 1rem;
}

.message-input:focus {
    outline: none;
    border-color: var(--accent);
}

.send-button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.loading, .spinner {
    text-align: center;
    padding: 2rem;
}

/* Session Sections */
.session-section {
    margin-bottom: 2rem;
}

.section-title {
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.section-title.muted {
    color: var(--text-secondary);
}

.inactive-section .session-portal {
    opacity: 0.7;
}

.session-portal.inactive {
    border-style: dashed;
}

.session-portal.inactive:hover {
    opacity: 1;
}

/* Delete Button */
.delete-button {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 24px;
    height: 24px;
    border: none;
    background: var(--error);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}

.session-portal:hover .delete-button {
    opacity: 1;
}

.delete-button:hover {
    background: #ff6b8a;
}

.muted {
    color: var(--text-secondary);
}

.path {
    color: var(--accent);
    word-break: break-all;
}

/* Turn-metrics header pill — sparkline of the user's recent per-turn
   performance (tok/s, TTFT, max gap, cache hit). Sits next to the spend
   chip; renders nothing when the recent-turn buffer is empty. */
.service-monitor {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    background: rgba(122, 162, 247, 0.08);
    border: 1px solid rgba(122, 162, 247, 0.18);
    cursor: pointer;
    user-select: none;
    font-family: var(--font-mono, monospace);
    font-size: 0.72rem;
    line-height: 1.15;
}

.service-monitor:hover {
    background: rgba(122, 162, 247, 0.14);
}

.service-monitor.empty {
    cursor: default;
}

/* Narrow windows: the header has room for the title and launch button only. */
@media (max-width: 1100px) {
    .service-monitor {
        display: none;
    }
}

.service-monitor .service-monitor-label,
.service-monitor .service-monitor-muted {
    color: var(--text-muted);
    white-space: nowrap;
}

.service-chip {
    display: inline-flex;
    flex-direction: column;
    gap: 0.15rem;
    white-space: nowrap;
}

.service-chip.stale,
.service-monitor-panel tr.stale {
    opacity: 0.45;
}

.service-chip-top,
.service-chip-stats {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.service-chip .sparkline {
    display: block;
    flex-shrink: 0;
}

.service-chip-pick {
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: 0;
    border-bottom: 1px dotted var(--text-muted);
    color: var(--text-primary, #c0caf5);
    font: inherit;
    font-weight: 600;
    padding: 0 0.9rem 0 0;
    cursor: pointer;
    max-width: 11rem;
    overflow: hidden;
    text-overflow: ellipsis;
    background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
        linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
    background-position: calc(100% - 0.45rem) 50%, calc(100% - 0.2rem) 50%;
    background-size: 0.25rem 0.25rem, 0.25rem 0.25rem;
    background-repeat: no-repeat;
}

.service-chip-pick:focus {
    outline: none;
    border-bottom-color: var(--accent, #7aa2f7);
}

.service-chip-pick option {
    background: var(--bg-darker, #16161e);
    color: var(--text-primary, #c0caf5);
}

.service-chip-cpu::before {
    content: "cpu ";
    color: var(--text-muted);
    font-weight: 400;
}

.service-chip-mem::before {
    content: "ram ";
    color: var(--text-muted);
    font-weight: 400;
}

.service-chip-load::before {
    content: "load ";
    color: var(--text-muted);
}

.service-chip-cpu,
.service-chip-mem,
.service-monitor-panel td.calm,
.service-monitor-panel td.busy,
.service-monitor-panel td.hot {
    font-weight: 600;
}

.service-chip-cpu.calm,
.service-chip-mem.calm,
.service-monitor-panel td.calm {
    color: var(--success, #9ece6a);
}

.service-chip-cpu.busy,
.service-chip-mem.busy,
.service-monitor-panel td.busy {
    color: var(--warning, #e0af68);
}

.service-chip-cpu.hot,
.service-chip-mem.hot,
.service-monitor-panel td.hot {
    color: var(--error, #f7768e);
}

.service-monitor .service-monitor-chevron {
    color: var(--text-muted);
    font-size: 0.7rem;
    transition: transform 0.15s;
}

.service-monitor .service-monitor-chevron.open {
    transform: rotate(180deg);
}

.service-monitor-panel {
    position: absolute;
    top: calc(100% + 6px);

    /* The chip is narrow and centred in the header; the table is wide, so
       anchor the panel to the chip's centre and let the viewport cap it. */
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    width: max-content;
    max-width: min(calc(100vw - 2rem), 1100px);
    overflow-x: auto;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    background: var(--bg-darker, #16161e);
    border: 1px solid var(--border, #292e42);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    cursor: default;
}

.service-monitor-panel table {
    border-collapse: collapse;
    width: 100%;
}

.service-monitor-panel th,
.service-monitor-panel td {
    text-align: left;
    padding: 0.25rem 0.6rem 0.25rem 0;
    white-space: nowrap;
    vertical-align: baseline;
}

.service-monitor-panel th {
    color: var(--text-muted);
    font-weight: 400;
    border-bottom: 1px solid var(--border, #292e42);
}

.service-row-name {
    display: flex;
    gap: 0.4rem;
    align-items: baseline;
}

.service-row-kind {
    color: var(--text-muted);
    font-size: 0.68rem;
    text-transform: uppercase;
}

.service-monitor-footnote {
    margin-top: 0.5rem;
    font-size: 0.68rem;
    white-space: normal;
}
