/* Shared appearance. Every light override is opt-in; existing dark rules remain intact. */
/* The icon represents the mode the button will activate. */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; min-width: 40px; height: 40px; min-height: 40px; padding: 0;
  border: 1px solid rgba(201,169,97,.48); border-radius: 50%;
  background: #21324a; color: #e2c787; cursor: pointer;
  flex: 0 0 40px; position: relative; z-index: 2; vertical-align: middle;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.theme-toggle:hover { border-color: #c9a961; box-shadow: 0 0 0 3px rgba(132,97,31,.12); transform: translateY(-1px); }
.theme-toggle:focus-visible { outline: 3px solid #2865a8; outline-offset: 3px; }
.theme-toggle__icon { display: block; flex-shrink: 0; pointer-events: none; width: 19px; height: 19px; }
.theme-toggle__moon { display: none; }
.theme-toggle[aria-checked="true"] { background: #f4f7fb; border-color: #a99a75; color: #223a57; }
.theme-toggle[aria-checked="true"] .theme-toggle__moon { display: block; }
.theme-toggle[aria-checked="true"] .theme-toggle__sun { display: none; }
.theme-toggle__label { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.top-right-controls { position: fixed; top: 16px; right: 20px; z-index: 999; display: flex; align-items: center; gap: 10px; max-width: calc((100vw - 600px) / 2 - 20px); }
.top-right-controls .top-right-welcome-bar { position: static !important; min-width: 0; max-width: 100%; overflow: hidden; }
.top-right-controls .welcome-text { display: block; overflow: hidden; text-overflow: ellipsis; }
.mobile-nav-theme-setting { display: none; }
.theme-standalone-control { display: flex; justify-content: flex-end; padding: 12px 20px; }
/* Keep global controls beside the compact notch on tablets and small laptops. */
@media (min-width: 769px) and (max-width: 1200px) {
  .fixed-header { width: clamp(260px, calc(100vw - 520px), 340px) !important; max-width: 340px !important; padding: 0 18px !important; }
  .fixed-header .header-logo span { font-size: 14px !important; letter-spacing: .8px !important; }
  .fixed-header .header-logo img { width: 32px !important; height: 32px !important; margin-right: 10px !important; }
  .fixed-header .header-clock, .fixed-header .analog-clock, .fixed-header .clock-face { width: 32px !important; height: 32px !important; }
  .top-right-controls { top: 8px; right: 16px; max-width: calc((100vw - clamp(260px, calc(100vw - 520px), 340px)) / 2 - 28px); }
  .top-right-controls .top-right-welcome-bar { padding: 8px 12px !important; }
  .top-right-controls .welcome-text { font-size: 11px !important; }
}
@media (max-width: 768px) {
  .top-right-controls { display: none; }
  .vertical-navbar.mobile-open .mobile-nav-theme-setting {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    flex-shrink: 0; min-height: 64px; margin-bottom: 8px; padding: 12px 18px;
    border-bottom: 1px solid rgba(201,169,97,.25);
  }
  .mobile-nav-theme-label { color: #dce6f4; font-size: 13px; font-weight: 600; }
  .mobile-nav-theme-setting .theme-toggle { width: 44px; min-width: 44px; height: 44px; min-height: 44px; flex-basis: 44px; }
  .mobile-nav-theme-setting .theme-toggle:focus-visible { outline-color: #d7b875; }
  .theme-toggle::after { content: ""; position: absolute; inset: -2px; border-radius: 50%; }
}
html[data-theme="light"] {
  color-scheme: light;
  --theme-bg: #f2f5f9; --theme-surface: #f8fafc; --theme-surface-alt: #f0f3f7;
  --theme-input: #fff; --theme-header: #e7edf5; --theme-control: #e9eff6;
  --theme-text: #172b46; --theme-muted: #40516a; --theme-border: #dbe3ed;
  --theme-panel: #eaf0f6; --theme-workspace: #fcfdff;
  --theme-nav-bg: #203a53; --theme-nav-hover: #304f72;
  --theme-primary: #284b6a; --theme-primary-hover: #203e59; --theme-gold: #c9a34d;
  --theme-accent: #85601f; --theme-success: #135c3f; --theme-danger: #9e1f2c;
  --theme-warning: #735014; --theme-info: #1d528f;
  --theme-shadow: 0 2px 5px rgba(23,43,70,.04), 0 10px 28px rgba(23,43,70,.07);
  --theme-focus: #2865a8; --theme-hover: #dce7f2;
  --theme-success-bg: #e6f4ed; --theme-danger-bg: #fff0f1;
  --theme-warning-bg: #fff0cc; --theme-info-bg: #eaf2ff;
  --theme-overlay: rgba(23,43,70,.45);
}
html[data-theme="light"] body {
  background: var(--theme-bg) !important; color: var(--theme-text) !important;
}
html[data-theme="light"] body::before,
html[data-theme="light"] body::after { background: none !important; }
html[data-theme="light"] .main-content { background: transparent !important; }
html[data-theme="light"] :is(.content-area, .container, .card, .form-container, .table-wrapper, .navbar) {
  background: var(--theme-surface) !important; color: var(--theme-text) !important;
  border-color: var(--theme-border) !important; box-shadow: var(--theme-shadow) !important;
}
html[data-theme="light"] .content-area { background: var(--theme-workspace) !important; }
html[data-theme="light"] .content-area::before,
html[data-theme="light"] .content-area::after { display: none !important; }
html[data-theme="light"] :is(.fixed-header, .mobile-bottom-tab-bar, .top-right-welcome-bar) {
  background: var(--theme-input) !important; color: var(--theme-text) !important;
  border-color: var(--theme-border) !important; box-shadow: var(--theme-shadow) !important;
}
html[data-theme="light"] :is(.vertical-navbar, .vertical-navbar.expanded, .vertical-navbar.mobile-open) {
  background: linear-gradient(165deg, #2d4a66 0%, var(--theme-nav-bg) 42%, #1c334a 100%) !important;
  color: #dce6f4 !important; border-color: #3e5871 !important;
  box-shadow: 6px 0 12px rgba(23,43,70,.14), 16px 0 36px rgba(23,43,70,.13), inset -1px 0 0 rgba(255,255,255,.10) !important;
}
html[data-theme="light"] .vertical-navbar::before {
  background: radial-gradient(ellipse at 15% 0%, rgba(229,207,155,.09), transparent 48%) !important;
}
html[data-theme="light"] .vertical-navbar :is(.nav-link, .nav-group-toggle, .nav-link i, .nav-group-toggle i, .nav-link span, .nav-group-toggle span) {
  color: #cedced !important; text-shadow: none !important;
}
/* Match the dark navigation's depth with softer highlights for a pale canvas. */
html[data-theme="light"] .vertical-navbar :is(.nav-link:hover, .nav-group-toggle:hover) {
  background: linear-gradient(135deg, rgba(255,255,255,.12), rgba(255,255,255,.04)) !important;
  color: #fff !important; border-left-color: #d7b875 !important;
  box-shadow: 0 3px 8px rgba(9,25,42,.14), inset 0 1px 0 rgba(255,255,255,.10) !important;
}
html[data-theme="light"] .vertical-navbar .nav-group.open > .nav-group-toggle {
  background: linear-gradient(135deg, #365570, #2b4863) !important;
  color: #fff !important; border-left-color: #d7b875 !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 2px 6px rgba(9,25,42,.12) !important;
}
html[data-theme="light"] .vertical-navbar .nav-link.active {
  background: linear-gradient(110deg, rgba(201,163,77,.30), rgba(201,163,77,.10)) !important;
  color: #fff !important; border-left-color: var(--theme-gold) !important;
  box-shadow: 0 4px 10px rgba(9,25,42,.22), inset 0 1px 0 rgba(255,235,190,.19), inset 0 -1px 0 rgba(9,25,42,.12) !important;
}
html[data-theme="light"] .vertical-navbar :is(.nav-link.active, .nav-link:hover, .nav-group.open > .nav-group-toggle) :is(i, span) { color: #fff !important; }
html[data-theme="light"] .vertical-navbar :is(.nav-link, .nav-group-toggle):focus-visible {
  outline: 2px solid #e6c982; outline-offset: -3px;
}
html[data-theme="light"] .vertical-navbar .nav-logout,
html[data-theme="light"] .vertical-navbar .nav-logout :is(i, span) { color: #ffc5cc !important; }
html[data-theme="light"] .navbar-logo-badge {
  background: linear-gradient(145deg, #385b79, #28445f) !important;
  border-color: rgba(218,197,143,.24) !important;
  box-shadow: 0 3px 10px rgba(9,25,42,.18), inset 0 1px 0 rgba(255,255,255,.10) !important;
}
html[data-theme="light"] .mobile-menu-toggle { background: var(--theme-surface-alt) !important; border-color: var(--theme-border) !important; }
html[data-theme="light"] :is(.bottom-tab, .bottom-tab span, .bottom-tab i, .welcome-text) { color: var(--theme-text) !important; -webkit-text-fill-color: currentColor !important; text-shadow: none !important; }
html[data-theme="light"] .bottom-tab.active { background: var(--theme-hover) !important; }
html[data-theme="light"] .hamburger-bar { background: var(--theme-text) !important; }
html[data-theme="light"] :is(.mobile-nav-backdrop, .modal-overlay) { background-color: var(--theme-overlay); }
html[data-theme="light"] :where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="submit"]):not([type="button"]), select, textarea),
html[data-theme="light"] .content-area .custom-select {
  background-color: var(--theme-input) !important; color: var(--theme-text) !important;
  border-color: var(--theme-border) !important; color-scheme: light !important;
}
html[data-theme="light"] :is(input, textarea)::placeholder { color: var(--theme-muted) !important; opacity: 1; }
html[data-theme="light"] :is(input, select, textarea):focus { border-color: var(--theme-focus) !important; box-shadow: 0 0 0 3px rgba(40,101,168,.13) !important; }
html[data-theme="light"] :is(input, select, textarea):disabled { background-color: var(--theme-surface-alt) !important; }
html[data-theme="light"] :is(input[type="checkbox"], input[type="radio"], input[type="range"]) { accent-color: var(--theme-info); }
html[data-theme="light"] :is(select option, select optgroup) { background: var(--theme-input); color: var(--theme-text); }
html[data-theme="light"] :is(.form-group label, .form-container label, .input-label) { color: var(--theme-text) !important; }
html[data-theme="light"] :is(table, td, th) { color: var(--theme-text) !important; }
html[data-theme="light"] :is(thead th, .content-area table thead th) {
  background: var(--theme-header) !important; color: var(--theme-text) !important; border-color: var(--theme-border) !important;
}
html[data-theme="light"] :is(tbody td, .content-area table tbody td) { border-color: var(--theme-border) !important; color: var(--theme-text) !important; }
html[data-theme="light"] :is(tbody tr, .content-area table tbody tr:nth-child(odd)) { background: var(--theme-surface) !important; }
html[data-theme="light"] :is(tbody tr:nth-child(even), .content-area table tbody tr:nth-child(even)) { background: var(--theme-panel) !important; }
html[data-theme="light"] :is(tbody tr:hover, .content-area table tbody tr:hover, table.min-w-full tbody tr:hover) { background: var(--theme-hover) !important; color: var(--theme-text) !important; }
html[data-theme="light"] :is(.select2-dropdown, .select2-selection, .select2-selection--single, .select2-selection--multiple, .select2-search__field, .select2-results__option) {
  background: var(--theme-input) !important; color: var(--theme-text) !important; border-color: var(--theme-border) !important;
}
html[data-theme="light"] :is(.select2-selection__rendered, .select2-selection__placeholder, .select2-selection__clear) { color: var(--theme-text) !important; }
html[data-theme="light"] :is(.select2-results__option--highlighted, .select2-results__option--selected, .select2-selection__choice) { background: var(--theme-hover) !important; color: var(--theme-text) !important; }
html[data-theme="light"] :is(.swal2-input, .swal2-textarea, .swal2-select) { background: var(--theme-input) !important; color: var(--theme-text) !important; border-color: var(--theme-border) !important; }
html[data-theme="light"] :is(.swal2-title, .swal2-html-container, .swal2-content, .swal2-footer, .swal2-close) { color: var(--theme-text) !important; }
html[data-theme="light"] .swal2-validation-message { background: var(--theme-danger-bg) !important; color: var(--theme-danger) !important; }
html[data-theme="light"] .swal2-styled.swal2-confirm { background: var(--theme-info) !important; color: #fff !important; }
html[data-theme="light"] .swal2-styled.swal2-cancel { background: #53657c !important; color: #fff !important; }
html[data-theme="light"] :is(.text-white, .text-gray-100, .text-gray-200, .text-gray-300) { color: var(--theme-text); }
html[data-theme="light"] :is(.text-gray-400, .text-gray-500, .text-muted) { color: var(--theme-muted); }
html[data-theme="light"] :is(.bg-gray-800, .bg-gray-900) { background: var(--theme-surface); }
html[data-theme="light"] :is(.bg-gray-700, .bg-gray-600) { background: var(--theme-surface-alt); }
html[data-theme="light"] :is(.leaflet-popup-content-wrapper, .leaflet-popup-tip, .leaflet-control-layers, .leaflet-bar a) {
  background: var(--theme-surface) !important; color: var(--theme-text) !important; border-color: var(--theme-border) !important;
}
html[data-theme="light"] :is(#ai-chat-panel, #ai-chat-header, #ai-chat-input-area, .ai-msg.assistant, .ai-typing) {
  background: var(--theme-input) !important; color: var(--theme-text) !important; border-color: var(--theme-border) !important;
}
html[data-theme="light"] :is(#ai-chat-header .ai-chat-title, #ai-chat-close) { color: var(--theme-text) !important; }
html[data-theme="light"] .ai-typing span { background: var(--theme-muted); }
html[data-theme="light"] .ai-msg.user { background: #245fa5; color: #fff; }
html[data-theme="light"] :focus-visible { outline-color: var(--theme-focus); }
html[data-theme="light"] ::selection { background: #cbdff8; color: #172b46; }
/* Flask-Admin keeps Bootstrap's vendor markup and form behavior. */
html[data-theme="light"] .navbar.navbar-dark,
html[data-theme="light"] :is(.dropdown-menu, .list-group-item, .modal-content, .popover) {
  background: var(--theme-surface) !important; color: var(--theme-text) !important; border-color: var(--theme-border) !important;
}
html[data-theme="light"] .navbar-dark :is(.navbar-brand, .navbar-nav .nav-link, .navbar-text),
html[data-theme="light"] :is(.dropdown-item, .modal-title, .close) { color: var(--theme-text) !important; }
html[data-theme="light"] :is(.dropdown-item:hover, .dropdown-item:focus, .dropdown-item.active, .nav-tabs .nav-link.active) {
  background: var(--theme-hover) !important; color: var(--theme-text) !important;
}
html[data-theme="light"] :is(.modal-header, .modal-footer, .card-header, .card-footer, .popover-header, .input-group-text) {
  background: var(--theme-surface-alt) !important; color: var(--theme-text) !important; border-color: var(--theme-border) !important;
}
html[data-theme="light"] .navbar-dark .navbar-toggler { border-color: var(--theme-muted); }
html[data-theme="light"] .navbar-dark .navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' viewBox='0 0 30 30'%3E%3Cpath stroke='%23172b46' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E");
}
html[data-theme="light"] .badge-info,
html[data-theme="light"] .btn-primary,
html[data-theme="light"] .btn-danger { color: #fff; }
html[data-theme="light"] .theme-admin-workspace a:not(.btn) { color: var(--theme-info); }
html[data-theme="light"] .theme-admin-workspace .btn-primary { background-color: var(--theme-info); color: #fff; }
html[data-theme="light"] .theme-admin-workspace .text-muted { color: var(--theme-muted) !important; }
@media (prefers-reduced-motion: reduce) {
  .theme-toggle { transition: none; }
}
@media print {
  .theme-toggle, .theme-standalone-control, .top-right-controls { display: none !important; }
  html[data-theme="light"] body { background: #fff !important; }
}

html[data-theme="light"] .swal2-popup { background: var(--theme-surface) !important; color: var(--theme-text) !important; border-color: var(--theme-border) !important; }

html[data-theme="light"] .theme-admin-workspace .text-danger { color: var(--theme-danger) !important; }
/* Public pages use the same section palette as authenticated pages. */
html[data-theme="light"] .public-header { background: var(--theme-surface-alt) !important; border-color: var(--theme-border) !important; }
html[data-theme="light"] .public-header .container { background: transparent !important; box-shadow: none !important; border: 0; }
html[data-theme="light"] .public-header .text-2xl { background: none !important; color: var(--theme-text) !important; -webkit-text-fill-color: currentColor !important; }
html[data-theme="light"] .public-header .text-xs { color: var(--theme-muted) !important; }
html[data-theme="light"] .public-header a[href="/login"] { background: var(--theme-control) !important; color: var(--theme-text) !important; border-color: var(--theme-border) !important; }

/* Raised global controls and an upward shadow on mobile navigation. */
html[data-theme="light"] .fixed-header {
  border-bottom-color: #dac58f !important;
  box-shadow: 0 2px 4px rgba(23,43,70,.06), 0 12px 30px rgba(23,43,70,.10), inset 0 1px 0 #fff !important;
}
html[data-theme="light"] .top-right-welcome-bar {
  box-shadow: 0 2px 4px rgba(23,43,70,.04), 0 6px 18px rgba(23,43,70,.08), inset 0 1px 0 #fff !important;
}
html[data-theme="light"] .mobile-bottom-tab-bar {
  box-shadow: 0 -2px 6px rgba(23,43,70,.05), 0 -10px 28px rgba(23,43,70,.10), inset 0 1px 0 #fff !important;
}
html[data-theme="light"] .bottom-tab.active {
  background: linear-gradient(180deg, #e2ebf5, #f0f4f9) !important;
  box-shadow: inset 0 2px 0 #c9a34d !important;
}

/* Restore the raised circular Home control without changing the other tabs. */
@media (max-width: 768px) {
  .mobile-bottom-tab-bar .bottom-tab-home {
    position: relative; bottom: 14px; align-self: center; justify-self: center;
    width: 62px; height: 62px; min-height: 62px; padding: 0; gap: 0;
    border-radius: 50%; overflow: hidden;
    background: linear-gradient(145deg, rgba(240,232,218,.97), rgba(235,226,210,.97));
    border: 2px solid rgba(201,169,97,.3);
    box-shadow: 0 4px 20px rgba(0,0,0,.3), inset 0 1px 2px rgba(245,238,225,.9);
  }
  .mobile-bottom-tab-bar .bottom-tab-home .bottom-tab-logo {
    width: 42px; height: 42px; object-fit: contain;
    filter: drop-shadow(0 0 10px rgba(201,169,97,.35));
  }
  .mobile-bottom-tab-bar .bottom-tab-home span { display: none; }
  .mobile-bottom-tab-bar .bottom-tab-home:is(:hover, :focus-visible, .active) {
    border-color: rgba(201,169,97,.5);
    box-shadow: 0 4px 24px rgba(0,0,0,.3), inset 0 1px 2px rgba(245,238,225,.9);
  }
  html[data-theme="light"] .mobile-bottom-tab-bar .bottom-tab-home {
    background: linear-gradient(145deg, #fff, #e9eff6) !important;
    border-color: #c2cfdc;
    box-shadow: 0 4px 18px rgba(23,43,70,.20), inset 0 1px 2px #fff !important;
  }
  html[data-theme="light"] .mobile-bottom-tab-bar .bottom-tab-home:is(:hover, :focus-visible, .active) { border-color: #c9a34d; }
}
@media (max-width: 480px) {
  .mobile-bottom-tab-bar .bottom-tab-home { width: 50px; height: 50px; min-height: 50px; bottom: 10px; }
  .mobile-bottom-tab-bar .bottom-tab-home .bottom-tab-logo { width: 34px; height: 34px; }
}

@media (max-width: 768px) {
  .mobile-bottom-tab-bar[data-nav-items="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
