/* RGS workspace UI layer
   Shared navigation, page headers, identity strips, table tools and loading states.
*/

:root {
  --rgs-mobile-bar-height: 58px;
  --rgs-ui-blue: #2456ad;
  --rgs-ui-blue-soft: #edf3ff;
  --rgs-ui-green: #087a55;
  --rgs-ui-green-soft: #eaf8f1;
  --rgs-ui-amber: #9a5a00;
  --rgs-ui-amber-soft: #fff6df;
  --rgs-ui-red: #b42318;
  --rgs-ui-red-soft: #fff0ef;
  --rgs-ui-gray: #526174;
  --rgs-ui-gray-soft: #f2f4f7;
}

.ui-icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  flex: 0 0 1em;
  background-color: currentColor;
  -webkit-mask-image: var(--ui-icon-source);
  mask-image: var(--ui-icon-source);
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-size: contain;
}

.person-favorite-name-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 0;
}

.person-favorite-name-line .masterdata-name-link {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-favorite-toggle-form {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  margin: 0;
}

.person-favorite-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  box-shadow: none;
  line-height: 1;
  appearance: none;
}

.person-favorite-toggle:hover {
  background: #f2f4f7;
  transform: none;
}

.person-favorite-toggle.is-active {
  background: transparent;
}

.person-favorite-star {
  display: block;
  color: #ffffff;
  font-family: Arial, sans-serif;
  font-size: 1.05rem;
  font-weight: 900;
  line-height: 1;
  -webkit-text-stroke: 0.9px #98a2b3;
  text-shadow: none;
  transition: color 140ms ease, transform 140ms ease, -webkit-text-stroke-color 140ms ease;
}

.person-favorite-toggle:hover .person-favorite-star {
  color: #eef2f6;
  -webkit-text-stroke-color: #475467;
  transform: scale(1.04);
}

.person-favorite-toggle.is-active .person-favorite-star {
  color: #36506d;
  -webkit-text-stroke: 0.65px #23364d;
  text-shadow: none;
}

.person-favorite-cell {
  padding-right: 3px !important;
  padding-left: 3px !important;
  text-align: center !important;
}

.person-favorite-star-heading {
  display: inline-block;
  color: #ffffff;
  font-size: 0.72rem;
  -webkit-text-stroke: 0.75px #98a2b3;
  text-shadow: none;
}

.person-favorite-toggle:focus-visible {
  outline: 2px solid rgba(54, 80, 109, 0.24);
  outline-offset: 1px;
}

.btn > .ui-icon,
button > .ui-icon,
.nav-link > .ui-icon,
.nav-dropdown a > .ui-icon {
  width: 1rem;
  height: 1rem;
  flex-basis: 1rem;
}

.nav-link > .ui-icon,
.nav-dropdown a > .ui-icon {
  margin-right: 9px;
}

.nav-link-toggle > .ui-icon {
  margin-right: 9px;
}

.nav-link-toggle .nav-label {
  margin-right: auto;
}

.emergency-link::before {
  display: none !important;
}

.emergency-link > .ui-icon {
  width: 16px;
  height: 16px;
}

.mobile-appbar,
.nav-drawer-close,
.nav-drawer-backdrop {
  display: none;
}

