/* ==========================================================================
   ChronicSync Design System
   Shared design tokens + component styles applied across the whole app
   (sidebar/navbar chrome, dashboard, CRUD cards/tables/forms, auth pages).
   Loaded AFTER custom.css so it layers on top without removing existing
   overrides. Purely additive/visual — no selectors here should ever be
   relied on by application JavaScript.
   ========================================================================== */

:root {
    /* Brand */
    --cs-navy: #071c36;
    --cs-dark-blue: #092b55;
    --cs-blue: #087ce8;
    --cs-cyan: #08b8d4;
    --cs-teal: #0bb6b4;
    --cs-green: #45c84a;

    /* Status */
    --cs-success: #2fb344;
    --cs-warning: #f0a202;
    --cs-danger: #e4572e;
    --cs-info: #08b8d4;

    /* Surfaces */
    --cs-white: #ffffff;
    --cs-background: #f6f9fc;
    --cs-surface: #ffffff;
    --cs-text: #14263a;
    --cs-muted: #69798c;
    --cs-border: #dce6ef;

    /* Shape */
    --cs-radius-sm: 6px;
    --cs-radius-md: 10px;
    --cs-radius-lg: 16px;

    /* Elevation */
    --cs-shadow-sm: 0 1px 3px rgba(7, 28, 54, 0.08), 0 1px 2px rgba(7, 28, 54, 0.06);
    --cs-shadow-md: 0 10px 30px rgba(7, 28, 54, 0.10);
}

/* ==========================================================================
   Base / overflow safety
   ========================================================================== */
.content-wrapper {
    overflow-x: hidden;
    max-width: 100vw;
}

.content-wrapper img {
    max-width: 100%;
    height: auto;
}

/* ==========================================================================
   Sidebar
   ========================================================================== */
.main-sidebar.cs-sidebar {
    background: linear-gradient(180deg, var(--cs-navy) 0%, var(--cs-dark-blue) 100%) !important;
}

.cs-sidebar .brand-link {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.cs-sidebar-brand.brand-link {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 14px;
    width: 100%;
}

/* Dark-mode logo variant (white wordmark) — sits directly on the sidebar's
   dark navy/blue gradient, no background chip needed. Fills the full
   sidebar width (scaled by width, not a fixed height) so it reads clearly
   instead of sitting small in the middle of the brand area. */
.cs-sidebar-logo {
    width: 100%;
    height: auto;
    max-width: 100%;
    object-fit: contain;
    display: block;
}

.cs-sidebar .nav-sidebar .nav-icon {
    width: 1.6rem;
    text-align: center;
    opacity: 0.9;
}

/* Pill-shaped nav links only in the full expanded desktop sidebar.
   Scoped to >=992px so it never fights AdminLTE's own icon-only
   (sidebar-collapse) or off-canvas mobile sidebar sizing/width rules. */
@media (min-width: 992px) {
    .cs-sidebar .nav-sidebar > .nav-item > .nav-link {
        border-radius: var(--cs-radius-sm);
        margin: 1px 8px;
        width: auto;
    }
}

[class*="sidebar-dark-"].cs-sidebar .nav-link:hover,
[class*="sidebar-dark-"].cs-sidebar .nav-treeview > .nav-item > .nav-link:hover {
    background-color: rgba(8, 124, 232, 0.22) !important;
    color: #fff !important;
}

[class*="sidebar-dark-"].cs-sidebar .nav-sidebar > .nav-item > .nav-link.active,
[class*="sidebar-dark-"].cs-sidebar .nav-treeview > .nav-item > .nav-link.active {
    background: var(--cs-blue) !important;
    color: #fff !important;
    box-shadow: var(--cs-shadow-sm);
}

/* ==========================================================================
   Navbar
   ========================================================================== */
.main-header.navbar.cs-navbar {
    border-bottom: 1px solid var(--cs-border);
    box-shadow: none;
}

.cs-navbar .nav-link {
    color: var(--cs-text);
}

.cs-navbar .nav-link:hover {
    color: var(--cs-blue);
}

/* ==========================================================================
   Cards
   ========================================================================== */
.content-wrapper .card {
    border: 1px solid var(--cs-border);
    border-radius: var(--cs-radius-md);
    box-shadow: var(--cs-shadow-sm);
}

.content-wrapper .card-header {
    border-top-left-radius: var(--cs-radius-md);
    border-top-right-radius: var(--cs-radius-md);
    background-color: var(--cs-surface);
}

/* Most CRUD pages put a title + one-or-more action buttons in a single
   `.card-header.d-flex` row. Bootstrap's d-flex defaults to nowrap, so on
   narrow screens the title and buttons were forced onto one line and
   overflowed the viewport. Wrapping fixes horizontal scroll without
   touching any markup across the ~50 views that use this pattern. */
.content-wrapper .card-header.d-flex {
    flex-wrap: wrap;
    row-gap: 8px;
}

.content-wrapper .card-header.d-flex > .card-title {
    flex: 1 1 auto;
    min-width: 0;
    word-break: break-word;
}

.content-wrapper .card-header.d-flex > .btn,
.content-wrapper .card-header.d-flex > a.btn,
.content-wrapper .card-header.d-flex > input.btn {
    flex: 0 0 auto;
}

.content-wrapper .small-box {
    border-radius: var(--cs-radius-md);
    box-shadow: var(--cs-shadow-sm);
}

/* ==========================================================================
   KPI Card component (dashboard stat cards)
   ========================================================================== */
.cs-kpi-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    background: var(--cs-surface);
    border: 1px solid var(--cs-border);
    border-radius: var(--cs-radius-md);
    box-shadow: var(--cs-shadow-sm);
    padding: 12px 16px 10px;
    overflow: hidden;
    transition: box-shadow 160ms ease, transform 160ms ease;
}

