@use 'mixins' as *;

/* ══════════════════════════════════
   CATCHER PANEL
   ══════════════════════════════════ */
.catcher-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg0);
}

.catcher-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    padding: 8px 12px 0;
    border-bottom: 1px solid var(--bg2);
    align-items: center;

    .ctab {
        position: relative;
        display: flex;
        align-items: center;
        gap: 4px;
        padding: 8px 16px;
        font-size: 12px;
        font-weight: 500;
        color: var(--text3);
        border-radius: 6px 6px 0 0;
        cursor: pointer;
        user-select: none;
        transition:
            background var(--transition-normal),
            color var(--transition-normal);

        &:hover {
            background: var(--bg2);
            color: var(--text1);
        }
        &.active {
            background: var(--bg1);
            color: var(--accent);
        }
    }

    .ctab-close {
        margin-left: 4px;
        font-size: 14px;
        opacity: 0.4;
        cursor: pointer;
        line-height: 1;
        &:hover {
            opacity: 1;
            color: var(--danger);
        }
    }

    .ctab-rename-input {
        width: 60px;
        padding: 1px 4px;
        border: 1px solid var(--accent);
        border-radius: 3px;
        background: var(--bg0);
        color: var(--text1);
        font-size: 12px;
        font-family: inherit;
        font-weight: 500;
        outline: none;
    }

    .ctab-add {
        font-size: 18px;
        font-weight: 600;
        color: var(--text3);
        padding: 8px 14px;
        &:hover {
            color: var(--accent);
        }
    }
}

// Generator sub-panel
.gen-layout {
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    flex: 1;
}

.gen-row {
    display: flex;
    align-items: center;
    gap: 10px;

    label {
        min-width: 70px;
        font-size: 12px;
        font-weight: 600;
        color: var(--text3);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    input,
    select {
        flex: 1;
        padding: 8px 12px;
        background: var(--bg2);
        border: 1px solid var(--bg3);
        border-radius: 6px;
        color: var(--text1);
        font-family: var(--mono);
        font-size: 13px;
        outline: none;
        transition: border-color var(--transition-normal);

        &:focus {
            border-color: var(--accent);
        }
    }
}

// Custom number input spinners (catcher + generator)
input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
    &::-webkit-inner-spin-button,
    &::-webkit-outer-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }
}
input[type="number"]:focus {
    appearance: textfield;
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.catcher-setup input[type="number"] {
    text-align: center;
    appearance: textfield;
    -moz-appearance: textfield;
    &::-webkit-inner-spin-button,
    &::-webkit-outer-spin-button {
        -webkit-appearance: none;
        margin: 0;
    }
}

.gen-output-wrap,
.gen-listener-wrap {
    border: 1px solid var(--bg3);
    border-radius: 8px;
    overflow: hidden;
}

.gen-output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--bg2);
    border-bottom: 1px solid var(--bg3);

    span {
        font-size: 11px;
        font-weight: 600;
        color: var(--text3);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
}

.gen-copy-btn {
    padding: 3px 10px;
    border: 1px solid var(--bg3);
    border-radius: 4px;
    background: transparent;
    color: var(--text3);
    font-size: 11px;
    cursor: pointer;
    transition:
        background var(--transition-normal),
        color var(--transition-normal);

    &:hover {
        background: var(--accent);
        color: var(--bg0);
        border-color: var(--accent);
    }
}

.gen-output {
    margin: 0;
    padding: 12px;
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.6;
    color: var(--green);
    background: var(--bg0);
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 160px;
    overflow-y: auto;
}

.gen-credit {
    padding: 8px 16px;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text3);
    text-align: center;
    opacity: 0.6;

    a {
        color: var(--accent);
        text-decoration: none;
        &:hover {
            text-decoration: underline;
        }
    }
}

// Listener panel
.catcher-listener-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
}

.catcher-listener-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg2);
    border-bottom: 1px solid var(--bg3);
    font-size: 12px;
    color: var(--text3);

    strong {
        color: var(--accent);
    }

    // When used as the setup form after stop/restart
    .catcher-setup-row {
        display: flex;
        align-items: center;
        gap: 8px;

        label {
            font-size: 12px;
            font-weight: 600;
            color: var(--text3);
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }
    }
}

.catcher-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.catcher-stopped-text {
    color: var(--danger);
    opacity: 0.7;
}

.catcher-stop-btn {
    padding: 4px 12px;
    border: 1px solid var(--danger);
    border-radius: 4px;
    background: transparent;
    color: var(--danger);
    font-size: 11px;
    cursor: pointer;
    transition:
        background var(--transition-normal),
        color var(--transition-normal);
    &:hover {
        background: var(--danger);
        color: var(--bg0);
    }
}

