/* ===================================
   MODERN LAYOUT CSS
   Professional, clean, mobile-first design
   =================================== */

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --topbar-height: 64px;
    --primary-color: #4F46E5;
    --primary-hover: #4338CA;
    --secondary-color: #6B7280;
    --success-color: #10B981;
    --danger-color: #EF4444;
    --warning-color: #F59E0B;
    --info-color: #3B82F6;
    --dark-bg: #1F2937;
    --darker-bg: #111827;
    --light-bg: #F9FAFB;
    --border-color: #E5E7EB;
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* ===================================
   GLOBAL STYLES
   =================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--light-bg);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* ===================================
   TOP NAVIGATION BAR
   =================================== */
.modern-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: white;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 1040;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    transition: padding-left 0.3s ease;
}

.modern-topbar.with-sidebar {
    padding-left: calc(var(--sidebar-width) + 1.5rem);
}

.modern-topbar.with-sidebar.collapsed {
    padding-left: calc(var(--sidebar-collapsed-width) + 1.5rem);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
}

.topbar-brand:hover {
    color: var(--primary-color);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--light-bg);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.topbar-user:hover {
    background: var(--border-color);
}

.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
}

/* ===================================
   SIDEBAR NAVIGATION
   =================================== */
.modern-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--dark-bg);
    color: white;
    overflow-y: auto;
    overflow-x: hidden;
    transition: all 0.3s ease;
    z-index: 1050;
    box-shadow: var(--shadow-lg);
}

.modern-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.modern-sidebar::-webkit-scrollbar {
    width: 6px;
}

.modern-sidebar::-webkit-scrollbar-track {
    background: var(--darker-bg);
}

.modern-sidebar::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 3px;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--topbar-height);
}

.sidebar-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: background 0.2s ease;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.modern-sidebar.collapsed .sidebar-brand,
.modern-sidebar.collapsed .sidebar-toggle {
    display: none;
}

.sidebar-nav {
    padding: 1rem 0;
}

.nav-section {
    margin-bottom: 1.5rem;
}

.nav-section-title {
    padding: 0.5rem 1.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--secondary-color);
    letter-spacing: 0.05em;
    transition: opacity 0.3s ease;
}

.modern-sidebar.collapsed .nav-section-title {
    opacity: 0;
    height: 0;
    padding: 0;
    margin: 0;
}

.nav-item {
    position: relative;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: all 0.2s ease;
    font-size: 0.95rem;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
    border-left-color: var(--primary-color);
}

.nav-link.active {
    background: linear-gradient(90deg, rgba(79, 70, 229, 0.15) 0%, rgba(79, 70, 229, 0) 100%);
    color: white;
    border-left-color: var(--primary-color);
    font-weight: 500;
}

.nav-link i {
    font-size: 1.25rem;
    min-width: 1.5rem;
    text-align: center;
}

.nav-link-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.3s ease;
}

.modern-sidebar.collapsed .nav-link-text {
    opacity: 0;
    width: 0;
}

.modern-sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 0.75rem;
}

/* Submenu */
.nav-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: rgba(0, 0, 0, 0.2);
}

.nav-submenu.show {
    max-height: 500px;
}

.nav-submenu .nav-link {
    padding-left: 3.5rem;
    font-size: 0.9rem;
}

.modern-sidebar.collapsed .nav-submenu {
    position: absolute;
    left: 100%;
    top: 0;
    width: 200px;
    background: var(--dark-bg);
    box-shadow: var(--shadow-lg);
    border-radius: 0 0.5rem 0.5rem 0;
}

.nav-dropdown-toggle {
    cursor: pointer;
}

.nav-dropdown-icon {
    margin-left: auto;
    transition: transform 0.3s ease;
    font-size: 0.875rem;
}

.nav-dropdown-toggle.active .nav-dropdown-icon {
    transform: rotate(180deg);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: auto;
}

/* ===================================
   MAIN CONTENT AREA
   =================================== */
