/* CSS Variables for Theming */
:root {
  /* Light theme (default) */
  --theme-bg: #ffffff;
  --theme-surface: #f8f9fa;
  --theme-text: #212529;
  --theme-text-muted: #6c757d;
  --theme-border: #dee2e6;
  --theme-link: #0d6efd;
  --theme-link-hover: #0a58ca;
  --theme-card-bg: #ffffff;
  --theme-card-border: #dee2e6;
  --theme-input-bg: #ffffff;
  --theme-input-border: #ced4da;
  --theme-input-focus-border: #86b7fe;
  --theme-navbar-bg: #ffffff;
  --theme-navbar-text: #212529;
  --theme-footer-bg: #ffffff;
  --theme-footer-text: #6c757d;
  --theme-shadow: rgba(0, 0, 0, 0.1);
}

/* Dark theme */
html[data-theme="dark"],
html.theme-dark {
  --theme-bg: #1a1a1a;
  --theme-surface: #2d2d2d;
  --theme-text: #e9ecef;
  --theme-text-muted: #adb5bd;
  --theme-border: #495057;
  --theme-link: #6ea8fe;
  --theme-link-hover: #86b7fe;
  --theme-card-bg: #2d2d2d;
  --theme-card-border: #495057;
  --theme-input-bg: #2d2d2d;
  --theme-input-border: #495057;
  --theme-input-focus-border: #6ea8fe;
  --theme-navbar-bg: #212529;
  --theme-navbar-text: #e9ecef;
  --theme-footer-bg: #212529;
  --theme-footer-text: #adb5bd;
  --theme-shadow: rgba(0, 0, 0, 0.3);
}

/* True Dark (OLED) theme */
html[data-theme="true-dark"],
html.theme-true-dark {
  --theme-bg: #000000;
  --theme-surface: #0a0a0a;
  --theme-text: #f8f9fa;
  --theme-text-muted: #ced4da;
  --theme-border: #1a1a1a;
  --theme-link: #6ea8fe;
  --theme-link-hover: #86b7fe;
  --theme-card-bg: #0a0a0a;
  --theme-card-border: #1a1a1a;
  --theme-input-bg: #0a0a0a;
  --theme-input-border: #1a1a1a;
  --theme-input-focus-border: #6ea8fe;
  --theme-navbar-bg: #000000;
  --theme-navbar-text: #f8f9fa;
  --theme-footer-bg: #000000;
  --theme-footer-text: #ced4da;
  --theme-shadow: rgba(0, 0, 0, 0.5);
}

