/* ─── MODERN SIDEBAR - shadcn-style dashboard ─── */
/* Uses theme CSS variables for emerald/zinc color scheme */

:root {
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 72px;
    --sidebar-brand-height: 64px;
}

/* ─── LAYOUT ─── */
.sidebar-layout {
    display: flex;
    min-height: 100vh;
    background: var(--background);
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar);
    color: var(--sidebar-foreground);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--sidebar-border);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* ─── BRAND HEADER ─── */
.sidebar-header {
    height: var(--sidebar-brand-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
    gap: 12px;
}

.sidebar-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 800;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
}

.sidebar-brand-text .brand-name {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--sidebar-foreground);
    white-space: nowrap;
}

.sidebar-brand-text .brand-name span {
    color: var(--primary);
}

.sidebar-collapse-btn {
    background: none;
    border: none;
    color: var(--sidebar-muted-foreground);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin-left: auto;
}

.sidebar-collapse-btn:hover {
    background: var(--sidebar-accent);
    color: var(--sidebar-foreground);
}

/* ─── NAVIGATION ─── */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 8px;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}
.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--sidebar-border);
    border-radius: 4px;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: var(--sidebar-muted-foreground);
}

.sidebar-section {
    margin-bottom: 24px;
}

.sidebar-section-title {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--sidebar-muted-foreground);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .sidebar-section-title {
    text-align: center;
    padding: 8px 4px;
}

.sidebar-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-menu-item {
    margin: 2px 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--sidebar-muted-foreground);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
    position: relative;
}

.sidebar-link:hover {
    background: var(--sidebar-accent);
    color: var(--sidebar-foreground);
}

.sidebar-link.active {
    background: var(--primary);
    color: var(--primary-foreground);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
}

.sidebar-link.active .sidebar-link-icon {
    color: var(--primary-foreground);
}

.sidebar-link-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 18px;
}

.sidebar-link-text {
    flex: 1;
    min-width: 0;
}

.sidebar-link-badge {
    background: var(--primary);
    color: var(--primary-foreground);
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

.sidebar.collapsed .sidebar-link-text,
.sidebar.collapsed .sidebar-section-title {
    display: none;
}

.sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding: 10px;
}

.sidebar.collapsed .sidebar-link-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    padding: 1px 4px;
    font-size: 9px;
}

/* ─── SIDEBAR FOOTER ─── */
.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    text-decoration: none;
    color: var(--sidebar-foreground);
    transition: background 0.2s;
    margin-bottom: 8px;
}

.sidebar-user:hover {
    background: var(--sidebar-accent);
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 12px;
    color: var(--sidebar-muted-foreground);
}

.sidebar-footer-actions {
    display: flex;
    gap: 4px;
}

.sidebar-footer-action {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border: none;
    background: none;
    color: var(--sidebar-muted-foreground);
    cursor: pointer;
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.2s;
}

.sidebar-footer-action:hover {
    background: var(--sidebar-accent);
    color: var(--sidebar-foreground);
}

.sidebar.collapsed .sidebar-user-info,
.sidebar.collapsed .sidebar-footer-actions {
    display: none;
}

.sidebar.collapsed .sidebar-user {
    justify-content: center;
    padding: 8px;
}

/* ─── SUBMENU ─── */
.sidebar-submenu-arrow {
    transition: transform 0.2s;
}

.sidebar-menu-item.has-submenu .sidebar-submenu-arrow {
    transform: rotate(0deg);
}

.sidebar-menu-item.has-submenu.open .sidebar-submenu-arrow {
    transform: rotate(180deg);
}

.sidebar-submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    display: none;
    padding-left: 2rem;
}

.sidebar-menu-item.has-submenu.open .sidebar-submenu {
    display: block;
}

.sidebar-submenu-item {
    margin: 2px 0;
}

.sidebar-submenu-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    color: var(--sidebar-muted-foreground);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.sidebar-submenu-link:hover {
    background: var(--sidebar-accent);
    color: var(--sidebar-foreground);
}

.sidebar-submenu-link.active {
    background: var(--primary);
    color: var(--primary-foreground);
}

.sidebar.collapsed .sidebar-submenu {
    display: none !important;
}

/* ─── MAIN CONTENT ─── */
.sidebar-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.3s;
}

.sidebar.collapsed ~ .sidebar-main {
    margin-left: var(--sidebar-collapsed-width);
}

