/* ============================================================
   THEME.CSS — Design tokens + Light/Dark palettes
   Single source of truth for the app theme.
   Usage: <html data-theme="light|dark"> (set before CSS paint)
   ============================================================ */

/* ---------- DARK (current palette, unchanged) ---------- */
[data-theme="dark"] {
    --bg-page: #1d2731;
    --bg-navbar: #1d2731;
    --bg-sidebar: #1d2731;
    --bg-sidebar-icon: #1d2731;
    --bg-card: #484c50;
    --bg-card-header: #3a3e42;
    --bg-input: #131212;
    --bg-input-focus: #000000;
    --bg-dropdown: #000000;
    --bg-table: #003049;
    --bg-table-alt: #0a3a52;
    --bg-footer: #1d2731;
    --bg-hover: #243340;

    --text-primary: #ffffff;
    --text-secondary: #2ecc71;
    --text-muted: #b8c4cc;
    --text-on-accent: #ffffff;

    --accent: #2ecc71;
    --accent-hover: #27ae60;
    --accent-contrast: #ffffff;

    --border-color: #313030;
    --border-input: #c5c5c5;
    --shadow: 1px 1px 1px black;

    --link: #2ecc71;
    --link-hover: #ffffff;

    --danger: #e74c3c;
    --bg-danger-soft: #4a2521;
    --text-danger: #ffa79e;
    --danger-border: rgba(231, 76, 60, 0.55);

    --toggle-track: #000000;
    --toggle-knob: #333333;
}

/* ---------- LIGHT (grey-toned, low glare) ----------
   The office asked for a slightly darker / greyer light theme, striping on
   every table, and a chrome (sidebar + navbar) that reads as a distinct
   surface rather than another slab of white.

   Tiers:
     canvas  #d3d9df   (grey page background)
     chrome  #c3ccd6   (sidebar + navbar — deliberately DARKER than the page
                        so the rail/header read as one solid dark band)
     content #fbfcfd   (cards, tables, inputs — near-white "paper" on top) */
[data-theme="light"] {
    --bg-page: #c3cbd4;
    --bg-navbar: #aab6c4;
    --bg-sidebar: #aab6c4;
    --bg-sidebar-icon: #aab6c4;
    --bg-card: #f5f7f9;
    --bg-card-header: #dbe3ea;
    --bg-input: #ffffff;
    --bg-input-focus: #ffffff;
    --bg-dropdown: #ffffff;
    --bg-table: #f5f7f9;
    --bg-table-alt: #d2dbe4;
    --bg-footer: #aab6c4;
    --bg-hover: #bfcbd8;

    --text-primary: #161d24;
    --text-secondary: #0e4a24;
    --text-muted: #3d4853;
    --text-on-accent: #ffffff;

    --accent: #27ae60;
    --accent-hover: #1e8449;
    --accent-contrast: #ffffff;

    --border-color: #9fabba;
    --border-input: #7d8b99;
    --shadow: 0 1px 2px rgba(22, 29, 36, 0.14);

    --link: #0e4a24;
    --link-hover: #0a3a1c;

    --danger: #b03325;
    --bg-danger-soft: #eccfcb;
    --text-danger: #7d2318;
    --danger-border: rgba(176, 51, 37, 0.45);

    --toggle-track: #9fabba;
    --toggle-knob: #ffffff;
}

/* ============================================================
   SHARED COMPONENT STYLES (token-driven, both themes)
   Replaces the triplicated inline style blocks in
   master.blade.php / app.blade.php / dueMaster.blade.php
   ============================================================ */

body {
    background-color: var(--bg-page);
    color: var(--text-primary);
}

/* ---------- Navbar / Topbar ----------
   The navbar sat flush against the content with no edge, so in light mode
   (where navbar and page have different tones) it read as part of the page,
   and in dark mode — where BOTH tokens are #1d2731 — there was no header at
   all. Pin it, and give it a hairline + soft shadow so the header reads as a
   distinct band in either theme. */
