/* Dark appearance for the panel and the PWA, switched on by data-theme="dark" on <html>
   (_ThemeHead). Loaded after every other stylesheet. Bootstrap here is 5.2, which has no dark
   theme of its own, so its colour variables and the few hard-coded light surfaces are overridden. */

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

    --app-brand-soft: #0E3346;
    --app-bg: #0F171D;
    --app-surface: #16212A;
    --app-surface-raised: #1C2933;
    --app-border: #2B3B47;
    --app-text: #E6EDF2;
    --app-text-muted: #9AABB7;
    --app-text-subtle: #75868F;
    --app-success: #3CC47A;
    --app-warning: #F0A33A;
    --app-danger: #F0605A;
    --app-danger-pressed: #D9473F;
    --app-danger-soft: #3A1916;

    --bs-body-color: #E6EDF2;
    --bs-body-color-rgb: 230, 237, 242;
    --bs-body-bg: #0F171D;
    --bs-body-bg-rgb: 15, 23, 29;
    --bs-border-color: #2B3B47;
    --bs-border-color-translucent: rgba(255, 255, 255, 0.12);
    --bs-light: #1C2933;
    --bs-light-rgb: 28, 41, 51;
    --bs-link-color: #4DBFF0;
    --bs-link-hover-color: #80D2F5;
    --bs-highlight-bg: #4A3B0B;
}

html[data-theme="dark"] body {
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
}

/* Bootstrap components */
html[data-theme="dark"] .card {
    --bs-card-bg: var(--app-surface);
    --bs-card-cap-bg: rgba(255, 255, 255, 0.03);
}

html[data-theme="dark"] .modal {
    --bs-modal-bg: var(--app-surface);
}

html[data-theme="dark"] .dropdown-menu {
    --bs-dropdown-color: var(--app-text);
    --bs-dropdown-bg: var(--app-surface-raised);
    --bs-dropdown-link-color: var(--app-text);
    --bs-dropdown-link-hover-color: var(--app-text);
    --bs-dropdown-link-hover-bg: var(--app-border);
    --bs-dropdown-header-color: var(--app-text-muted);
}

html[data-theme="dark"] .list-group {
    --bs-list-group-color: var(--app-text);
    --bs-list-group-bg: var(--app-surface);
    --bs-list-group-border-color: var(--app-border);
    --bs-list-group-action-color: var(--app-text);
    --bs-list-group-action-hover-color: var(--app-text);
    --bs-list-group-action-hover-bg: var(--app-surface-raised);
    --bs-list-group-action-active-color: var(--app-text);
    --bs-list-group-action-active-bg: var(--app-border);
    --bs-list-group-disabled-color: var(--app-text-subtle);
    --bs-list-group-disabled-bg: var(--app-surface);
}

html[data-theme="dark"] .accordion {
    --bs-accordion-color: var(--app-text);
    --bs-accordion-bg: var(--app-surface);
    --bs-accordion-btn-color: var(--app-text);
    --bs-accordion-active-color: var(--app-text);
    --bs-accordion-active-bg: var(--app-brand-soft);
}

html[data-theme="dark"] .nav-tabs {
    --bs-nav-tabs-border-color: var(--app-border);
    --bs-nav-tabs-link-hover-border-color: var(--app-border) var(--app-border) var(--app-border);
    --bs-nav-tabs-link-active-color: var(--app-text);
    --bs-nav-tabs-link-active-bg: var(--app-surface);
    --bs-nav-tabs-link-active-border-color: var(--app-border) var(--app-border) var(--app-surface);
}

html[data-theme="dark"] .pagination,
html[data-theme="dark"] .datatable-pagination ul {
    --bs-pagination-bg: var(--app-surface);
    --bs-pagination-border-color: var(--app-border);
    --bs-pagination-hover-bg: var(--app-surface-raised);
    --bs-pagination-hover-border-color: var(--app-border);
    --bs-pagination-focus-bg: var(--app-surface-raised);
    --bs-pagination-disabled-color: var(--app-text-subtle);
    --bs-pagination-disabled-bg: var(--app-surface);
    --bs-pagination-disabled-border-color: var(--app-border);
}

html[data-theme="dark"] .datatable-pagination a:hover {
    background-color: var(--app-surface-raised);
}

html[data-theme="dark"] .toast {
    --bs-toast-bg: rgba(28, 41, 51, 0.95);
    --bs-toast-header-color: var(--app-text-muted);
    --bs-toast-header-bg: rgba(28, 41, 51, 0.95);
    --bs-toast-header-border-color: var(--app-border);
}

html[data-theme="dark"] .popover {
    --bs-popover-bg: var(--app-surface-raised);
    --bs-popover-header-bg: var(--app-surface);
    --bs-popover-body-color: var(--app-text);
}

html[data-theme="dark"] .offcanvas {
    --bs-offcanvas-bg: var(--app-surface);
}

html[data-theme="dark"] .table,
html[data-theme="dark"] .datatable-table {
    --bs-table-striped-bg: rgba(255, 255, 255, 0.035);
    --bs-table-active-bg: rgba(255, 255, 255, 0.08);
    --bs-table-hover-bg: rgba(255, 255, 255, 0.06);
}

