/* General Styles */
.main-content {
    padding: 2rem;
}

/* Dark mode transition */
:root {
    transition: color-scheme 0.3s ease;
}

[data-bs-theme="dark"] {
    color-scheme: dark;
}

/* Login Page */
.login-card {
    max-width: 400px;
    margin: 2rem auto;
}

/* POS Styles */
.product-card {
    cursor: pointer;
    transition: all 0.3s ease;
}

.product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.cart-table {
    max-height: 400px;
    overflow-y: auto;
}

/* Analytics Dashboard */
.stat-card {
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.stat-card h3 {
    margin: 0;
    color: var(--bs-primary);
}

/* Tables */
.table-responsive {
    margin-bottom: 1rem;
}

.table th {
    background-color: var(--bs-secondary-bg);
}

/* Alerts */
.low-stock {
    color: var(--bs-danger);
}

.medium-stock {
    color: var(--bs-warning);
}

/* Forms */
.form-control:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.2rem rgba(var(--bs-primary-rgb), 0.25);
}

/* Dark mode specific styles */
[data-bs-theme="dark"] {
    /* NOTE: --bs-body-bg / --bs-body-color / --bs-primary are now
       owned by /css/theme.css so they pick up the configurable brand.
       Leave only the secondary background here. */
    --bs-secondary-bg: #343a40;
}

[data-bs-theme="dark"] .card {
    background-color: #2c3034;
    border-color: #373b3e;
}

[data-bs-theme="dark"] .modal-content {
    background-color: #2c3034;
    border-color: #373b3e;
}

[data-bs-theme="dark"] .dropdown-menu {
    background-color: #2c3034;
    border-color: #373b3e;
}

[data-bs-theme="dark"] .dropdown-item:hover {
    background-color: #373b3e;
}

/* Loading state for cards */
.card.loading {
    position: relative;
}

.card.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(var(--bs-dark-rgb), 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.card.loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    border: 3px solid var(--bs-secondary);
    border-top: 3px solid var(--bs-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 1001;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Chart container heights */
#sales-chart, #payment-methods-chart {
    height: 300px !important;
}

/* Processing button states */
.btn.processing {
    position: relative;
    pointer-events: none;
    color: transparent !important;
}

.btn.processing::after {
    content: '';
    position: absolute;
    width: 1em;
    height: 1em;
    top: 50%;
    left: 50%;
    margin-left: -0.5em;
    margin-top: -0.5em;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.6s linear infinite;
}

.btn.processing.btn-danger::after {
    border-color: rgba(255, 255, 255, 0.2);
    border-top-color: white;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Disable pointer events during processing */
.processing-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.1);
    z-index: 9999;
    display: none;
}

/* -------------------------------------------------------------------- *
 * Global AJAX loader (see public/js/app-loader.js)
 * -------------------------------------------------------------------- */
.app-loader {
    position: fixed;
    inset: 0;
    z-index: 10500;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 150ms ease-out, visibility 150ms ease-out;
    pointer-events: none;
}