html {
  font-size: 14px;
  background-color: var(--theme-bg);
  color: var(--theme-text);
  transition: background-color 0.2s ease, color 0.2s ease;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem var(--theme-bg), 0 0 0 0.25rem var(--theme-input-focus-border);
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
  background-color: var(--theme-bg);
  color: var(--theme-text);
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Navbar theming */
.navbar {
  background-color: var(--theme-navbar-bg) !important;
  border-bottom-color: var(--theme-border) !important;
  min-height: auto !important;
}

.navbar-brand {
  color: var(--theme-navbar-text) !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

.nav-link {
  color: var(--theme-navbar-text) !important;
}

.nav-link:hover {
  color: var(--theme-link-hover) !important;
}

/* Footer theming */
.footer {
  background-color: var(--theme-footer-bg) !important;
  border-top-color: var(--theme-border) !important;
  color: var(--theme-footer-text) !important;
}

.footer a {
  color: var(--theme-link) !important;
}

.footer a:hover {
  color: var(--theme-link-hover) !important;
}

/* Card theming */
.card {
  background-color: var(--theme-card-bg) !important;
  border-color: var(--theme-card-border) !important;
  color: var(--theme-text) !important;
}

.card-header {
  background-color: var(--theme-surface) !important;
  border-bottom-color: var(--theme-border) !important;
  color: var(--theme-text) !important;
}

/* Form controls */
.form-control,
.form-select {
  background-color: var(--theme-input-bg) !important;
  border-color: var(--theme-input-border) !important;
  color: var(--theme-text) !important;
}

.form-control:focus,
.form-select:focus {
  background-color: var(--theme-input-bg) !important;
  border-color: var(--theme-input-focus-border) !important;
  color: var(--theme-text) !important;
}

.form-control::placeholder {
  color: var(--theme-text-muted) !important;
}

/* Text muted */
.text-muted {
  color: var(--theme-text-muted) !important;
}

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

a:hover {
  color: var(--theme-link-hover);
}

/* Breadcrumbs */
.breadcrumb {
  --bs-breadcrumb-divider-color: var(--theme-text-muted);
}

.breadcrumb-item,
.breadcrumb-item a {
  color: var(--theme-text-muted);
}

.breadcrumb-item a:hover {
  color: var(--theme-link-hover);
}

.breadcrumb-item.active {
  color: var(--theme-text);
}

.breadcrumb-item + .breadcrumb-item::before {
  color: var(--theme-text-muted);
}

/* FAQ / Accordions */
.accordion-item {
  background-color: var(--theme-card-bg);
  border-color: var(--theme-border);
}

.accordion-button {
  background-color: var(--theme-card-bg);
  color: var(--theme-text);
}

.accordion-button:not(.collapsed) {
  background-color: var(--theme-surface);
  color: var(--theme-text);
  box-shadow: none;
}

.accordion-button::after {
  filter: invert(0);
}

html[data-theme="dark"] .accordion-button::after,
html[data-theme="true-dark"] .accordion-button::after,
html.theme-dark .accordion-button::after,
html.theme-true-dark .accordion-button::after {
  filter: invert(1);
}

.accordion-body {
  background-color: var(--theme-card-bg);
  color: var(--theme-text);
}

/* Tables (BulkReview spreadsheet, etc.) */
.table {
  --bs-table-color: var(--theme-text);
  --bs-table-bg: var(--theme-card-bg);
  --bs-table-border-color: var(--theme-border);
  --bs-table-striped-color: var(--theme-text);
  --bs-table-striped-bg: rgba(0, 0, 0, 0.03);
  --bs-table-hover-color: var(--theme-text);
  --bs-table-hover-bg: rgba(0, 0, 0, 0.06);
}

html[data-theme="dark"] .table,
html[data-theme="true-dark"] .table,
html.theme-dark .table,
html.theme-true-dark .table {
  --bs-table-striped-bg: rgba(255, 255, 255, 0.04);
  --bs-table-hover-bg: rgba(255, 255, 255, 0.07);
}

.table thead th {
  background-color: var(--theme-surface);
  color: var(--theme-text);
  border-bottom-color: var(--theme-border);
}

/* Table scroll indicators */
.table-scrollable {
  position: relative;
}

.table-scroll-indicator-left,
.table-scroll-indicator-right {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.875rem;
  z-index: 10;
  pointer-events: none;
  white-space: nowrap;
}

.table-scroll-indicator-left {
  left: 10px;
}

.table-scroll-indicator-right {
  right: 10px;
}

html[data-theme="dark"] .table-scroll-indicator-left,
html[data-theme="dark"] .table-scroll-indicator-right,
html[data-theme="true-dark"] .table-scroll-indicator-left,
html[data-theme="true-dark"] .table-scroll-indicator-right,
html.theme-dark .table-scroll-indicator-left,
html.theme-dark .table-scroll-indicator-right,
html.theme-true-dark .table-scroll-indicator-left,
html.theme-true-dark .table-scroll-indicator-right {
  background: rgba(255, 255, 255, 0.8);
  color: #000;
}

/* Responsive table improvements for mobile/tablet */
@media (max-width: 991.98px) {
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    overflow-y: visible;
  }

  /* Larger tap targets for action buttons on mobile */
  .table .btn-sm {
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem;
  }

  /* Better spacing for editable cells on mobile */
  .table td[contenteditable="true"] {
    min-height: 44px;
    padding: 0.75rem 0.5rem;
  }

  /* Make status badges more readable on small screens */
  .table .badge {
    font-size: 0.7rem;
    padding: 0.35rem 0.5rem;
  }
}

.table td,
.table th {
  border-color: var(--theme-border);
}

/* BulkReview editable cells: keep a clear focus state in dark themes */
#addressesTable td[contenteditable="true"]:focus {
  outline: 2px solid var(--theme-input-focus-border);
  outline-offset: -2px;
}

/* Dark/True Dark: make bootstrap contextual rows more readable */
html[data-theme="dark"] #addressesTable .table-warning,
html[data-theme="true-dark"] #addressesTable .table-warning,
html.theme-dark #addressesTable .table-warning,
html.theme-true-dark #addressesTable .table-warning {
  --bs-table-bg: rgba(255, 193, 7, 0.12);
  --bs-table-color: var(--theme-text);
}

html[data-theme="dark"] #addressesTable .table-danger,
html[data-theme="true-dark"] #addressesTable .table-danger,
html.theme-dark #addressesTable .table-danger,
html.theme-true-dark #addressesTable .table-danger {
  --bs-table-bg: rgba(220, 53, 69, 0.16);
  --bs-table-color: var(--theme-text);
}

/* Borders */
.border,
.border-top,
.border-bottom,
.border-end {
  border-color: var(--theme-border) !important;
}

/* Theme switcher button styling */
.theme-switcher .theme-dropdown-toggle {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  white-space: nowrap;
}

.theme-switcher .dropdown-menu {
  background-color: var(--theme-card-bg);
  border-color: var(--theme-border);
}

.theme-switcher .dropdown-item {
  color: var(--theme-text);
}

.theme-switcher .dropdown-item:hover,
.theme-switcher .dropdown-item:focus {
  background-color: var(--theme-surface);
  color: var(--theme-text);
}

.theme-switcher .dropdown-item.active {
  background-color: var(--theme-link);
  color: #ffffff;
}

