:root {
    --app-height: 100dvh;
    --keyboard-height: 0px;

    --bg: #06111d;
    --bg-deep: #030a12;
    --panel: rgba(8, 24, 39, 0.92);

    --line: rgba(46, 218, 210, 0.22);
    --line-strong: rgba(46, 218, 210, 0.42);

    --text: #e9fbff;
    --text-soft: #94aebb;

    --cyan: #29e1dc;
    --cyan-soft: #75f5ee;

    --green: #31e6a1;

    --prompt: #49e8e0;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);

    --header-height: 68px;
    --dock-min-height: 76px;
}

* {
    box-sizing: border-box;
}

html {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;

    background: var(--bg);

    overflow: hidden;

    overscroll-behavior: none;

    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    width: 100%;
    height: var(--app-height);

    min-width: 0;

    margin: 0;
    padding: 0;

    overflow: hidden;

    background:
        radial-gradient(
            circle at 50% -20%,
            rgba(24, 138, 150, 0.16),
            transparent 44%
        ),
        linear-gradient(
            180deg,
            var(--bg) 0%,
            var(--bg-deep) 100%
        );

    color: var(--text);

    font-family:
        ui-monospace,
        SFMono-Regular,
        Menlo,
        Monaco,
        Consolas,
        "Liberation Mono",
        "Courier New",
        monospace;

    -webkit-font-smoothing: antialiased;

    touch-action: manipulation;
}

button,
input {
    font: inherit;
}

.app-shell {
    position: fixed;

    top: 0;
    right: 0;
    bottom: auto;
    left: 0;

    width: 100%;

    height: var(--app-height);

    min-width: 0;

    display: flex;
    flex-direction: column;

    overflow: hidden;

    padding:
        var(--safe-top)
        var(--safe-right)
        0
        var(--safe-left);
}

.topbar {
    flex: 0 0 auto;

    min-height: var(--header-height);

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 12px;

    padding:
        12px
        16px
        10px
        16px;

    background:
        linear-gradient(
            180deg,
            rgba(6, 17, 29, 0.98),
            rgba(6, 17, 29, 0.90)
        );

    z-index: 20;
}

.brand {
    min-width: 0;
}

.brand-name {
    color: var(--cyan);

    font-size: 15px;
    font-weight: 800;

    letter-spacing: 0.13em;

    line-height: 1.15;

    white-space: nowrap;
}

.brand-subtitle {
    margin-top: 5px;

    color: var(--text-soft);

    font-size: 11px;
    font-weight: 500;

    line-height: 1.2;

    white-space: nowrap;

    overflow: hidden;
    text-overflow: ellipsis;
}

.live-status {
    flex: 0 0 auto;

    display: flex;
    align-items: center;

    gap: 6px;

    color: var(--green);

    font-size: 11px;
    font-weight: 800;

    letter-spacing: 0.08em;
}

.live-dot {
    width: 7px;
    height: 7px;

    border-radius: 50%;

    background: var(--green);

    box-shadow:
        0 0 5px rgba(49, 230, 161, 0.9),
        0 0 12px rgba(49, 230, 161, 0.35);

    animation:
        livePulse
        1.8s
        ease-in-out
        infinite;
}

@keyframes livePulse {
    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.48;
    }
}

.top-divider {
    flex: 0 0 1px;

    height: 1px;

    margin:
        0
        14px;

    background:
        linear-gradient(
            90deg,
            transparent,
            var(--line-strong),
            transparent
        );
}

.terminal {
    position: relative;

    flex: 1 1 auto;

    min-height: 0;
    min-width: 0;

    overflow-x: hidden;
    overflow-y: auto;

    overscroll-behavior: contain;

    -webkit-overflow-scrolling: touch;

    padding:
        14px
        14px
        8px
        14px;

    scroll-behavior: smooth;
}

.terminal-history {
    width: 100%;
    min-width: 0;

    font-size: 13px;
    line-height: 1.58;

    white-space: pre-wrap;

    overflow-wrap: anywhere;
    word-break: break-word;
}

.history-command {
    display: flex;
    align-items: flex-start;

    width: 100%;

    min-width: 0;

    margin:
        0
        0
        12px
        0;
}

