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

body {
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-family: var(--font-family-sans);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    overflow: hidden;
    /* App-like feel */
    display: flex;
    flex-direction: column;
    /* Changed from default (row) to column */
}

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

/* Typography Utilities */
.text-sm {
    font-size: 0.875rem;
}

.text-xs {
    font-size: 0.75rem;
}

.text-muted {
    color: var(--text-secondary);
}

.font-medium {
    font-weight: 500;
}

.font-bold {
    font-weight: 600;
}

/* Layout Utilities */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: var(--space-2);
}

.gap-4 {
    gap: var(--space-4);
}

.w-full {
    width: 100%;
}

.h-full {
    height: 100%;
}

/* Spacing Utilities */
.mb-2 {
    margin-bottom: var(--space-2);
}

.mb-4 {
    margin-bottom: var(--space-4);
}

.mb-6 {
    margin-bottom: var(--space-6);
}

.mt-4 {
    margin-top: var(--space-4);
}

.mt-8 {
    margin-top: var(--space-8);
}

.mr-1 {
    margin-right: var(--space-1);
}

.mr-2 {
    margin-right: var(--space-2);
}

/* Components: Sidebar */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    padding: var(--space-4);
    padding-top: var(--space-2);
    /* Reduced top padding since logo is gone */
    flex-shrink: 0;
    transition: width 0.3s ease;
    height: 100%;
    /* Fill app-body */
    overflow-y: auto;
}

.app-sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
    padding-left: var(--space-2);
    padding-right: var(--space-2);
}

.app-sidebar.collapsed .sidebar-logo span,
.app-sidebar.collapsed .nav-link-text,
.app-sidebar.collapsed .sidebar-header {
    display: none;
}

.app-sidebar.collapsed .sidebar-logo {
    justify-content: center;
}

.app-sidebar.collapsed .nav-link {
    justify-content: center;
    padding: var(--space-2);
}

.app-sidebar.collapsed .nav-link i {
    margin-right: 0;
}

.sidebar-logo {
    font-weight: 700;
    font-size: 1.125rem;
    margin-bottom: var(--space-8);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.nav-link {
    display: flex;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all 0.2s ease;
    margin-bottom: 2px;
}

.nav-link:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
}

.nav-link.active {
    background-color: var(--bg-active);
    color: var(--text-primary);
}

.app-sidebar.collapsed .nav-link i {
    margin-right: 0;
}


.app-sidebar.collapsed .sidebar-toggle-container {
    justify-content: center;
}

/* Layout: Top Bar & Body */
.app-topbar {
    height: var(--header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    padding: 0 var(--space-6);
    /* Match app-header padding */
    flex-shrink: 0;
    justify-content: space-between;
    z-index: 50;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--text-primary);
}

.flex-1 {
    flex: 1;
}

/* 2-Column Grid Layout */
.grid-2-1 {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: 100%;
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.app-header {
    height: var(--header-height);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-6);
    background-color: rgba(22, 23, 25, 0.8);
    backdrop-filter: blur(8px);
    z-index: 10;
}

.app-content {
    flex: 1;
    padding: var(--space-6) var(--space-8);
    overflow-y: auto;
}

/* Components: Cards */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
}

/* Components: Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    font-size: 0.875rem;
}

.btn-primary {
    background-color: var(--color-brand);
    color: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

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

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    box-shadow: none;
    padding: var(--space-2);
}

.btn-ghost:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
}

/* Forms */
.form-input,
.form-select,
.form-textarea,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
select,
textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    color-scheme: dark;
}

/* Fix calendar icon color for dark mode on Webkit */
::-webkit-calendar-picker-indicator {
    filter: invert(1);
    cursor: pointer;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 2px rgba(94, 106, 210, 0.2);
}

.form-input::placeholder,
input::placeholder,
textarea::placeholder {
    color: var(--text-disabled);
}

.is-invalid {
    border-color: var(--color-danger) !important;
}

.invalid-feedback {
    color: var(--color-danger);
    font-size: 0.75rem;
    margin-top: 4px;
}

/* Carousel Component */
.carousel-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background-color: var(--bg-overlay);
    border-radius: var(--radius-lg);
}

.carousel-slides {
    position: relative;
    width: 100%;
    height: 100%;
}

.carousel-slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease;
    z-index: 0;
}

