/* Flow-inspired Theme */
:root {
    /* Primary Colors - Gofrugal Inspired */
    --primary-color: #4A82E3;
    --primary-hover: #3d6fca;
    --secondary-color: #252F3E; /* Dark Slate for Sidebar */
    
    /* Functional Colors */
    --success-color: #10B981;
    --danger-color: #EF4444;
    --warning-color: #F59E0B;
    
    /* Neutrals */
    --background-color: #F0F2F5; /* Light Gray Background */
    --surface-color: #FFFFFF;
    --text-primary: #1D212E;
    --text-secondary: #64748B;
    --border-color: #E2E8F0;
    
    /* Effects */
    --shadow-sm: 0 1px 2px 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-card: 0 10px 25px rgba(0, 0, 0, 0.03);
    --sidebar-width: 260px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Work Sans', 'Inter', sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Poppins', 'Inter', sans-serif;
    color: var(--text-primary);
    font-weight: 600;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Layout Wrapper */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--secondary-color);
    color: white;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.sidebar-header {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo {
    font-weight: 700;
    font-size: 1.25rem;
    color: white;
    text-decoration: none;
    font-family: 'Poppins', sans-serif;
    letter-spacing: -0.5px;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    border-left: 4px solid transparent;
    margin-bottom: 0.25rem;
}

.sidebar-link:hover, .sidebar-link.active {
    background-color: rgba(255, 255, 255, 0.05);
    color: white;
    border-left-color: var(--primary-color);
}

.sidebar-link i {
    margin-right: 0.75rem;
    width: 20px;
    text-align: center;
}

/* Main Content */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.top-header {
    height: 70px;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 999;
}

.header-search {
    max-width: 400px;
    width: 100%;
    position: relative;
}

.header-search i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.header-search input {
    width: 100%;
    padding: 0.6rem 1rem 0.6rem 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--background-color);
    font-size: 0.9rem;
}

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

/* Responsive Sidebar */
@media (max-width: 992px) {
    .sidebar {
        left: -100%;
    }

    .sidebar.active {
        left: 0;
    }

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

    .nav-toggle {
        display: block !important;
        background: none;
        border: none;
        cursor: pointer;
    }
}

/* Grid System */
.grid {
    display: grid;
    gap: 1.5rem;
}

.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
@media (min-width: 768px) {
    .grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
    .grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Rounded Cards */
.card {
    background: var(--surface-color);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: var(--shadow-card);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 1px solid rgba(0,0,0,0.02);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.08);
}

/* Modern Buttons (Pill / Soft Round) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-family: 'Poppins', sans-serif;
    font-size: 0.95rem;
    text-align: center;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 14px 0 rgba(1, 112, 185, 0.39);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(1, 112, 185, 0.23);
}

/* Tables Responsive */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface-color);
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

th {
    background: var(--background-color);
    color: var(--text-secondary);
    font-weight: 600;
}

/* Spacing Utilities */
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.p-4 { padding: 1rem; }

/* Form Controls */
.form-control {
    width: 100%;
    padding: 0.75rem 1.15rem;
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: #F8FAFC;
    background-clip: padding-box;
    border: 1px solid #E2E8F0;
    border-radius: 10px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    font-family: inherit;
}

.form-control:focus {
    background-color: #FFFFFF;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(74, 130, 227, 0.12);
}

.form-control::placeholder {
    color: #94A3B8;
    opacity: 0.8;
}

select.form-control {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1.25rem;
    padding-right: 2.5rem;
}

.field-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: #475569;
    margin-bottom: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Responsive Adjustments */
@media (max-width: 600px) {
    .container {
        padding: 0 0.75rem;
    }
    
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    
    .card {
        padding: 1rem;
    }
}


/* ── Money values: tabular numerals ─────────────────
   .mv is injected by the |money template filter. */
.mv {
    display: inline-block;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    margin-left: 0.15rem;
}
td:has(.mv),
th:has(.mv) {
    text-align: right !important;
}

/* ── Select2 Custom Theme ──────────────────────────── */
.select2-container--default .select2-selection--single {
    height: 42px !important;
    padding: 6px 12px !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    background-color: #F8FAFC !important;
    font-family: inherit !important;
    font-size: 0.95rem !important;
    transition: all 0.2s ease !important;
}

.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: var(--primary-color) !important;
    background-color: #FFFFFF !important;
    box-shadow: 0 0 0 4px rgba(74, 130, 227, 0.12) !important;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 28px !important;
    color: var(--text-primary) !important;
    padding-left: 0 !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 40px !important;
    right: 8px !important;
}

.select2-dropdown {
    border: 1px solid var(--border-color) !important;
    border-radius: 8px !important;
    box-shadow: var(--shadow-md) !important;
    z-index: 9999 !important;
}

.select2-results__option {
    padding: 8px 12px !important;
    font-size: 0.9rem !important;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--primary-color) !important;
}

.select2-search--dropdown .select2-search__field {
    border-radius: 6px !important;
    border: 1px solid var(--border-color) !important;
    padding: 6px 10px !important;
}

/* Custom Modal Implementation (Bootstrap-compatible markup) */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 1050;
    overflow-x: hidden;
    overflow-y: auto;
    opacity: 0;
    transition: opacity 0.15s linear;
}

.modal.show {
    display: block;
    opacity: 1;
}

.modal-dialog {
    position: relative;
    width: auto;
    margin: 1.75rem auto;
    max-width: 500px;
    transition: transform 0.3s ease-out;
    transform: translateY(-50px);
}

.modal.show .modal-dialog {
    transform: translateY(0);
}

.modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    pointer-events: auto;
    background-color: var(--surface-color);
    background-clip: padding-box;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    outline: 0;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

.modal-header {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    border-top-left-radius: calc(12px - 1px);
    border-top-right-radius: calc(12px - 1px);
}

.modal-title {
    margin-bottom: 0;
    line-height: 1.5;
    font-size: 1.25rem;
}

.btn-close {
    box-sizing: content-box;
    width: 1em;
    height: 1em;
    padding: 0.25em 0.25em;
    color: #000;
    background: transparent;
    border: 0;
    border-radius: 0.25rem;
    opacity: 0.5;
    cursor: pointer;
}
.btn-close:before {
    content: "✕";
    font-size: 1.25rem;
    line-height: 1;
}
.btn-close:hover {
    color: #000;
    text-decoration: none;
    opacity: 0.75;
}

.modal-body {
    position: relative;
    flex: 1 1 auto;
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    flex-shrink: 0;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    border-bottom-right-radius: calc(12px - 1px);
    border-bottom-left-radius: calc(12px - 1px);
    gap: 0.5rem;
}

/* Form Spacing for Modals */
.mb-3 {
    margin-bottom: 1rem;
}
.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* ── User Profile Dropdown ─────────────────────────── */
.user-dropdown {
    position: relative;
    display: inline-block;
}

.user-dropdown-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}
.user-dropdown-btn:hover {
    transform: scale(1.05);
}

.user-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background-color: var(--surface-color);
    min-width: 180px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    border: 1px solid var(--border-color);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1050;
    padding: 0.5rem 0;
}

.user-dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-dropdown-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.25rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background-color 0.2s;
    cursor: pointer;
}

.user-dropdown-item i {
    margin-right: 0.75rem;
    color: var(--text-secondary);
    width: 16px;
    text-align: center;
    transition: color 0.2s;
}

.user-dropdown-item:hover {
    background-color: var(--background-color);
    color: var(--primary-color);
}
.user-dropdown-item:hover i {
    color: var(--primary-color);
}
.user-dropdown-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.5rem 0;
}
