/* ==========================================================================
   TrainingBook — shared theme layer
   Loaded LAST (views/load_packages.php), after Bootstrap, AdminLTE, toastr
   and select2, so every page speaks the visual language of the activities
   page: light canvas, white 12px cards, uppercase micro-labels, soft blue
   accent, 38-40px controls.

   - Element / class selectors only: the page rules of main-improved.css
     (body#xxx_page ..., #calendar ...) keep winning, so the calendar, the
     modals and the pages already redesigned stay as they are.
   - Colours live in the tokens below: change them here to retheme the app.
   - Type: Inter (views/load_packages.php), the system font while it loads.
   - Dark look: section 12, switched with html[data-theme="dark"]
     (moon button of the top menu, saved on the user).
   ========================================================================== */

:root {
    --tb-bg:            #f7f9fc;
    --tb-surface:       #ffffff;
    --tb-surface-2:     #fbfcfe;
    --tb-border:        #e6e9ef;
    --tb-border-strong: #dde2ea;
    --tb-divider:       #f1f4f8;
    --tb-text:          #2d3748;
    --tb-text-2:        #5a6577;
    --tb-muted:         #8a94a3;
    --tb-accent:        #2b6cb0;
    --tb-primary:       #7fb3d9;
    --tb-primary-hover: #6aa9d6;
    --tb-primary-soft:  #f4f9fd;
    --tb-grey:          #eef1f6;
    --tb-grey-hover:    #e2e7ee;
    --tb-success:       #7ec48a;
    --tb-success-hover: #6bb679;
    --tb-danger:        #e5737b;
    --tb-danger-hover:  #d9606a;
    --tb-ring:          rgba(127, 179, 217, .28);
    --tb-radius:        14px;
    --tb-radius-sm:     10px;
    --tb-shadow:        0 1px 2px rgba(30, 41, 59, .04), 0 2px 8px rgba(30, 41, 59, .05);
    --tb-shadow-hover:  0 2px 4px rgba(30, 41, 59, .05), 0 8px 22px rgba(30, 41, 59, .10);
    --tb-shadow-pop:    0 16px 40px rgba(30, 41, 59, .16), 0 2px 8px rgba(30, 41, 59, .06);
    --tb-font:          "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}


/* --------------------------------------------------------------------------
   1. Canvas & text
   -------------------------------------------------------------------------- */

body.layout-top-nav {
    color: var(--tb-text);
    font-family: var(--tb-font);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}
.tooltip, .popover, #toast-container, .select2-container, .ui-datepicker { font-family: var(--tb-font); }

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 { letter-spacing: -.01em; }
.modal-title, .card-title, .act-page-title { letter-spacing: -.015em; }

/* Inner pages on the light canvas (the calendar keeps its own surface;
   login / register / recover / terms have their own full-height design) */
body.layout-top-nav:not(.full-height):not(#calendar_page),
body.layout-top-nav.bg-gradient-light:not(.full-height) {
    background: var(--tb-bg) !important;
}

::selection { background: rgba(127, 179, 217, .35); }

a { color: var(--tb-accent); }
a:hover { color: #1f4e8c; }

hr { border-top-color: var(--tb-divider); }

/* Pages without a layout of their own (no body id): same gutters as the redesigned ones */
body.layout-top-nav:not([id]):not(.full-height) > .wrapper > section > .container-fluid {
    padding: 0 24px 48px;
}
body.layout-top-nav:not([id]):not(.full-height) > .wrapper > section > .container {
    padding-bottom: 48px;
}
@media (max-width: 992px) {
    body.layout-top-nav:not([id]):not(.full-height) > .wrapper > section > .container-fluid { padding: 0 12px 40px; }
}


/* --------------------------------------------------------------------------
   2. Page head, toolbar and table card (activities / competitions pattern,
      usable on any page)
   -------------------------------------------------------------------------- */

.act-page-head {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: 12px; padding: 24px 0 16px;
}
.act-page-title {
    font-size: 22px; font-weight: 700; color: var(--tb-text); margin: 0; letter-spacing: -.2px;
}
.act-page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.act-toolbar,
.act-table-card {
    background: var(--tb-surface); border: 1px solid var(--tb-border);
    border-radius: var(--tb-radius); box-shadow: var(--tb-shadow);
}
.act-toolbar    { padding: 14px 16px; margin: 0 0 14px; }
.act-table-card { padding: 8px 14px 14px; }

/* AdminLTE content header (FAQ) reads like the other page titles */
section.content-header h1 {
    font-size: 22px; font-weight: 700; color: var(--tb-text); letter-spacing: -.2px; margin: 0;
}


/* --------------------------------------------------------------------------
   3. Tables (inside a table card) + DataTables chrome
   -------------------------------------------------------------------------- */

.act-table-card .table { margin-bottom: 0; }
.act-table-card .table thead th {
    border-top: 0; border-bottom: 1px solid #eef1f6;
    font-size: 11px; font-weight: 700; color: var(--tb-muted);
    text-transform: uppercase; letter-spacing: .3px;
    padding: 12px 8px; white-space: nowrap;
}
.act-table-card .table td {
    border-top: 1px solid var(--tb-divider);
    padding: 10px 8px; vertical-align: middle;
    font-size: 13px; color: #3d4757;
}
.act-table-card .table-hover tbody tr:hover td { background: var(--tb-bg); }
.act-table-card .table td img { border-radius: 50%; }

/* DataTables (Bootstrap 4 build, its CSS loads after this file: hence the body prefix) */
body .dataTables_wrapper .dataTables_filter input,
body .dataTables_wrapper .dataTables_length select {
    height: 36px; border: 1px solid var(--tb-border-strong); border-radius: var(--tb-radius-sm);
    font-size: 13px; color: var(--tb-text); background-color: #ffffff; box-shadow: none;
}
body .dataTables_wrapper .dataTables_filter input { padding: 0 12px; }
body .dataTables_wrapper .dataTables_filter input:focus,
body .dataTables_wrapper .dataTables_length select:focus {
    outline: none; border-color: #a9c9e4; box-shadow: 0 0 0 3px var(--tb-ring);
}
body .dataTables_wrapper .dataTables_filter label,
body .dataTables_wrapper .dataTables_length label { font-size: 12px; font-weight: 600; color: var(--tb-muted); }
body .dataTables_wrapper .dataTables_info { font-size: 12px; color: var(--tb-muted); padding-top: 14px; }
body div.dataTables_wrapper div.dataTables_processing {
    border: 1px solid var(--tb-border); border-radius: var(--tb-radius);
    box-shadow: var(--tb-shadow-pop); background: #ffffff; color: var(--tb-text-2);
}

/* Pagination (Bootstrap, also used by DataTables): borderless chips */
.pagination .page-link {
    border: 0; border-radius: 8px !important; margin: 0 2px;
    background-color: transparent;
    font-size: 12px; font-weight: 600; color: var(--tb-text-2);
}
.pagination .page-link:hover { background-color: var(--tb-grey); color: var(--tb-accent); }
.pagination .page-link:focus { box-shadow: 0 0 0 3px var(--tb-ring); }
.pagination .page-item.active .page-link { background-color: var(--tb-primary); color: #ffffff; }
.pagination .page-item.disabled .page-link { background-color: transparent; color: #c3cad5; }


/* --------------------------------------------------------------------------
   4. Cards
   -------------------------------------------------------------------------- */

.card {
    border: 1px solid var(--tb-border);
    border-radius: var(--tb-radius);
    box-shadow: var(--tb-shadow);
}
.card > .card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--tb-divider);
}
.card > .card-header:first-child { border-radius: calc(var(--tb-radius) - 1px) calc(var(--tb-radius) - 1px) 0 0; }
.card > .card-footer {
    background-color: var(--tb-surface-2);
    border-top: 1px solid var(--tb-divider);
}
.card > .card-footer:last-child { border-radius: 0 0 calc(var(--tb-radius) - 1px) calc(var(--tb-radius) - 1px); }
.card-title { font-weight: 700; }
.card.card-outline { border-top-width: 3px; }
.card-secondary.card-outline { border-top-color: var(--tb-border-strong); }
.card-primary.card-outline   { border-top-color: var(--tb-primary); }

/* FAQ answers: readable grey instead of AdminLTE's teal */
section.content .card-body.text-info { color: var(--tb-text-2) !important; line-height: 1.6; }


/* --------------------------------------------------------------------------
   5. Buttons (the calendar header and the modals keep their own rules)
   -------------------------------------------------------------------------- */

.btn {
    border-radius: 10px;
    font-weight: 600;
    letter-spacing: .1px;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.btn-sm, .btn-group-sm > .btn { border-radius: 8px; }
.btn-lg, .btn-group-lg > .btn { border-radius: 12px; }
.btn:focus, .btn.focus { box-shadow: 0 0 0 3px var(--tb-ring); }

.btn-primary,
.btn-primary.disabled, .btn-primary:disabled {
    background-color: var(--tb-primary); border-color: var(--tb-primary); color: #ffffff;
}
.btn-primary:hover, .btn-primary:focus, .btn-primary.focus,
.btn-primary:not(:disabled):not(.disabled):active,
.btn-primary:not(:disabled):not(.disabled).active {
    background-color: var(--tb-primary-hover); border-color: var(--tb-primary-hover); color: #ffffff;
}

.btn-secondary,
.btn-secondary.disabled, .btn-secondary:disabled {
    background-color: var(--tb-grey); border-color: var(--tb-grey); color: var(--tb-text-2);
}
.btn-secondary:hover, .btn-secondary:focus, .btn-secondary.focus,
.btn-secondary:not(:disabled):not(.disabled):active,
.btn-secondary:not(:disabled):not(.disabled).active {
    background-color: var(--tb-grey-hover); border-color: var(--tb-grey-hover); color: var(--tb-text);
}

.btn-success,
.btn-success.disabled, .btn-success:disabled {
    background-color: var(--tb-success); border-color: var(--tb-success); color: #ffffff;
}
.btn-success:hover, .btn-success:focus, .btn-success.focus,
.btn-success:not(:disabled):not(.disabled):active,
.btn-success:not(:disabled):not(.disabled).active {
    background-color: var(--tb-success-hover); border-color: var(--tb-success-hover); color: #ffffff;
}

.btn-danger,
.btn-danger.disabled, .btn-danger:disabled {
    background-color: var(--tb-danger); border-color: var(--tb-danger); color: #ffffff;
}
.btn-danger:hover, .btn-danger:focus, .btn-danger.focus,
.btn-danger:not(:disabled):not(.disabled):active,
.btn-danger:not(:disabled):not(.disabled).active {
    background-color: var(--tb-danger-hover); border-color: var(--tb-danger-hover); color: #ffffff;
}

.btn-default {
    background-color: #ffffff; border-color: var(--tb-border-strong); color: var(--tb-text-2);
}
.btn-default:hover, .btn-default:focus { background-color: var(--tb-bg); border-color: #c7cfdb; color: var(--tb-text); }


/* --------------------------------------------------------------------------
   6. Form controls outside the modals (the modals have their own rules)
   -------------------------------------------------------------------------- */

.form-control,
.custom-select {
    border: 1px solid var(--tb-border-strong);
    border-radius: var(--tb-radius-sm);
    color: var(--tb-text);
    box-shadow: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:hover,
.custom-select:hover { border-color: #c7cfdb; }
.form-control:focus,
.custom-select:focus {
    border-color: #a9c9e4;
    box-shadow: 0 0 0 3px var(--tb-ring);
}
.form-control::placeholder { color: #a8b0bd; }
.form-control:disabled { background-color: var(--tb-surface-2); }

.custom-control-input:checked ~ .custom-control-label::before {
    background-color: var(--tb-primary); border-color: var(--tb-primary);
}
.custom-control-input:focus ~ .custom-control-label::before { box-shadow: 0 0 0 3px var(--tb-ring); }

.input-group-text {
    background-color: var(--tb-bg); border-color: var(--tb-border-strong); color: var(--tb-muted);
}


/* --------------------------------------------------------------------------
   7. Dropdowns, tooltips, popovers
   -------------------------------------------------------------------------- */

.dropdown-menu {
    border: 1px solid var(--tb-border);
    border-radius: var(--tb-radius);
    box-shadow: var(--tb-shadow-pop);
    padding: 6px;
}
.dropdown-item {
    border-radius: 8px;
    padding: 7px 12px;
    font-size: 13px;
    color: var(--tb-text);
}
.dropdown-item:hover, .dropdown-item:focus { background-color: #f4f6fa; color: var(--tb-text); }
.dropdown-item.active, .dropdown-item:active { background-color: var(--tb-primary-soft); color: var(--tb-accent); }
.dropdown-divider { border-top-color: var(--tb-divider); margin: 6px 0; }
.dropdown-header {
    font-size: 10.5px; font-weight: 700; color: var(--tb-muted);
    text-transform: uppercase; letter-spacing: .4px;
}

.tooltip { font-size: 12px; }
.tooltip-inner {
    background-color: var(--tb-text);
    border-radius: 8px;
    padding: 6px 10px;
    box-shadow: 0 4px 14px rgba(30, 41, 59, .18);
}
.bs-tooltip-top .arrow::before,    .bs-tooltip-auto[x-placement^="top"] .arrow::before    { border-top-color: var(--tb-text); }
.bs-tooltip-bottom .arrow::before, .bs-tooltip-auto[x-placement^="bottom"] .arrow::before { border-bottom-color: var(--tb-text); }
.bs-tooltip-left .arrow::before,   .bs-tooltip-auto[x-placement^="left"] .arrow::before   { border-left-color: var(--tb-text); }
.bs-tooltip-right .arrow::before,  .bs-tooltip-auto[x-placement^="right"] .arrow::before  { border-right-color: var(--tb-text); }

.popover {
    border: 1px solid var(--tb-border);
    border-radius: var(--tb-radius);
    box-shadow: var(--tb-shadow-pop);
}


/* --------------------------------------------------------------------------
   8. Badges & alerts (soft tints instead of solid AdminLTE blocks)
   -------------------------------------------------------------------------- */

.badge { border-radius: 999px; font-weight: 700; padding: .35em .6em; }

.alert {
    border-radius: var(--tb-radius);
    border: 1px solid transparent;
    font-size: 13px;
}
.alert-info    { background-color: #eef6fc; border-color: #cfe3f4; color: #2b6c9e; }
.alert-success { background-color: #eaf6ec; border-color: #cfe6d4; color: #3f7a4d; }
.alert-warning { background-color: #fdf3e6; border-color: #f4e2c6; color: #8a5a14; }
.alert-danger  { background-color: #fdeef0; border-color: #f6d3d7; color: #b0444d; }
.alert a { color: inherit; font-weight: 700; text-decoration: underline; }
.alert .close { color: inherit; opacity: .5; text-shadow: none; }


/* --------------------------------------------------------------------------
   9. Toasts (toastr)
   -------------------------------------------------------------------------- */

#toast-container > div {
    border-radius: var(--tb-radius);
    box-shadow: var(--tb-shadow-pop);
    opacity: .97;
    font-size: 13px;
    line-height: 1.45;
}
#toast-container > div:hover { box-shadow: var(--tb-shadow-pop); opacity: 1; }
#toast-container > .toast-success { background-color: #4e9a63; }
#toast-container > .toast-error   { background-color: #d9606a; }
#toast-container > .toast-info    { background-color: #3d78bd; }
#toast-container > .toast-warning { background-color: #d39132; }
#toast-container .toast-title { font-weight: 700; }


/* --------------------------------------------------------------------------
   10. Top menu and footer (club colours stay: they come inline)
   -------------------------------------------------------------------------- */

.main-header.navbar { border-bottom: 1px solid var(--tb-border); box-shadow: 0 1px 2px rgba(30, 41, 59, .04); }

@media (min-width: 1100px) {
    .main-header .navbar-nav .nav-link {
        border-radius: 8px;
        font-weight: 600;
        transition: background-color .15s ease, color .15s ease;
    }
    .main-header .navbar-nav .nav-link:hover { background-color: rgba(45, 55, 72, .06); }
    /* current page (marked by functions.js) */
    .main-header .navbar-nav .nav-link.tb-current { background-color: rgba(127, 179, 217, .18); }
}

.main-footer {
    border-top: 1px solid var(--tb-border);
    font-size: 12.5px;
}

.main-header .navbar-brand .brand-text { font-weight: 700 !important; letter-spacing: -.02em; }

/* Light / dark button of the top menu */
.main-header .tb-theme-toggle i { font-size: 15px; transition: transform .3s ease; }
.main-header .tb-theme-toggle:hover i { transform: rotate(-18deg); }


/* --------------------------------------------------------------------------
   11. Details: modals, cards, focus, scrollbars (simple and quiet)
   -------------------------------------------------------------------------- */

.modal-content {
    border: 0;
    border-radius: 18px;
    box-shadow: var(--tb-shadow-pop);
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--tb-divider); }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--tb-divider); }
.modal-title { font-weight: 700; }
.modal-header .close { opacity: .45; text-shadow: none; transition: opacity .15s ease; }
.modal-header .close:hover { opacity: .8; }
.modal-backdrop.show { opacity: .38; }
.modal-backdrop { -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }

.card { transition: box-shadow .2s ease; }
a.card:hover, .card.card-hover:hover { box-shadow: var(--tb-shadow-hover); }

.btn:not(:disabled):not(.disabled):active { transform: translateY(1px); }

/* Keyboard focus visible, mouse focus quiet */
a:focus-visible, button:focus-visible, .btn:focus-visible, [tabindex]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--tb-ring);
}

a { text-underline-offset: 2px; }

/* Thin scrollbars in the app colours */
* { scrollbar-width: thin; scrollbar-color: #cfd6e0 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cfd6e0; border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #b6bfcc; border: 3px solid transparent; background-clip: padding-box; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}


/* --------------------------------------------------------------------------
   12. Dark look (html[data-theme="dark"])
   The whole page turns to dark tones in one layer, so every page, window
   and box of the app follows (the pastel palette keeps its hues). Photos,
   maps, logos and the share image are turned back: they keep their real
   colours. Colours set here are the ones *before* that layer: light ones
   come out dark and dark ones light.
   -------------------------------------------------------------------------- */

html[data-theme="dark"] {
    min-height: 100%;
    background-color: #f7f9fc;
    filter: invert(1) hue-rotate(180deg) contrast(.9);
}

/* Real colours for pictures and maps (the exact inverse of the layer above) */
html[data-theme="dark"] img,
html[data-theme="dark"] video,
html[data-theme="dark"] picture,
html[data-theme="dark"] iframe,
html[data-theme="dark"] .tb-keep-colors,
html[data-theme="dark"] [style*="background-image"] {
    filter: contrast(1.111) hue-rotate(180deg) invert(1);
}
/* ...but not twice for a picture inside one already turned back */
html[data-theme="dark"] [style*="background-image"] img,
html[data-theme="dark"] .tb-keep-colors img { filter: none; }

/* Shadows would turn into glows: very soft ones only */
html[data-theme="dark"] {
    --tb-shadow:       0 1px 2px rgba(255, 255, 255, .02);
    --tb-shadow-hover: 0 2px 8px rgba(255, 255, 255, .04);
    --tb-shadow-pop:   0 0 0 1px rgba(0, 0, 0, .06);
}

/* Main buttons: light tint + dark text here = deep tint + light text on screen */
html[data-theme="dark"] {
    --tb-primary:       #cfe3f3;
    --tb-primary-hover: #bdd8ee;
    --tb-success:       #cdebd3;
    --tb-success-hover: #bce3c5;
    --tb-danger:        #f6cfd3;
    --tb-danger-hover:  #f1bcc2;
}
html[data-theme="dark"] .btn-primary,
html[data-theme="dark"] .btn-success,
html[data-theme="dark"] .btn-danger { color: #10233a; }
html[data-theme="dark"] .btn-primary:hover,
html[data-theme="dark"] .btn-success:hover,
html[data-theme="dark"] .btn-danger:hover { color: #0b1a2c; }

html[data-theme="dark"] ::selection { background: rgba(127, 179, 217, .45); }
html[data-theme="dark"] * { scrollbar-color: #b6bfcc transparent; }
