:root {
    --color-bg-start: #0f0c29;
    --color-bg-mid: #302b63;
    --color-bg-end: #1a1a2e;
    --color-primary: #7c5cff;
    --color-primary-alt: #a855f7;
    --color-surface: rgba(255, 255, 255, 0.06);
    --color-surface-border: rgba(255, 255, 255, 0.12);
    --color-text: #f4f4f8;
    --color-text-muted: #a3a3b8;
    --color-danger: #ff5c7c;
    --radius: 14px;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

* {
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--color-text);
    background: linear-gradient(135deg, var(--color-bg-start), var(--color-bg-mid) 55%, var(--color-bg-end));
}

body {
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* Topbar */
#topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    flex: 0 0 60px;
    padding: 0 24px;
    background: rgba(15, 12, 41, 0.55);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--color-surface-border);
    z-index: 10;
}

#topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

#topbar-logo {
    font-family: "Geomanist", "Avenir Next", "Century Gothic", "Poppins", -apple-system, sans-serif;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
    background: linear-gradient(135deg, #fff, #c4b5fd);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.env-badge {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    padding: 3px 10px;
    border-radius: 999px;
    text-transform: uppercase;
}

.env-badge.env-test {
    background: rgba(250, 204, 21, 0.15);
    color: #facc15;
    border: 1px solid rgba(250, 204, 21, 0.4);
}

.env-badge.env-stage {
    background: rgba(56, 189, 248, 0.15);
    color: #38bdf8;
    border: 1px solid rgba(56, 189, 248, 0.4);
}

.env-badge.env-prod {
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
    border: 1px solid rgba(248, 113, 113, 0.4);
}

#topbar-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

/* Websocket status indicator */
.ws-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 4px 12px 4px 9px;
    border-radius: 999px;
}

.ws-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.ws-status.ws-connecting {
    background: rgba(163, 163, 184, 0.15);
    color: var(--color-text-muted);
    border: 1px solid rgba(163, 163, 184, 0.35);
}

.ws-status.ws-connecting .ws-dot {
    background: var(--color-text-muted);
    animation: ws-pulse 1s ease-in-out infinite;
}

.ws-status.ws-connected {
    background: rgba(250, 204, 21, 0.15);
    color: #facc15;
    border: 1px solid rgba(250, 204, 21, 0.4);
}

.ws-status.ws-connected .ws-dot {
    background: #facc15;
}

.ws-status.ws-authorized {
    background: rgba(74, 222, 128, 0.15);
    color: #4ade80;
    border: 1px solid rgba(74, 222, 128, 0.4);
}

.ws-status.ws-authorized .ws-dot {
    background: #4ade80;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
}

.ws-status.ws-disconnected {
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
    border: 1px solid rgba(248, 113, 113, 0.4);
}

.ws-status.ws-disconnected .ws-dot {
    background: #f87171;
}

@keyframes ws-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.3;
    }
}

/* Buttons */
.btn {
    border: none;
    border-radius: 10px;
    padding: 11px 18px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-alt));
    color: #fff;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 24px rgba(124, 92, 255, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--color-surface-border);
    color: var(--color-text-muted);
    padding: 8px 14px;
    font-size: 0.8rem;
}

.btn-ghost:hover {
    color: var(--color-text);
    border-color: var(--color-primary);
}

/* Main area */
#app-main {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 24px;
}

/* Login card */
#login-form {
    width: min(380px, 100%);
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-surface-border);
    border-radius: var(--radius);
    padding: 32px;
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow);
}

#login-form h1 {
    margin: 0;
    font-size: 1.4rem;
}

#login-form .subtitle {
    margin: -8px 0 4px;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.field input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--color-surface-border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--color-text);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.field input:focus {
    outline: none;
    border-color: var(--color-primary);
    background: rgba(255, 255, 255, 0.08);
}

.error-banner {
    background: rgba(255, 92, 124, 0.12);
    border: 1px solid rgba(255, 92, 124, 0.4);
    color: var(--color-danger);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.82rem;
}

/* Spinners */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.spinner-lg {
    width: 36px;
    height: 36px;
    border-width: 3px;
    border-color: rgba(255, 255, 255, 0.15);
    border-top-color: var(--color-primary);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Loading screen */
#loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* Iframe select */
#iframe-select {
    background: rgba(255, 255, 255, 0.06);
    color: var(--color-text);
    border: 1px solid var(--color-surface-border);
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 0.85rem;
}

#iframe-select option {
    background: #1a1a2e;
    color: var(--color-text);
}

/* Iframes */
#iframe-container {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

#iframe-container iframe {
    border: none;
    position: absolute;
    top: 0;
    left: 0;
    background: #000;
}
