/* Global theme refinements for second-pass UI polish */

:root {
  --portal-radius: 1rem;
  --portal-card-shadow: 0 10px 30px rgba(47, 43, 61, 0.08);
  --portal-card-shadow-hover: 0 14px 36px rgba(47, 43, 61, 0.12);
  --portal-border: rgba(47, 43, 61, 0.1);
}

body {
  background:
    radial-gradient(1200px 600px at 0% -10%, rgba(105, 108, 255, 0.12), transparent 50%),
    radial-gradient(900px 500px at 100% 0%, rgba(255, 76, 81, 0.08), transparent 55%);
}

html[data-bs-theme='dark'] {
  --portal-card-shadow: 0 14px 38px rgba(2, 6, 23, 0.42);
  --portal-card-shadow-hover: 0 18px 46px rgba(2, 6, 23, 0.5);
  --portal-border: rgba(148, 163, 184, 0.22);
}

html[data-bs-theme='dark'] body {
  background:
    radial-gradient(1200px 680px at 0% -10%, rgba(59, 130, 246, 0.2), transparent 52%),
    radial-gradient(900px 560px at 100% 0%, rgba(16, 185, 129, 0.14), transparent 58%),
    linear-gradient(180deg, #09101d 0%, #0f172a 48%, #111827 100%);
}

.layout-navbar {
  position: relative;
  min-height: 4rem;
  border-bottom: 1px solid var(--portal-border);
}

#fullscreen-toggle {
  border-radius: 0.65rem;
  padding-inline: 0.55rem;
}

#pwa-install-btn,
#fullscreen-toggle {
  width: 2rem;
  min-width: 2rem;
  height: 2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#theme-toggle {
  width: 2rem;
  min-width: 2rem;
  height: 2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#sync-status-toggle {
  position: relative;
  width: auto;
  min-width: 2rem;
  gap: 0.35rem;
  padding-inline: 0.55rem;
}

.sync-status-dot {
  width: 0.48rem;
  height: 0.48rem;
  border-radius: 999px;
  background: #94a3b8;
  box-shadow: 0 0 0 0 rgba(148, 163, 184, 0.45);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.sync-status-link.is-online .sync-status-dot {
  background: #f59e0b;
  box-shadow: 0 0 0 0.24rem rgba(245, 158, 11, 0.15);
}

.sync-status-link.is-lan .sync-status-dot {
  background: #10b981;
  box-shadow: 0 0 0 0.24rem rgba(16, 185, 129, 0.16);
}

.sync-status-link.is-offline .sync-status-dot,
.sync-status-link.is-error .sync-status-dot {
  background: #ef4444;
  box-shadow: 0 0 0 0.24rem rgba(239, 68, 68, 0.14);
}

.sync-status-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1rem;
  height: 1.1rem;
  border-radius: 999px;
  padding: 0 0.3rem;
  background: rgba(105, 108, 255, 0.16);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
}

.sync-status-link.pe-none {
  pointer-events: none;
}

html[data-bs-theme='dark'] .theme-toggle-dark-icon,
html[data-bs-theme='light'] .theme-toggle-light-icon {
  display: none;
}

.topbar-tools {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: nowrap;
}

.topbar-lang-form {
  margin: 0;
}

.topbar-lang-select {
  min-width: 4.25rem;
  padding-inline: 0.45rem;
  padding-right: 1.35rem;
  line-height: 1.15;
  background-position: right 0.38rem center;
  background-size: 0.72rem 0.6rem;
}

#app-shell-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 3px;
  z-index: 2000;
  background: linear-gradient(90deg, var(--bs-primary), #49c2ff);
  transition: width 0.2s ease, opacity 0.25s ease;
  opacity: 0;
}

.layout-container {
  gap: 0.75rem;
  padding: 0.75rem 0.75rem 0;
}

.layout-menu {
  margin: 0;
  border-radius: 1rem;
  height: calc(100vh - 1.5rem);
  top: 0.75rem;
}

