:root {
    /* Colors - Light Mode */
    --primary: #4A90E2;
    --primary-dark: #357ABD;
    --secondary: #50C878;
    --secondary-dark: #3DA862;
    --background: #F5F7FA;
    --surface: #FFFFFF;
    --text-main: #2C3E50;
    --text-muted: #7F8C8D;
    --border: #E1E8ED;
    --danger: #E74C3C;
    --warning: #F1C40F;
    --success: #2ECC71;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 16px;

    /* Shadow */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

/* Dark Mode */
.dark-mode {
    --primary: #5BA3F5;
    --primary-dark: #4A90E2;
    --secondary: #60D888;
    --secondary-dark: #50C878;
    --background: #1a1a1a;
    --surface: #2d2d2d;
    --text-main: #E8E8E8;
    --text-muted: #A0A0A0;
    --border: #404040;
    --danger: #F55C5C;
    --warning: #F5D042;
    --success: #3EDD81;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    transition: background-color 0.3s ease, color 0.3s ease;
}

html * {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--background);
    color: var(--text-main);
    line-height: 1.5;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* Layout */
#app {
    display: grid;
    grid-template-columns: 250px 1fr;
    height: 100vh;
    height: 100dvh; /* Dynamic Viewport Height for mobile browsers */
    overflow: hidden;
    /* Prevent body scroll, handle internally */
}

/* Sidebar */
.sidebar {
    background-color: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: var(--spacing-lg);
    z-index: 10;
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-xl);
}

.nav-links {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    text-decoration: none;
    color: var(--text-muted);
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.nav-item:hover,
.nav-item.active {
    background-color: rgba(74, 144, 226, 0.1);
    color: var(--primary);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--border);
}

.avatar {
    width: 40px;
    height: 40px;
    background-color: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.info {
    display: flex;
    flex-direction: column;
}

.info .name {
    font-weight: 500;
    font-size: 0.9rem;
}

.info .role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Main Content */
.main-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden; /* Lock main content, scroll view-container */
    position: relative;
    min-width: 0;
}

.top-bar {
    background-color: var(--surface);
    padding: var(--spacing-md) var(--spacing-xl);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-md);
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 90;
}

.top-bar-main {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex: 1 1 14rem;
}

.top-bar-logo {
    flex-shrink: 0;
}

.breadcrumbs {
    font-weight: 500;
    color: var(--text-main);
    min-width: 0;
    overflow-wrap: anywhere;
    flex: 1;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 0 0 auto;
    flex-wrap: nowrap;
}

.view-container {
    padding: var(--spacing-xl);
    flex: 1;
    overflow-y: auto;
    /* Scrollable content */
    -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
    min-height: 0; /* Crucial for nested flex scrolling */
}

/* Common UI Elements */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

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

.fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background-color: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    transition: transform 0.2s;
    z-index: 100;
}

.fab:hover {
    transform: scale(1.1);
}

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(74, 144, 226, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s linear infinite;
    margin-bottom: var(--spacing-md);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Bottom Navigation */
.bottom-nav {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--surface);
    border-top: 1px solid var(--border);
    padding: var(--spacing-sm) var(--spacing-md) calc(var(--spacing-sm) + env(safe-area-inset-bottom, 0px));
    justify-content: space-around;
    z-index: 100;
    transform: translate3d(0, 0, 0);
    will-change: transform;
    backface-visibility: hidden;
}

.bottom-nav .nav-item {
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 0.7rem;
    padding: 4px 2px;
    border-radius: var(--radius-sm);
    text-align: center;
    white-space: nowrap;
}

.bottom-nav .nav-item i {
    font-size: 1.25rem;
}

/* Responsive */
@media (max-width: 1024px) {
    #app {
        grid-template-columns: 1fr;
        /* padding-bottom: 60px; Removed to handle in view-container */
    }

    .sidebar {
        display: none;
    }

    .bottom-nav {
        display: flex;
        align-items: stretch;
    }

    .view-container {
        padding: var(--spacing-md);
        padding-bottom: 100px; /* Space for bottom nav + fab */
    }

    .top-bar {
        padding: var(--spacing-md);
        position: sticky;
        top: 0;
    }

    .fab {
        bottom: 80px;
        /* Above bottom nav */
    }
}

@media (max-width: 640px) {
    .top-bar {
        flex-wrap: nowrap;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
    }

    .top-bar-main {
        flex: 1 1 auto;
        min-width: 0;
    }

    .top-bar-logo img {
        height: 2rem;
    }

    .breadcrumbs {
        font-size: 0.95rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .top-bar-actions {
        gap: 0.35rem;
        margin-left: auto;
    }

    .top-bar-actions .btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        padding: 0.5rem;
        justify-content: center;
        flex-shrink: 0;
    }
}

/* Auth Tabs (Segmented Control Style) */
.tab-btn-tw {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    position: relative;
    cursor: pointer;
    border: none;
    background: transparent;
    /* color: var(--text-muted);  <-- Removed to let Tailwind control */
}
