/* ── Reset ────────────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Variables ───────────────────────────────────────────────────────── */
:root {
    --bg:          #07070e;
    --bg-1:        #0c0c1a;
    --bg-2:        #111124;
    --bg-3:        #16162e;
    --border:      #1c1c36;
    --border-2:    #252545;
    --accent:      #7c6dfa;
    --accent-soft: rgba(124,109,250,.14);
    --accent-glow: rgba(124,109,250,.28);
    --text-1:      #eeeeff;
    --text-2:      #9090b8;
    --text-3:      #55557a;
    --green:       #20d68a;
    --red:         #ff4466;
    --yellow:      #f5c842;
    --topbar-h:    54px;
    --radius:      10px;
    --radius-sm:   6px;
    --ease:        cubic-bezier(.4,0,.2,1);
    --t:           180ms;
    --font:        'Inter', system-ui, sans-serif;
}

/* ── Base ─────────────────────────────────────────────────────────────── */
html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text-1);
    font-family: var(--font);
    font-size: 18px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

body { display: flex; }

/* ── Sidebar ──────────────────────────────────────────────────────────── */

/* Brand */

/* Nav section */
.nav-section {
    padding: 16px 10px 8px;
    flex-shrink: 0;
}
.nav-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.1px;
    color: var(--text-3);
    text-transform: uppercase;
    padding: 0 8px;
    margin-bottom: 8px;
}

/* Dropdown trigger */
.app-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 200px;
    height: 36px;
    padding: 0 12px;
    background: var(--bg-2);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-1);
    font-family: var(--font);
    font-size: 17px;
    font-weight: 500;
    transition: border-color var(--t), background var(--t), box-shadow var(--t);
    white-space: nowrap;
}
.app-trigger:hover {
    border-color: var(--accent);
    background: var(--bg-3);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.app-trigger[aria-expanded="true"] {
    border-color: var(--accent);
    background: var(--bg-3);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.app-trigger-left {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    overflow: hidden;
}
.trigger-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.trigger-caret {
    width: 15px;
    height: 15px;
    color: var(--text-3);
    flex-shrink: 0;
    transition: transform var(--t) var(--ease);
}
.trigger-caret.open { transform: rotate(180deg); }

/* Trigger health dot */
.trigger-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-3);
    flex-shrink: 0;
    transition: background .4s, box-shadow .4s;
}
.trigger-dot.online  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.trigger-dot.offline { background: var(--red);   box-shadow: 0 0 6px var(--red); }

/* App list dropdown */
.app-list {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 300px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    z-index: 1000;
    overflow: hidden;
    display: none;
    padding: 6px;
}
.app-list.open { 
    display: block;
}

/* Each dropdown item */
.app-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px 9px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--t);
    position: relative;
    margin-bottom: 2px;
}
.app-item:hover { background: var(--bg-3); }
.app-item.active {
    background: var(--accent-soft);
    border: 1px solid rgba(124,109,250,.25);
}
.app-item.active .ai-name { color: var(--accent); }

/* Left accent bar */
.app-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    bottom: 20%;
    width: 3px;
    border-radius: 3px;
    background: var(--accent);
}

.ai-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 17px;
    font-weight: 700;
    color: #fff;
}
.ai-info { flex: 1; min-width: 0; }
.ai-name {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-desc {
    font-size: 10.5px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-health {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-3);
    flex-shrink: 0;
    transition: background .4s, box-shadow .4s;
}
.ai-health.online  { background: var(--green); box-shadow: 0 0 5px var(--green); }
.ai-health.offline { background: var(--red);   box-shadow: 0 0 5px var(--red); }


/* ── Shared icon button ────────────────────────────────────────────── */
.icon-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    cursor: pointer;
    transition: border-color var(--t), color var(--t);
    flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn.spinning svg { animation: spin .75s linear infinite; }

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

/* ── Main ─────────────────────────────────────────────────────────── */
.main {
    flex: 1;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ── Topbar ───────────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    background: rgba(11,11,20,.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 14px;
    flex-shrink: 0;
    z-index: 100;
}
.topbar-dropdown {
    position: relative;
}
.topbar-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.topbar-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-1);
    white-space: nowrap;
}
.topbar-desc {
    font-size: 20px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-desc:not(:empty)::before { content: '·'; margin-right: 8px; color: var(--border-2); }

/* API pill */
.api-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: var(--bg-2);
    border: 1px solid var(--border-2);
    border-radius: 20px;
    font-size: 11px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--text-2);
    flex-shrink: 0;
    margin-left: auto;
}
.api-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-3);
    transition: background .4s, box-shadow .4s;
}
.api-dot.online  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.api-dot.offline { background: var(--red);   box-shadow: 0 0 6px var(--red); }