.layout-navbar {
  margin-bottom: 0.75rem;
  border-radius: 1rem;
  border: 1px solid var(--portal-border);
  box-shadow: var(--portal-card-shadow);
}

.portal-brand-logo {
  min-width: 26px;
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.portal-brand-name {
  max-width: 170px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html.layout-menu-collapsed .portal-brand-name {
  display: none;
}

html.layout-menu-collapsed .portal-brand-logo {
  margin-inline-end: 0;
}

.layout-page {
  min-height: 100vh;
  min-width: 0;
}

.main-content-spacer {
  padding-top: 1.25rem;
}

.card {
  border: 1px solid var(--portal-border);
  border-radius: var(--portal-radius);
  box-shadow: var(--portal-card-shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--portal-card-shadow-hover);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border-bottom: 1px solid var(--portal-border);
  font-weight: 700;
}

.table-responsive {
  border: 1px solid var(--portal-border);
  border-radius: 0.85rem;
}

.table.table-modern {
  margin-bottom: 0;
}

.table.table-modern thead th {
  background: linear-gradient(180deg, rgba(105, 108, 255, 0.07) 0%, rgba(105, 108, 255, 0.03) 100%);
  border-bottom: 1px solid var(--portal-border);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #566074;
  position: sticky;
  top: 0;
  z-index: 1;
}

.table.table-modern tbody tr {
  transition: background-color 0.15s ease;
}

.table.table-modern tbody tr:hover {
  background-color: rgba(105, 108, 255, 0.05);
}

.table.table-modern th.is-sortable {
  cursor: pointer;
  user-select: none;
}

.table.table-modern th.is-sortable::after {
  content: "  <>";
  font-size: 0.85em;
  opacity: 0.45;
}

.table.table-modern th.is-sortable[aria-sort='ascending']::after {
  content: "  ^";
  opacity: 0.8;
}

.table.table-modern th.is-sortable[aria-sort='descending']::after {
  content: "  v";
  opacity: 0.8;
}

.table-count-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  background: rgba(105, 108, 255, 0.12);
  color: var(--bs-primary);
}

.btn {
  border-radius: 0.7rem;
  font-weight: 600;
}

.form-control,
.form-select {
  border-radius: 0.7rem;
}

.modal-content {
  border-radius: 1rem;
}

.page-header .d-flex {
  flex-wrap: wrap;
}

.table td,
.table th {
  vertical-align: middle;
}

html[data-bs-theme='dark'] .layout-navbar,
html[data-bs-theme='dark'] .layout-menu,
html[data-bs-theme='dark'] .card,
html[data-bs-theme='dark'] .table-responsive,
html[data-bs-theme='dark'] .modal-content,
html[data-bs-theme='dark'] .dropdown-menu,
html[data-bs-theme='dark'] .offcanvas,
html[data-bs-theme='dark'] .accordion-item,
html[data-bs-theme='dark'] .list-group-item,
html[data-bs-theme='dark'] .authentication-wrapper .authentication-inner {
  box-shadow: var(--portal-card-shadow);
}

html[data-bs-theme='dark'] .layout-navbar {
  background: rgba(15, 23, 42, 0.9) !important;
  backdrop-filter: blur(18px);
}

html[data-bs-theme='dark'] .layout-menu {
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.98) 0%, rgba(17, 24, 39, 0.98) 100%) !important;
}

html[data-bs-theme='dark'] .menu-inner-shadow {
  background: linear-gradient(var(--bs-paper-bg), transparent 65%);
}

html[data-bs-theme='dark'] .menu-vertical .menu-item .menu-link,
html[data-bs-theme='dark'] .menu-vertical .menu-sub .menu-link,
html[data-bs-theme='dark'] .text-body,
html[data-bs-theme='dark'] .text-body-secondary {
  color: var(--bs-body-color) !important;
}

