/* ═══════════════════════════════════════════════════════════════════
   Platform Dashboard — Apple-inspired Dark Theme
   ═══════════════════════════════════════════════════════════════════ */

:root {
    /* Backgrounds */
    --bg-base: #1c1c1e;
    --bg-elevated: #2c2c2e;
    --bg-card: #2c2c2e;
    --bg-sidebar: #1c1c1e;
    --bg-topbar: #1c1c1ee6;
    --bg-hover: #3a3a3c;
    --bg-active: #48484a;
    --bg-input: #1c1c1e;

    /* Text */
    --text-primary: #f5f5f7;
    --text-secondary: #a1a1a6;
    --text-tertiary: #636366;

    /* Accent */
    --accent: #0a84ff;
    --accent-hover: #409cff;
    --green: #30d158;
    --green-glow: rgba(48, 209, 88, 0.25);
    --orange: #ff9f0a;
    --red: #ff453a;
    --yellow: #ffd60a;
    --purple: #bf5af2;

    /* Borders */
    --border: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(10, 132, 255, 0.5);

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Shadows */
    --shadow-card: 0 1px 3px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.15);
    --shadow-elevated: 0 4px 24px rgba(0,0,0,0.4);

    /* Layout */
    --sidebar-width: 240px;
    --topbar-height: 60px;

    /* Font */
    --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', 'Inter', sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', monospace;
}

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

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-base);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ── Login Overlay ───────────────────────────────────────────── */
.login-overlay {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-base);
}
.login-card {
    width: 360px; padding: 40px;
    background: var(--bg-elevated);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-elevated);
    text-align: center;
    animation: fadeInUp 0.4s ease;
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
.login-logo { font-size: 48px; margin-bottom: 12px; }
.login-card h1 {
    font-size: 28px; font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}
.login-subtitle {
    color: var(--text-secondary);
    font-size: 15px; margin-bottom: 32px;
}
.input-group { margin-bottom: 16px; }
.input-group input {
    width: 100%; padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 15px; font-family: var(--font);
    outline: none; transition: border-color 0.2s;
}
.input-group input:focus { border-color: var(--border-focus); }
.input-group input::placeholder { color: var(--text-tertiary); }
#login-btn {
    width: 100%; padding: 12px;
    background: var(--accent);
    border: none; border-radius: var(--radius-md);
    color: white; font-size: 15px; font-weight: 600;
    font-family: var(--font);
    cursor: pointer; transition: background 0.2s;
    margin-top: 8px;
}
#login-btn:hover { background: var(--accent-hover); }
#login-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.login-error {
    margin-top: 16px; padding: 10px 14px;
    background: rgba(255, 69, 58, 0.12);
    border: 1px solid rgba(255, 69, 58, 0.3);
    border-radius: var(--radius-sm);
    color: var(--red); font-size: 13px;
    text-align: left;
}

/* ── App Layout ──────────────────────────────────────────────── */
.app {
    display: flex; height: 100vh; overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width); min-width: var(--sidebar-width);
    height: 100vh; background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
}
.sidebar-logo {
    height: var(--topbar-height);
    display: flex; align-items: center; gap: 10px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
}
.logo-icon { font-size: 24px; }
.logo-text { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.sidebar-nav {
    flex: 1; overflow-y: auto;
    padding: 12px 12px 0;
}
.nav-section-label {
    padding: 16px 8px 6px;
    font-size: 11px; font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-tertiary);
}
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none; font-size: 14px;
    font-weight: 500;
    transition: all 0.15s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--accent); color: white; }
.nav-item.active svg { stroke: white; }
.nav-item .agent-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    flex-shrink: 0;
    transition: background 0.3s, box-shadow 0.3s;
}
.nav-item .agent-dot.active {
    background: var(--green);
    box-shadow: 0 0 8px var(--green-glow);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}
.sidebar-user {
    display: flex; align-items: center; gap: 10px;
}
.user-avatar {
    width: 32px; height: 32px;
    background: var(--accent);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 600;
}
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-tertiary); }

/* ── Main Content ────────────────────────────────────────────── */
.main-content {
    flex: 1; display: flex; flex-direction: column;
    overflow: hidden;
}

/* ── Top Bar ─────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-height); min-height: var(--topbar-height);
    display: flex; align-items: center; gap: 16px;
    padding: 0 24px;
    background: var(--bg-topbar);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    z-index: 50;
}
.topbar-menu-btn {
    display: none; background: none; border: none;
    color: var(--text-secondary); cursor: pointer; padding: 4px;
}
.topbar-title { flex: 1; display: flex; align-items: center; gap: 12px; }
.topbar-title h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.topbar-connection {
    display: flex; align-items: center; gap: 6px;
    font-size: 12px; color: var(--text-tertiary);
}
.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
}
.status-dot.connected { background: var(--green); box-shadow: 0 0 6px var(--green-glow); }
.status-dot.disconnected { background: var(--red); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-time {
    font-size: 13px; color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* ── Pages ───────────────────────────────────────────────────── */
.page { display: none; flex: 1; overflow-y: auto; padding: 24px; }
.page.active { display: flex; flex-direction: column; gap: 24px; }

/* ── Sections ────────────────────────────────────────────────── */
.section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}
.section-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
}
.section-header h2 {
    font-size: 17px; font-weight: 700;
    letter-spacing: -0.2px;
}