/* A single visual rhythm for all internal page headings. */
.main .app-page-header:not(.identity-strip) {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  min-height: 92px;
  margin: 0 0 18px;
  padding: 20px 2px 14px;
  border: 0;
  border-bottom: 1px solid #e5e7eb;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.main .app-page-header:not(.identity-strip)::before,
.main .app-page-header:not(.identity-strip)::after {
  display: none;
}

.main .app-page-header h1 {
  margin: 0;
  color: #111827;
  font-size: 2rem;
  font-weight: 740;
  line-height: 1.08;
}

.main .app-page-header p {
  max-width: 860px;
  margin: 5px 0 0;
  color: #667085;
  font-size: 0.88rem;
  line-height: 1.45;
}

.main .app-page-header .badge:first-child {
  min-height: 24px;
  margin-bottom: 7px;
  padding: 4px 7px;
  border-radius: 6px;
  font-size: 0.68rem;
}

.main .app-page-header .hero-actions,
.main .app-page-header .settings-actions,
.main .app-page-header .masterdata-action-links {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.main .app-page-header .btn,
.main .app-page-header button {
  min-height: 38px;
  padding: 8px 11px;
  border-radius: 8px;
  font-size: 0.82rem;
  box-shadow: none;
}

.masterdata-hero.app-page-header {
  align-items: stretch;
  padding-bottom: 18px;
}

.masterdata-hero.app-page-header .masterdata-hero-copy {
  align-self: flex-end;
}

/* Resident and staff records start with a compact identity strip. */
.main .identity-strip {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  margin: 12px 0 18px;
  padding: 16px 18px;
  border: 1px solid #e1e5eb;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

.main .identity-strip::before,
.main .identity-strip::after {
  display: none;
}

.identity-avatar {
  display: grid;
  width: 84px;
  height: 84px;
  flex: 0 0 84px;
  place-items: center;
  overflow: hidden;
  border: 1px solid #dbe2ea;
  border-radius: 50%;
  background: #f3f6fa;
  color: #5270a5;
}

.identity-avatar .ui-icon {
  width: 38px;
  height: 38px;
}

.identity-copy {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.identity-type {
  color: #667085;
  font-size: 0.72rem;
  font-weight: 720;
  line-height: 1;
  text-transform: uppercase;
}

.identity-strip h1 {
  overflow: hidden;
  margin: 0;
  color: #111827;
  font-size: 1.75rem;
  font-weight: 750;
  line-height: 1.08;
  text-overflow: ellipsis;
}

.identity-facts,
.identity-statuses,
.identity-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  flex-wrap: wrap;
}

.identity-fact {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 5px 8px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #f8f9fb;
  color: #475467;
  font-size: 0.76rem;
  font-weight: 650;
  white-space: nowrap;
}

.identity-fact strong {
  color: #1f2937;
  font-weight: 750;
}

.identity-controls {
  display: grid;
  justify-items: end;
  gap: 10px;
  min-width: 190px;
}

.identity-actions {
  justify-content: flex-end;
}

.identity-actions .btn,
.identity-action-trigger {
  min-height: 36px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  box-shadow: none;
}

.identity-action-menu {
  position: relative;
}

.identity-action-menu > summary {
  list-style: none;
}

.identity-action-menu > summary::-webkit-details-marker {
  display: none;
}

.identity-action-trigger {
  display: inline-grid;
  width: 38px;
  min-width: 38px;
  padding: 0;
  place-items: center;
  border: 1px solid #d9e0e9;
  background: #ffffff;
  color: #344054;
  cursor: pointer;
}

.identity-action-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 45;
  display: grid;
  gap: 2px;
  width: 220px;
  padding: 6px;
  border: 1px solid #dfe4eb;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.12);
}

.identity-action-list .btn,
.identity-action-list a,
.identity-action-list button {
  width: 100%;
  min-height: 36px;
  justify-content: flex-start;
  padding: 8px 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #344054;
  font-size: 0.8rem;
  text-decoration: none;
  box-shadow: none;
}

.identity-action-list .btn:hover,
.identity-action-list a:hover,
.identity-action-list button:hover {
  background: #f2f4f7;
}

.identity-action-list .btn-danger-soft,
.identity-action-list .btn-danger {
  color: var(--rgs-ui-red);
}

.resident-identity-strip .hero-photo {
  order: -1;
  width: 112px;
  max-width: 112px;
  flex-basis: 112px;
}

.resident-identity-strip .photo-dropzone {
  width: 112px;
  min-height: 112px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #f3f6fa;
}

.resident-identity-strip .photo-dropzone img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.resident-identity-strip .photo-placeholder {
  padding: 9px;
  font-size: 0.7rem;
}

.resident-identity-strip .photo-actions {
  margin-top: 7px;
  gap: 5px;
}

.resident-identity-strip .photo-actions .btn,
.resident-identity-strip .photo-actions button {
  min-height: 30px;
  padding: 5px 7px;
  border-radius: 6px;
  font-size: 0.68rem;
}

/* Aktennavigation and the per-person control history. */
.record-tabs {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  min-width: 0;
  margin: 0 0 18px;
  border-bottom: 1px solid #dfe4eb;
}

.record-tab {
  position: relative;
  display: inline-flex;
  min-width: 0;
  min-height: 42px;
  padding: 10px 13px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #667085;
  font-size: 0.82rem;
  font-weight: 720;
  text-decoration: none;
  white-space: nowrap;
}

.record-tab:hover {
  color: #1f4fd7;
}

.record-tab.active {
  color: #173f9d;
}

.record-tab.active::after {
  position: absolute;
  right: 8px;
  bottom: -1px;
  left: 8px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: #2456ad;
  content: "";
}

.control-history-identity .identity-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.control-history-shell {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.control-event-pill {
  display: inline-flex;
  min-height: 28px;
  padding: 5px 9px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.control-event-entry {
  border-color: #a8dfbe;
  background: #eaf8ef;
  color: #147a42;
}

.control-event-exit {
  border-color: #f0b8b8;
  background: #fff0f0;
  color: #b52b2b;
}

.masterdata-presence-badge {
  display: inline-flex;
  min-width: 62px;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.masterdata-presence-badge .ui-icon {
  width: 14px;
  height: 14px;
}

.control-history-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid #e1e5eb;
  border-radius: 8px;
  background: #ffffff;
}

.control-history-stat {
  display: grid;
  min-width: 0;
  min-height: 68px;
  padding: 11px 14px;
  align-content: center;
  gap: 3px;
  border-right: 1px solid #e8ebf0;
}

.control-history-stat:last-child {
  border-right: 0;
}

.control-history-stat span {
  overflow: hidden;
  color: #667085;
  font-size: 0.7rem;
  font-weight: 690;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-history-stat strong {
  color: #172033;
  font-size: 1.3rem;
  line-height: 1;
}

.control-history-filter-panel,
.control-history-list-panel {
  min-width: 0;
  padding: 18px;
}

.control-history-panel-head {
  display: flex;
  margin-bottom: 14px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.control-history-panel-head h2 {
  margin: 0 0 4px;
  font-size: 1.08rem;
}

.control-history-panel-head p {
  margin: 0;
  color: #667085;
  font-size: 0.78rem;
}

.control-history-filter-form {
  display: grid;
  gap: 14px;
}

.control-history-filter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(135px, 0.72fr)) minmax(170px, 1fr) minmax(180px, 1.15fr) minmax(170px, 1fr);
  align-items: end;
  gap: 10px;
}

.control-history-filter-grid .field {
  min-width: 0;
}

.control-history-filter-grid label {
  display: block;
  margin-bottom: 5px;
  color: #667085;
  font-size: 0.7rem;
  font-weight: 720;
}

.control-history-filter-grid input,
.control-history-filter-grid select {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 7px 9px;
  border-radius: 7px;
  font-size: 0.8rem;
}

.control-history-filter-grid .errorlist {
  margin: 5px 0 0;
  padding: 0;
  color: #b42318;
  font-size: 0.72rem;
  list-style: none;
}

.control-history-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.control-history-actions .btn,
.control-history-actions button {
  min-height: 38px;
  padding: 8px 11px;
  border-radius: 8px;
  font-size: 0.78rem;
}

.control-history-table-wrap {
  min-width: 0;
  overflow: visible;
}

.control-history-table {
  width: 100%;
  table-layout: fixed;
}

.control-history-table th,
.control-history-table td {
  padding-right: 9px;
  padding-left: 9px;
  vertical-align: middle;
}

.control-history-table th:nth-child(1) { width: 15%; }
.control-history-table th:nth-child(2) { width: 18%; }
.control-history-table th:nth-child(3) { width: 10%; }
.control-history-table th:nth-child(4) { width: 14%; }
.control-history-table th:nth-child(5) { width: 20%; }
.control-history-table th:nth-child(6) { width: 13%; }
.control-history-table th:nth-child(7) { width: 10%; }

.control-module {
  display: inline-flex;
  max-width: 100%;
  min-height: 26px;
  padding: 4px 7px;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 730;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-module-access {
  border-color: #cad8f0;
  background: #edf3ff;
  color: #2456ad;
}

.control-module-allowance {
  border-color: #b9e5d2;
  background: #eaf8f1;
  color: #087a55;
}

.control-module-meal {
  border-color: #efd59d;
  background: #fff6df;
  color: #8b5207;
}

.control-history-location {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-history-location .ui-icon {
  color: #667085;
}

.control-history-details {
  display: -webkit-box;
  overflow: hidden;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.control-history-empty {
  padding: 30px 16px !important;
  color: #667085;
  text-align: center;
}

.control-history-pagination {
  display: flex;
  margin-top: 14px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.control-history-pagination .page-link,
.control-history-pagination .page-ellipsis {
  display: inline-grid;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  place-items: center;
  border: 1px solid #dce2ea;
  border-radius: 7px;
  background: #ffffff;
  color: #344054;
  font-size: 0.76rem;
  font-weight: 720;
  text-decoration: none;
}

.control-history-pagination .page-link.active {
  border-color: #2456ad;
  background: #2456ad;
  color: #ffffff;
}

.control-history-pagination .page-ellipsis {
  border-color: transparent;
  background: transparent;
}

/* Resident status history keeps lifecycle changes separate from scan history. */
.status-history-shell {
  display: grid;
  min-width: 0;
  gap: 16px;
}

.status-history-summary {
  display: grid;
  overflow: hidden;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid #e1e6ed;
  border-radius: 8px;
  background: #ffffff;
}

.status-history-stat {
  display: grid;
  min-width: 0;
  min-height: 68px;
  padding: 12px 16px;
  align-content: center;
  gap: 3px;
  border-right: 1px solid #e8ebf0;
}

.status-history-stat:last-child {
  border-right: 0;
}

.status-history-stat span {
  overflow: hidden;
  color: #667085;
  font-size: 0.7rem;
  font-weight: 740;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-history-stat strong {
  color: #14213d;
  font-size: 1.28rem;
  line-height: 1.05;
}

.status-history-panel {
  min-width: 0;
  padding: 20px;
}

.status-history-panel-head {
  margin-bottom: 8px;
}

.status-history-panel-head h2 {
  margin-bottom: 3px;
}

.status-history-panel-head p {
  margin: 0;
  color: #667085;
  font-size: 0.78rem;
}

.status-history-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.status-history-entry {
  display: grid;
  min-width: 0;
  padding: 16px 0;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 13px;
  border-top: 1px solid #e8ebf0;
}

.status-history-entry:first-child {
  border-top: 0;
}

.status-history-marker {
  display: inline-flex;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid #d9dee6;
  border-radius: 8px;
  background: var(--rgs-ui-gray-soft);
  color: var(--rgs-ui-gray);
}

.status-history-marker .ui-icon {
  width: 16px;
  height: 16px;
}

.status-history-entry-success .status-history-marker {
  border-color: #b9e5d2;
  background: var(--rgs-ui-green-soft);
  color: var(--rgs-ui-green);
}

.status-history-entry-warning .status-history-marker {
  border-color: #efd59d;
  background: var(--rgs-ui-amber-soft);
  color: var(--rgs-ui-amber);
}

.status-history-entry-danger .status-history-marker {
  border-color: #efc0bc;
  background: var(--rgs-ui-red-soft);
  color: var(--rgs-ui-red);
}

.status-history-entry-info .status-history-marker {
  border-color: #cbd9f2;
  background: var(--rgs-ui-blue-soft);
  color: var(--rgs-ui-blue);
}

.status-history-content {
  min-width: 0;
}

.status-history-heading {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-history-heading > div {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
}

.status-history-heading time {
  color: #667085;
  font-size: 0.74rem;
  font-weight: 680;
  white-space: nowrap;
}

.status-history-actor {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 5px;
  color: #667085;
  font-size: 0.74rem;
  font-weight: 680;
  white-space: nowrap;
}

.status-history-actor .ui-icon {
  width: 14px;
  height: 14px;
}

.status-history-content p {
  margin: 8px 0 0;
  color: #344054;
  font-size: 0.84rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.status-history-empty {
  display: flex;
  min-height: 150px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid #e8ebf0;
  color: #667085;
  text-align: center;
}

.status-history-empty .ui-icon {
  width: 24px;
  height: 24px;
}

/* Unified semantic states. JS adds these classes from the visible status label. */
.status-semantic-success,
.badge.status-semantic-success,
.status-pill.status-semantic-success,
.status-big.status-semantic-success,
.chip.status-semantic-success {
  border-color: #b9e5d2 !important;
  background: var(--rgs-ui-green-soft) !important;
  color: var(--rgs-ui-green) !important;
}

.status-semantic-warning,
.badge.status-semantic-warning,
.status-pill.status-semantic-warning,
.status-big.status-semantic-warning,
.chip.status-semantic-warning {
  border-color: #efd59d !important;
  background: var(--rgs-ui-amber-soft) !important;
  color: var(--rgs-ui-amber) !important;
}

.status-semantic-danger,
.badge.status-semantic-danger,
.status-pill.status-semantic-danger,
.status-big.status-semantic-danger,
.chip.status-semantic-danger {
  border-color: #efc0bc !important;
  background: var(--rgs-ui-red-soft) !important;
  color: var(--rgs-ui-red) !important;
}

.status-semantic-info,
.badge.status-semantic-info,
.status-pill.status-semantic-info,
.status-big.status-semantic-info,
.chip.status-semantic-info {
  border-color: #cbd9f2 !important;
  background: var(--rgs-ui-blue-soft) !important;
  color: var(--rgs-ui-blue) !important;
}

.status-semantic-neutral,
.badge.status-semantic-neutral,
.status-pill.status-semantic-neutral,
.status-big.status-semantic-neutral,
.chip.status-semantic-neutral {
  border-color: #d9dee6 !important;
  background: var(--rgs-ui-gray-soft) !important;
  color: var(--rgs-ui-gray) !important;
}

.badge[class*="status-semantic-"]::before,
.status-pill[class*="status-semantic-"]::before,
.status-big[class*="status-semantic-"]::before,
.identity-status[class*="status-semantic-"]::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 6px;
  border-radius: 50%;
  background: currentColor;
}

.identity-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 5px 8px;
  border: 1px solid #d9dee6;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 720;
  white-space: nowrap;
}

/* Sticky table headings and one shared table density preference. */
body .table-wrap.has-sticky-table,
body .masterdata-table-wrap.has-sticky-table {
  overflow: visible;
}

.has-sticky-table table {
  border-collapse: separate;
  border-spacing: 0;
}

.has-sticky-table thead th {
  position: sticky;
  top: 0;
  z-index: 8;
  background: #f5f7fa !important;
  box-shadow: inset 0 -1px 0 #dfe4eb;
}

.table-density-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 36px;
  padding: 4px 5px;
  border: 1px solid #e1e5eb;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: #fafbfc;
}

.table-density-control {
  display: inline-grid;
  grid-template-columns: repeat(2, 32px);
  gap: 2px;
  padding: 2px;
  border: 1px solid #dde3eb;
  border-radius: 7px;
  background: #ffffff;
}

.table-density-button {
  display: grid;
  width: 32px;
  height: 28px;
  min-width: 32px;
  min-height: 28px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #667085;
  cursor: pointer;
  box-shadow: none;
}

.table-density-button:hover {
  background: #f2f4f7;
  color: #344054;
}

.table-density-button.active {
  background: var(--rgs-ui-blue-soft);
  color: var(--rgs-ui-blue);
}

.table-density-toolbar + table {
  border-top-left-radius: 0 !important;
  border-top-right-radius: 0 !important;
}

body.table-density-compact table th,
body.table-density-compact table td,
body.table-density-compact .masterdata-table th,
body.table-density-compact .masterdata-table td {
  padding-top: 6px !important;
  padding-bottom: 6px !important;
  font-size: 0.76rem;
  line-height: 1.18;
}

body.table-density-compact table th,
body.table-density-compact .masterdata-table th {
  font-size: 0.66rem;
}

/* Existing menus use the same compact icon trigger and menu surface. */
.masterdata-action-trigger,
.visitor-action-trigger,
.action-menu-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.masterdata-action-trigger.icon-only-action,
.visitor-action-trigger.icon-only-action,
.action-menu-trigger.icon-only-action {
  width: 36px;
  min-width: 36px;
  min-height: 34px;
  padding: 0;
  font-size: 0 !important;
}

.masterdata-action-trigger.icon-only-action .ui-icon,
.visitor-action-trigger.icon-only-action .ui-icon,
.action-menu-trigger.icon-only-action .ui-icon {
  width: 17px;
  height: 17px;
}

/* Navigation and form transitions show a lightweight skeleton only when needed. */
.app-loading-overlay {
  position: fixed;
  inset: 0 0 0 var(--sidebar-width);
  z-index: 65;
  display: none;
  padding: 28px clamp(16px, 3vw, 44px);
  overflow: hidden;
  background: #f7f8fa;
}

body.is-page-loading .app-loading-overlay {
  display: block;
}

.app-loading-inner {
  display: grid;
  gap: 18px;
  width: 100%;
  max-width: 1580px;
  margin: 0 auto;
}

.app-operation-loading {
  display: none;
  width: min(360px, 100%);
  padding: 26px 24px;
  border: 1px solid #d9e0e8;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
  color: #12233f;
  text-align: center;
}

.app-operation-loading strong,
.app-operation-loading > span:last-child {
  display: block;
}

.app-operation-loading strong {
  margin-top: 14px;
  font-size: 1rem;
}

.app-operation-loading > span:last-child {
  margin-top: 6px;
  color: #66788f;
  font-size: 0.9rem;
}

.app-operation-spinner {
  display: inline-block;
  width: 42px;
  height: 42px;
  border: 4px solid #dce5f2;
  border-top-color: #2f63c6;
  border-radius: 50%;
  animation: rgs-operation-spin 0.8s linear infinite;
}

body.is-operation-loading .app-loading-overlay {
  inset: 0;
  z-index: 3200;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(17, 24, 39, 0.26);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

body.is-operation-loading .app-loading-inner {
  display: none;
}

body.is-operation-loading .app-operation-loading {
  display: block;
}

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

.skeleton-line,
.skeleton-block,
.media-loading::after {
  background: linear-gradient(90deg, #eceff3 0%, #f7f8fa 48%, #eceff3 100%);
  background-size: 220% 100%;
  animation: rgs-skeleton-shift 1.25s ease-in-out infinite;
}

.skeleton-header {
  display: grid;
  gap: 10px;
  padding: 14px 0 18px;
  border-bottom: 1px solid #e1e5eb;
}

.skeleton-line {
  height: 13px;
  border-radius: 5px;
}

.skeleton-line.title {
  width: min(340px, 58vw);
  height: 30px;
}

.skeleton-line.subtitle {
  width: min(620px, 82vw);
}

.skeleton-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid #e1e5eb;
  border-radius: 8px;
  background: #e1e5eb;
}

.skeleton-block.metric {
  height: 88px;
  border-radius: 0;
}

.skeleton-panel {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid #e1e5eb;
  border-radius: 8px;
  background: #ffffff;
}

.skeleton-block.table-row {
  height: 42px;
  border-radius: 6px;
}

.media-loading {
  position: relative;
  overflow: hidden;
}

.media-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

@keyframes rgs-skeleton-shift {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

@media (max-width: 980px) {
  body.nav-drawer-open {
    overflow: hidden;
  }

  .shell:not(.shell-guest) {
    padding-left: 0;
  }

  .topbar {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    bottom: auto;
    z-index: 80;
    width: 100%;
    height: var(--rgs-mobile-bar-height);
    overflow: visible;
    border: 0;
    border-bottom: 1px solid #e1e5eb;
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
  }

  .mobile-appbar {
    position: relative;
    z-index: 84;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) 40px;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: var(--rgs-mobile-bar-height);
    padding: 7px 10px 7px 12px;
  }

  .mobile-appbar-brand {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
  }

  .mobile-appbar-brand img {
    display: block;
    width: auto;
    height: 35px;
    max-width: 132px;
  }

  .mobile-appbar-context {
    min-width: 0;
    overflow: hidden;
    color: #667085;
    font-size: 0.74rem;
    font-weight: 650;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .nav-drawer-open-button,
  .nav-drawer-close {
    display: grid;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    place-items: center;
    border: 1px solid #dce2ea;
    border-radius: 8px;
    background: #ffffff;
    color: #344054;
    cursor: pointer;
    box-shadow: none;
  }

  .nav-drawer-open-button .ui-icon,
  .nav-drawer-close .ui-icon {
    width: 19px;
    height: 19px;
  }

  .topbar .topbar-inner {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 86;
    display: flex;
    width: min(340px, 88vw);
    max-width: min(340px, 88vw);
    height: 100dvh;
    min-height: 100vh;
    margin: 0;
    padding: 14px 12px 12px;
    overflow-x: hidden;
    overflow-y: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    border-right: 1px solid #dfe4eb;
    background: #fbfcfd;
    box-shadow: 18px 0 48px rgba(15, 23, 42, 0.16);
    transform: translateX(-104%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }

  body.nav-drawer-open .topbar .topbar-inner {
    transform: translateX(0);
  }

  .topbar .brand {
    min-height: 54px;
    justify-content: flex-start;
    padding: 2px 48px 12px 6px;
  }

  .topbar .brand-logo {
    height: 44px;
    max-width: 180px;
  }

  .nav-drawer-close {
    position: absolute;
    top: 14px;
    right: 12px;
    z-index: 2;
  }

  .topbar .nav {
    display: flex;
    width: 100%;
    padding: 0;
    overflow: visible;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 3px;
  }

  .topbar .nav-item,
  .topbar .nav-item.has-dropdown {
    width: 100%;
  }

  .topbar .nav-link,
  .topbar button.nav-link-toggle {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 8px 10px;
    font-size: 0.84rem;
  }

  .topbar .nav-dropdown {
    position: static;
    width: auto;
    min-width: 0;
    max-width: 100%;
    padding: 0 0 0 11px;
    margin: 0 0 0 14px;
    border: 0;
    border-left: 1px solid transparent;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .topbar .nav-item.has-dropdown.open .nav-dropdown {
    width: auto;
    min-width: 0;
    max-width: 100%;
    padding: 3px 0 3px 11px;
    margin: 3px 0 5px 14px;
    border: 0;
    border-left: 1px solid #d9dee7;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .topbar .nav-dropdown a {
    min-height: 36px;
  }

  .topbar .sidebar-emergency {
    width: 100%;
    margin-top: auto;
    padding: 10px 0 0;
  }

  .topbar .emergency-link {
    width: 100%;
    min-width: 0;
  }

  .topbar .topbar-right {
    display: flex;
    width: 100%;
    margin: 0;
    padding: 6px;
    overflow: visible;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
  }

  .topbar .user-badge {
    width: 100%;
    max-width: none;
  }

  .topbar .topbar-right form {
    width: 100%;
    padding: 5px 0 0;
    border-top: 1px solid #e5e7eb;
    border-left: 0;
  }

  .topbar .topbar-logout {
    width: 100%;
  }

  .nav-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 75;
    display: block;
    padding: 0;
    border: 0;
    background: rgba(17, 24, 39, 0.32);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }

  body.nav-drawer-open .nav-drawer-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .app-loading-overlay {
    inset: var(--rgs-mobile-bar-height) 0 0;
    padding: 18px 12px;
  }

  .has-sticky-table thead th {
    top: var(--rgs-mobile-bar-height);
  }

  .main .identity-strip {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
  }

  .identity-controls {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    justify-items: stretch;
    padding-top: 10px;
    border-top: 1px solid #e5e7eb;
  }

  .identity-statuses,
  .identity-actions {
    justify-content: flex-start;
  }

  .control-history-filter-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .control-history-table,
  .control-history-table tbody {
    display: block;
    width: 100%;
  }

  .control-history-table thead {
    display: none;
  }

  .control-history-table tbody tr {
    display: grid;
    width: 100%;
    padding: 8px 0;
    border-top: 1px solid #e8ebf0;
  }

  .control-history-table tbody tr:first-child {
    border-top: 0;
  }

  .control-history-table tbody td {
    display: grid;
    width: 100%;
    min-width: 0;
    padding: 6px 8px;
    grid-template-columns: 105px minmax(0, 1fr);
    align-items: start;
    gap: 9px;
    border: 0;
    white-space: normal;
  }

  .control-history-table tbody td::before {
    color: #667085;
    content: attr(data-label);
    font-size: 0.66rem;
    font-weight: 740;
    text-transform: uppercase;
  }

  .control-history-table .control-history-details {
    display: grid;
    overflow: visible;
    -webkit-line-clamp: unset;
  }

  .control-history-table .control-history-empty {
    display: block;
    padding: 24px 10px !important;
  }

  .control-history-table .control-history-empty::before {
    display: none;
  }
}

@media (max-width: 620px) {
  .main .app-page-header:not(.identity-strip) {
    min-height: 0;
    padding: 17px 2px 12px;
    flex-direction: column;
    align-items: stretch;
  }

  .main .app-page-header h1 {
    font-size: 1.55rem;
  }

  .main .app-page-header .hero-actions,
  .main .app-page-header .settings-actions,
  .main .app-page-header .masterdata-action-links {
    justify-content: flex-start;
  }

  .main .app-page-header .quickstart {
    display: none;
  }

  .masterdata-hero.app-page-header .masterdata-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
  }

  .masterdata-hero.app-page-header .masterdata-stat {
    min-height: 58px;
    padding: 9px 10px;
  }

  .masterdata-hero.app-page-header .masterdata-stat-label {
    margin-bottom: 4px;
    font-size: 0.65rem;
    white-space: nowrap;
  }

  .masterdata-hero.app-page-header .masterdata-stat-value {
    font-size: 1.22rem;
  }

  .identity-action-list {
    right: auto;
    left: 0;
    width: min(220px, calc(100vw - 32px));
  }

  .record-tabs {
    gap: 0;
  }

  .record-tab {
    flex: 1 1 0;
    padding-right: 8px;
    padding-left: 8px;
    font-size: 0.76rem;
  }

  .status-history-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-history-stat:nth-child(2) {
    border-right: 0;
  }

  .status-history-stat:nth-child(-n + 2) {
    border-bottom: 1px solid #e8ebf0;
  }

  .status-history-panel {
    padding: 14px;
  }

  .status-history-entry {
    padding: 14px 0;
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 10px;
  }

  .status-history-marker {
    width: 30px;
    height: 30px;
  }

  .status-history-heading,
  .status-history-heading > div {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .status-history-content p {
    margin-top: 7px;
    font-size: 0.8rem;
  }

  .control-history-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .control-history-stat {
    min-height: 58px;
    padding: 9px 11px;
    border-right: 1px solid #e8ebf0;
    border-bottom: 1px solid #e8ebf0;
  }

  .control-history-stat:nth-child(3n) {
    border-right: 0;
  }

  .control-history-stat:nth-child(n + 4) {
    border-bottom: 0;
  }

  .control-history-stat:last-child {
    border-right: 0;
  }

  .control-history-filter-panel,
  .control-history-list-panel {
    padding: 14px;
  }

  .control-history-filter-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-history-filter-grid .field:nth-child(4) {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  .control-history-filter-grid .field:nth-child(5) {
    grid-column: 2;
    grid-row: 2;
  }

  .control-history-actions {
    align-items: stretch;
  }

  .control-history-actions .btn,
  .control-history-actions button {
    width: auto;
    flex: 1 1 calc(50% - 4px);
  }

  .control-history-actions > :last-child {
    flex-basis: 100%;
  }

  .control-history-table tbody td {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .main .app-page-header .btn,
  .main .app-page-header button {
    width: auto;
  }

  .main .identity-strip {
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 12px;
    padding: 13px;
  }

  .identity-avatar {
    width: 72px;
    height: 72px;
    flex-basis: 72px;
  }

  .identity-strip h1 {
    font-size: 1.28rem;
  }

  .identity-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .identity-fact {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .resident-identity-strip .hero-photo {
    width: 72px;
    max-width: 72px;
    flex-basis: 72px;
  }

  .resident-identity-strip .photo-dropzone {
    width: 72px;
    min-height: 72px;
  }

  .resident-identity-strip .photo-placeholder,
  .resident-identity-strip .photo-actions {
    display: none;
  }

  .skeleton-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body .report-responsive-table thead th {
    position: static;
  }
}

@media (max-width: 390px) {
  .mobile-appbar-context {
    font-size: 0.68rem;
  }

  .record-tab {
    padding-right: 4px;
    padding-left: 4px;
    font-size: 0.68rem;
  }

  .record-tab .ui-icon {
    display: none;
  }
}

@media (max-width: 340px) {
  .identity-facts {
    grid-template-columns: 1fr;
  }

  .control-history-summary,
  .control-history-filter-grid,
  .status-history-summary {
    grid-template-columns: 1fr;
  }

  .status-history-stat,
  .status-history-stat:nth-child(2),
  .status-history-stat:nth-child(-n + 2) {
    border-right: 0;
    border-bottom: 1px solid #e8ebf0;
  }

  .status-history-stat:last-child {
    border-bottom: 0;
  }

  .control-history-filter-grid .field:nth-child(4) {
    grid-column: auto;
    grid-row: auto;
  }

  .control-history-filter-grid .field:nth-child(5) {
    grid-column: auto;
    grid-row: auto;
  }

  .control-history-stat,
  .control-history-stat:nth-child(3n),
  .control-history-stat:last-child {
    border-right: 0;
    border-bottom: 1px solid #e8ebf0;
  }

  .control-history-stat:last-child {
    border-bottom: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .topbar .topbar-inner,
  .nav-drawer-backdrop,
  .skeleton-line,
  .skeleton-block,
  .media-loading::after {
    transition: none;
    animation: none;
  }
}