.history-command .history-prompt {
    flex: 0 0 auto;

    margin-right: 7px;

    color: var(--prompt);

    font-weight: 700;

    white-space: nowrap;
}

.history-command .history-value {
    min-width: 0;

    color: var(--text);

    overflow-wrap: anywhere;
}

.history-output {
    width: 100%;

    margin:
        0
        0
        18px
        0;

    color: var(--text);

    white-space: pre-wrap;

    overflow-wrap: anywhere;
}

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

.history-success {
    color: var(--green);
}

.history-cyan {
    color: var(--cyan-soft);
}

.terminal-spacer {
    height: 4px;
}

.command-dock {
    position: relative;

    flex: 0 0 auto;

    width: 100%;

    min-width: 0;

    padding:
        10px
        14px
        calc(10px + var(--safe-bottom))
        14px;

    background:
        linear-gradient(
            180deg,
            rgba(3, 10, 18, 0.90),
            rgba(3, 10, 18, 0.99)
        );

    border-top:
        1px
        solid
        var(--line);

    box-shadow:
        0 -12px 30px rgba(0, 0, 0, 0.22);

    z-index: 30;
}

.command-line {
    width: 100%;

    min-width: 0;

    display: flex;
    align-items: center;

    gap: 7px;

    min-height: 38px;

    padding:
        7px
        0;

    cursor: text;
}

.prompt {
    flex: 0 0 auto;

    color: var(--prompt);

    font-size: 13px;
    font-weight: 700;

    line-height: 24px;

    white-space: nowrap;

    user-select: none;
}

.input-shell {
    position: relative;

    flex: 1 1 auto;

    min-width: 0;

    height: 26px;

    display: flex;
    align-items: center;

    overflow: hidden;
}

.terminal-input {
    position: absolute;

    top: 0;
    left: 0;

    width: 100%;
    height: 26px;

    margin: 0;
    padding: 0;

    border: 0;
    outline: 0;

    border-radius: 0;

    background: transparent;

    color: transparent;

    caret-color: transparent;

    font-family: inherit;
    font-size: 13px;
    font-weight: 500;

    line-height: 26px;

    appearance: none;
    -webkit-appearance: none;

    opacity: 0.02;

    z-index: 5;
}

.input-mirror {
    position: relative;

    z-index: 2;

    max-width: calc(100% - 12px);

    color: var(--text);

    font-size: 13px;
    font-weight: 500;

    line-height: 26px;

    white-space: pre;

    overflow: hidden;

    pointer-events: none;
}

.terminal-cursor {
    position: relative;

    z-index: 2;

    display: inline-block;

    flex: 0 0 auto;

    width: 8px;
    height: 17px;

    margin-left: 2px;

    background: var(--cyan);

    box-shadow:
        0 0 8px rgba(41, 225, 220, 0.38);

    pointer-events: none;

    animation:
        cursorBlink
        1.05s
        steps(1, end)
        infinite;
}

@keyframes cursorBlink {
    0%,
    48% {
        opacity: 1;
    }

    49%,
    100% {
        opacity: 0;
    }
}

.command-line:focus-within {
    background:
        linear-gradient(
            90deg,
            rgba(41, 225, 220, 0.035),
            transparent 80%
        );
}

.command-line:focus-within .terminal-cursor {
    animation-duration: 0.8s;
}

.keyboard-hint {
    min-height: 14px;

    color: rgba(148, 174, 187, 0.65);

    font-size: 9px;

    line-height: 12px;

    letter-spacing: 0.02em;

    text-align: left;

    user-select: none;
}

body.keyboard-open .keyboard-hint {
    display: none;
}

body.keyboard-open .command-dock {
    padding-bottom: 7px;
}

body.keyboard-open .topbar {
    min-height: 48px;

    padding-top: 7px;
    padding-bottom: 6px;
}

body.keyboard-open .brand-subtitle {
    display: none;
}

body.keyboard-open .terminal {
    padding-top: 8px;
}

