@import url('https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #1d4ed8;
    --primary-hover: #1e40af;
    --primary-soft: #eff6ff;
    --success: #059669;
    --success-soft: #ecfdf5;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --info: #0284c7;
    --info-soft: #f0f9ff;
    --bg-main: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --sidebar-width: 260px;
    --header-height: 64px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.07), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
}

body {
    font-family: 'Hind Siliguri', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* App Header */
.app-header {
    height: var(--header-height);
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1020;
    box-shadow: var(--shadow-sm);
}

.brand-badge {
    background: linear-gradient(135deg, #1d4ed8 0%, #3b82f6 100%);
    color: #fff;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    letter-spacing: 0.5px;
}

/* Sidebar for authenticated layout */
.app-layout-wrapper {
    display: flex;
    flex: 1;
    min-height: calc(100vh - var(--header-height));
    position: relative;
}

.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.25rem 0.75rem;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    height: calc(100dvh - var(--header-height));
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
    z-index: 1010;
}

.sidebar-mobile-header {
    margin-bottom: 0.5rem;
}

.sidebar-user-card {
    background-color: #f8fafc;
    border: 1px solid var(--border);
}

.sidebar-heading {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.75rem 0.75rem 0.35rem 0.75rem;
    letter-spacing: 0.5px;
}

.sidebar-nav .nav-link {
    color: #334155;
    font-size: 0.95rem;
    font-weight: 500;
    min-height: 44px; /* Accessible touch target */
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
    border-left: 3.5px solid transparent;
    transition: background-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                border-color 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.15s ease;
}

.sidebar-nav .nav-link i {
    font-size: 1.15rem;
    color: #64748b;
    transition: color 0.2s ease;
    flex-shrink: 0;
}

.sidebar-nav .nav-link:hover {
    color: var(--primary);
    background-color: var(--primary-soft);
    border-left-color: rgba(29, 78, 216, 0.4);
    transform: translateX(3px);
}

.sidebar-nav .nav-link:hover i {
    color: var(--primary);
}

.sidebar-nav .nav-link.active {
    color: var(--primary);
    background-color: var(--primary-soft);
    border-left-color: var(--primary);
    font-weight: 600;
}

.sidebar-nav .nav-link.active i {
    color: var(--primary);
}

.sidebar-nav .nav-link:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.app-main-content {
    flex: 1;
    padding: 1.75rem;
    max-width: 100%;
    overflow-x: hidden;
}

/* Accessible Touch Targets & Drawer Toggle Controls */
.drawer-toggle-btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    line-height: 1;
    touch-action: manipulation;
}

.drawer-toggle-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.sidebar-close-btn {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    padding: 0;
    touch-action: manipulation;
}

.sidebar-close-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Accessible Modern Mobile Sidebar Drawer & Backdrop */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background-color: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.28s;
}

.sidebar-backdrop.show {
    opacity: 1;
    visibility: visible;
}

body.sidebar-open {
    overflow: hidden;
    touch-action: none;
}

@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(300px, 85vw);
        height: 100vh;
        height: 100svh;
        height: 100dvh;
        max-height: 100dvh;
        padding: 1.25rem 1rem;
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
        z-index: 1045;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
        will-change: transform;
    }

    .app-sidebar.show {
        transform: translateX(0);
    }

    .app-main-content {
        padding: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-sidebar,
    .sidebar-backdrop,
    .sidebar-nav .nav-link,
    .drawer-toggle-btn,
    .sidebar-close-btn {
        transition: none !important;
    }
}

/* Centralized Cards */
.card-box {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease;
    margin-bottom: 1.5rem;
}

.card-box:hover {
    box-shadow: var(--shadow-md);
}

.hover-primary {
    transition: color 0.15s ease;
}

.hover-primary:hover {
    color: var(--primary) !important;
}

.text-warning {
    color: var(--warning) !important;
}

.hover-shadow {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.hover-shadow:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md) !important;
}