.navbar-laravel {
    position: sticky;
    top: 0;
    z-index: 1030;
    background-color: var(--bg-navbar) !important;
    color: var(--text-secondary) !important;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(29, 39, 49, 0.08);
    /* Offset for the fixed icon rail (90px). Was an inline
       `margin-left:90px; padding:12px 0` on the <nav>; moved here so the
       responsive breakpoints can override it. */
    margin-left: 90px;
    padding: 12px 0;
}
/* In dark mode the navbar and the page share #1d2731 and --border-color is
   #313030, which is almost invisible on both. Give the header its own
   slightly lighter hairline so the band is readable. */
[data-theme="dark"] .navbar-laravel {
    border-bottom-color: #3d4a56;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}
.navbar-laravel .nav-link {
    color: var(--text-secondary) !important;
}
.navbar-laravel .navbar-brand {
    color: var(--text-secondary) !important;
}
.navbar-light .navbar-brand,
.navbar-light .navbar-brand:focus,
.navbar-light .navbar-brand:hover {
    color: var(--text-secondary);
}
.navbar-light .navbar-nav .nav-link {
    color: var(--text-secondary);
}
.navbar-light .navbar-nav .active > .nav-link,
.navbar-light .navbar-nav .nav-link.active,
.navbar-light .navbar-nav .nav-link.show,
.navbar-light .navbar-nav .show > .nav-link {
    color: var(--text-primary);
}
.navbar-light .navbar-nav .nav-link:focus,
.navbar-light .navbar-nav .nav-link:hover {
    color: var(--text-primary);
}
.nav-link {
    color: var(--text-secondary);
}
a.nav-link:focus,
a.nav-link:hover,
a.nav-link.active {
    color: var(--text-primary);
}

/* ---------- Sidebar ---------- */
.w3-light-grey,
.w3-hover-light-grey:hover,
.w3-light-gray,
.w3-hover-light-gray:hover {
    color: var(--text-primary) !important;
    background-color: var(--bg-sidebar) !important;
}
.w3-sidebar {
    height: 100%;
    width: 200px;
    background-color: var(--bg-sidebar);
    position: fixed !important;
    z-index: 1;
    overflow: auto;
    border-right: 1px solid var(--border-color);
}
li.nav-item.dropdown.middle {
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}
a.nav-link img {
    width: 36px;
    margin-right: 7px;
    height: 40px;
}

/* ---------- Footer ---------- */
.footer {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    background-color: var(--bg-footer);
    color: var(--text-secondary);
    text-align: center;
    border-top: 1px solid var(--border-color);
}

/* ---------- Cards ---------- */
.card {
    background-color: var(--bg-card);
    border-color: var(--border-color);
    color: var(--text-primary);
}
.card-header {
    background-color: var(--bg-card-header);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}
.card-body {
    background-color: var(--bg-card);
}
.card-body label {
    color: var(--text-secondary);
}

/* ---------- Forms ---------- */
.card-body input,
.card-body select.form-control {
    background-color: var(--bg-input);
    color: var(--text-primary);
}
.card-body select.form-control:focus {
    background-color: var(--bg-input-focus);
}
.form-control {
    background-color: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--border-input);
}
.form-control:focus {
    border: 0;
    box-shadow: none;
    background-color: var(--bg-input-focus);
    color: var(--text-primary);
}
/* Kept verbatim from the original layout: this app styles labels as underlined
   captions and gives controls a 2px bottom edge. Components that need the
   plain look (e.g. the payment receipt modal) reset it locally instead. */
label {
    border-bottom: 4px solid var(--border-input) !important;
}
input,
select {
    border-bottom: 2px solid var(--border-input) !important;
    box-shadow: var(--shadow);
    color: var(--text-primary);
}
.formTitle {
    color: var(--text-secondary);
}

/* ---------- Tables ----------
   Office request: EVERY table is striped in both themes, and the hover state
   was unreliable — on many tables nothing happened, and on striped tables the
   hover colour was fought by the stripe rule so rows flickered between tones.

   Rules below:
     - striping is applied to all .table (and DataTables) tbody rows, not only
       when the .table-striped class happens to be present;
     - the stripe uses a low-contrast token so it is subtle in light mode;
     - hover is applied with higher specificity than the stripe and also to the
       individual <td>s, because Bootstrap paints row backgrounds at cell level
       on striped tables. */