@media (max-width: 390px) {

    :root {
        --header-height: 62px;
    }

    .topbar {
        padding-left: 12px;
        padding-right: 12px;
    }

    .terminal {
        padding-left: 11px;
        padding-right: 11px;
    }

    .command-dock {
        padding-left: 11px;
        padding-right: 11px;
    }

    .brand-name {
        font-size: 14px;
    }

    .brand-subtitle {
        font-size: 10px;
    }

    .prompt,
    .terminal-input,
    .input-mirror {
        font-size: 12px;
    }

    .terminal-history {
        font-size: 12px;
    }

    .prompt {
        letter-spacing: -0.03em;
    }
}

@media (max-width: 340px) {

    .live-status span:last-child {
        display: none;
    }

    .brand-subtitle {
        max-width: 190px;
    }

    .prompt,
    .terminal-input,
    .input-mirror,
    .terminal-history {
        font-size: 11px;
    }

    .command-line {
        gap: 5px;
    }
}

@media (orientation: landscape) and (max-height: 520px) {

    :root {
        --header-height: 44px;
    }

    .topbar {
        min-height: 44px;

        padding-top: 6px;
        padding-bottom: 5px;
    }

    .brand-subtitle {
        display: none;
    }

    .terminal {
        padding-top: 7px;
    }

    .keyboard-hint {
        display: none;
    }

    .command-dock {
        padding-top: 4px;
        padding-bottom:
            calc(4px + var(--safe-bottom));
    }
}


/* ==========================================================
   TECH PACKER — TELEGRAM FULLSCREEN HEADER V3
   ========================================================== */

/*
   Telegram owns the very top fullscreen control region.

   The native Close button appears on the left and the
   chevron/menu controls appear on the right.

   Keep Tech Packer content below that region.
*/

:root {
    --telegram-control-clearance: 76px;
}

.topbar {
    min-height: auto;

    padding:
        calc(
            var(--telegram-control-clearance)
            + var(--safe-top)
        )
        16px
        12px
        16px;

    align-items: flex-end;
}

.header-left {
    display: flex;
    align-items: center;

    gap: 11px;

    min-width: 0;

    flex: 1 1 auto;
}

.logo-shell {
    width: 42px;
    height: 42px;

    flex: 0 0 42px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 12px;

    overflow: hidden;

    background:
        rgba(41, 225, 220, 0.04);
}

.techpacker-logo {
    display: block;

    width: 100%;
    height: 100%;

    object-fit: contain;
}

.header-right {
    flex: 0 0 auto;

    display: flex;
    flex-direction: column;

    align-items: flex-end;
    justify-content: flex-end;

    gap: 7px;

    min-width: 0;
}

.current-timestamp {
    color: var(--text-soft);

    font-size: 10px;
    font-weight: 600;

    line-height: 1;

    letter-spacing: 0.02em;

    white-space: nowrap;

    font-variant-numeric:
        tabular-nums;
}

.live-status {
    justify-content: flex-end;
}

/*
   When the keyboard is open we still need the header to
   remain below Telegram's native fullscreen controls.
*/

body.keyboard-open .topbar {
    min-height: auto;

    padding:
        calc(
            var(--telegram-control-clearance)
            + var(--safe-top)
        )
        12px
        7px
        12px;
}

body.keyboard-open .brand-subtitle {
    display: none;
}

body.keyboard-open .logo-shell {
    width: 34px;
    height: 34px;

    flex-basis: 34px;
}

body.keyboard-open .current-timestamp {
    font-size: 9px;
}


/* ----------------------------------------------------------
   Small phones
   ---------------------------------------------------------- */

@media (max-width: 390px) {

    :root {
        --telegram-control-clearance: 72px;
    }

    .topbar {
        padding-left: 12px;
        padding-right: 12px;
    }

    .logo-shell {
        width: 38px;
        height: 38px;

        flex-basis: 38px;
    }

    .header-left {
        gap: 9px;
    }

    .current-timestamp {
        font-size: 9px;
    }

}


/* ----------------------------------------------------------
   Very narrow phones
   ---------------------------------------------------------- */

@media (max-width: 340px) {

    .logo-shell {
        width: 34px;
        height: 34px;

        flex-basis: 34px;
    }

    .brand-name {
        font-size: 12px;
    }

    .current-timestamp {
        font-size: 8px;
    }

}


/* ----------------------------------------------------------
   Landscape
   ---------------------------------------------------------- */

