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

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 260px;
    height: 100vh;
    background: #ffffff;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 1100;
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    overflow-y: auto;
    overflow-x: hidden;
}
[data-theme="dark"] .sidebar { background: var(--bg-secondary); }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0; height: 64px;
    background: var(--topbar-bg);
    color: var(--topbar-text);
    flex-shrink: 0;
    padding: 0 1rem;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.logo-icon { font-size: 1.75rem; }
.logo-text { display: flex; flex-direction: column; }
.logo-title { font-weight: 800; font-size: 1.05rem; color: var(--topbar-text); line-height: 1.2; }
.logo-subtitle { font-size: 0.7rem; color: rgba(255,255,255,0.85); line-height: 1.3; max-width: 160px; }

.sidebar-close {
    display: none;
    background: none; border: none;
    color: var(--text-secondary); cursor: pointer;
    padding: 0.25rem; border-radius: 0.375rem;
}
.sidebar-close:hover { background: var(--bg-tertiary); color: var(--text-primary); }

/* Sidebar Navigation */
.sidebar-nav { flex: 1; padding: 0.75rem 0; overflow-y: auto; }
.nav-section { padding: 0 0.75rem; margin-bottom: 0.5rem; }
.nav-section-title {
    display: block;
    padding: 0.5rem 0.75rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary, var(--text-secondary));
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.85rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: #475569;
    text-decoration: none;
    transition: all 0.15s;
    margin-bottom: 3px;
    position: relative;
}
[data-theme="dark"] .sidebar-link { color: var(--text-secondary); }
.sidebar-link:hover {
    background: var(--bg-tertiary);
    color: var(--color-primary);
    text-decoration: none;
}
.sidebar-link.active {
    background: linear-gradient(90deg, rgba(59,130,246,0.12), rgba(59,130,246,0.04));
    color: var(--color-primary);
    font-weight: 600;
}
.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: -0.75rem;
    top: 25%; bottom: 25%;
    width: 3px;
    background: var(--color-primary);
    border-radius: 0 3px 3px 0;
}

.sidebar-icon { width: 20px; height: 20px; flex-shrink: 0; }