.table {
    background: var(--bg-table);
    color: var(--text-primary);
}
.table th,
.table td {
    color: var(--text-primary);
    border-color: var(--border-color);
}

/* --- striping (all tables, both themes) --- */
.table > tbody > tr:nth-of-type(odd),
.table-striped > tbody > tr:nth-of-type(odd),
table.dataTable > tbody > tr:nth-of-type(odd) {
    background-color: var(--bg-table-alt);
}
.table > tbody > tr:nth-of-type(odd) > td,
.table-striped > tbody > tr:nth-of-type(odd) > td,
table.dataTable > tbody > tr:nth-of-type(odd) > td {
    background-color: transparent;
}
/* keep the even rows on the base surface */
.table > tbody > tr:nth-of-type(even),
.table-striped > tbody > tr:nth-of-type(even),
table.dataTable > tbody > tr:nth-of-type(even) {
    background-color: var(--bg-table);
}

/* --- hover (must beat the stripe rule) --- */
.table-hover > tbody > tr:hover,
.table > tbody > tr:hover,
table.dataTable > tbody > tr:hover,
table.dataTable.hover > tbody > tr:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}
.table-hover > tbody > tr:hover > td,
.table > tbody > tr:hover > td,
table.dataTable > tbody > tr:hover > td {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}
table.dataTable.dtr-inline.collapsed > tbody > tr[role="row"] > td:first-child:before,
table.dataTable.dtr-inline.collapsed > tbody > tr[role="row"] > th:first-child:before {
    top: 16px;
}

/* ---------- Pagination ---------- */
.page-item.active .page-link {
    background-color: var(--accent);
    border-color: var(--accent);
    color: var(--text-on-accent);
}
.page-link {
    color: var(--text-secondary);
    background-color: var(--bg-card);
    border-color: var(--border-color);
}

/* ---------- Links ---------- */
a {
    color: var(--link);
}
a:hover {
    color: var(--link-hover);
}

/* ---------- Bootstrap dark-utility neutralization (theme-aware) ---------- */
.bg-dark,
.bg-secondary {
    background-color: var(--bg-card-header) !important;
    color: var(--text-primary) !important;
}
/* `.text-white` must stay white — it is used for icons/labels sitting on their
   own colored surfaces (e.g. bg-primary avatars). The more-specific
   `.bg-dark.text-white`, `.bg-secondary.text-white` and `.card-header.*` rules
   below re-map it to the theme text color where the surface is neutralized. */
.text-white {
    color: #ffffff !important;
}
.table-dark,
.table-dark th,
.table-dark td,
.table-dark thead th {
    background-color: var(--bg-table);
    color: var(--text-primary);
    border-color: var(--border-color);
}
/* .table-dark rows follow the same striping + hover contract as .table so the
   whole app behaves identically regardless of the class used in the markup. */
.table-dark > tbody > tr:nth-of-type(odd),
.table-dark.table-striped > tbody > tr:nth-of-type(odd) {
    background-color: var(--bg-table-alt);
}
.table-dark > tbody > tr:nth-of-type(odd) > td {
    background-color: transparent;
}
.table-dark > tbody > tr:nth-of-type(even) {
    background-color: var(--bg-table);
}
.table-dark > tbody > tr:hover,
.table-dark.table-hover > tbody > tr:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}
.table-dark > tbody > tr:hover > td {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}
.bg-dark.text-white,
.bg-secondary.text-white {
    color: var(--text-primary) !important;
}
/* Card headers / tables that carry dark Bootstrap classes get token colors,
   but keep their semantic text-on-surface pairing intact. */
.card-header.bg-dark,
.card-header.bg-secondary,
.card-header.text-white.bg-dark,
.card-header.text-white.bg-secondary {
    color: var(--text-primary) !important;
}
.card-header.bg-dark *,
.card-header.bg-secondary * {
    color: var(--text-primary);
}