@media (orientation: landscape) and (max-height: 520px) {

    :root {
        --telegram-control-clearance: 52px;
    }

    .topbar {
        min-height: auto;

        padding:
            calc(
                var(--telegram-control-clearance)
                + var(--safe-top)
            )
            12px
            6px
            12px;
    }

    .logo-shell {
        width: 32px;
        height: 32px;

        flex-basis: 32px;
    }

    .brand-subtitle {
        display: none;
    }

}


/* ==========================================================
   TECH PACKER — MINI APP CONTROLLER V1
   ========================================================== */

.terminal-upload-button {
    appearance: none;
    -webkit-appearance: none;

    flex: 0 0 auto;

    min-height: 38px;

    margin-right: 9px;

    padding: 0 12px;

    border:
        1px solid
        rgba(44, 226, 220, 0.62);

    border-radius: 10px;

    background:
        rgba(24, 126, 135, 0.14);

    color: #52e6df;

    font-family: inherit;

    font-size: 12px;
    font-weight: 700;

    white-space: nowrap;

    cursor: pointer;

    touch-action: manipulation;
}

.terminal-upload-button:active {
    transform: scale(0.97);

    background:
        rgba(44, 226, 220, 0.22);
}

.workflow-upload-input {
    display: none !important;
}

.techpacker-auth-message {
    padding: 16px;

    color: #ffcc66;

    white-space: pre-wrap;
}

body.techpacker-locked #command-dock {
    opacity: 0.35;
    pointer-events: none;
}

@media (max-width: 390px) {

    .terminal-upload-button {
        min-height: 36px;

        padding-left: 9px;
        padding-right: 9px;

        margin-right: 7px;

        font-size: 11px;
    }

}


/* ==========================================================
   TECH PACKER — FINAL CONTEXTUAL UPLOAD
   ========================================================== */

.terminal-upload-panel[hidden] {
    display: none !important;
}

.terminal-upload-panel {
    flex: 0 0 auto;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 10px;

    margin:
        0
        max(12px, var(--safe-right))
        8px
        max(12px, var(--safe-left));

    padding:
        9px
        11px;

    border:
        1px solid
        rgba(44, 226, 220, 0.35);

    border-radius:
        10px;

    background:
        rgba(3, 21, 30, 0.98);

    box-shadow:
        0 8px 28px
        rgba(0, 0, 0, 0.24);
}

.upload-panel-copy {
    min-width: 0;

    display: flex;
    flex-direction: column;

    gap: 2px;
}

.upload-panel-title {
    color: #dffcf9;

    font-size: 11px;
    font-weight: 700;
}

.upload-panel-subtitle {
    color:
        rgba(191, 218, 222, 0.68);

    font-size: 9px;
}

.terminal-upload-panel
.terminal-upload-button {
    flex: 0 0 auto;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-height: 36px;

    padding:
        0
        12px;

    border:
        1px solid
        rgba(44, 226, 220, 0.75);

    border-radius:
        8px;

    background:
        rgba(8, 49, 59, 0.98);

    color: #35e6df;

    font-family: inherit;
    font-size: 10px;
    font-weight: 700;

    cursor: pointer;
}

.terminal-upload-panel
.terminal-upload-button:active {
    transform: translateY(1px);
}

.workflow-upload-input {
    display: none !important;
}

@media (max-width: 390px) {

    .terminal-upload-panel {
        margin-left:
            max(
                8px,
                var(--safe-left)
            );

        margin-right:
            max(
                8px,
                var(--safe-right)
            );

        padding:
            8px
            9px;
    }

}


/* ==========================================================
   TECH PACKER — TERMINAL UX V5
   ========================================================== */

.terminal-output-block {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.52;
    font-variant-ligatures: none;
}

.history-command {
    margin-top: 10px;
    margin-bottom: 5px;
}

.history-prompt {
    font-weight: 700;
}

.history-value {
    color: inherit;
}

#terminal-history {
    font-variant-ligatures: none;
}

#command-line .prompt {
    white-space: nowrap;
    flex: 0 0 auto;
}

#command-line .input-shell {
    min-width: 0;
}

#terminal-input {
    min-width: 0;
}

.terminal-upload-panel {
    font-variant-ligatures: none;
}