/* ─── TOPBAR (mobile) ─── */
.sidebar-topbar {
    display: none;
    height: var(--sidebar-brand-height);
    align-items: center;
    padding: 0 16px;
    background: var(--sidebar);
    color: var(--sidebar-foreground);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999;
    border-bottom: 1px solid var(--sidebar-border);
    gap: 12px;
}

.sidebar-topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.sidebar-topbar-brand a {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--sidebar-foreground);
    text-decoration: none;
}

.sidebar-topbar-brand a span {
    color: var(--primary);
}

.sidebar-topbar-toggle {
    background: none;
    border: none;
    color: var(--sidebar-foreground);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    font-size: 20px;
}

.sidebar-topbar-toggle:hover {
    background: var(--sidebar-accent);
}

/* ─── PAGE LAYOUT ─── */
.page-container {
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
}

.page-header {
    margin-bottom: 24px;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--foreground);
    margin: 0 0 4px;
}

.page-subtitle {
    color: var(--muted-foreground);
    font-size: 0.9rem;
    margin: 0;
}

/* ─── STATS GRID ─── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: all 0.2s;
}

.stat-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
}

.stat-card.accent::before {
    background: var(--accent);
}

.stat-card.warning::before {
    background: #f59e0b;
}

.stat-card.danger::before {
    background: var(--destructive);
}

.stat-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 12px;
}

.stat-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: var(--primary);
    color: var(--primary-foreground);
    opacity: 0.9;
}

.stat-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--foreground);
    line-height: 1.2;
}

.stat-card-label {
    font-size: 0.875rem;
    color: var(--muted-foreground);
    margin-top: 4px;
}

.stat-card-trend {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    margin-top: 8px;
}

.stat-card-trend.up {
    color: var(--primary);
}

.stat-card-trend.down {
    color: var(--destructive);
}

/* ─── CARDS / PANELS ─── */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--foreground);
    margin: 0;
}

.card-description {
    font-size: 0.875rem;
    color: var(--muted-foreground);
    margin: 0;
}

.card-content {
    padding: 20px;
}

.card-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

/* ─── GRID LAYOUTS ─── */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
}

@media (max-width: 1200px) {
    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .grid-2, .grid-3 {
        grid-template-columns: 1fr;
    }
}

/* ─── CHARTS PLACEHOLDER ─── */
.chart-container {
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--muted);
    border-radius: var(--radius);
    color: var(--muted-foreground);
    font-size: 0.875rem;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 100px;
    padding: 0 20px;
}

.chart-bar {
    width: 24px;
    background: linear-gradient(to top, var(--primary), var(--accent));
    border-radius: 4px 4px 0 0;
    transition: height 0.3s ease;
}

/* ─── TABLES ─── */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table thead {
    background: var(--muted);
}

.data-table th {
    text-align: left;
    padding: 12px 16px;
    font-weight: 600;
    color: var(--muted-foreground);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--foreground);
}

.data-table tbody tr:hover td {
    background: var(--card);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* ─── BADGES ─── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.badge-success {
    background: rgba(16, 185, 129, 0.15);
    color: var(--primary);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--destructive);
}

.badge-info {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.badge-secondary {
    background: rgba(107, 114, 128, 0.15);
    color: #6b7280;
}

/* ─── BUTTONS ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: var(--primary-foreground);
}

.btn-primary:hover {
    background: var(--primary-hover, var(--accent-hover));
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--secondary);
    color: var(--secondary-foreground);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--foreground);
}

.btn-outline:hover {
    background: var(--muted);
    border-color: var(--primary);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 16px;
}

/* ─── RESPONSIVE ─── */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
        z-index: 1001;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar.open::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }

    .sidebar-main {
        margin-left: 0;
    }

    .sidebar-topbar {
        display: flex;
    }

    .page-container {
        padding: 16px;
        padding-top: calc(var(--sidebar-brand-height) + 16px);
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

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

.stat-card {
    animation: fadeIn 0.3s ease forwards;
}

.stat-card:nth-child(1) { animation-delay: 0ms; }
.stat-card:nth-child(2) { animation-delay: 50ms; }
.stat-card:nth-child(3) { animation-delay: 100ms; }
.stat-card:nth-child(4) { animation-delay: 150ms; }
.stat-card:nth-child(5) { animation-delay: 200ms; }
.stat-card:nth-child(6) { animation-delay: 250ms; }