.carousel-slide.active {
    opacity: 1;
    visibility: visible;
    z-index: 10;
    position: relative;
    /* Maintain flow for first item logic if needed, but absolute stack usually better. Let's stick to absolute stack */
    position: absolute;
}

.carousel-slide img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.carousel-control {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.4);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    backdrop-filter: blur(4px);
    z-index: 20;
    opacity: 0;
}

.carousel-container:hover .carousel-control {
    opacity: 1;
}

.carousel-control:hover {
    background-color: rgba(0, 0, 0, 0.6);
}

.carousel-control.prev {
    left: 8px;
}

.carousel-control.next {
    right: 8px;
}

.carousel-indicators {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    padding: 8px;
    border-radius: 9999px;
    background-color: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(2px);
    z-index: 20;
}

.carousel-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.4);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    transform: scale(1);
    padding: 0;
}

.carousel-dot:hover {
    background-color: rgba(255, 255, 255, 0.8);
}

.carousel-dot.active {
    background-color: white;
    transform: scale(1.25);
}

.carousel-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 0.75rem;
    text-align: center;
    z-index: 15;
}

/* Sidebar Toggle Overrides (Must be after .btn and .btn-ghost) */
.sidebar-toggle-container {
    display: flex;
    width: 100%;
    justify-content: flex-end;
    flex-shrink: 0;
    /* Container shouldn't shrink */
    min-height: 40px;
    /* Reserve vertical space */
    overflow: visible;
    /* Ensure nothing is hidden */
}

.sidebar-toggle-btn {
    display: flex !important;
    /* Override .btn inline-flex */
    align-items: center;
    justify-content: center;
    width: 36px !important;
    height: 36px !important;
    padding: 0 !important;
    /* Override .btn padding */
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all 0.2s;
    flex-shrink: 0 !important;
    flex: 0 0 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
}

.sidebar-toggle-btn svg {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    min-height: 20px !important;
    transition: none;
}

.sidebar-toggle-btn:hover {
    color: var(--text-primary);
    background-color: var(--bg-surface-hover);
}

/* ==========================================================================
   Responsive Layout (Tablet & Mobile)
   ========================================================================== */

/* Tablet Breakpoint */
@media (max-width: 1024px) {
    .app-sidebar {
        position: absolute;
        z-index: 100;
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
        height: calc(100vh - var(--header-height));
        top: var(--header-height);
    }
    
    .app-sidebar.show {
        transform: translateX(0);
    }
    
    .sidebar-toggle-container {
        justify-content: flex-start;
    }
}

/* Mobile Breakpoint */
.bottom-nav {
    display: none;
}

@media (max-width: 768px) {
    /* Hide topbar profile (moved to bottom nav) */
    .topbar-actions {
        display: none; 
    }

    /* Make room for bottom nav */
    .app-main {
        padding-bottom: 60px; 
    }

    .app-sidebar {
        display: none !important; /* Disabled completely on phone */
    }

    .app-content {
        padding: var(--space-4); /* Reduce padding on small screens */
    }
    
    /* Make flex rows stack nicely on mobile */
    .flex-mobile-col {
        flex-direction: column !important;
    }

    /* Make 2-1 grids stack vertically on mobile */
    .grid-2-1 {
        grid-template-columns: 1fr !important;
    }

    /* Tighten cards */
    .card {
        padding: var(--space-3);
    }

    /* Bottom Navigation Styles */
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 60px;
        background-color: var(--bg-surface);
        border-top: 1px solid var(--border-subtle);
        justify-content: space-around;
        align-items: center;
        z-index: 1000;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        padding-bottom: env(safe-area-inset-bottom); /* iOS safe area */
    }

    .bottom-nav-link {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: var(--text-secondary);
        font-size: 0.65rem;
        flex: 1;
        height: 100%;
        text-decoration: none;
        transition: color 0.2s;
        gap: 2px;
    }

    .bottom-nav-link i {
        width: 20px;
        height: 20px;
    }

    .bottom-nav-link.active {
        color: var(--color-brand);
    }

    .bottom-nav-link:hover {
        color: var(--text-primary);
    }
    
    /* Responsive Tables */
    .table-container, table.responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Hide specific elements on mobile */
    .hide-on-mobile {
        display: none !important;
    }
}