html[data-bs-theme='dark'] .menu-vertical .menu-item.active > .menu-link,
html[data-bs-theme='dark'] .menu-vertical .menu-item.open > .menu-link,
html[data-bs-theme='dark'] .menu-vertical .menu-item .menu-link:hover,
html[data-bs-theme='dark'] .menu-vertical .menu-sub .menu-link:hover {
  background: rgba(99, 102, 241, 0.18) !important;
}

html[data-bs-theme='dark'] .card,
html[data-bs-theme='dark'] .modal-content,
html[data-bs-theme='dark'] .dropdown-menu,
html[data-bs-theme='dark'] .offcanvas,
html[data-bs-theme='dark'] .accordion-item,
html[data-bs-theme='dark'] .list-group-item,
html[data-bs-theme='dark'] .table-responsive,
html[data-bs-theme='dark'] .authentication-wrapper .authentication-inner,
html[data-bs-theme='dark'] .bg-footer-theme {
  background: rgba(15, 23, 42, 0.82) !important;
  border-color: var(--portal-border) !important;
}

html[data-bs-theme='dark'] .card-header,
html[data-bs-theme='dark'] .card-footer,
html[data-bs-theme='dark'] .modal-header,
html[data-bs-theme='dark'] .modal-footer,
html[data-bs-theme='dark'] .offcanvas-header,
html[data-bs-theme='dark'] .accordion-button {
  background: rgba(30, 41, 59, 0.72) !important;
  border-color: var(--portal-border) !important;
}

html[data-bs-theme='dark'] .accordion-button:not(.collapsed) {
  color: var(--bs-body-color);
  box-shadow: inset 0 calc(-1 * var(--bs-accordion-border-width)) 0 var(--portal-border);
}

html[data-bs-theme='dark'] .table.table-modern thead th,
html[data-bs-theme='dark'] .table > :not(caption) > * > th {
  background: linear-gradient(180deg, rgba(99, 102, 241, 0.18) 0%, rgba(30, 41, 59, 0.94) 100%);
  color: #dbe7ff;
}

html[data-bs-theme='dark'] .table.table-modern tbody tr:hover,
html[data-bs-theme='dark'] .table-hover > tbody > tr:hover > * {
  background-color: rgba(99, 102, 241, 0.08) !important;
}

html[data-bs-theme='dark'] .table,
html[data-bs-theme='dark'] .table > :not(caption) > * > * {
  --bs-table-bg: transparent;
  --bs-table-color: var(--bs-body-color);
  --bs-table-border-color: var(--portal-border);
  --bs-table-striped-bg: rgba(148, 163, 184, 0.04);
  --bs-table-hover-bg: rgba(99, 102, 241, 0.08);
}

html[data-bs-theme='dark'] .form-control,
html[data-bs-theme='dark'] .form-select,
html[data-bs-theme='dark'] .input-group-text,
html[data-bs-theme='dark'] .btn-outline-secondary,
html[data-bs-theme='dark'] .btn-outline-primary,
html[data-bs-theme='dark'] .btn-outline-warning,
html[data-bs-theme='dark'] .btn-outline-info,
html[data-bs-theme='dark'] .btn-outline-success,
html[data-bs-theme='dark'] .btn-outline-danger {
  background-color: rgba(15, 23, 42, 0.75);
  border-color: rgba(148, 163, 184, 0.28);
}

html[data-bs-theme='dark'] .form-control:focus,
html[data-bs-theme='dark'] .form-select:focus {
  background-color: rgba(15, 23, 42, 0.92);
}

html[data-bs-theme='dark'] .dropdown-item:hover,
html[data-bs-theme='dark'] .dropdown-item:focus,
html[data-bs-theme='dark'] .list-group-item-action:hover,
html[data-bs-theme='dark'] .list-group-item-action:focus {
  background-color: rgba(99, 102, 241, 0.12);
}

