/* ===============================================
   CSS VARIABLES
   =============================================== */
:root {
    --primary-color: #ffffff;
    --secondary-color: #f1f5f9;
    --accent-color: #34d399;
    --accent-hover: #10b981;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --success-color: #34d399;
    --danger-color: #f87171;
    --warning-color: #fbbf24;
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --transition: 0.25s ease;
}

/* ===============================================
   RESET & BASE
   =============================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    line-height: 1.6;
    display: flex;
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ===============================================
   SIDEBAR
   =============================================== */
.sidebar {
    width: var(--sidebar-width);
    background: #ffffff;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    overflow: hidden;
    transition: transform var(--transition);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-color);
    text-decoration: none;
    letter-spacing: -0.01em;
}

.sidebar-brand i {
    font-size: 1.4rem;
}

.sidebar-brand-icon {
    width: 28px;
    height: 28px;
    object-fit: contain;
    filter: drop-shadow(0 0 4px rgba(56, 189, 248, 0.5));
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.25rem;
    display: none;
    transition: color var(--transition);
}

.sidebar-toggle:hover {
    color: var(--text-color);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.sidebar-section-title {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 1rem 1.25rem 0.35rem;
    margin-top: 0.25rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1.25rem;
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 0;
    transition: all var(--transition);
    position: relative;
    margin: 0.1rem 0.5rem;
    border-radius: 0.5rem;
}

.sidebar-link i {
    width: 18px;
    text-align: center;
    font-size: 0.95rem;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: color var(--transition);
}

.sidebar-link:hover {
    background-color: rgba(56, 189, 248, 0.08);
    color: var(--accent-color);
}

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

.sidebar-link.active {
    background-color: rgba(56, 189, 248, 0.12);
    color: var(--accent-color);
    font-weight: 600;
}

.sidebar-link.active i {
    color: var(--accent-color);
}

.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 15%;
    height: 70%;
    width: 3px;
    background: var(--accent-color);
    border-radius: 0 2px 2px 0;
    margin-left: -0.5rem;
}

.sidebar-spacer {
    flex: 1;
    min-height: 1rem;
}

/* User info at bottom of sidebar */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    margin: 0.5rem;
    background-color: rgba(0, 0, 0, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    flex-shrink: 0;
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-color), #10b981);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--primary-color);
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

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

.sidebar-user-email {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- Sidebar Dropdown ---- */
.sidebar-dropdown {
    margin: 0;
}

.sidebar-dropdown-btn {
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}

.sidebar-dropdown-count {
    margin-left: auto;
    background: rgba(52, 211, 153, 0.15);
    color: var(--accent-color);
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: 9999px;
    flex-shrink: 0;
}

.sidebar-dropdown-arrow {
    font-size: 0.7rem !important;
    flex-shrink: 0;
    transition: transform var(--transition);
    margin-left: 0.25rem;
}

.sidebar-dropdown-menu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.sidebar-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1.25rem 0.5rem 2.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    border-radius: 0.5rem;
    margin: 0.05rem 0.5rem;
    transition: all var(--transition);
}

.sidebar-dropdown-item:hover {
    color: var(--accent-color);
    background: rgba(52, 211, 153, 0.07);
}

.sidebar-dropdown-item.active {
    color: var(--accent-color);
    font-weight: 600;
    background: rgba(52, 211, 153, 0.1);
}

.sidebar-dropdown-empty {
    padding: 0.5rem 1.25rem 0.5rem 2.5rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    font-style: italic;
}

.sidebar-logout {
    color: var(--text-muted);
    font-size: 1rem;
    padding: 0.25rem;
    transition: color var(--transition);
    flex-shrink: 0;
}

.sidebar-logout:hover {
    color: var(--danger-color);
}

/* Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
    backdrop-filter: blur(2px);
}

/* ===============================================
   TOPBAR
   =============================================== */
.topbar {
    height: var(--topbar-height);
    background-color: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0.4rem;
    display: none;
    transition: color var(--transition);
    border-radius: 0.375rem;
}

.topbar-toggle:hover {
    color: var(--text-color);
    background-color: var(--secondary-color);
}

