/* ═══════════════════════════════════════════════════════
   KeySEO — Sidebar CSS
   WordPress-style Admin Layout
════════════════════════════════════════════════════════ */

/* ── Variables ─────────────────────────────────────────── */
:root {
    --sidebar-w:        240px;
    --sidebar-w-col:    68px;   /* Collapsed width */
    --topbar-h:         56px;
    --sidebar-bg:       #1e1e3f;
    --sidebar-hover:    #2d2d5e;
    --sidebar-active:   #4f46e5;
    --sidebar-text:     #c5c7e8;
    --sidebar-muted:    #7c7fa8;
    --sidebar-brand-h:  64px;
    --accent:           #4f46e5;
    --radius:           8px;
    --transition:       0.22s ease;
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { background: #f4f5f7; font-family: 'Inter', sans-serif; }

/* ══════════════════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════════════════ */
.sidebar-nav {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 200;
    transition: width var(--transition), transform var(--transition);
    overflow: hidden;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
}

/* Collapsed state */
.sidebar-nav.collapsed {
    width: var(--sidebar-w-col);
}
.sidebar-nav.collapsed .sidebar-brand-text,
.sidebar-nav.collapsed .sidebar-section-label,
.sidebar-nav.collapsed .sidebar-project-header,
.sidebar-nav.collapsed .sidebar-item span:not(.sidebar-badge),
.sidebar-nav.collapsed .sidebar-badge,
.sidebar-nav.collapsed .sidebar-footer {
    opacity: 0;
    pointer-events: none;
    width: 0;
    overflow: hidden;
    white-space: nowrap;
}
.sidebar-nav.collapsed .sidebar-item {
    justify-content: center;
    padding: 10px;
}
.sidebar-nav.collapsed .sidebar-icon {
    margin: 0;
}
.sidebar-nav.collapsed .sidebar-item-sub {
    display: none;
}

/* ── Brand ─────────────────────────────────────────────── */
.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: var(--sidebar-brand-h);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}
.sidebar-logo-icon {
    width: 34px; height: 34px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    flex-shrink: 0;
}
.sidebar-brand-text {
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.3px;
    transition: opacity var(--transition), width var(--transition);
    white-space: nowrap;
}
.sidebar-toggle-btn {
    color: var(--sidebar-muted);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: none; /* only visible on mobile */
}
.sidebar-toggle-btn:hover { color: #fff; background: var(--sidebar-hover); }

/* ── Scroll Area ────────────────────────────────────────── */
.sidebar-nav {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #2d2d5e transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #2d2d5e; border-radius: 4px; }

/* ── Section ────────────────────────────────────────────── */
.sidebar-section {
    padding: 8px 0;
    flex-shrink: 0;
}
.sidebar-section-label {
    padding: 4px 18px 2px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
    white-space: nowrap;
    transition: opacity var(--transition);
}
.sidebar-divider {
    height: 1px;
    background: rgba(255,255,255,0.06);
    margin: 4px 0;
    flex-shrink: 0;
}

/* ── Project Header ─────────────────────────────────────── */
.sidebar-project-header {
    padding: 10px 18px;
    transition: opacity var(--transition);
}
.sidebar-project-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
    margin-bottom: 4px;
}
.sidebar-project-name {
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 190px;
}
.sidebar-project-domain {
    font-size: 11px;
    color: var(--sidebar-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

/* ── Menu Items ─────────────────────────────────────────── */
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px 9px 18px;
    margin: 1px 8px;
    border-radius: 7px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
    overflow: hidden;
    position: relative;
}
.sidebar-item:hover {
    background: var(--sidebar-hover);
    color: #fff;
}
.sidebar-item.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
}
.sidebar-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 18px;
    background: #a5b4fc;
    border-radius: 0 3px 3px 0;
}
.sidebar-item-sub {
    padding-left: 44px;
    font-size: 12.5px;
    color: var(--sidebar-muted);
}
.sidebar-item-sub:hover { color: #fff; }
.sidebar-item-sub.active { color: #fff; }

/* ── Icon ───────────────────────────────────────────────── */
.sidebar-icon {
    width: 18px; height: 18px;
    flex-shrink: 0;
    transition: transform var(--transition);
}
.sidebar-item:hover .sidebar-icon { transform: scale(1.1); }

/* ── Badge ──────────────────────────────────────────────── */
.sidebar-badge {
    margin-left: auto;
    background: rgba(79, 70, 229, 0.35);
    color: #a5b4fc;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 20px;
    flex-shrink: 0;
    min-width: 22px;
    text-align: center;
}
.sidebar-item.active .sidebar-badge {
    background: rgba(255,255,255,0.2);
    color: #fff;
}

/* ── Footer ─────────────────────────────────────────────── */
.sidebar-footer {
    margin-top: auto;
    padding: 12px 18px;
    border-top: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
    transition: opacity var(--transition);
}

/* ══════════════════════════════════════════════════════
   MAIN AREA
══════════════════════════════════════════════════════ */
.main-area {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition);
    min-width: 0;
    width: 0; /* flex:1 + width:0 đảm bảo stretch đúng trong flex parent */
}
.main-area.sidebar-collapsed {
    margin-left: var(--sidebar-w-col);
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    flex-shrink: 0;
}
.topbar-menu-btn {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}
.topbar-menu-btn:hover { background: #f3f4f6; color: #111; }
.topbar-breadcrumb {
    display: flex;
    align-items: center;
    font-size: 13.5px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.topbar-btn-primary {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 7px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.1s;
}
.topbar-btn-primary:hover { background: #4338ca; transform: translateY(-1px); }

/* ── Flash Messages ─────────────────────────────────────── */
.flash-success,
.flash-error {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 24px;
    font-size: 13.5px;
    font-weight: 500;
    border-bottom: 1px solid transparent;
}
.flash-success {
    background: #ecfdf5;
    color: #065f46;
    border-bottom-color: #6ee7b7;
}
.flash-error {
    background: #fef2f2;
    color: #991b1b;
    border-bottom-color: #fca5a5;
}

/* ── Page Content ───────────────────────────────────────── */
.page-content {
    padding: 24px;
    flex: 1;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

/* ══════════════════════════════════════════════════════
   OVERLAY (mobile)
══════════════════════════════════════════════════════ */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
}
.sidebar-overlay.active { display: block; }

/* ══════════════════════════════════════════════════════
   RESPONSIVE — Mobile
══════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .sidebar-nav {
        transform: translateX(-100%);
        width: var(--sidebar-w) !important;
    }
    .sidebar-nav.open {
        transform: translateX(0);
    }
    .sidebar-toggle-btn { display: flex; }

    .main-area {
        margin-left: 0 !important;
    }

    .page-content { padding: 16px; }
    .topbar { padding: 0 16px; }
}

/* ══════════════════════════════════════════════════════
   EXISTING UTILITY CLASSES (từ style.css cũ)
══════════════════════════════════════════════════════ */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 7px;
    padding: 8px 16px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover { background: #4338ca; transform: translateY(-1px); }

.table-hover tbody tr:hover { background: #f5f7ff; }

/* Card styles */
.card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    border: 1px solid #e5e7eb;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-body { padding: 20px; }

/* Alerts (auto-hide via JS) */
.alert { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Cluster Grid Layout ────────────────────────────────── */
.grid-toggle-btn {
    background: #fff;
    color: #6b7280;
    border-color: #d1d5db;
    cursor: pointer;
    letter-spacing: 1px;
}
.grid-toggle-btn:hover {
    background: #f5f3ff;
    border-color: #6d28d9;
    color: #4f46e5;
}
.grid-toggle-btn.active {
    background: #4f46e5;
    color: #fff;
    border-color: #4f46e5;
}

/* Cluster full-width (unassigned) */
.cluster-full-width {
    grid-column: 1 / -1;
}

/* Responsive grid fallback */
@media (max-width: 768px) {
    #clustersList {
        grid-template-columns: 1fr !important;
    }
    .cluster-full-width {
        grid-column: 1 / -1 !important;
    }
}