.catcher-restart-btn {
    padding: 4px 12px;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: transparent;
    color: var(--accent);
    font-size: 11px;
    cursor: pointer;
    transition:
        background var(--transition-normal),
        color var(--transition-normal);
    &:hover {
        background: var(--accent);
        color: var(--bg0);
    }
}

// Setup form (port + start button before listener is active)
.catcher-setup {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--bg3);
    background: var(--bg2);

    label {
        min-width: 36px;
        font-size: 12px;
        font-weight: 600;
        color: var(--text3);
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    input {
        width: 100px;
        padding: 6px 10px;
        background: var(--bg1);
        border: 1px solid var(--bg3);
        border-radius: 4px;
        color: var(--text1);
        font-family: var(--mono);
        font-size: 13px;
        outline: none;
        &:focus {
            border-color: var(--accent);
        }
    }
}

.catcher-start-btn {
    padding: 6px 16px;
    border: 1px solid var(--green);
    border-radius: 4px;
    background: transparent;
    color: var(--green);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition:
        background var(--transition-normal),
        color var(--transition-normal);
    &:hover {
        background: var(--green);
        color: var(--bg0);
    }
    &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }
}

.catcher-sessions {
    flex: 1;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.catcher-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text3);
    font-size: 13px;
    font-style: italic;
}

// Session card
.catcher-session {
    border: 1px solid var(--bg3);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 300px;
}

.catcher-session-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg2);
    border-bottom: 1px solid var(--bg3);
}

.catcher-session-addr {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text2);
    flex: 1;
}

.catcher-session-connect,
.catcher-session-kill {
    padding: 3px 10px;
    border: 1px solid var(--bg3);
    border-radius: 4px;
    background: transparent;
    font-size: 11px;
    cursor: pointer;
    transition:
        background var(--transition-normal),
        color var(--transition-normal);
}

.catcher-session-connect {
    color: var(--green);
    border-color: var(--green);
    &:hover {
        background: var(--green);
        color: var(--bg0);
    }
}

.catcher-session-kill {
    color: var(--danger);
    border-color: var(--danger);
    &:hover {
        background: var(--danger);
        color: var(--bg0);
    }
}

.catcher-session-resize {
    padding: 3px 8px;
    border: 1px solid var(--bg3);
    border-radius: 4px;
    background: transparent;
    color: var(--text2);
    font-size: 14px;
    cursor: pointer;
    transition:
        background var(--transition-normal),
        color var(--transition-normal);
    line-height: 1;
    &:hover {
        background: var(--bg3);
        color: var(--text0);
    }
}

// Upgrade dropdown
.catcher-upgrade-wrap {
    position: relative;
    display: inline-block;
}
.catcher-session-upgrade {
    padding: 3px 10px;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: transparent;
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition:
        background var(--transition-normal),
        color var(--transition-normal);
    &:hover {
        background: var(--accent);
        color: var(--bg0);
    }
}
.catcher-upgrade-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 50;
    background: var(--bg1);
    border: 1px solid var(--bg3);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    white-space: nowrap;
    margin-top: 2px;

    button {
        display: block;
        width: 100%;
        padding: 6px 14px;
        border: none;
        background: transparent;
        color: var(--text1);
        font-size: 12px;
        text-align: left;
        cursor: pointer;
        &:hover {
            background: var(--bg2);
            color: var(--accent);
        }
    }
}
.catcher-upgrade-wrap.open .catcher-upgrade-menu {
    display: block;
}

.catcher-session-linemode {
    padding: 3px 10px;
    border: 1px solid var(--bg3);
    border-radius: 4px;
    background: transparent;
    color: var(--text2);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition:
        background var(--transition-normal),
        color var(--transition-normal),
        border-color var(--transition-normal);
    &:hover {
        background: var(--bg3);
        color: var(--text0);
    }
    &.active {
        border-color: var(--warn);
        background: var(--warn-dim);
        color: var(--warn);
    }
    &:disabled {
        opacity: 0.35;
        cursor: not-allowed;
        pointer-events: none;
    }
}

// Terminal container
.catcher-terminal {
    flex: 1;
    min-height: 250px;
    background: #2e3440;
    padding: 4px;

    .xterm {
        height: 100%;
    }
}

// Badge dot for catcher tab notification
#catcher-badge.dot {
    &::after {
        content: "";
        display: block;
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: var(--danger);
        animation: pulse-dot 1.5s ease-in-out infinite;
    }
}

@keyframes pulse-dot {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}