/* ── Workspace ────────────────────────────────────────────────────── */
.workspace {
    flex: 1;
    position: relative;
    overflow: hidden;
}
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* ── Welcome Screen ───────────────────────────────────────────────── */
.welcome-screen {
    background: var(--bg);
    overflow-y: auto;
    animation: fadeUp .4s var(--ease);
}
/* Dot grid background */
.welcome-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(circle, rgba(124,109,250,.07) 1px, transparent 1px);
    background-size: 28px 28px;
    pointer-events: none;
}
.welcome-glow {
    position: absolute;
    width: 600px;
    height: 400px;
    background: radial-gradient(ellipse, rgba(124,109,250,.07) 0%, transparent 70%);
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
}
.welcome-body {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
    max-width: 1000px;
    width: 100%;
    gap: 32px;
}

.welcome-card {
    background: rgba(12, 12, 26, 0.4);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    padding: 40px 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3), 
                inset 0 0 0 1px rgba(255, 255, 255, 0.05);
    max-width: 500px;
    width: 100%;
    text-align: center;
}

.welcome-logo { 
    width: 64px; 
    height: 64px; 
    margin-bottom: 8px; 
    object-fit: contain;
    filter: drop-shadow(0 0 15px rgba(124, 109, 250, 0.3));
}

.welcome-title {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-1);
}

.welcome-sub {
    font-size: 18px;
    color: var(--text-2);
    opacity: 0.8;
}

/* Welcome app grid */
.welcome-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    width: 100%;
}
.wcard {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    cursor: pointer;
    transition: border-color var(--t), transform var(--t), box-shadow var(--t), background var(--t);
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    overflow: hidden;
}
.wcard:hover {
    border-color: var(--card-color, var(--accent));
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0,0,0,.4);
    background: var(--bg-2);
}
.wcard-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
}
.wcard-name {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-1);
}
.wcard-desc {
    font-size: 11.5px;
    color: var(--text-3);
    line-height: 1.4;
}
.wcard-health {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-3);
    margin-top: auto;
    padding-top: 4px;
}
.wcard-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-3);
    transition: background .4s;
}
.wcard-dot.online  { background: var(--green); }
.wcard-dot.offline { background: var(--red); }

/* ── Loading Screen ───────────────────────────────────────────────── */
.loading-screen {
    background: var(--bg);
    gap: 18px;
    animation: fadeUp .2s var(--ease);
}
.spinner { width: 44px; height: 44px; }
.spin-arc { animation: rotate 1s linear infinite; transform-origin: 22px 22px; }
@keyframes rotate { to { transform: rotate(360deg); } }
.loading-label { font-size: 17px; color: var(--text-2); }

/* ── Error Screen ─────────────────────────────────────────────────── */
.error-screen {
    background: var(--bg);
    gap: 12px;
    animation: fadeUp .3s var(--ease);
}
.error-icon { font-size: 36px; }
.error-title { font-size: 18px; font-weight: 700; color: var(--text-1); }
.error-msg { font-size: 17px; color: var(--text-2); text-align: center; max-width: 380px; }

/* ── App iframe ───────────────────────────────────────────────────── */
.app-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: var(--bg);
    animation: fadeUp .3s var(--ease);
}

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: var(--radius);
    font-size: 17px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: opacity var(--t), transform var(--t);
    margin-top: 6px;
}
.btn-primary:hover { opacity: .88; transform: translateY(-1px); }

/* ── Mobile overlay ───────────────────────────────────────────────── */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 90;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}
.overlay.active { display: block; }

/* ── Animations ───────────────────────────────────────────────────── */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Scrollbar ────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .welcome-title { font-size: 36px; }
    .welcome-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .api-pill { display: none !important; }
}