html[data-bs-theme='dark'] .nav-pills .nav-link.active,
html[data-bs-theme='dark'] .page-link.active,
html[data-bs-theme='dark'] .page-item.active .page-link {
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.28);
}

html[data-bs-theme='dark'] .page-link,
html[data-bs-theme='dark'] .btn-outline-secondary,
html[data-bs-theme='dark'] .btn-outline-primary,
html[data-bs-theme='dark'] .btn-outline-warning,
html[data-bs-theme='dark'] .btn-outline-info,
html[data-bs-theme='dark'] .btn-outline-success,
html[data-bs-theme='dark'] .btn-outline-danger {
  color: var(--bs-body-color);
}

html[data-bs-theme='dark'] .table-count-pill,
html[data-bs-theme='dark'] .bg-label-primary {
  background: rgba(99, 102, 241, 0.22) !important;
}

html[data-bs-theme='dark'] .sync-status-count {
  background: rgba(99, 102, 241, 0.22);
}

html[data-bs-theme='dark'] .indicator-detail-box,
html[data-bs-theme='dark'] .manager-panel,
html[data-bs-theme='dark'] .note-preview-box,
html[data-bs-theme='dark'] .permission-group,
html[data-bs-theme='dark'] .permission-item,
html[data-bs-theme='dark'] .selection-group {
  background: rgba(15, 23, 42, 0.76) !important;
  border-color: var(--portal-border) !important;
}

html[data-bs-theme='dark'] #standardsManagerModal .modal-content {
  background: rgba(2, 6, 23, 0.96);
  border-color: var(--portal-border);
}

html[data-bs-theme='dark'] #standardsManagerModal .modal-header,
html[data-bs-theme='dark'] #standardsManagerModal .modal-footer,
html[data-bs-theme='dark'] #standardsManagerModal .table td,
html[data-bs-theme='dark'] #standardsManagerModal .table th {
  border-color: var(--portal-border) !important;
}

html[data-bs-theme='dark'] #standardsManagerModal .table td,
html[data-bs-theme='dark'] #standardsManagerModal .table th,
html[data-bs-theme='dark'] #standardsManagerModal .form-label,
html[data-bs-theme='dark'] #standardsManagerModal .text-muted {
  color: var(--bs-body-color) !important;
}

html[data-bs-theme='dark'] #standardsManagerModal .text-muted {
  opacity: 0.75;
}

html[data-bs-theme='dark'] .page-item .page-link {
  background-color: rgba(15, 23, 42, 0.82);
  border-color: var(--portal-border);
  color: #93c5fd;
}

html[data-bs-theme='dark'] .table th,
html[data-bs-theme='dark'] .selection-subtables,
html[data-bs-theme='dark'] .indicator-evidence-list li,
html[data-bs-theme='dark'] .role-tab-content {
  border-color: var(--portal-border) !important;
}

html[data-bs-theme='dark'] .table th {
  background-color: rgba(30, 41, 59, 0.72);
}

html[data-bs-theme='dark'] .border,
html[data-bs-theme='dark'] .border-top,
html[data-bs-theme='dark'] .border-end,
html[data-bs-theme='dark'] .border-bottom,
html[data-bs-theme='dark'] .border-start,
html[data-bs-theme='dark'] hr,
html[data-bs-theme='dark'] .dropdown-divider {
  border-color: var(--portal-border) !important;
}

html[data-bs-theme='dark'] .patients-mobile-topbar,
html[data-bs-theme='dark'] .patient-mobile-card,
html[data-bs-theme='dark'] .patients-mobile-empty,
html[data-bs-theme='dark'] .patients-mobile-submit .btn,
html[data-bs-theme='dark'] .patient-mobile-token,
html[data-bs-theme='dark'] #patient-queue-card .list-group-item,
html[data-bs-theme='dark'] .inv-stat-card,
html[data-bs-theme='dark'] .inv-alert-card,
html[data-bs-theme='dark'] .inv-pill,
html[data-bs-theme='dark'] .inv-import-form .form-control,
html[data-bs-theme='dark'] .inv-actions .btn {
  border-color: var(--portal-border) !important;
}

