/* ==========================================================================
   Web Terminal — Stylesheet
   Aesthetic: refined dark terminal. JetBrains Mono throughout. Deep black
   base, phosphor-green accent. Subtle noise texture, crisp hairline borders.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

:root {
    /* Palette */
    --bg-deep:    #0a0a0b;
    --bg-base:    #101012;
    --bg-raise:   #18181b;
    --bg-hover:   #1f1f23;
    --border:     #26262b;
    --border-bright: #3a3a42;

    --text-primary:   #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-muted:     #71717a;
    --text-faint:     #52525b;

    --accent:        #7ee787;
    --accent-dim:    #4a8a52;
    --accent-glow:   rgba(126, 231, 135, 0.15);
    --danger:        #f87171;
    --warn:          #fbbf24;

    /* Type */
    --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

    /* Layout */
    --topbar-h: 44px;
    --radius:   6px;
    --radius-sm: 4px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Subtle film grain — gives the dark surfaces some texture so they don't read flat */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    opacity: 0.025;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    mix-blend-mode: overlay;
}

button {
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

input, textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

/* ==========================================================================
   LOGIN PAGE
   ========================================================================== */

.login-shell {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    overflow: auto;
    /* Subtle radial vignette so attention focuses center */
    background:
        radial-gradient(ellipse 80% 60% at 50% 40%, rgba(126, 231, 135, 0.04), transparent 70%),
        var(--bg-deep);
}

.login-card {
    width: 100%;
    max-width: 440px;
    position: relative;
    z-index: 2;
}

/* Decorative ASCII bracket frame around the card */
.login-card::before,
.login-card::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    border: 1px solid var(--accent-dim);
}

.login-card::before {
    top: -8px;
    left: -8px;
    border-right: none;
    border-bottom: none;
}

.login-card::after {
    bottom: -8px;
    right: -8px;
    border-left: none;
    border-top: none;
}

.login-header {
    margin-bottom: 32px;
}

.login-logo {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 28px;
    letter-spacing: 0.04em;
}

.login-logo .blink {
    color: var(--accent);
    animation: blink 1.2s steps(2, end) infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

.login-title {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.login-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
}

.login-subtitle code {
    background: var(--bg-raise);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 12px;
    color: var(--accent);
}

.login-form {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.field-group {
    margin-bottom: 16px;
}

.field-group:last-of-type {
    margin-bottom: 0;
}

.field-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}

.field-label-text {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-secondary);
}

.field-label-hint {
    font-size: 11px;
    color: var(--text-faint);
}

.text-input {
    width: 100%;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    color: var(--text-primary);
    font-size: 13px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    line-height: 1.5;
}