.topbar-breadcrumb {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.topbar-actions {
    font-size: 0.88rem;
    color: var(--text-muted);
}

.topbar-actions strong {
    color: var(--text-color);
}

/* ===============================================
   MAIN WRAPPER
   =============================================== */
.main-wrapper {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
}

.page-content {
    flex: 1;
    padding: 2rem;
}

/* ===============================================
   FLASH MESSAGES
   =============================================== */
.flash-container {
    padding: 0 1.5rem;
}

.flash-message {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border-radius: 0.5rem;
    margin-top: 0.75rem;
    font-size: 0.9rem;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.flash-close {
    background: none;
    border: none;
    cursor: pointer;
    margin-left: auto;
    color: inherit;
    opacity: 0.7;
    padding: 0.1rem 0.3rem;
    font-size: 0.85rem;
    transition: opacity var(--transition);
}

.flash-close:hover { opacity: 1; }

.flash-success {
    background-color: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.35);
    color: #15803d;
}

.flash-danger {
    background-color: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #b91c1c;
}

.flash-warning, .flash-info {
    background-color: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.35);
    color: #b45309;
}

/* ===============================================
   CARDS
   =============================================== */
.card {
    background-color: var(--card-bg);
    border-radius: 0.75rem;
    padding: 2rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
}

.card-sm {
    padding: 1.25rem;
}

/* ===============================================
   BUTTONS
   =============================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
    text-decoration: none;
    transition: all var(--transition);
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-color), #10b981);
    color: #ffffff;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(52, 211, 153, 0.35);
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

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

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-sm {
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
}

/* ===============================================
   FORMS
   =============================================== */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-color);
}

.form-control {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    background-color: #ffffff;
    color: var(--text-color);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

/* ===============================================
   TABLES
   =============================================== */
.table-wrapper {
    overflow-x: auto;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th {
    background-color: var(--primary-color);
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

td {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-color);
}

tr:hover td {
    background-color: rgba(0, 0, 0, 0.02);
}

/* ===============================================
   BADGES
   =============================================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-accent {
    background: rgba(56, 189, 248, 0.15);
    color: var(--accent-color);
}

.badge-success {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success-color);
}

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

.badge-muted {
    background: rgba(148, 163, 184, 0.15);
    color: var(--text-muted);
}

/* ===============================================
   PAGE HEADER
   =============================================== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.75rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0;
    background: linear-gradient(to right, var(--accent-color), #6ee7b7);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.page-header p {
    color: var(--text-muted);
    margin: 0.25rem 0 0 0;
    font-size: 0.9rem;
}

/* ===============================================
   HERO (index page)
   =============================================== */
.hero {
    text-align: center;
    padding: 4rem 0 3rem;
}

.hero h1 {
    font-size: 2.8rem;
    font-weight: 800;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--accent-color), #6ee7b7);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero p {
    color: var(--text-muted);
    font-size: 1.1rem;
    max-width: 500px;
    margin: 0 auto 2rem;
}

/* ===============================================
   SECTION TABS (for profile sub-sections)
   =============================================== */
.tabs {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

.tab {
    padding: 0.6rem 1.1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border: none;
    background: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all var(--transition);
    font-family: inherit;
    border-radius: 0.375rem 0.375rem 0 0;
}

.tab:hover {
    color: var(--text-color);
}

.tab.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

/* ===============================================
   STAT CARDS
   =============================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.25rem;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-color);
    line-height: 1;
}

.stat-card .stat-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ===============================================
   EMPTY STATE
   =============================================== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.4;
    display: block;
}

.empty-state p {
    margin: 0 0 1.5rem;
    font-size: 1rem;
}

/* ===============================================
   RESPONSIVE
   =============================================== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
    }

    .sidebar-overlay.active {
        display: block;
    }

    .sidebar-toggle,
    .topbar-toggle {
        display: block;
    }

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

    .page-content {
        padding: 1.25rem;
    }

    .hero h1 {
        font-size: 1.9rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 769px) {
    .sidebar-toggle {
        display: none !important;
    }
}

h1, h2, h3, h4 {
    margin-top: 0;
    color: var(--text-color);
}