@media (max-width: 575.98px) {
    .card-box {
        margin-bottom: 1rem;
    }
}

/* Responsive Width Utilities (extends Bootstrap 5) */
@media (min-width: 576px) {
    .w-sm-auto {
        width: auto !important;
    }
    .w-sm-100 {
        width: 100% !important;
    }
}

@media (min-width: 768px) {
    .w-md-auto {
        width: auto !important;
    }
    .w-md-100 {
        width: 100% !important;
    }
    .display-md-5 {
        font-size: calc(1.425rem + 2.1vw) !important;
    }
    .fs-md-5 {
        font-size: 1.25rem !important;
    }
}

@media (min-width: 992px) {
    .sticky-lg-top {
        position: -webkit-sticky !important;
        position: sticky !important;
        top: 80px !important;
        z-index: 10;
    }
}

/* Accessible Touch Targets (WCAG 2.2 AA >= 44x44px) */
.touch-target {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Select2 Bootstrap 5 Theme Touch Target, Polish & Validation Sync */
.select2-container--bootstrap-5 .select2-selection {
    min-height: 44px;
    display: flex;
    align-items: center;
    border-color: #dee2e6;
    border-radius: var(--radius-sm);
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    color: var(--text-primary);
    padding-left: 0.75rem;
    padding-right: 2rem;
    font-size: 0.95rem;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__placeholder {
    color: var(--text-muted);
}

.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection {
    border-color: rgba(29, 78, 216, 0.5) !important;
    box-shadow: 0 0 0 0.2rem rgba(29, 78, 216, 0.15) !important;
    outline: 0;
}

.select2-container--bootstrap-5 .select2-dropdown {
    border-color: rgba(29, 78, 216, 0.5);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
}

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

.select2-container--bootstrap-5 .select2-results__option--selected {
    background-color: var(--primary-soft) !important;
    color: var(--primary) !important;
    font-weight: 600;
}

.was-validated .select2-container--bootstrap-5 .select2-selection,
.is-invalid + .select2-container--bootstrap-5 .select2-selection,
.input-validation-error + .select2-container--bootstrap-5 .select2-selection,
.was-validated select.input-validation-error + .select2-container--bootstrap-5 .select2-selection {
    border-color: var(--danger) !important;
}

.select2-container--bootstrap-5.is-invalid.select2-container--focus .select2-selection,
.input-validation-error + .select2-container--bootstrap-5.select2-container--focus .select2-selection {
    box-shadow: 0 0 0 0.2rem rgba(220, 38, 38, 0.15) !important;
}

.card-box-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-box-body {
    padding: 1.25rem;
}

/* KPI Stat Cards */
.kpi-card {
    border-radius: var(--radius-md);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    border: 1px solid var(--border);
    background-color: var(--surface);
    box-shadow: var(--shadow-sm);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.kpi-icon.blue { background-color: var(--primary-soft); color: var(--primary); }
.kpi-icon.green { background-color: var(--success-soft); color: var(--success); }
.kpi-icon.amber { background-color: var(--warning-soft); color: var(--warning); }
.kpi-icon.red { background-color: var(--danger-soft); color: var(--danger); }
.kpi-icon.cyan { background-color: var(--info-soft); color: var(--info); }

.kpi-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

.kpi-value {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

/* Buttons */
.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary);
    font-weight: 500;
}
.btn-primary:hover, .btn-primary:focus {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-success {
    background-color: var(--success);
    border-color: var(--success);
    font-weight: 500;
}

/* Status Badges */
.badge-status {
    padding: 0.35rem 0.65rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}
.badge-status.approved, .badge-status.paid, .badge-status.active, .badge-status.disbursed {
    background-color: var(--success-soft);
    color: var(--success);
    border: 1px solid #a7f3d0;
}
.badge-status.pending, .badge-status.unpaid {
    background-color: var(--warning-soft);
    color: var(--warning);
    border: 1px solid #fde68a;
}
.badge-status.rejected, .badge-status.failed {
    background-color: var(--danger-soft);
    color: var(--danger);
    border: 1px solid #fecaca;
}
.badge-status.waived {
    background-color: var(--info-soft);
    color: var(--info);
    border: 1px solid #bae6fd;
}

/* Printable Receipt styling */
@media print {
    body {
        background-color: #fff !important;
    }
    .app-header, .app-sidebar, .no-print, .btn, footer {
        display: none !important;
    }
    .app-layout-wrapper {
        display: block !important;
    }
    .app-main-content {
        padding: 0 !important;
    }
    .receipt-container {
        border: none !important;
        box-shadow: none !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    .table-responsive {
        overflow: visible !important;
    }
}

/* =========================================================
   DataTables & Table Layout Optimization for PC / Desktop
   Complies with datatable-serverside-efcore best practices
   ========================================================= */

@media (min-width: 992px) {
    .table-responsive {
        overflow-x: visible !important;
    }

    .table-responsive .table,
    .table-responsive table.dataTable,
    table.dataTable {
        width: 100% !important;
        max-width: 100% !important;
        table-layout: auto !important;
    }

    /* Override forced rigid inline min-widths so table columns adapt fluidly to screen width on PC */
    .table-responsive .table th,
    .table-responsive .table td,
    table.dataTable th,
    table.dataTable td {
        min-width: unset !important;
    }

    /* Maintain clean alignment and non-wrapping for badges, amounts, and actions */
    .table-responsive .table th.text-end,
    .table-responsive .table td.text-end,
    .table-responsive .table .badge-status,
    .table-responsive .table .btn-sm,
    table.dataTable th.text-end,
    table.dataTable td.text-end {
        white-space: nowrap !important;
    }

    /* Wrap text naturally in content columns */
    .table-responsive .table td,
    table.dataTable td {
        word-break: normal;
        overflow-wrap: break-word;
    }
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.35rem 0.65rem;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* =========================================================
   Universal Modern Selection & Autofill Styling
   ========================================================= */

/* Refined Subtle Text Selection */
::selection {
    background-color: rgba(29, 78, 216, 0.18);
    color: inherit;
}

::-moz-selection {
    background-color: rgba(29, 78, 216, 0.18);
    color: inherit;
}

input::selection,
textarea::selection,
select::selection {
    background-color: rgba(29, 78, 216, 0.22);
    color: var(--text-primary);
}

/* Override harsh browser autofill backgrounds (Chrome/Edge/Safari/Android) */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus,
textarea:-webkit-autofill:active,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus,
select:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 1000px #ffffff inset !important;
    box-shadow: 0 0 0 1000px #ffffff inset !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    caret-color: var(--text-primary) !important;
    font-size: inherit !important;
    font-family: inherit !important;
    transition: background-color 5000s ease-in-out 0s;
}

/* Autofilled input focus ring synchronization */
input:-webkit-autofill:focus,
textarea:-webkit-autofill:focus,
select:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px #ffffff inset, 0 0 0 0.2rem rgba(29, 78, 216, 0.15) !important;
    box-shadow: 0 0 0 1000px #ffffff inset, 0 0 0 0.2rem rgba(29, 78, 216, 0.15) !important;
    border-color: rgba(29, 78, 216, 0.5) !important;
}

/* Input group autofilled focus handled by group container */
.input-group > input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px #ffffff inset !important;
    box-shadow: 0 0 0 1000px #ffffff inset !important;
}

/* Light / Readonly background autofill override */
input[readonly]:-webkit-autofill,
input.bg-light:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px #f8fafc inset !important;
    box-shadow: 0 0 0 1000px #f8fafc inset !important;
    -webkit-text-fill-color: var(--text-primary) !important;
}

/* =========================================================
   Form Controls & Input Groups Seamless Focus Harmonization
   ========================================================= */

.form-control,
.form-select {
    border-color: #dee2e6;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control:focus,
.form-select:focus {
    border-color: rgba(29, 78, 216, 0.5);
    box-shadow: 0 0 0 0.2rem rgba(29, 78, 216, 0.15);
    outline: 0;
}

/* ASP.NET Core Unobtrusive Validation & Bootstrap is-invalid Sync */
.form-control.input-validation-error,
.form-select.input-validation-error {
    border-color: var(--danger) !important;
}

.form-control.input-validation-error:focus,
.form-select.input-validation-error:focus {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 38, 38, 0.15) !important;
}

/* Input group cohesive border and glow */
.input-group {
    border-radius: var(--radius-sm);
    transition: box-shadow 0.15s ease-in-out;
}

.input-group:focus-within {
    box-shadow: 0 0 0 0.2rem rgba(29, 78, 216, 0.15);
    border-radius: var(--radius-sm);
}

.input-group > .form-control:focus {
    box-shadow: none !important;
    border-color: rgba(29, 78, 216, 0.5) !important;
    z-index: 2;
}

.input-group:focus-within > .form-control,
.input-group:focus-within > .input-group-text,
.input-group:focus-within > .password-toggle-btn {
    border-color: rgba(29, 78, 216, 0.5) !important;
}

/* Seamless Password Visibility Toggle Button */
.password-toggle-btn {
    border-color: #dee2e6 !important;
    background-color: #ffffff !important;
    color: #64748b !important;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}

.password-toggle-btn:hover {
    background-color: #f8fafc !important;
    color: var(--primary) !important;
    border-color: #dee2e6 !important;
}

.password-toggle-btn:focus,
.password-toggle-btn:focus-visible {
    outline: none !important;
    box-shadow: none !important;
    color: var(--primary) !important;
    background-color: #eff6ff !important;
    border-color: rgba(29, 78, 216, 0.5) !important;
}

/* Input Group Validation state sync for both Bootstrap and ASP.NET Core */
.input-group:has(.form-control.is-invalid):focus-within,
.input-group:has(.form-control.input-validation-error):focus-within {
    box-shadow: 0 0 0 0.2rem rgba(220, 38, 38, 0.15) !important;
}

.input-group:has(.form-control.is-invalid) > .password-toggle-btn,
.input-group:has(.form-control.input-validation-error) > .password-toggle-btn,
.input-group:has(.form-control.is-invalid) > .input-group-text,
.input-group:has(.form-control.input-validation-error) > .input-group-text {
    border-color: var(--danger) !important;
}

/* =========================================================
   6-Box OTP Discrete Square Input Pattern (WCAG 2.2 Compliant)
   ========================================================= */
.otp-input-group {
    display: flex;
    justify-content: center;
    gap: 8px;
    direction: ltr;
}

.otp-digit-box {
    width: 44px;
    height: 48px;
    font-size: 1.35rem;
    font-weight: 700;
    text-align: center;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    background-color: #ffffff;
    color: var(--text-primary);
    padding: 0;
    transition: all 0.15s ease-in-out;
    -webkit-appearance: none;
    -moz-appearance: textfield;
}

.otp-digit-box::-webkit-outer-spin-button,
.otp-digit-box::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

@media (min-width: 576px) {
    .otp-input-group {
        gap: 12px;
    }
    .otp-digit-box {
        width: 52px;
        height: 54px;
        font-size: 1.5rem;
        border-radius: 10px;
    }
}

.otp-digit-box:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 0.25rem rgba(29, 78, 216, 0.2) !important;
    background-color: #f8faff !important;
    outline: none;
}

.otp-digit-box.is-filled {
    border-color: var(--success);
    background-color: #fafffa;
}

.otp-digit-box.is-invalid {
    border-color: var(--danger) !important;
    background-color: #fff8f8 !important;
}

.otp-digit-box.is-invalid:focus {
    box-shadow: 0 0 0 0.25rem rgba(220, 38, 38, 0.2) !important;
}