.cs-kpi-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--cs-blue), var(--cs-cyan));
}

.cs-kpi-card.cs-tint-green::before { background: linear-gradient(90deg, var(--cs-green), var(--cs-teal)); }
.cs-kpi-card.cs-tint-warning::before { background: linear-gradient(90deg, #f0a202, #f4c04f); }
.cs-kpi-card.cs-tint-danger::before { background: linear-gradient(90deg, var(--cs-danger), #f28b63); }

.cs-kpi-card:hover {
    box-shadow: var(--cs-shadow-md);
    transform: translateY(-2px);
}

.cs-kpi-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.cs-kpi-icon {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    border-radius: var(--cs-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    color: var(--cs-white);
    box-shadow: var(--cs-shadow-sm);
}

.cs-kpi-icon.cs-tint-blue { background: linear-gradient(135deg, var(--cs-blue), var(--cs-cyan)); }
.cs-kpi-icon.cs-tint-green { background: linear-gradient(135deg, var(--cs-green), var(--cs-teal)); }
.cs-kpi-icon.cs-tint-warning { background: linear-gradient(135deg, #f0a202, #f4c04f); }
.cs-kpi-icon.cs-tint-danger { background: linear-gradient(135deg, var(--cs-danger), #f28b63); }

.cs-kpi-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    color: var(--cs-muted);
    background: var(--cs-background);
    text-decoration: none;
    font-size: 11px;
    transition: color 160ms ease, background 160ms ease;
}

.cs-kpi-link:hover {
    color: var(--cs-white);
    background: var(--cs-blue);
}

.cs-kpi-body {
    min-width: 0;
}

.cs-kpi-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--cs-muted);
    text-transform: uppercase;
    letter-spacing: .02em;
    margin: 0 0 4px;
}

.cs-kpi-stats {
    display: flex;
    align-items: stretch;
}

.cs-kpi-stat {
    flex: 1 1 50%;
    min-width: 0;
}

.cs-kpi-stat + .cs-kpi-stat {
    margin-left: 14px;
    padding-left: 14px;
    border-left: 1px solid var(--cs-border);
}

.cs-kpi-stat-value {
    display: block;
    font-size: 17px;
    font-weight: 700;
    color: var(--cs-text);
    line-height: 1.2;
}

.cs-kpi-stat-muted .cs-kpi-stat-value {
    color: var(--cs-muted);
}

.cs-kpi-stat-label {
    display: block;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--cs-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-top: 2px;
}

/* Page header */
.cs-page-header-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: var(--cs-radius-sm);
    background: linear-gradient(135deg, var(--cs-blue), var(--cs-cyan));
    color: var(--cs-white);
    margin-right: 10px;
    font-size: 16px;
    vertical-align: middle;
}

.cs-page-subtitle {
    color: var(--cs-muted);
    font-size: 13.5px;
    margin: 2px 0 0;
}

.cs-card-icon {
    color: var(--cs-blue);
    margin-right: 8px;
}

/* ==========================================================================
   Metric list (e.g. "Patients Information")
   ========================================================================== */
.cs-metric-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.cs-metric-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--cs-border);
}

.cs-metric-row:last-child {
    border-bottom: none;
}

.cs-metric-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: var(--cs-text);
    font-size: 13.5px;
}

.cs-metric-label i {
    color: var(--cs-blue);
    width: 16px;
    text-align: center;
}

.cs-metric-value {
    font-weight: 700;
    color: var(--cs-text);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.content-wrapper .btn {
    border-radius: var(--cs-radius-sm);
}

.content-wrapper .btn-primary {
    background-color: var(--cs-blue);
    border-color: var(--cs-blue);
}

.content-wrapper .btn-primary:hover,
.content-wrapper .btn-primary:focus {
    background-color: var(--cs-dark-blue);
    border-color: var(--cs-dark-blue);
}

/* ==========================================================================
   Tables / DataTables
   One shared grid design system: every Index page's `table#datatable-advance`
   uses the same DataTables + Bootstrap4 integration, so styling the classes
   DataTables itself generates (dataTables_filter, _length, _info,
   _paginate, _processing, dtr-* responsive child rows) restyles every grid
   in the app at once — no per-page markup or JS changes needed.
   ========================================================================== */
.content-wrapper table.dataTable thead th {
    background-color: var(--cs-background);
    color: var(--cs-text);
    border-bottom: 2px solid var(--cs-border);
    font-weight: 600;
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: .02em;
    white-space: nowrap;
}

.content-wrapper table.dataTable tbody td {
    padding-top: 12px;
    padding-bottom: 12px;
    vertical-align: middle;
    border-color: var(--cs-border);
}

.content-wrapper table.dataTable tbody tr:hover {
    background-color: rgba(8, 124, 232, 0.04);
}

.content-wrapper table.dataTable thead .sorting:after,
.content-wrapper table.dataTable thead .sorting_asc:after,
.content-wrapper table.dataTable thead .sorting_desc:after {
    color: var(--cs-blue);
}

/* Flatten the dated dark filter-toolbar background used on most Index
   pages' status/search row to the light, minimal look of the rest of the
   design system. */
.content-wrapper .card-body.bg-gradient-gray-dark {
    background: var(--cs-background) !important;
    border-radius: var(--cs-radius-sm);
}

/* ---- DataTables generated toolbar (search / length / info / pagination) ---- */
.content-wrapper .dataTables_wrapper {
    padding-top: 2px;
}

.content-wrapper .dataTables_filter label {
    position: relative;
    font-weight: 500;
    color: var(--cs-muted);
    /* Hides DataTables' own "Search:" text node (purely visual — the
       underlying <input> this label wraps is untouched, so the actual
       search/filter behavior is unaffected) so the icon below sits at the
       input's left edge instead of overlapping that text. */
    font-size: 0;
}

.content-wrapper .dataTables_filter input {
    border: 1px solid var(--cs-border) !important;
    border-radius: var(--cs-radius-sm) !important;
    background: var(--cs-surface) !important;
    color: var(--cs-text);
    padding: 6px 12px 6px 30px !important;
    min-width: 220px;
    height: 34px;
    font-size: 13px;
    box-shadow: none !important;
}

.content-wrapper .dataTables_filter input:focus {
    border-color: var(--cs-blue) !important;
    box-shadow: 0 0 0 3px rgba(8, 124, 232, 0.12) !important;
    outline: none;
}

.content-wrapper .dataTables_filter label::before {
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    content: "\f002";
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-1px);
    color: var(--cs-muted);
    font-size: 12px;
    pointer-events: none;
    z-index: 2;
}

.content-wrapper .dataTables_length select {
    border-radius: var(--cs-radius-sm);
}

.content-wrapper .dataTables_info {
    color: var(--cs-muted);
    font-size: 13px;
    padding-top: 10px !important;
}

.content-wrapper .dataTables_paginate .pagination {
    margin: 0;
}

.content-wrapper .dataTables_paginate .page-link {
    border-radius: var(--cs-radius-sm) !important;
    margin-left: 4px;
    border-color: var(--cs-border);
    color: var(--cs-text);
}

.content-wrapper .dataTables_paginate .page-item.active .page-link {
    background-color: var(--cs-blue);
    border-color: var(--cs-blue);
    color: var(--cs-white);
}

.content-wrapper .dataTables_paginate .page-item.disabled .page-link {
    color: var(--cs-muted);
}

.content-wrapper .dataTables_processing {
    border-radius: var(--cs-radius-md);
    box-shadow: var(--cs-shadow-md);
    border: 1px solid var(--cs-border);
    color: var(--cs-text);
}

/* ---- Empty state (DataTables' own "no data" row — no JS/data touched) ---- */
.content-wrapper table.dataTable tbody td.dataTables_empty {
    padding: 48px 16px;
    text-align: center;
    color: var(--cs-muted);
    font-size: 13.5px;
}

.content-wrapper table.dataTable tbody td.dataTables_empty::before {
    font-family: "Font Awesome 5 Free";
    font-weight: 400;
    content: "\f0ce";
    display: block;
    font-size: 26px;
    color: var(--cs-border);
    margin-bottom: 8px;
}

/* ---- Responsive extension: mobile "card" presentation for collapsed columns ---- */
.content-wrapper table.dataTable > tbody > tr.child {
    background: var(--cs-background);
}

.content-wrapper table.dataTable > tbody > tr.child ul.dtr-details {
    list-style: none;
    margin: 0;
    padding: 8px 4px;
}

.content-wrapper table.dataTable > tbody > tr.child ul.dtr-details > li {
    padding: 6px 4px;
    border-bottom: 1px solid var(--cs-border);
}

.content-wrapper table.dataTable > tbody > tr.child ul.dtr-details > li:last-child {
    border-bottom: none;
}

.content-wrapper table.dataTable > tbody > tr.child span.dtr-title {
    font-weight: 600;
    color: var(--cs-muted);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .02em;
    display: block;
    margin-bottom: 2px;
}

.content-wrapper table.dataTable > tbody > tr > td.dtr-control::before {
    background-color: var(--cs-blue);
    box-shadow: none;
    top: 50%;
    transform: translateY(-50%);
}

/* ---- Action column buttons (view/edit/delete icon buttons) ---- */
.content-wrapper table.dataTable .btn-group-sm > .btn,
.content-wrapper table.dataTable .btn-group-sm > a.btn {
    border-radius: var(--cs-radius-sm);
    min-width: 32px;
}

.content-wrapper table.dataTable .btn-group-sm > .btn:hover {
    filter: brightness(0.95);
}

/* ==========================================================================
   Full-bleed grid pages
   Every Index page built around table#datatable-advance shares the same
   container-fluid > row > col-* > card > card-body chain. AdminLTE's JS
   already stretches .content-wrapper to the full viewport height (minus
   navbar/footer) via an inline min-height, but that chain doesn't pass the
   space down, so the grid shrinks to its content and leaves blank page
   below the pagination bar, with unused gutters on the sides. Turning the
   chain into a flex column lets the grid fill the remaining width and
   height instead. Scoped via :has() to pages that actually contain the
   grid so every other page (dashboards, forms, ...) is untouched.
   ========================================================================== */
.content-wrapper:has(table.dataTable) {
    display: flex;
    flex-direction: column;
}

.content-wrapper:has(table.dataTable) > section.content {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
}

.content-wrapper:has(table.dataTable) .container-fluid {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    padding-left: 0;
    padding-right: 0;
}

.content-wrapper:has(table.dataTable) .container-fluid > .row {
    flex: 1 1 auto;
    margin-left: 0;
    margin-right: 0;
}

.content-wrapper:has(table.dataTable) .container-fluid > .row > [class*="col-"] {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    padding-left: 0;
    padding-right: 0;
}

.content-wrapper:has(table.dataTable) .container-fluid > .row > [class*="col-"] > .card {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
}

/* Only the card-body holding the grid itself should claim the extra
   space - not the filter/search toolbar above it (Bootstrap gives every
   .card-body flex: 1 1 auto by default, which would otherwise split the
   growth between the two and leave dead whitespace under the filters). */
.content-wrapper:has(table.dataTable) .card-body.bg-gradient-gray-dark {
    flex: 0 0 auto;
}

.content-wrapper:has(table.dataTable) .card-body.pt-2 {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
}

.content-wrapper:has(table.dataTable) .card-body.pt-2 .dataTables_wrapper {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
}

.content-wrapper:has(table.dataTable) .card-body.pt-2 table.dataTable {
    width: 100% !important;
}

/* ==========================================================================
   Forms
   ========================================================================== */
.content-wrapper .form-control:focus {
    border-color: var(--cs-blue);
    box-shadow: 0 0 0 3px rgba(8, 124, 232, 0.12);
}

.content-wrapper .select2-container--bootstrap4 .select2-selection:focus,
.content-wrapper .select2-container--bootstrap4.select2-container--focus .select2-selection {
    border-color: var(--cs-blue);
    box-shadow: 0 0 0 3px rgba(8, 124, 232, 0.12);
}

/* Shared toggle switch (used by UserManagement etc.) */
.cs-toggle {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.cs-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.cs-toggle .cs-toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #ccd5e0;
    transition: .2s;
    border-radius: 34px;
}

.cs-toggle .cs-toggle-slider::before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: var(--cs-white);
    transition: .2s;
    border-radius: 50%;
}

.cs-toggle input:checked + .cs-toggle-slider {
    background-color: var(--cs-blue);
}

.cs-toggle input:focus + .cs-toggle-slider {
    box-shadow: 0 0 0 3px rgba(8, 124, 232, 0.18);
}

.cs-toggle input:checked + .cs-toggle-slider::before {
    transform: translateX(20px);
}

/* ==========================================================================
   Badges
   ========================================================================== */
.content-wrapper .badge {
    border-radius: var(--cs-radius-sm);
    font-weight: 600;
    padding: .35em .6em;
}

/* ==========================================================================
   Modals
   ========================================================================== */
.content-wrapper .modal-content {
    border-radius: var(--cs-radius-md);
    border: none;
    box-shadow: var(--cs-shadow-md);
}

.content-wrapper .modal-header.blue-model-bg {
    background: linear-gradient(135deg, var(--cs-navy), var(--cs-blue));
    border-top-left-radius: var(--cs-radius-md);
    border-top-right-radius: var(--cs-radius-md);
}

.content-wrapper .modal-header.blue-model-bg .modal-title {
    color: #fff;
}

/* ==========================================================================
   Dashboard analytics cards
   ========================================================================== */
.cs-chart-card {
    display: flex;
    flex-direction: column;
    background: var(--cs-surface);
    border: 1px solid var(--cs-border);
    border-radius: var(--cs-radius-md);
    box-shadow: var(--cs-shadow-sm);
    padding: 12px 14px;
    height: 100%;
    min-width: 0;
}

.cs-chart-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--cs-text);
    margin: 0 0 6px;
    display: flex;
    align-items: center;
    flex: 0 0 auto;
}