.text-input:focus {
    outline: none;
    border-color: var(--accent-dim);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.text-input::placeholder {
    color: var(--text-faint);
}

.submit-row {
    margin-top: 20px;
    display: flex;
    gap: 12px;
    align-items: center;
}

.submit-btn {
    flex: 1;
    background: var(--accent);
    color: var(--bg-deep);
    font-weight: 600;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.submit-btn:hover:not(:disabled) {
    background: #95edaa;
    box-shadow: 0 0 24px var(--accent-glow);
}

.submit-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.submit-btn .arrow {
    transition: transform 0.15s ease;
}

.submit-btn:hover:not(:disabled) .arrow {
    transform: translateX(3px);
}

.error-msg {
    margin-top: 14px;
    padding: 10px 12px;
    border: 1px solid rgba(248, 113, 113, 0.3);
    background: rgba(248, 113, 113, 0.08);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 12px;
    display: none;
}

.error-msg.visible {
    display: block;
    animation: shake 0.4s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.login-footer {
    margin-top: 24px;
    text-align: center;
    font-size: 11px;
    color: var(--text-faint);
    letter-spacing: 0.04em;
}

.login-footer .accent {
    color: var(--accent-dim);
}

/* ==========================================================================
   TERMINAL PAGE
   ========================================================================== */

.terminal-shell {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    /* Height is dynamic — set by terminal.js via --viewport-height to track
       the visual viewport (so the keyboard doesn't hide the prompt on mobile).
       Falls back to 100vh, then 100dvh for browsers that support it. */
    height: 100vh;
    height: 100dvh;
    height: var(--viewport-height, 100dvh);
    display: flex;
    flex-direction: column;
    background: var(--bg-deep);
}

.topbar {
    height: var(--topbar-h);
    flex: 0 0 var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    background: var(--bg-base);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 10;
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.topbar-brand {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.topbar-brand .bullet {
    color: var(--accent);
}

.topbar-divider {
    width: 1px;
    height: 18px;
    background: var(--border);
    flex-shrink: 0;
}

.host-info {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.host-info .host-name {
    color: var(--text-primary);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--bg-raise);
    border: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    transition: all 0.2s ease;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-faint);
    transition: background 0.2s ease, box-shadow 0.2s ease;
}

.status-pill[data-state="connected"] {
    border-color: rgba(126, 231, 135, 0.25);
    color: var(--accent);
}

.status-pill[data-state="connected"] .status-dot {
    background: var(--accent);
    box-shadow: 0 0 6px var(--accent);
    animation: pulse 2.5s ease-in-out infinite;
}

.status-pill[data-state="disconnected"] {
    border-color: rgba(248, 113, 113, 0.25);
    color: var(--danger);
}

.status-pill[data-state="disconnected"] .status-dot {
    background: var(--danger);
}

.status-pill[data-state="connecting"] {
    border-color: rgba(251, 191, 36, 0.25);
    color: var(--warn);
}

.status-pill[data-state="connecting"] .status-dot {
    background: var(--warn);
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    50% { opacity: 0.6; }
}

.icon-btn {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.icon-btn svg {
    width: 16px;
    height: 16px;
}

/* Terminal mount point */
.term-container {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    background: var(--bg-deep);
    /* Padding so cursor isn't glued to the edge */
    padding: 8px 4px 4px 8px;
}

#terminal {
    width: 100%;
    height: 100%;
}

/* xterm.js viewport tweaks */
.xterm-viewport::-webkit-scrollbar {
    width: 8px;
}

.xterm-viewport::-webkit-scrollbar-track {
    background: transparent;
}

.xterm-viewport::-webkit-scrollbar-thumb {
    background: var(--border-bright);
    border-radius: 4px;
}

.xterm-viewport::-webkit-scrollbar-thumb:hover {
    background: var(--text-faint);
}

/* Overlay for disconnect / reconnect state */
.overlay {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(10, 10, 11, 0.92);
    backdrop-filter: blur(4px);
    z-index: 20;
    text-align: center;
    padding: 20px;
}

.overlay.visible {
    display: flex;
    animation: fadeIn 0.2s ease;
}

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

.overlay-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-raise);
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    color: var(--danger);
}

.overlay-icon svg {
    width: 22px;
    height: 22px;
}

.overlay-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.overlay-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    max-width: 320px;
}

.reconnect-btn {
    margin-top: 8px;
    background: var(--accent);
    color: var(--bg-deep);
    font-weight: 600;
    padding: 10px 22px;
    border-radius: var(--radius-sm);
    transition: background 0.15s ease, box-shadow 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.reconnect-btn:hover {
    background: #95edaa;
    box-shadow: 0 0 24px var(--accent-glow);
}

/* ==========================================================================
   RESPONSIVE — mobile tweaks
   ========================================================================== */

@media (max-width: 600px) {
    :root {
        --topbar-h: 40px;
    }

    .topbar {
        padding: 0 10px;
    }

    .topbar-brand {
        font-size: 11px;
    }

    .host-info {
        font-size: 11px;
    }

    .status-pill {
        padding: 3px 8px;
        font-size: 10px;
    }

    /* On really tight screens, hide the host info — the status pill carries
       the essential signal */
    .topbar-divider,
    .host-info {
        display: none;
    }

    .term-container {
        padding: 4px 2px 2px 4px;
    }

    .login-shell {
        padding: 16px;
    }

    .login-form {
        padding: 20px;
    }

    .login-title {
        font-size: 20px;
    }
}

/* Prevent iOS Safari from zooming when focusing inputs */
@media (max-width: 600px) {
    .text-input {
        font-size: 16px;
    }
}