/* ---------- Semantic status surfaces ----------
   Bootstrap's literal `.bg-danger` (`#dc3545`) is far too loud applied to a
   whole table row, and in dark mode it left dark text on a bright red band.
   Status is still obvious, but as a tint + accent edge rather than a slab. */
.bg-danger {
    background-color: var(--bg-danger-soft) !important;
    color: var(--text-danger) !important;
}
.bg-danger > td {
    background-color: transparent !important;
    color: var(--text-danger) !important;
}
.table > tbody > tr.bg-danger > td {
    border-top-color: var(--danger-border) !important;
}
tr.bg-danger td:first-child {
    box-shadow: inset 3px 0 0 var(--danger);
}
.badge-danger,
.badge-due {
    background-color: var(--danger) !important;
    color: #ffffff !important;
}
.text-danger,
.alert-danger {
    color: var(--text-danger) !important;
}
.alert-danger {
    background-color: var(--bg-danger-soft) !important;
    border-color: var(--danger-border) !important;
}

/* ---------- Dropdowns ---------- */
.dropdown-menu {
    background-color: var(--bg-dropdown);
    border-color: var(--border-color);
}
.dropdown-item {
    color: var(--text-primary);
}
.dropdown-item:hover,
.dropdown-item:focus {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

/* ---------- Select2 ---------- */
.select2-container--default .select2-selection--single {
    background-color: var(--bg-input);
}
.select2-container {
    display: block;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 36px;
    color: var(--text-primary);
}
.select2-container .select2-selection--single {
    height: 38px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
    border-bottom: 2px solid var(--border-input) !important;
}
.select2 {
    border-bottom: 2px solid var(--border-input) !important;
    box-shadow: var(--shadow);
}
.select2-dropdown {
    background: var(--bg-dropdown);
    color: var(--text-primary);
    border-color: var(--border-color);
}
.select2-container--default .select2-search--dropdown .select2-search__field {
    background: var(--bg-input);
    color: var(--text-primary);
}
.select2-container--default .select2-results__option[aria-selected="true"] {
    background-color: var(--accent);
    color: var(--text-on-accent);
}
.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--accent);
    color: var(--text-on-accent);
}
.select2-container--default .select2-results__option {
    color: var(--text-primary);
    background-color: var(--bg-dropdown);
}

/* ---------- Modals ---------- */
.modal-content {
    background-color: var(--bg-table);
    color: var(--text-primary);
    border-color: var(--border-color);
}
.modal-header,
.modal-footer {
    border-color: var(--border-color);
}
.modal-header .close {
    color: var(--text-primary);
    text-shadow: none;
    opacity: 0.85;
}
.modal-body {
    color: var(--text-primary);
}

/* ---------- Toggle switch (existing .switch markup) ---------- */
.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}
.switch input {
    display: none;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--toggle-track);
    -webkit-transition: 0.4s;
    transition: 0.4s;
}
.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: var(--toggle-knob);
    -webkit-transition: 0.4s;
    transition: 0.4s;
}
input:checked + .slider {
    background-color: var(--accent);
}
input:focus + .slider {
    box-shadow: 0 0 1px #2196f3;
}
input:checked + .slider:before {
    -webkit-transform: translateX(26px);
    -ms-transform: translateX(26px);
    transform: translateX(26px);
}

/* ---------- Theme toggle button (topbar) ---------- */
.theme-toggle {
    cursor: pointer;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 34px;
    height: 34px;
    line-height: 32px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 15px;
    margin-left: 10px;
    transition: background-color 0.2s, color 0.2s;
}
.theme-toggle:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

/* ---------- DataTables misc ---------- */
#datatable_wrapper .buttons-html5 {
    display: none;
}
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_processing,
.dataTables_wrapper .dataTables_paginate {
    color: var(--text-primary);
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
    color: var(--text-secondary) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: var(--accent);
    color: var(--text-on-accent) !important;
    border-color: var(--accent);
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: var(--bg-hover);
    color: var(--text-primary) !important;
    border-color: var(--border-color);
}
/* DataTables rows inherit the global striping/hover contract defined in the
   Tables section above — nothing extra is needed here. Previously a blanket
   `table.dataTable tbody tr { background-color: var(--bg-table) }` sat here
   and overrode every odd-row stripe, which is part of why hover/striping
   looked inconsistent from table to table. */