.modern-main {
    margin-left: var(--sidebar-width);
    margin-top: var(--topbar-height);
    padding: 2rem;
    min-height: calc(100vh - var(--topbar-height));
    transition: margin-left 0.3s ease;
    width: calc(100% - var(--sidebar-width));
}

    .modern-main.no-sidebar {
        margin-left: 0;
        margin-top: 0 !important;
        width: 100%;
    }

.modern-main.collapsed-sidebar {
    margin-left: var(--sidebar-collapsed-width);
    width: calc(100% - var(--sidebar-collapsed-width));
}

/* Full width container inside main */
.modern-main .container-fluid {
    max-width: 100%;
    padding: 0;
}

/* Page Header */
.page-header {
    margin-bottom: 2rem;
}

.page-title {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.page-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
}

/* ===================================
   CARDS & CONTAINERS
   =================================== */
.modern-card {
    background: white;
    border-radius: 0.75rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

.modern-card:hover {
    box-shadow: var(--shadow-md);
}

.modern-card-header {
    padding: 1.25rem 1.5rem;
    background: white;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.modern-card-header.colored {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    color: white;
    border-bottom: none;
}

.modern-card-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.modern-card-header.colored .modern-card-title {
    color: white;
}

.modern-card-body {
    padding: 1.5rem;
}

.modern-card-footer {
    padding: 1rem 1.5rem;
    background: var(--light-bg);
    border-top: 1px solid var(--border-color);
}

/* ===================================
   BUTTONS
   =================================== */
.btn-modern {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5;
    border-radius: 0.5rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn-modern:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-modern:active {
    transform: translateY(0);
}

.btn-modern-primary {
    background: var(--primary-color);
    color: white;
}

.btn-modern-primary:hover {
    background: var(--primary-hover);
    color: white;
}

.btn-modern-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-modern-success {
    background: var(--success-color);
    color: white;
}

.btn-modern-danger {
    background: var(--danger-color);
    color: white;
}

.btn-modern-warning {
    background: var(--warning-color);
    color: white;
}

.btn-modern-info {
    background: var(--info-color);
    color: white;
}

.btn-modern-outline {
    background: transparent;
    border-color: var(--border-color);
    color: var(--text-primary);
}

.btn-modern-sm {
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
}

.btn-modern-lg {
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
}

.btn-group-modern {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ===================================
   BADGES
   =================================== */
.badge-modern {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 0.375rem;
    white-space: nowrap;
}

.badge-modern-primary {
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary-color);
}

.badge-modern-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.badge-modern-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

.badge-modern-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning-color);
}

.badge-modern-info {
    background: rgba(59, 130, 246, 0.1);
    color: var(--info-color);
}

.badge-modern-secondary {
    background: rgba(107, 114, 128, 0.1);
    color: var(--secondary-color);
}

/* ===================================
   TABLES
   =================================== */
.table-modern {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.table-modern thead th {
    padding: 1rem;
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    background: var(--light-bg);
    border-bottom: 2px solid var(--border-color);
    text-align: left;
}

.table-modern tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
}

.table-modern tbody tr:hover {
    background: var(--light-bg);
}

.table-modern tbody td {
    padding: 1rem;
    font-size: 0.9375rem;
    color: var(--text-primary);
}

.table-responsive-modern {
    overflow-x: auto;
    border-radius: 0.75rem;
}

/* ===================================
   FORMS
   =================================== */
.form-group-modern {
    margin-bottom: 1.5rem;
}

.form-label-modern {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* Ultra-specific icon spacing rules - Force override all other styles */
.form-label-modern > i,
.form-label-modern > .fas,
.form-label-modern > .far,
.form-label-modern > .fab,
.form-label-modern > .fa {
    margin-right: 0.5rem !important;
    margin-left: 0 !important;
    display: inline-block !important;
}

.form-control-modern {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    line-height: 1.5;
    color: var(--text-primary);
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

.form-control-modern:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* ===================================
   INPUT GROUP - Comprehensive Solution
   =================================== */

/* Base input-group container */
.input-group {
    position: relative;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
    width: 100%;
}

/* All direct children of input-group */
.input-group > * {
    position: relative;
    flex: 0 1 auto;
    margin-bottom: 0 !important;
}

/* The input field itself should grow */
.input-group > .form-control-modern,
.input-group > .form-control {
    flex: 1 1 auto;
    width: 1%;
    min-width: 0;
}

/* Remove border-radius on inner sides for seamless connection */
.input-group > *:not(:last-child),
.input-group > .btn-modern:not(:last-child),
.input-group > button:not(:last-child) {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

.input-group > *:not(:first-child),
.input-group > .btn-modern:not(:first-child),
.input-group > button:not(:first-child) {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
}

/* Special handling for first and last elements to keep outer radius */
.input-group > *:first-child {
    border-top-left-radius: 0.5rem !important;
    border-bottom-left-radius: 0.5rem !important;
}

.input-group > *:last-child {
    border-top-right-radius: 0.5rem !important;
    border-bottom-right-radius: 0.5rem !important;
}

/* Input group text (prefix/suffix like £, @, etc.) */
.input-group > .input-group-text {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 0.875rem;
    margin-bottom: 0;
    font-size: 0.9375rem;
    font-weight: 400;
    line-height: 1.5;
    color: var(--text-primary);
    text-align: center;
    white-space: nowrap;
    background-color: var(--light-bg);
    border: 1px solid var(--border-color);
}

/* Remove adjacent borders to prevent double borders */
.input-group > .input-group-text:first-child {
    border-right: 0;
}

.input-group > .input-group-text:last-child {
    border-left: 0;
}

.input-group > .input-group-text + .form-control-modern,
.input-group > .input-group-text + .form-control {
    border-left: 1px solid var(--border-color);
}

/* Buttons inside input-group (both regular button and btn-modern) */
.input-group > .btn,
.input-group > button,
.input-group > .btn-modern {
    position: relative;
    z-index: 2;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 0.875rem;
    margin-bottom: 0 !important;
    white-space: nowrap;
    flex: 0 0 auto;
}

/* Specific styling for btn-modern in input-group */
.input-group .btn-modern {
    min-width: auto;
    border: 1px solid var(--border-color);
    gap: 0;
}

.input-group .btn-modern-secondary {
    background: var(--light-bg);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.input-group .btn-modern-secondary:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

/* Disable transform effects on buttons inside input-group to prevent layout breaks */
.input-group .btn:hover,
.input-group .btn-modern:hover,
.input-group button:hover {
    transform: none !important;
    box-shadow: none !important;
}

/* Handle borders between form-control and adjacent elements */
.input-group > .form-control-modern:not(:first-child),
.input-group > .form-control:not(:first-child) {
    margin-left: -1px;
}

.input-group > .btn:not(:first-child),
.input-group > .btn-modern:not(:first-child),
.input-group > button:not(:first-child) {
    border-left: 1px solid var(--border-color);
}

.input-group > .form-control-modern + .btn,
.input-group > .form-control-modern + .btn-modern,
.input-group > .form-control-modern + button,
.input-group > .form-control + .btn,
.input-group > .form-control + .btn-modern,
.input-group > .form-control + button {
    border-left: 0;
    margin-left: -1px;
}

/* Ensure proper height alignment */
.input-group > .btn,
.input-group > .btn-modern,
.input-group > button,
.input-group > .input-group-text {
    min-height: calc(1.5em + 1.25rem + 2px); /* Match form-control-modern height */
}

/* Form check labels (checkboxes and radios) - Ultra-specific */
.form-check-label > i,
.form-check-label > .fas,
.form-check-label > .far,
.form-check-label > .fab,
.form-check-label > .fa {
    margin-right: 0.5rem !important;
    margin-left: 0 !important;
    display: inline-block !important;
}

/* Bootstrap form labels - Ultra-specific */
label > i,
label > .fas,
label > .far,
label > .fab,
label > .fa,
.control-label > i,
.control-label > .fas,
.control-label > .far,
.control-label > .fab,
.control-label > .fa {
    margin-right: 0.5rem !important;
    margin-left: 0 !important;
    display: inline-block !important;
}

/* Override Bootstrap's .me-2 class if it's not working */
.form-label-modern .me-2,
.form-check-label .me-2,
label .me-2 {
    margin-right: 0.5rem !important;
}

/* Card titles with icons - Ultra-specific */
.modern-card-title > i,
.modern-card-title > .fas,
.modern-card-title > .far,
.modern-card-title > .fab,
.modern-card-title > .fa {
    margin-right: 0.5rem !important;
    margin-left: 0 !important;
    display: inline-block !important;
}

/* ===================================
   INFO BOXES (Dashboard)
   =================================== */
.info-box-modern {
    background: white;
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
    text-decoration: none;
    display: block;
    height: 100%;
}

.info-box-modern:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    text-decoration: none;
}

.info-box-icon {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    margin-bottom: 1rem;
}

.info-box-content h5 {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.info-box-content h3 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

/* ===================================
   ALERTS
   =================================== */
.alert-modern {
    padding: 1rem 1.25rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    border-left: 4px solid;
    display: flex;
    align-items: start;
    gap: 0.75rem;
}

.alert-modern-success {
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--success-color);
    color: #065f46;
}

.alert-modern-danger {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger-color);
    color: #991b1b;
}

.alert-modern-warning {
    background: rgba(245, 158, 11, 0.1);
    border-color: var(--warning-color);
    color: #92400e;
}

.alert-modern-info {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--info-color);
    color: #1e40af;
}

/* ===================================
   RESPONSIVE DESIGN
   =================================== */
@media (max-width: 1024px) {
    .modern-sidebar {
        transform: translateX(-100%);
    }

    .modern-sidebar.show {
        transform: translateX(0);
    }

    .modern-main {
        margin-left: 0;
        width: 100%;
    }

    .modern-topbar.with-sidebar {
        padding-left: 1.5rem;
    }

    .mobile-menu-toggle {
        display: block;
    }

    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1045;
        display: none;
    }

    .sidebar-overlay.show {
        display: block;
    }
}

@media (max-width: 768px) {
    .modern-topbar {
        padding: 0 1rem;
    }

    .modern-main {
        padding: 1rem;
    }

    .page-title {
        font-size: 1.5rem;
    }

    .modern-card-header {
        padding: 1rem;
    }

    .modern-card-body {
        padding: 1rem;
    }

    .table-modern thead th,
    .table-modern tbody td {
        padding: 0.75rem 0.5rem;
        font-size: 0.875rem;
    }

    .btn-group-modern {
        width: 100%;
    }

    .btn-group-modern .btn-modern {
        flex: 1;
    }
}

@media (max-width: 480px) {
    .topbar-brand {
        font-size: 1rem;
    }

    .modern-card-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ===================================
   UTILITIES
   =================================== */
.text-muted {
    color: var(--text-secondary) !important;
}

.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.5rem !important; }
.mb-2 { margin-bottom: 1rem !important; }
.mb-3 { margin-bottom: 1.5rem !important; }
.mb-4 { margin-bottom: 2rem !important; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: 0.5rem !important; }
.mt-2 { margin-top: 1rem !important; }
.mt-3 { margin-top: 1.5rem !important; }
.mt-4 { margin-top: 2rem !important; }

.d-flex { display: flex !important; }
.flex-wrap { flex-wrap: wrap !important; }
.align-items-center { align-items: center !important; }
.justify-content-between { justify-content: space-between !important; }
.gap-2 { gap: 1rem !important; }

/* ===================================
   LEGACY COMPATIBILITY
   =================================== */
.container-full {
    width: 100%;
    max-width: 100%;
    padding: 0;
}

/* Keep existing color utilities working */
.card-header {
    background-color: var(--dark-bg) !important;
}

.custom-navbar-bg {
    background-color: var(--dark-bg) !important;
}