html[data-theme="dark"] .table-light {
    --bs-table-color: var(--app-text);
    --bs-table-bg: var(--app-surface-raised);
    --bs-table-border-color: var(--app-border);
    --bs-table-striped-bg: var(--app-surface-raised);
    --bs-table-striped-color: var(--app-text);
    --bs-table-active-bg: var(--app-border);
    --bs-table-active-color: var(--app-text);
    --bs-table-hover-bg: var(--app-border);
    --bs-table-hover-color: var(--app-text);
}

html[data-theme="dark"] .alert-light {
    --bs-alert-color: var(--app-text);
    --bs-alert-bg: var(--app-surface-raised);
    --bs-alert-border-color: var(--app-border);
}

/* Forms */
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .datatable-input,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] .datatable-selector,
html[data-theme="dark"] .input-group-text,
html[data-theme="dark"] #addressPAC input {
    color: var(--app-text);
    background-color: var(--app-surface-raised);
    border-color: var(--app-border);
}

html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
    color: var(--app-text);
    background-color: var(--app-surface-raised);
}

html[data-theme="dark"] .form-control:disabled,
html[data-theme="dark"] .form-control[readonly],
html[data-theme="dark"] .form-select:disabled {
    background-color: var(--app-surface);
    color: var(--app-text-muted);
}

html[data-theme="dark"] .form-control::placeholder {
    color: var(--app-text-subtle);
}

html[data-theme="dark"] .form-select,
html[data-theme="dark"] .datatable-selector {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23c3ced6' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

html[data-theme="dark"] .form-check-input:not(:checked) {
    background-color: var(--app-surface-raised);
    border-color: #4A5D6A;
}

html[data-theme="dark"] .form-control::file-selector-button {
    color: var(--app-text);
    background-color: var(--app-border);
}

html[data-theme="dark"] gmp-place-autocomplete::part(input) {
    color: var(--app-text);
    background-color: var(--app-surface-raised);
    border-color: var(--app-border);
}

html[data-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

/* Utilities that Bootstrap 5.2 hard-codes */
html[data-theme="dark"] .bg-white {
    background-color: var(--app-surface) !important;
}

html[data-theme="dark"] .text-muted {
    color: var(--app-text-muted) !important;
}

html[data-theme="dark"] .text-bg-light,
html[data-theme="dark"] .bg-light.text-dark {
    color: var(--app-text) !important;
}

/* App components with their own light colours */
html[data-theme="dark"] .app-btn-secondary:hover,
html[data-theme="dark"] .app-btn-secondary:active {
    background-color: #134560;
    border-color: #134560;
}

html[data-theme="dark"] .catalog-search-icon {
    color: var(--app-text-muted);
}

html[data-theme="dark"] .profile-menu-whatsapp {
    color: #3CC47A;
    background: #12301F;
}

html[data-theme="dark"] body:not(.app-shell) .profile-page .app-card {
    background-color: var(--app-surface);
    border-color: var(--app-border);
}

html[data-theme="dark"] body:not(.app-shell) .seller-order-section-title,
html[data-theme="dark"] body:not(.app-shell) .seller-order-stat-count {
    color: var(--app-text);
}

html[data-theme="dark"] body:not(.app-shell) .seller-order-stat {
    background: var(--app-surface);
    border-color: var(--app-border);
}

html[data-theme="dark"] body:not(.app-shell) .seller-order-stat-label {
    color: var(--app-text-muted);
}

/* StoreOrder/IncomingOrders */
html[data-theme="dark"] .store-orders-page .orders-card {
    border-color: var(--app-border);
}

html[data-theme="dark"] .store-orders-page .orders-card > .card-header,
html[data-theme="dark"] .store-orders-page .orders-tab {
    background: var(--app-surface);
    border-color: var(--app-border);
}

html[data-theme="dark"] .store-orders-page .orders-title-icon,
html[data-theme="dark"] .store-orders-page .order-avatar {
    background: var(--app-brand-soft);
    color: #8FD3F2;
}

html[data-theme="dark"] .store-orders-page .orders-count,
html[data-theme="dark"] .store-orders-page .orders-tab,
html[data-theme="dark"] .store-orders-page .orders-table tbody td {
    color: var(--app-text-muted);
}

html[data-theme="dark"] .store-orders-page .orders-count,
html[data-theme="dark"] .store-orders-page .orders-tab:hover,
html[data-theme="dark"] .store-orders-page .orders-empty-icon {
    background: var(--app-surface-raised);
}

html[data-theme="dark"] .store-orders-page .orders-tab:hover,
html[data-theme="dark"] .store-orders-page .order-no {
    color: var(--app-text);
}

html[data-theme="dark"] .store-orders-page .orders-tab.active {
    background: var(--app-brand);
    border-color: var(--app-brand);
    color: #fff;
}

html[data-theme="dark"] .store-orders-page .orders-table thead th,
html[data-theme="dark"] .store-orders-page .orders-table tbody td {
    border-bottom-color: var(--app-border);
}

html[data-theme="dark"] .store-orders-page .orders-table tbody tr:hover td {
    background: var(--app-surface-raised);
}

/* Onboarding */
html[data-theme="dark"] .onboarding-overlay {
    background: var(--app-bg);
}

html[data-theme="dark"] .onboarding-header,
html[data-theme="dark"] .onboarding-card {
    background: var(--app-surface);
}

/* Appearance picker on Profilim */
.theme-picker {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--app-space-sm);
}