/* ---------- jQuery UI datepicker ---------- */
.ui-datepicker {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.ui-datepicker-header {
    background: var(--bg-card-header);
    color: var(--text-primary);
    border-color: var(--border-color);
}
.ui-datepicker th {
    color: var(--text-secondary);
}
.ui-datepicker td a,
.ui-datepicker td span {
    color: var(--text-primary);
}
.ui-state-default,
.ui-widget-content .ui-state-default {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--border-color);
}
.ui-state-highlight {
    background: var(--accent);
    color: var(--text-on-accent);
}

/* ============================================================
   RESPONSIVE LAYOUT
   The shell uses a fixed 90px icon sidebar plus a hardcoded
   `margin-left:90px` on ~89 views. Those offsets are inline styles,
   so the breakpoints below use !important to collapse the rail and
   reclaim width on narrow screens.
   ============================================================ */

/* Make the content column a scroll container so the many wide
   DataTables (11-16 columns) can pan instead of blowing out the page. */
.main-section {
    min-width: 0;
}

/* The topbar carries ~14 action links; without wrap they force the whole
   page wider than the viewport. */
.navbar-laravel .navbar-collapse {
    min-width: 0;
}
.navbar-laravel .navbar-nav {
    flex-wrap: wrap;
    justify-content: flex-end;
}
.navbar-laravel .nav-link {
    padding: 0.35rem 0.55rem;
}

/* ---- Tablet / small laptop ---- */
@media (max-width: 991.98px) {
    .w3-sidebar {
        width: 58px !important;
    }
    .w3-sidebar .nav-link {
        padding: 8px 0;
    }
    .w3-sidebar .nav-link span {
        display: none;
    }
    .w3-sidebar .nav-link i {
        font-size: 1.25rem !important;
    }
    .w3-sidebar .nav-link img {
        width: 28px;
        height: 32px;
        margin-right: 0;
    }
    li.nav-item.dropdown.middle {
        margin-bottom: 4px;
        padding-bottom: 4px;
    }

    /* Covers both `margin-left:90px` and `margin-left: 90px` as authored
       across the ~89 views that hardcode the content offset for the icon
       rail, so the whole shell narrows together. */
    [style*="margin-left:90px"],
    [style*="margin-left: 90px"] {
        margin-left: 58px !important;
    }

    /* let tables pan horizontally inside their column */
    .table-responsive,
    .dataTables_wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .main-section .table,
    .main-section table.dataTable {
        min-width: 640px;
    }

    /* page heading + topbar tighten up */
    .formTitle {
        font-size: 1.35rem;
    }
    .navbar-laravel {
        padding: 8px 0 !important;
        margin-left: 58px !important;
    }
}

/* ---- Phone ---- */
@media (max-width: 575.98px) {
    .w3-sidebar {
        width: 48px !important;
    }
    .w3-sidebar .nav-link i {
        font-size: 1.05rem !important;
    }
    .navbar-laravel {
        margin-left: 48px !important;
    }
    [style*="margin-left:90px"],
    [style*="margin-left: 90px"] {
        margin-left: 48px !important;
    }

    .formTitle {
        font-size: 1.15rem;
    }
    .container-fluid {
        padding-left: 8px;
        padding-right: 8px;
    }

    /* nav tabs in the dashboard become a horizontally scrollable strip */
    .main-section .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .main-section .nav-tabs .nav-link {
        white-space: nowrap;
    }

    /* stack cards and form columns */
    .card-body .row > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* ---------- Touch: avoid sticky hover states on the rail ---------- */
@media (hover: none) {
    .w3-sidebar .nav-link:hover {
        color: var(--text-secondary);
    }
}

/* ---------- Global safety: never let a wide element break the viewport ---------- */
img,
canvas,
svg {
    max-width: 100%;
}

/* ---------- Smooth theme transition ---------- */
body,
.card,
.table,
.navbar,
.dropdown-menu,
.form-control,
.select2-dropdown,
.w3-sidebar {
    transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}