html[data-bs-theme='dark'] .patients-mobile-topbar,
html[data-bs-theme='dark'] .patient-mobile-card,
html[data-bs-theme='dark'] .patients-mobile-empty,
html[data-bs-theme='dark'] #patient-queue-card .list-group-item {
  background: rgba(15, 23, 42, 0.84) !important;
  color: var(--bs-body-color) !important;
}

html[data-bs-theme='dark'] .patients-mobile-tab {
  color: #cbd5e1 !important;
}

html[data-bs-theme='dark'] .patients-mobile-tab.is-active,
html[data-bs-theme='dark'] .patients-mobile-submit .btn,
html[data-bs-theme='dark'] .patient-mobile-token {
  background: rgba(30, 41, 59, 0.96) !important;
  color: #e2e8f0 !important;
}

html[data-bs-theme='dark'] .patient-mobile-meta,
html[data-bs-theme='dark'] .patient-mobile-subtext,
html[data-bs-theme='dark'] .patient-mobile-label,
html[data-bs-theme='dark'] #patient-queue-card .text-muted,
html[data-bs-theme='dark'] #patient-queue-card small {
  color: #94a3b8 !important;
}

html[data-bs-theme='dark'] .patient-mobile-grid strong {
  color: #e5eefc !important;
}

html[data-bs-theme='dark'] .inv-stat-card,
html[data-bs-theme='dark'] .inv-alert-card,
html[data-bs-theme='dark'] #inv-panel-main,
html[data-bs-theme='dark'] .inv-import-form .form-control {
  background: rgba(15, 23, 42, 0.82) !important;
}

html[data-bs-theme='dark'] .inv-pill.bg-label-warning {
  background: rgba(245, 158, 11, 0.2) !important;
  color: #fcd34d !important;
}

html[data-bs-theme='dark'] .inv-pill.bg-label-danger {
  background: rgba(239, 68, 68, 0.18) !important;
  color: #fca5a5 !important;
}

@media (max-width: 767.98px) {
  .pagination {
    flex-wrap: wrap;
    row-gap: 0.4rem;
  }
}

@media (max-width: 991.98px) {
  .layout-container {
    padding: 0;
    gap: 0;
  }

  .layout-menu {
    top: 0;
    height: 100vh;
    border-radius: 0;
  }

  .layout-navbar {
    margin-bottom: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  #layout-navbar {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  .navbar-nav-right {
    min-width: 0;
  }

  .topbar-tools {
    margin-right: 0.4rem !important;
  }

  .topbar-lang-select {
    min-width: 4.1rem;
    max-width: 4.1rem;
    font-size: 0.75rem;
    padding-right: 1.25rem;
    background-position: right 0.32rem center;
  }

  .nav-item.navbar-dropdown.dropdown-user .nav-link {
    padding-left: 0.25rem !important;
    padding-right: 0.1rem !important;
  }

  .main-content-spacer {
    padding-top: 0.85rem;
    padding-left: 0.2rem;
    padding-right: 0.2rem;
  }

  .container-xxl {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.55rem;
    margin-bottom: 0.9rem;
  }

  .row {
    margin-left: -0.35rem;
    margin-right: -0.35rem;
  }

  [class^='col-'],
  [class*=' col-'],
  .col {
    padding-left: 0.35rem;
    padding-right: 0.35rem;
  }

  .card {
    margin-bottom: 0.75rem;
  }

  .card-header,
  .card-body,
  .card-footer {
    padding: 0.75rem;
  }

  .table-responsive {
    border-radius: 0.7rem;
  }

  .table.table-modern th,
  .table.table-modern td {
    white-space: nowrap;
    font-size: 0.8rem;
    padding: 0.55rem 0.5rem;
  }

  .btn,
  .form-control,
  .form-select {
    min-height: 2.35rem;
  }
}