/* Fixed-height, positioned wrapper around every Chart.js canvas.
   Chart.js with maintainAspectRatio:false sizes itself to fill its parent;
   without this explicit height the canvas and an auto-height flex parent
   fight over height and the canvas grows without bound. */
.cs-chart-canvas {
    position: relative;
    flex: 1 1 auto;
    height: 140px;
    min-height: 140px;
    max-height: 140px;
}

/* Caps the dashboard's "Patients Information" list and the Date Lookup
   widget so their content scrolls within the card instead of growing the
   whole page — a long metric list or a tall calendar widget can never push
   the dashboard into needing a page-level scroll. */
.cs-scroll-card-body {
    max-height: 220px;
    overflow-y: auto;
}

.cs-chart-canvas canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}

.cs-chart-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--cs-muted);
    font-size: 13px;
    height: 100%;
}

.cs-chart-empty i {
    font-size: 26px;
    color: var(--cs-border);
}

/* ==========================================================================
   Responsive
   Mobile-first overrides layered on top of Bootstrap 4's own grid/utility
   breakpoints (576 / 768 / 992 / 1200), which the rest of this app already
   relies on for column stacking.
   ========================================================================== */
.content-header h1 {
    font-size: clamp(1.25rem, 4vw, 1.8rem);
}

.cs-dashboard-header.content-header {
    padding: 6px 0.5rem;
}

@media (max-width: 767.98px) {
    .cs-chart-canvas {
        height: 150px;
        min-height: 150px;
        max-height: 150px;
    }
}

@media (max-width: 576px) {
    .cs-kpi-card {
        padding: 14px;
    }

    .cs-page-header-icon {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    .cs-kpi-stat-value {
        font-size: 19px;
    }

    .cs-metric-label {
        font-size: 13px;
    }
}