.theme-switcher .theme-icon {
  font-size: 0.875rem;
  margin-right: 0.25rem;
}

/* Prevent navigation links from wrapping - reduce font size if needed */
.navbar-nav {
  flex-wrap: nowrap !important;
  white-space: nowrap;
}

.navbar-nav .nav-link {
  white-space: nowrap;
  padding-left: 0.75rem !important;
  padding-right: 0.75rem !important;
}

/* Responsive font size reduction for navigation links */
@media (max-width: 1200px) {
  .navbar-nav .nav-link {
    font-size: 0.9rem;
    padding-left: 0.6rem !important;
    padding-right: 0.6rem !important;
  }
}

@media (max-width: 992px) {
  .navbar-nav .nav-link {
    font-size: 0.85rem;
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }
}

/* Responsive improvements for navbar and theme switcher */
@media (max-width: 991.98px) {
  /* Better spacing for navbar items on mobile/tablet */
  .navbar-nav .nav-item {
    margin-bottom: 0.25rem;
  }
  
  /* Allow wrapping in collapsed menu on mobile */
  .navbar-collapse .navbar-nav {
    flex-wrap: wrap !important;
  }
}

@media (max-width: 576px) {
  .theme-switcher .theme-dropdown-toggle {
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
  }

  /* Keep the theme icon visible on small screens */
  .theme-switcher .theme-icon {
    display: inline-block;
    margin-right: 0.25rem;
  }
  
  /* Reduce heading sizes on mobile */
  .display-4 {
    font-size: 2rem;
  }
  
  h1 {
    font-size: 1.75rem;
  }
  
  h2 {
    font-size: 1.5rem;
  }
  
  /* Better button sizing on mobile */
  .btn-lg {
    padding: 0.75rem 1rem;
    font-size: 1rem;
  }
}

/* Widen content on mobile by reducing padding */
@media (max-width: 767.98px) {
  /* Reduce main container padding */
  main.pb-3 {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }
  
  /* Reduce row gutters on mobile */
  .row {
    --bs-gutter-x: 0.5rem !important;
    margin-left: -0.25rem !important;
    margin-right: -0.25rem !important;
  }
  
  .row > * {
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }
  
  /* Reduce form group spacing */
  .mb-3, .mb-4 {
    margin-bottom: 0.75rem !important;
  }
  
  /* Reduce card margins */
  .card {
    margin-bottom: 0.75rem !important;
  }
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--theme-text-muted);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}

/* Modal styling for dark and true dark modes */
.modal-content {
  background-color: var(--theme-card-bg) !important;
  border-color: var(--theme-border) !important;
  color: var(--theme-text) !important;
}

.modal-header {
  background-color: var(--theme-surface) !important;
  border-bottom-color: var(--theme-border) !important;
  color: var(--theme-text) !important;
}

.modal-title {
  color: var(--theme-text) !important;
}

.modal-body {
  background-color: var(--theme-card-bg) !important;
  color: var(--theme-text) !important;
}

.modal-footer {
  background-color: var(--theme-surface) !important;
  border-top-color: var(--theme-border) !important;
}

/* Modal close button (btn-close) styling for dark modes */
.btn-close {
  filter: invert(0);
}

html[data-theme="dark"] .btn-close,
html[data-theme="true-dark"] .btn-close,
html.theme-dark .btn-close,
html.theme-true-dark .btn-close {
  filter: invert(1);
}

/* Navbar toggler (hamburger menu) styling for dark modes */
.navbar-toggler {
  border-color: var(--theme-border) !important;
}

.navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%2833, 37, 41, 0.75%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

html[data-theme="dark"] .navbar-toggler-icon,
html[data-theme="true-dark"] .navbar-toggler-icon,
html.theme-dark .navbar-toggler-icon,
html.theme-true-dark .navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28233, 236, 239, 0.75%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

/* Wider container widths for better content utilization - only for main content, not nav/footer */
/* Mobile: Maximum width with minimal padding */
@media (max-width: 575.98px) {
  main .container-sm, 
  main .container,
  main .container-fluid {
    max-width: 100% !important;
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }
}

/* Tablet: Maximum width with minimal padding */
@media (min-width: 576px) and (max-width: 991.98px) {
  main .container-sm, 
  main .container-md, 
  main .container,
  main .container-fluid {
    max-width: 100% !important;
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }
}

@media (min-width: 576px) {
  main .container-sm, 
  main .container {
    max-width: 800px;
  }
}

@media (min-width: 768px) {
  main .container-md, 
  main .container-sm, 
  main .container {
    max-width: 1000px;
  }
}

@media (min-width: 992px) {
  .container-lg, .container-md, .container-sm, .container {
    max-width: 1200px;
  }
}

@media (min-width: 1200px) {
  .container-xl, .container-lg, .container-md, .container-sm, .container {
    max-width: 1400px;
  }
}

@media (min-width: 1400px) {
  .container-xxl, .container-xl, .container-lg, .container-md, .container-sm, .container {
    max-width: 1600px;
  }
}