/* Sidebar Footer */
.sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding: 0.75rem;
    flex-shrink: 0;
}
.sidebar-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.control-select {
    flex: 1;
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 0.8rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
}
.control-btn {
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}
.control-btn:hover { background: var(--bg-tertiary, #f3f4f6); color: var(--text-primary); }

.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }
[data-theme="dark"] .theme-icon-dark { display: block; }

.sidebar-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem;
    border-radius: 0.5rem;
    background: var(--bg-tertiary, #f3f4f6);
}
.user-profile-link {
    display: flex; align-items: center; gap: 0.625rem;
    text-decoration: none; color: var(--text-primary);
    flex: 1; min-width: 0;
}
.user-profile-link:hover { text-decoration: none; }
.user-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--gradient-primary, linear-gradient(135deg, #3b82f6, #2563eb));
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.875rem;
    flex-shrink: 0;
}
.user-details { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-weight: 600; font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role-badge { font-size: 0.65rem; color: var(--text-secondary); text-transform: capitalize; }

.sidebar-logout {
    display: flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    border-radius: 0.375rem;
    color: var(--text-secondary);
    transition: all 0.15s;
    flex-shrink: 0;
}
.sidebar-logout:hover { background: rgba(239,68,68,0.1); color: #ef4444; }

.sidebar-overlay {
    display: none;
    position: fixed; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 1050;
    backdrop-filter: blur(2px);
}

/* ===== Top Bar (brand blue) ===== */
.topbar {
    display: flex;
    position: fixed; top: 0; left: 260px; right: 0;
    height: 64px;
    background: var(--topbar-bg);
    color: var(--topbar-text);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem;
    z-index: 1000;
    transition: left 0.3s;
}
.hamburger {
    display: none;
    background: rgba(255,255,255,0.15); border: none;
    color: var(--topbar-text);
    cursor: pointer; padding: 0.5rem;
    border-radius: 0.5rem;
    align-items: center; justify-content: center;
}
.hamburger:hover { background: rgba(255,255,255,0.25); }
.topbar-title { font-weight: 700; font-size: 1.1rem; color: var(--topbar-text); }
.topbar-user-name {
    font-weight: 600;
    color: var(--topbar-text);
    margin-right: 0.5rem;
    white-space: nowrap;
}
.topbar-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.4);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.9rem; text-decoration: none;
    flex-shrink: 0;
    transition: all 0.15s;
}
.topbar-avatar:hover { background: rgba(255,255,255,0.3); transform: scale(1.05); }
.topbar-bell {
    position: relative;
    width: 40px; height: 40px;
    border-radius: 0.5rem;
    display: flex; align-items: center; justify-content: center;
    color: var(--topbar-text);
    background: rgba(255,255,255,0.1);
    transition: all 0.15s;
    flex-shrink: 0;
    text-decoration: none;
}
.topbar-bell:hover { background: rgba(255,255,255,0.22); }
.bell-badge {
    position: absolute; top: 2px; right: 2px;
    background: #ef4444; color: white;
    font-size: 0.65rem; font-weight: 700;
    min-width: 18px; height: 18px;
    border-radius: 9px; padding: 0 5px;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid #2f80ed;
}
.topbar-logout {
    width: 40px; height: 40px;
    border-radius: 0.5rem;
    display: flex; align-items: center; justify-content: center;
    color: var(--topbar-text);
    background: rgba(255,255,255,0.1);
    text-decoration: none;
    transition: all 0.15s;
    flex-shrink: 0;
}
.topbar-logout:hover { background: rgba(239,68,68,0.4); }
.nav-badge {
    margin-left: auto;
    background: #ef4444; color: white;
    font-size: 0.65rem; font-weight: 700;
    min-width: 18px; height: 18px;
    border-radius: 9px; padding: 0 5px;
    display: inline-flex; align-items: center; justify-content: center;
}

/* Search */
.topbar-search {
    flex: 1; max-width: 480px;
    position: relative;
    display: flex; align-items: center;
}
.topbar-search .search-icon {
    position: absolute; left: 0.75rem;
    color: var(--text-secondary);
    pointer-events: none;
}
.topbar-search input {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.topbar-search input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.search-results {
    display: none;
    position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    max-height: 400px; overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    z-index: 1500;
}
.search-results.open { display: block; }
.search-result-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    text-decoration: none;
    color: var(--text-primary);
    transition: background 0.15s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover, .search-result-item.active { background: var(--bg-tertiary, #f3f4f6); text-decoration: none; }
.search-result-icon { font-size: 1.1rem; flex-shrink: 0; }
.search-result-label { flex: 1; min-width: 0; font-weight: 500; font-size: 0.875rem; }
.search-result-sub { color: var(--text-secondary); font-size: 0.75rem; }
.search-empty {
    padding: 1.25rem; text-align: center;
    color: var(--text-secondary); font-size: 0.875rem;
}

/* ===== App Layout ===== */
.app-layout {
    margin-left: 260px;
    padding-top: 64px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s;
}
.main-content {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem;
}

/* Auth Layout */
.auth-layout { min-height: 100vh; display: flex; flex-direction: column; }
.auth-controls {
    position: fixed; top: 1.25rem; right: 1.5rem;
    display: flex; gap: 0.5rem; z-index: 1500;
}
.auth-controls .control-select,
.auth-controls .control-btn {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}
.auth-main { flex: 1; display: flex; align-items: center; justify-content: center; }

/* ===== Flash Messages ===== */
.flash-messages {
    position: fixed;
    top: 1rem; right: 1rem;
    z-index: 2000;
    max-width: 420px;
    width: calc(100% - 2rem);
}
.flash-message {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    animation: flashIn 0.35s ease-out;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    backdrop-filter: blur(8px);
}
.flash-icon { flex-shrink: 0; display: flex; }
.flash-text { flex: 1; }
.flash-close {
    background: none; border: none; cursor: pointer;
    color: inherit; opacity: 0.6; padding: 0;
    display: flex; flex-shrink: 0;
    transition: opacity 0.15s;
}
.flash-close:hover { opacity: 1; }

.flash-success { background: #d1fae5; color: #065f46; border-left: 4px solid #10b981; }
.flash-error   { background: #fee2e2; color: #7f1d1d; border-left: 4px solid #ef4444; }
.flash-info    { background: #dbeafe; color: #1e3a8a; border-left: 4px solid #3b82f6; }
.flash-warning { background: #fef3c7; color: #78350f; border-left: 4px solid #f59e0b; }

[data-theme="dark"] .flash-success { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .flash-error   { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .flash-info    { background: #1e3a8a; color: #93c5fd; }
[data-theme="dark"] .flash-warning { background: #451a03; color: #fcd34d; }

@keyframes flashIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ===== Footer ===== */
.footer {
    padding: 1.5rem 2rem;
    text-align: center;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-top: auto;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }

.btn-primary { background: var(--color-primary); color: white; box-shadow: 0 2px 4px rgba(37,99,235,0.2); }
.btn-primary:hover { background: var(--color-primary-hover, #1d4ed8); box-shadow: 0 4px 8px rgba(37,99,235,0.3); color: white; }

.btn-secondary { background: var(--bg-tertiary, #f3f4f6); color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-secondary:hover { border-color: var(--border-hover, #d1d5db); color: var(--text-primary); }

.btn-success { background: var(--color-success); color: white; }
.btn-success:hover { opacity: 0.9; color: white; }

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

.btn-warning { background: var(--color-warning); color: white; }
.btn-warning:hover { opacity: 0.9; color: white; }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; }
.btn-block { display: flex; width: 100%; }
.btn-icon { padding: 0.5rem; width: 2.25rem; height: 2.25rem; }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: block; }
    .sidebar-overlay.open { display: block; }

    .topbar { left: 0; }
    .hamburger { display: inline-flex; }
    .app-layout { margin-left: 0; }
    .main-content { padding: 1.25rem; }
    .flash-messages { top: 64px; }
}

@media (max-width: 640px) {
    .topbar-search { display: none; }
}

@media (max-width: 640px) {
    .main-content { padding: 1rem; }
}