.app-loader--visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.app-loader__panel {
    background: var(--bs-body-bg, #fff);
    color: var(--bs-body-color, #111);
    padding: 1.25rem 1.75rem;
    border-radius: 0.75rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-width: 180px;
    transform: scale(0.96);
    transition: transform 150ms ease-out;
}

.app-loader--visible .app-loader__panel {
    transform: scale(1);
}

.app-loader__spinner {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 3px solid rgba(var(--brand-primary-rgb, 37, 99, 235), 0.25);
    border-top-color: var(--brand-primary, #2563EB);
    animation: app-loader-spin 0.7s linear infinite;
    flex-shrink: 0;
}

.app-loader__label {
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1;
}

@keyframes app-loader-spin {
    to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .app-loader,
    .app-loader__panel {
        transition: none;
    }
    .app-loader__spinner {
        animation-duration: 1.5s;
    }
}

[data-bs-theme="dark"] .app-loader {
    background: rgba(0, 0, 0, 0.55);
}

/* Add Select2 custom styles */
.select2-container--bootstrap-5 .select2-selection {
    min-height: 38px;
}

.select2-container--bootstrap-5 .select2-selection--single {
    padding-top: 4px;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__arrow {
    top: 4px;
}

/* Ensure dropdown is above modals */
.select2-dropdown {
    z-index: 1056;
}

/*
 * Select2 in dark mode.
 *
 * Neither select2.css nor select2-bootstrap-5-theme knows about Bootstrap
 * 5.3's [data-bs-theme] switch: both compile fixed colours, so in dark mode
 * the closed control, the dropdown and the search box all stay white while
 * every other input on the page turns dark. This maps them onto the theme
 * variables the form controls already use, so the pickers in the POS, in
 * Leagues and on the products list follow the theme like everything else.
 *
 * The selectors below deliberately repeat the theme's own long chains
 * (`.select2-container--bootstrap-5 .select2-dropdown .select2-results__options
 * .select2-results__option.select2-results__option--highlighted`) rather than
 * the short class on its own. The theme's rules are that deep, so a shorter
 * selector loses on specificity and the row silently stays light grey - which
 * is exactly what a first attempt at this did.
 *
 * Note the theme's vocabulary: `--highlighted` is the row under the cursor or
 * the arrow keys, `--selected` is the one already chosen. They are not what
 * their names suggest at a glance.
 *
 * Scoped to the dark theme on purpose: light mode already looks right, and
 * restyling it would change three screens nobody asked about. The dropdown is
 * appended to <body>, still inside the themed <html>, so these descendant
 * selectors reach it.
 */
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection {
    background-color: var(--bs-body-bg);
    border-color: var(--bs-border-color);
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__rendered {
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__placeholder {
    color: var(--bs-secondary-color);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__arrow b,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__clear {
    color: var(--bs-secondary-color);
    border-top-color: var(--bs-secondary-color);
}

/* A disabled picker should read as disabled, not as a differently-broken one. */
[data-bs-theme="dark"] .select2-container--bootstrap-5.select2-container--disabled .select2-selection,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection[aria-disabled="true"] {
    background-color: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
}

/* Dropdown panel. The border is left alone: the theme paints it in the focus
   blue while the dropdown is open, which is a cue worth keeping. */
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown {
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown .select2-search .select2-search__field {
    background-color: var(--bs-body-bg);
    border-color: var(--bs-border-color);
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option {
    color: var(--bs-body-color);
}

/* Under the cursor or the arrow keys. */
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option.select2-results__option--highlighted {
    background-color: var(--bs-secondary-bg);
    color: var(--bs-body-color);
}

/*
 * Already chosen.
 *
 * The `:not(--highlighted)` is load-bearing, and mirrors the theme's own
 * rule. Select2 4.1 sets aria-selected="true" on the row under the keyboard
 * cursor as well as on the chosen one, so without it the first row of every
 * freshly opened dropdown paints itself blue as though it were selected.
 */
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option.select2-results__option--selected,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option[aria-selected="true"]:not(.select2-results__option--highlighted) {
    background-color: var(--bs-primary);
    color: #fff;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option.select2-results__option--disabled,
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown .select2-results__options .select2-results__option.select2-results__message {
    color: var(--bs-secondary-color);
}

/* Dark mode toggle button */
#darkModeToggle {
    padding: 0.5rem;
    font-size: 1.25rem;
    color: var(--bs-navbar-color);
    transition: color 0.3s ease;
}

#darkModeToggle:hover {
    color: var(--bs-navbar-active-color);
}

.hr-with-label {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 20px 0;
}

.hr-with-label::before,
.hr-with-label::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #000;
}

.hr-with-label span {
    padding: 0 10px;
    font-weight: bold;
    color: #333;
}

#products-table tr td:nth-child(8), 
#products-table tr th:nth-child(8) {
    visibility: hidden;
    position: absolute;
}

#backToTop {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: rgba(var(--bs-dark-rgb), 0.7)!important;
    color: white;
    border: none;
    border-radius: 50%;
    padding: 20px;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.3);
  }
  
  #backToTop:hover {
    background-color: rgba(var(--bs-dark-rgb),1)!important;
  }

/*
 * Masked field that is NOT <input type="password">.
 *
 * Kept as a fallback for the sale PIN. The PIN fields are password-type with
 * autocomplete="one-time-code", which is what keeps them out of the
 * browser's password manager. If some future Chrome still offers to save a
 * PIN anyway, the guaranteed fix is to stop having a password field at all:
 * swap that input to type="text" and add this class, and no heuristic has
 * anything to latch onto.
 *
 * -webkit-text-security covers Chrome, Edge, Safari and Opera; Firefox does
 * not support it and would show the digits, so this is a fallback rather
 * than the default.
 */
.pin-masked {
    -webkit-text-security: disc;
    text-security: disc; /* not in any shipping engine yet; harmless, future-proof */
}