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

/* ── App Loader (shown until auth resolves) ──────────────── */
.app-loader {
    position: fixed; inset: 0; z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    background: #f5f7fa;
}
.app-loader-spinner {
    width: 36px; height: 36px;
    border: 3px solid #e5e7eb;
    border-top-color: #00aeff;
    border-radius: 50%;
    animation: loader-spin .7s linear infinite;
}
@keyframes loader-spin { to { transform: rotate(360deg); } }

:root {
    --primary: #1a1a2e;
    --primary-light: #2d2d44;
    --accent: #00aeff;
    --accent-hover: #0090d0;
    --accent-light: #e6f6ff;
    --bg: #f5f7fa;
    --bg-card: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --border: #e5e7eb;
    --border-light: #f0f0f0;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.12);
    --transition: 0.2s ease;
    --sidebar-width: 260px;
    --toolbar-height: 56px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html { font-size: 15px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── Layout ──────────────────────────────────────────────── */
#app {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--toolbar-height) 1fr;
    grid-template-areas:
        "toolbar toolbar"
        "sidebar content";
    min-height: 100vh;
}

.toolbar {
    grid-area: toolbar;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--toolbar-height);
}
.toolbar-left { display: flex; align-items: center; gap: 12px; }
.toolbar-right { display: flex; align-items: center; gap: 12px; }

.menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-xs);
    color: var(--text);
}
.menu-btn:hover { background: var(--bg); }

.logo { display: flex; align-items: center; gap: 10px; }
.logo-text { font-weight: 700; font-size: 1.1rem; color: var(--text); }

.lang-btn {
    font-size: 0.8rem;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg-card);
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
}
.lang-btn:hover { border-color: var(--accent); color: var(--accent); }

.sidebar {
    grid-area: sidebar;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 20px 12px;
    overflow-y: auto;
    height: calc(100vh - var(--toolbar-height));
    position: sticky;
    top: var(--toolbar-height);
}

.sidebar-profile {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0 20px;
    border-bottom: 1px solid var(--border-light);
    margin-bottom: 16px;
}
.sidebar-username { font-weight: 600; margin-top: 8px; font-size: 0.95rem; }
.sidebar-email { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.role-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    background: var(--accent-light);
    color: var(--accent);
    margin-top: 4px;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    transition: var(--transition);
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--accent-light); color: var(--accent); }

.content {
    grid-area: content;
    padding: 24px;
    overflow-y: auto;
    height: calc(100vh - var(--toolbar-height));
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    font-family: var(--font);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg { padding: 12px 28px; font-size: 1rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-title { font-weight: 600; font-size: 1rem; margin-bottom: 6px; }
.card-desc { color: var(--text-secondary); font-size: 0.85rem; line-height: 1.5; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-weight: 500; font-size: 0.85rem; margin-bottom: 6px; color: var(--text); }
.form-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font);
    transition: var(--transition);
    background: var(--bg-card);
    color: var(--text);
}
.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,174,255,0.1); }
textarea.form-input { resize: vertical; min-height: 80px; }

/* ── Avatar ──────────────────────────────────────────────── */
.avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 0.85rem;
    cursor: pointer;
    position: relative;
}
.avatar-lg { width: 56px; height: 56px; font-size: 1.2rem; }
.avatar-sm { width: 28px; height: 28px; font-size: 0.7rem; flex-shrink: 0; }

/* ── User menu dropdown ──────────────────────────────────── */
.user-menu { position: relative; }
.user-menu-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 4px 8px 4px 4px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}
.user-menu-trigger:hover { background: var(--bg); }
.user-menu-info {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}
.user-menu-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}
.user-menu-email {
    font-size: 0.72rem;
    color: var(--text-muted);
}
@media (max-width: 600px) {
    .user-menu-info { display: none; }
}
.dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    padding: 8px 0;
    z-index: 200;
}
.dropdown.open { display: block; }
.dropdown-header { padding: 10px 16px 2px; font-weight: 600; font-size: 0.9rem; }
.dropdown-email { padding: 0 16px 4px; font-size: 0.75rem; color: var(--text-muted); }
.dropdown-role { padding: 0 16px 8px; font-size: 0.75rem; color: var(--text-muted); }
.dropdown hr { border: none; border-top: 1px solid var(--border-light); margin: 4px 0; }
.dropdown a {
    display: block; padding: 8px 16px; color: var(--text);
    font-size: 0.85rem; transition: var(--transition);
}
.dropdown a:hover { background: var(--bg); }

/* ── Auth pages ──────────────────────────────────────────── */
.auth-page {
    display: flex; align-items: center; justify-content: center;
    min-height: calc(100vh - var(--toolbar-height) - 48px);
}
.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}
.auth-card h2 { text-align: center; margin-bottom: 24px; font-size: 1.3rem; }
.auth-card .form-error { color: var(--danger); font-size: 0.8rem; margin-top: 8px; text-align: center; }
.auth-footer { text-align: center; margin-top: 16px; font-size: 0.85rem; color: var(--text-secondary); }
.auth-divider { display: flex; align-items: center; margin: 18px 0; color: var(--text-secondary); font-size: 0.8rem; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; border-bottom: 1px solid var(--border); }
.auth-divider span { padding: 0 12px; }
.btn-google { width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 11px 20px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text-primary); font-size: 0.9rem; font-weight: 500; cursor: pointer; transition: background 0.15s, box-shadow 0.15s; }
.btn-google:hover { background: var(--bg-secondary); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

/* ── Agent grid ──────────────────────────────────────────── */
.agents-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.agents-header h1 { font-size: 1.4rem; font-weight: 700; }
.agents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}
.agent-card { cursor: pointer; }
.agent-card:hover { border-color: var(--accent); }
.agent-card .agent-name {
    font-weight: 600; font-size: 1rem;
    margin-bottom: 4px;
    display: flex; align-items: center; gap: 8px;
}
.agent-card .agent-desc {
    color: var(--text-secondary); font-size: 0.85rem;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.agent-card .agent-meta {
    display: flex; gap: 12px; margin-top: 12px; font-size: 0.75rem; color: var(--text-muted);
}
.agent-icon {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent), #6366f1);
    display: flex; align-items: center; justify-content: center;
}
.agent-icon svg { color: #fff; }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state svg { margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-size: 1.1rem; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { font-size: 0.9rem; margin-bottom: 20px; }

/* ── Table ───────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border-light); }
th { font-weight: 600; color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }
tr:hover td { background: var(--bg); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 500;
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 28px;
    width: 90%; max-width: 500px;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: transform 0.2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal h3 { margin-bottom: 16px; font-size: 1.1rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* ── Toast ───────────────────────────────────────────────── */
.toast-container { position: fixed; top: 72px; right: 20px; z-index: 600; display: flex; flex-direction: column; gap: 8px; }
.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease;
    max-width: 360px;
}
.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--accent); color: #fff; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Loading ─────────────────────────────────────────────── */
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    #app {
        grid-template-columns: 1fr;
        grid-template-areas: "toolbar" "content";
    }
    .sidebar {
        position: fixed;
        left: -280px;
        top: var(--toolbar-height);
        width: 280px;
        height: calc(100vh - var(--toolbar-height));
        z-index: 150;
        transition: left 0.3s ease;
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { left: 0; }
    .menu-btn { display: block; }
    .content { padding: 16px; }
    .agents-grid { grid-template-columns: 1fr; }
}