/* ── Dashboard Top (Agents + Health split) ───────────────────── */
.dashboard-top {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* Agent Cards */
.agent-section { min-height: 200px; }
.agent-count, .log-count {
    background: var(--bg-active);
    color: var(--text-secondary);
    font-size: 12px; font-weight: 600;
    padding: 2px 8px; border-radius: 10px;
}
.agent-grid {
    display: flex; flex-direction: column; gap: 10px;
}
.agent-card {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 16px;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
    cursor: default;
}
.agent-card.active {
    border-color: rgba(48, 209, 88, 0.4);
    box-shadow: 0 0 20px var(--green-glow), inset 0 0 20px rgba(48, 209, 88, 0.05);
}
.agent-card.active .agent-avatar {
    box-shadow: 0 0 12px var(--green-glow);
}
.agent-avatar {
    width: 44px; height: 44px; min-width: 44px;
    border-radius: 50%;
    background: var(--bg-elevated);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    transition: box-shadow 0.3s;
}
.agent-info { flex: 1; min-width: 0; }
.agent-name {
    font-size: 15px; font-weight: 700;
    letter-spacing: -0.2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.agent-model {
    font-size: 12px; color: var(--text-tertiary);
    font-family: var(--font-mono);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.agent-role {
    font-size: 11px; color: var(--text-secondary);
    margin-top: 1px;
}
.agent-status-badge {
    padding: 3px 10px; border-radius: 12px;
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.agent-status-badge.active {
    background: rgba(48, 209, 88, 0.15); color: var(--green);
}
.agent-status-badge.idle {
    background: var(--bg-active); color: var(--text-tertiary);
}

/* Health Panel */
.health-live-badge {
    padding: 3px 10px; border-radius: 12px;
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1px;
    background: rgba(255, 69, 58, 0.15);
    color: var(--red);
    animation: pulse-badge 2s infinite;
}
@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}
.health-card {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
}
.health-label {
    font-size: 11px; color: var(--text-tertiary);
    text-transform: uppercase; letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.health-value {
    font-size: 22px; font-weight: 700;
    letter-spacing: -0.5px;
    font-variant-numeric: tabular-nums;
}
.health-bar {
    margin-top: 8px; height: 4px;
    background: var(--bg-active);
    border-radius: 2px; overflow: hidden;
}
.health-bar-fill {
    height: 100%; border-radius: 2px;
    background: var(--accent);
    transition: width 0.5s ease, background 0.3s;
    width: 0%;
}
.health-bar-fill.warn { background: var(--orange); }
.health-bar-fill.crit { background: var(--red); }

/* ── Console ─────────────────────────────────────────────────── */
.console-section { padding: 0; overflow: hidden; }
.console-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
}
.console-header h2 { font-size: 15px; font-weight: 700; }
.console-controls { display: flex; align-items: center; gap: 8px; }
.console-select {
    padding: 6px 12px;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px; font-family: var(--font);
    outline: none; cursor: pointer;
}
.console-select option { background: var(--bg-elevated); }
.console-clear-btn {
    padding: 6px 12px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px; font-family: var(--font);
    cursor: pointer; transition: all 0.15s;
}
.console-clear-btn:hover { background: var(--bg-active); color: var(--text-primary); }
.console-body {
    height: 280px; overflow-y: auto;
    padding: 16px 20px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    background: #141414;
}
.console-welcome { color: var(--text-tertiary); }
.console-prompt {
    color: var(--green); font-weight: 700;
    margin-right: 8px;
}
.console-line { margin-bottom: 4px; word-break: break-word; }
.console-line.user { color: var(--accent); }
.console-line.agent { color: var(--text-primary); }
.console-line.system { color: var(--text-tertiary); font-style: italic; }
.console-line .time {
    color: var(--text-tertiary);
    font-size: 11px;
    margin-right: 8px;
}
.console-input-row {
    display: flex; align-items: center; gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: #141414;
}
.console-input {
    flex: 1; padding: 8px 0;
    background: transparent; border: none;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 13px; outline: none;
}
.console-input::placeholder { color: var(--text-tertiary); }
.console-send-btn {
    background: var(--accent);
    border: none; border-radius: var(--radius-sm);
    color: white; padding: 8px 12px;
    cursor: pointer; transition: background 0.15s;
    display: flex; align-items: center;
}
.console-send-btn:hover { background: var(--accent-hover); }
.console-send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Logs ────────────────────────────────────────────────────── */
.logs-section { max-height: 400px; }
.logs-body {
    max-height: 280px; overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 12px;
}
.log-entry {
    display: flex; gap: 10px; align-items: baseline;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.1s;
}
.log-entry:hover { background: var(--bg-hover); }
.log-time { color: var(--text-tertiary); white-space: nowrap; font-size: 11px; }
.log-source {
    font-weight: 600; white-space: nowrap;
    min-width: 80px;
}
.log-level {
    font-weight: 600; text-transform: uppercase;
    font-size: 10px; letter-spacing: 0.5px;
    min-width: 40px;
}
.log-level.info { color: var(--accent); }
.log-level.warn { color: var(--orange); }
.log-level.error { color: var(--red); }
.log-level.debug { color: var(--text-tertiary); }
.log-msg { color: var(--text-secondary); word-break: break-word; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-elevated); }
    .topbar-menu-btn { display: flex; }
    .dashboard-top { grid-template-columns: 1fr; }
}
