﻿/* Icon button */
.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-height-m);
  height: var(--control-height-m);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-8);
  background: transparent;
  color: var(--text-secondary);
  transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.icon-btn:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
}

/* A header icon that reflects a live on/off state (Clock In/Out, Counter
   Open/Close) starts muted like any inactive control - same as a plain
   .icon-btn - and only shows brand color while aria-pressed="true",
   reverting to muted the moment the state turns off again. The doubled
   class selector beats :hover's specificity so the tint holds even while
   hovering a pressed button. */
.icon-btn.icon-btn--stateful {
  color: var(--text-secondary);
}

.icon-btn.icon-btn--stateful[aria-pressed="true"],
.icon-btn.icon-btn--stateful.is-active {
  color: var(--brand-primary);
}

.icon-btn--sm {
  width: 28px;
  height: 28px;
}

.icon-btn__badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-8);
  background: var(--danger);
  color: var(--text-inverse);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  text-align: center;
}

/* Header dropdown menus */
.header-menu {
  position: relative;
}

.header-menu__panel {
  position: absolute;
  top: calc(100% + var(--space-8));
  left: 0;
  width: 280px;
  padding: var(--space-8);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-12);
  background: var(--bg-surface);
  box-shadow: var(--shadow-none);
  z-index: 50;
  display: none;
  flex-direction: column;
  gap: var(--space-4);
}

.header-menu__panel--right {
  left: auto;
  right: 0;
}

.header-menu.is-open .header-menu__panel {
  display: flex;
}

.header-menu__title {
  padding: var(--space-8) var(--space-8);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
}

.header-menu__title--row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
}

.header-menu__clear {
  padding: 0;
  border: none;
  background: none;
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--brand-primary);
  cursor: pointer;
}

.header-menu__clear:hover {
  text-decoration: underline;
}

.header-menu__clear:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  text-decoration: none;
}

.header-menu__row {
  display: flex;
  align-items: stretch;
  gap: var(--space-4);
}

.header-menu__row .header-menu__item {
  flex: 1;
  min-width: 0;
}

.header-menu__item-action {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 32px;
  border: none;
  border-radius: var(--radius-8);
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}

.header-menu__item-action:hover {
  background: var(--bg-page);
  color: var(--text-primary);
}

.header-menu__item-action .material-symbols-rounded {
  font-size: var(--icon-size-s);
}

.header-menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  padding: var(--space-8);
  border-radius: var(--radius-8);
  color: var(--text-secondary);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
}

.header-menu__item:hover {
  background: var(--bg-page);
  color: var(--text-primary);
}

.header-menu__item .material-symbols-rounded {
  font-size: var(--icon-size-s);
  color: var(--text-muted);
}

.header-menu__item-text {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.header-menu__item-title {
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
}

.header-menu__item-meta {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
}

.header-menu__footer {
  display: block;
  margin-top: var(--space-4);
  padding: var(--space-8);
  text-align: center;
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--brand-primary);
  border-top: 1px solid var(--border-default);
}

/* Profile trigger */
.profile-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  height: var(--control-height-m);
  padding: var(--space-4) var(--space-8);
  border: 1px solid transparent;
  border-radius: var(--radius-8);
  background: transparent;
}

.avatar {
  display: grid;
  place-items: center;
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: var(--radius-8);
  background: var(--brand-primary);
  color: var(--text-inverse);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  flex-shrink: 0;
}

.profile-trigger__text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: var(--leading-tight);
}

.profile-trigger__name {
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
}

.profile-trigger__role {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
}

@media (max-width: 767px) {
  .profile-trigger__text {
    display: none;
  }
}

/* Sidebar navigation */
.app-nav {
  padding: var(--space-8);
}

.app-nav__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.app-nav__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-8);
  border-radius: var(--radius-8);
  color: var(--text-secondary);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
}

.app-nav__link:hover {
  background: var(--bg-page);
  color: var(--text-primary);
}

.app-nav__icon {
  font-size: var(--icon-size-m);
  color: var(--text-muted);
  flex-shrink: 0;
}

.app-nav__text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-nav__soon {
  padding: var(--space-4) var(--space-8);
  border-radius: var(--radius-4);
  background: var(--bg-hover);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  flex-shrink: 0;
}

.app-nav__link.is-active {
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
  font-weight: var(--weight-semibold);
}

.app-nav__link.is-active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: var(--space-8);
  bottom: var(--space-8);
  width: 3px;
  border-radius: var(--radius-4);
  background: var(--brand-primary);
}

.app-nav__link.is-disabled {
  color: var(--text-muted);
  cursor: default;
  pointer-events: none;
}

.app-nav__link.is-disabled .app-nav__icon {
  color: var(--text-muted);
}

/* Left-nav + right-content shell for pages with multiple settings-style
   sections (Settings, Master) - same active/hover language as .app-nav__link. */
.settings-shell {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: var(--space-24);
  align-items: start;
}

.settings-shell__nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  position: sticky;
  top: var(--space-16);
}

.settings-shell__nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-8) var(--space-12);
  border: 0;
  border-radius: var(--radius-8);
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  text-align: left;
  cursor: pointer;
}

.settings-shell__nav-item:hover {
  background: var(--bg-page);
  color: var(--text-primary);
}

.settings-shell__nav-item.is-active {
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
  font-weight: var(--weight-semibold);
}

.settings-shell__nav-item.is-active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: var(--space-8);
  bottom: var(--space-8);
  width: 3px;
  border-radius: var(--radius-4);
  background: var(--brand-primary);
}

.settings-shell__pane {
  min-width: 0;
}

/* Each pane's wrapper div lost .workspace's flex gap once nested a level
   deeper inside .settings-shell__pane - restore it here so a pane with more
   than one card (e.g. Master's form-card + table-card) still gets spacing
   between them. */
.settings-shell__pane > div {
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

@media (max-width: 767px) {
  .settings-shell {
    grid-template-columns: 140px 1fr;
    gap: var(--space-12);
  }

  .settings-shell__nav-item {
    padding: var(--space-8);
    font-size: var(--text-xs);
  }
}

/* Sidebar module groups (parent module + child sub-pages) */
.app-nav__group {
  border-radius: var(--radius-8);
}

.app-nav__group-toggle {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-8);
  border-radius: var(--radius-8);
  color: var(--text-secondary);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  cursor: pointer;
  list-style: none;
}

.app-nav__group-toggle::-webkit-details-marker {
  display: none;
}

.app-nav__group-toggle:hover {
  background: var(--bg-page);
  color: var(--text-primary);
}

.app-nav__caret {
  font-size: var(--icon-size-s);
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform var(--duration-fast) var(--ease-standard);
}

.app-nav__group[open] > .app-nav__group-toggle .app-nav__caret {
  transform: rotate(90deg);
}

.app-nav__children {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-top: var(--space-4);
  padding-left: var(--space-12);
  border-left: 1px solid var(--border-default);
  margin-left: var(--space-12);
}

.app-nav__children .app-nav__link {
  padding: var(--space-8) var(--space-8);
}

/* Page header */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-12);
  flex-wrap: wrap;
}

.page-header__title {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

.page-header__desc {
  margin-top: var(--space-4);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
}

.page-header__actions {
  display: flex;
  gap: var(--space-8);
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  height: var(--control-height-m);
  padding: 0 var(--space-12);
  border: 1px solid transparent;
  border-radius: var(--radius-8);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  white-space: nowrap;
  transition: background var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard);
}

.btn .material-symbols-rounded {
  font-size: var(--icon-size-s);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--brand-primary);
  color: var(--text-inverse);
}

.btn--primary:hover {
  filter: brightness(1.05);
}

.btn--secondary {
  background: var(--bg-surface);
  border-color: var(--border-default);
  color: var(--text-primary);
}

.btn--secondary:hover {
  background: var(--bg-page);
  border-color: var(--border-strong);
}

.btn--destructive {
  background: var(--danger);
  color: var(--text-inverse);
}

.btn--destructive:hover {
  filter: brightness(1.05);
}

/* Loading feedback (design.md Animation System - the sanctioned exception to
   "avoid continuous animation": a spinner is the standard way to represent
   an in-flight request). window.setButtonLoading() in app.js toggles this. */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  opacity: 0.8;
  animation: spin 0.6s linear infinite;
}

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

.btn.is-loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.icon-btn.is-loading {
  color: transparent;
  pointer-events: none;
}

.btn.is-loading .spinner,
.icon-btn.is-loading .spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -7px 0 0 -7px;
  color: var(--text-secondary);
}

.btn--primary.is-loading .spinner, .btn--destructive.is-loading .spinner {
  color: var(--text-inverse);
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 1.5s;
  }
}

/* Filter bar */
.filter-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-12);
  flex-wrap: wrap;
  padding: var(--space-12);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-12);
  background: var(--bg-surface);
}

.filter-bar__group {
  display: flex;
  align-items: flex-end;
  gap: var(--space-12);
  flex-wrap: wrap;
}

/* A filter-bar pairing a period segmented control with a From/To date
   range (Dashboard, Recharge, and any future page using the same shape)
   has few enough controls to always fit one row instead of wrapping -
   scoped to filter-bars that actually contain .filter-bar__group--dates
   so pages with more/variable filter buttons (People, Drawer, Recharge's
   own network filter, etc.) keep the default wrapping behavior above. */
.filter-bar:has(.filter-bar__group--dates) {
  flex-wrap: nowrap;
}

.filter-bar:has(.filter-bar__group--dates) .segmented {
  flex-wrap: nowrap;
}

.filter-bar:has(.filter-bar__group--dates) .segmented__btn {
  white-space: nowrap;
}

/* From/To are a single date-range control and should never split apart
   from each other. Narrower date inputs so period buttons + From + To
   all fit one row without a scrollbar - 100px clips "DD/MM/YYYY" against
   the icon's padding-right, 120px clears it. */
.filter-bar__group--dates {
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.filter-bar__group--dates .date-picker__input {
  width: 120px;
}

@media (max-width: 639px) {
  .filter-bar:has(.filter-bar__group--dates) {
    flex-direction: row;
    align-items: flex-end;
  }
}

/* Every segmented option carries an icon, so all of them share one layout:
   icon and text centred on one line with a small gap. */
.segmented__btn,
.segmented__btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
}

.segmented__btn .material-symbols-rounded {
  font-size: var(--icon-size-s);
}

@media (max-width: 1023px) {
  .segmented__btn .material-symbols-rounded {
    display: none;
  }
}

/* Segmented control */
.segmented {
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
  /* Same height as inputs; long option lists wrap onto extra rows. */
  min-height: var(--control-height-m);
  padding: var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  background: var(--bg-page);
  flex-wrap: wrap;
  row-gap: var(--space-4);
}

.segmented--equal {
  display: flex;
  width: 100%;
}

.segmented--equal .segmented__btn {
  /* Share the width evenly; wrap only when options genuinely do not fit. */
  flex: 1 1 0;
  min-width: max-content;
  padding: 0 var(--space-4);
  text-align: center;
}

.segmented__btn {
  /* Fills the 36px control: 36 - 2 x 4px padding - 2 x 1px border = 26px. */
  height: calc(var(--control-height-m) - 2 * var(--space-4) - 2px);
  border: 1px solid transparent;
  background: transparent;
  padding: 0 var(--space-12);
  /* Inner corner one step below the group's 8px. */
  border-radius: var(--radius-4);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
  white-space: nowrap;
  transition: background var(--duration-fast) var(--ease-standard), color var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard);
}

.segmented__btn:hover {
  color: var(--text-primary);
}

.segmented__btn.is-active {
  background: var(--bg-surface);
  color: var(--brand-primary);
  border: 1px solid var(--border-default);
}

.segmented__btn:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Fields */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

.field--row {
  flex-direction: row;
  align-items: center;
  gap: var(--space-8);
}

.field--row .field__label {
  white-space: nowrap;
}

.field__label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
}

.field__label-icon {
  font-size: var(--icon-size-s);
  color: var(--text-muted);
}

.field__control {
  height: var(--control-height-m);
  padding: 0 var(--space-12);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  background: var(--bg-surface);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
}

.field__control:focus {
  outline: none;
  border-color: var(--border-focus);
}

.field__control:disabled,
.field__control[readonly] {
  background: var(--bg-page);
  color: var(--text-muted);
  cursor: not-allowed;
}

.field-prefix {
  position: relative;
  display: flex;
  align-items: center;
}

.field-prefix__symbol {
  position: absolute;
  left: var(--space-12);
  color: var(--text-muted);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  pointer-events: none;
}

.field-prefix__control {
  width: 100%;
  padding-left: 32px;
}

/* Form card (create/edit workspace used across module pages) */
.form-card {
  padding: var(--card-padding);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

.form-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-8);
}

.form-card__code {
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
  white-space: nowrap;
}

.form-card__title {
  font-size: var(--text-m);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

.form-card__error {
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--danger);
  background: var(--danger-soft);
  padding: var(--space-8) var(--space-12);
  border-radius: var(--radius-8);
}

.form-card__success {
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--success);
  background: var(--success-soft);
  padding: var(--space-8) var(--space-12);
  border-radius: var(--radius-8);
}

.form-card__actions {
  display: flex;
  gap: var(--space-8);
  justify-content: flex-end;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-12);
}

.form-grid--4 {
  grid-template-columns: repeat(4, 1fr);
}

.form-grid--2 {
  grid-template-columns: repeat(2, 1fr);
}

/* Master > Drawer: name gets two-thirds, status one-third. */
.form-grid--drawer {
  grid-template-columns: 2fr 1fr;
}

.form-grid--8 {
  grid-template-columns: repeat(8, 1fr);
}

.form-grid--5 {
  grid-template-columns: repeat(5, 1fr);
}

.form-grid--16 {
  grid-template-columns: repeat(16, 1fr);
}

.form-grid--6 {
  grid-template-columns: repeat(6, 1fr);
}

.form-grid--20 {
  grid-template-columns: repeat(20, 1fr);
}

.form-grid--24 {
  grid-template-columns: repeat(24, 1fr);
}

.field--span-2 {
  grid-column: span 2;
}

.field--span-3 {
  grid-column: span 3;
}

.field--span-4 {
  grid-column: span 4;
}

.field--span-5 {
  grid-column: span 5;
}

.field--span-12 {
  grid-column: span 12;
}

.field--col-4 {
  grid-column: 4;
}

@media (min-width: 768px) and (max-width: 1023px) {
  .form-grid--4,
  .form-grid--5,
  .form-grid--6,
  .form-grid--8,
  .form-grid--16,
  .form-grid--20,
  .form-grid--24 {
    grid-template-columns: repeat(2, 1fr);
  }

  .field--span-3,
  .field--span-4,
  .field--span-5,
  .field--span-12,
  .field--col-4 {
    grid-column: span 2;
  }
}

@media (max-width: 767px) {
  .form-grid,
  .form-grid--drawer,
  .form-grid--4,
  .form-grid--2,
  .form-grid--5,
  .form-grid--6,
  .form-grid--8,
  .form-grid--16,
  .form-grid--20,
  .form-grid--24 {
    grid-template-columns: 1fr;
  }

  .field--span-2,
  .field--span-3,
  .field--span-4,
  .field--span-5,
  .field--span-12,
  .field--col-4 {
    grid-column: auto;
  }
}

/* Summary list (key/value rows used in payment panels and view modals) */
.summary-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  overflow: hidden;
}

.summary-list__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
  margin: 0;
  padding: var(--space-12) var(--space-12);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
  background: var(--bg-surface);
}

.summary-list__row + .summary-list__row {
  border-top: 1px solid var(--border-default);
}

.summary-list__row dt {
  font-weight: var(--weight-regular);
}

.summary-list__row dd {
  margin: 0;
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  text-align: right;
}

.summary-list__row--strong {
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-4);
  background: var(--bg-page);
}

.summary-list__row--strong dt {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.summary-list__row--strong dd {
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
  text-align: left;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-scrim);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--space-12);
  opacity: 0;
  transition: opacity var(--duration-base) var(--ease-standard);
}

.modal-overlay.is-open {
  opacity: 1;
}

.modal {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - var(--space-12) * 2);
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-12);
  box-shadow: var(--shadow-none);
  display: flex;
  flex-direction: column;
  transform: translateY(var(--space-8)) scale(0.98);
  transition: transform var(--duration-base) var(--ease-standard);
}

.modal-overlay.is-open .modal {
  transform: translateY(0) scale(1);
}

@media (prefers-reduced-motion: reduce) {
  .modal-overlay,
  .modal {
    transition: none;
  }
}

.modal--wide {
  max-width: 720px;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
  padding: var(--dialog-padding);
  border-bottom: 1px solid var(--border-default);
}

.modal__header--plain {
  border-bottom: 0;
}

.modal__header--tall {
  align-items: flex-start;
}

.modal__header-start {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.modal__title {
  font-size: var(--text-l);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

.modal__header-end {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.modal__body {
  padding: var(--dialog-padding);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

.modal__text {
  margin: 0;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-8);
  padding: var(--dialog-padding);
  border-top: 1px solid var(--border-default);
}

.modal__footer--plain {
  border-top: 0;
}

/* Printing a View modal's Print button: window.print() always prints the whole
   page, so while a modal is open, hide everything else and let only the modal
   content flow onto the page (its own action buttons excluded). Gated on
   body.has-modal (toggled by modal.js) rather than :has(.modal-overlay) -
   :has() support inside @media print has been inconsistent, and a
   fixed-position element that isn't correctly repositioned here typically
   prints as a blank page rather than failing loudly. */
@media print {
  body.has-modal .app-shell {
    display: none;
  }

  body.has-modal .modal-overlay {
    position: static;
    background: none;
    padding: 0;
    display: block;
  }

  body.has-modal .modal {
    max-width: none;
    max-height: none;
    border: 0;
    /* Short modal content (a plain summary list, a bulk-export table) would
       otherwise leave the page's gray canvas showing below it instead of a
       full white fill, for every printed modal, not just document-style
       ones. On paper this is A4 (297mm) minus @page's 24mm margin on both
       top and bottom = 249mm, but binary-searching actual print renders
       found this browser's real usable page height for this layout lands
       between 247mm and 248mm, not the theoretical 249mm - at 248mm or
       above, the modal box's own forced height tips a hair past the real
       page boundary and spills a blank second page for every short,
       single-page document (Letter, Invoice, etc.). 246mm stays safely
       under that measured edge; the couple of millimetres of shortfall on
       the white fill isn't visible. */
    min-height: 246mm;
  }

  .modal__header,
  .modal__footer {
    display: none;
  }

  /* The modal's own padding would bypass doc-page's fixed
     __header/__footer bands, which anchor to the page box itself. */
  .modal__body:has(.doc-page) {
    padding: 0;
  }

  /* Most pages don't load print.css (that's only pulled in by the handful of
     controllers with a real document to print), so without this the browser
     falls back to its own default print margins, which don't match the
     min-height above and leaves a gray gap at the bottom of the page. */
  @page {
    size: A4;
    margin: 24mm;
  }
}

/* Toast (transient status notifications, stacked bottom-right) */
.toast-stack {
  position: fixed;
  right: var(--space-12);
  bottom: var(--space-12);
  z-index: 200;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-8);
  width: 100%;
  max-width: 360px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--space-8);
  padding: var(--card-padding);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-12);
  background: var(--bg-surface);
  box-shadow: var(--shadow-none);
  opacity: 0;
  transform: translateY(var(--space-8));
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(var(--space-4));
}

.toast__icon {
  flex-shrink: 0;
  margin-top: 1px;
}

.toast__body {
  flex: 1;
  min-width: 0;
}

.toast__title {
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
}

.toast__message {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
  margin-top: var(--space-4);
}

.toast__close {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 0;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
}

.toast__close .material-symbols-rounded {
  font-size: var(--icon-size-s);
}

.toast--success { border-color: var(--success-soft); background: var(--success-soft); }
.toast--success .toast__icon { color: var(--success); }
.toast--success .toast__title { color: var(--success); }

.toast--error { border-color: var(--danger-soft); background: var(--danger-soft); }
.toast--error .toast__icon { color: var(--danger); }
.toast--error .toast__title { color: var(--danger); }

.toast--warning { border-color: var(--warning-soft); background: var(--warning-soft); }
.toast--warning .toast__icon { color: var(--warning); }
.toast--warning .toast__title { color: var(--warning); }

.toast--info { border-color: var(--info-soft); background: var(--info-soft); }
.toast--info .toast__icon { color: var(--info); }
.toast--info .toast__title { color: var(--info); }

@media (max-width: 639px) {
  .toast-stack {
    left: var(--space-12);
    right: var(--space-12);
    max-width: none;
  }
}

/* Combobox (search & dropdown for relational fields) */
.combobox {
  position: relative;
}

.combobox__control {
  position: relative;
  display: flex;
  align-items: center;
}

.combobox__input {
  width: 100%;
  padding-right: calc(var(--space-12) + var(--icon-size-s));
}

.combobox__icon {
  position: absolute;
  right: var(--space-12);
  color: var(--text-muted);
  font-size: var(--icon-size-s);
  pointer-events: none;
}

.combobox__list {
  position: absolute;
  top: calc(100% + var(--space-4));
  left: 0;
  right: 0;
  z-index: 30;
  max-height: 240px;
  overflow-y: auto;
  margin: 0;
  padding: var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  background: var(--bg-surface);
  box-shadow: var(--shadow-none);
  animation: dropdown-panel-in var(--duration-fast) var(--ease-standard);
}

/* Shared entrance animation for dropdown-style panels (combobox list,
   date-picker/time-picker panels) - these toggle the `hidden` attribute
   rather than a class, so a CSS transition (which needs two committed
   states) can't drive them; a keyframe animation plays automatically the
   moment `hidden` is removed and the element becomes displayable. There is
   no matching exit animation since removing `hidden` again is instant. */
@keyframes dropdown-panel-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .combobox__list,
  .date-picker__panel,
  .time-picker__panel {
    animation: none;
  }
}

/* Password / PIN field with inline show-hide toggle */
.password-field {
  position: relative;
  display: flex;
  align-items: center;
}

.password-field__input {
  width: 100%;
  padding-right: calc(var(--space-8) + 20px + var(--space-4));
}

.password-field__toggle {
  position: absolute;
  right: var(--space-8);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: var(--radius-4);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.password-field__toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.password-field__toggle .material-symbols-rounded {
  font-size: var(--icon-size-s);
}

/* Password / PIN strength meter */
.password-strength {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin-top: var(--space-8);
}

.password-strength__track {
  flex: 1;
  display: flex;
  gap: var(--space-4);
}

.password-strength__segment {
  height: 4px;
  flex: 1;
  border-radius: var(--radius-4);
  background: var(--border-default);
}

.password-strength__segment.is-filled--weak {
  background: var(--danger);
}

.password-strength__segment.is-filled--medium {
  background: var(--warning);
}

.password-strength__segment.is-filled--strong {
  background: var(--success);
}

.password-strength__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
  white-space: nowrap;
}

.password-strength__label--weak {
  color: var(--danger);
}

.password-strength__label--medium {
  color: var(--warning);
}

.password-strength__label--strong {
  color: var(--success);
}

.combobox__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-8);
  padding: var(--space-8) var(--space-8);
  border-radius: var(--radius-8);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
  cursor: pointer;
}

.combobox__option.is-active {
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
}

.combobox__option-meta {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
  flex-shrink: 0;
}

.combobox__option.is-active .combobox__option-meta {
  color: var(--brand-primary);
}

.combobox__empty {
  padding: var(--space-8);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
  text-align: center;
}

/* Time picker */
.time-picker {
  position: relative;
}

.time-picker__control {
  position: relative;
  display: flex;
  align-items: center;
}

.time-picker__input {
  width: 100%;
  padding-right: calc(var(--space-12) + var(--icon-size-s));
  cursor: pointer;
}

.time-picker__icon {
  position: absolute;
  right: var(--space-12);
  color: var(--text-muted);
  font-size: var(--icon-size-s);
  pointer-events: none;
}

.time-picker__panel {
  position: fixed;
  top: calc(100% + var(--space-4));
  left: 0;
  /* Portalled to document.body while open (see time-picker.js) - a sibling
     of .modal-overlay (z-index 100), so this must clear that to render on
     top of an open modal instead of behind it. */
  z-index: 150;
  width: 224px;
  padding: var(--space-8);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  background: var(--bg-surface);
  box-shadow: var(--shadow-none);
  animation: dropdown-panel-in var(--duration-fast) var(--ease-standard);
}

.time-picker__columns {
  display: flex;
  gap: var(--space-4);
}

.time-picker__col {
  flex: 1;
  max-height: 176px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.time-picker__col--meridiem {
  flex: 0 0 56px;
  max-height: none;
  overflow: visible;
}

.time-picker__option {
  padding: var(--space-8) var(--space-8);
  border-radius: var(--radius-8);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
  text-align: center;
  cursor: pointer;
}

.time-picker__option:hover {
  background: var(--bg-hover);
}

.time-picker__option.is-active {
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
  font-weight: var(--weight-semibold);
}

.time-picker__footer {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin-top: var(--space-8);
  padding-top: var(--space-8);
  border-top: 1px solid var(--border-default);
}

.time-picker__quick,
.time-picker__done {
  flex: 1;
  height: 28px;
  border: 1px solid transparent;
  border-radius: var(--radius-8);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  cursor: pointer;
}

.time-picker__quick {
  background: var(--bg-page);
  border-color: var(--border-default);
  color: var(--text-secondary);
}

.time-picker__quick:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.time-picker__done {
  background: var(--brand-primary);
  color: var(--text-inverse);
}

.time-picker__done:hover {
  filter: brightness(1.05);
}

/* Date picker */
.date-picker {
  position: relative;
}

.date-picker__control {
  position: relative;
  display: flex;
  align-items: center;
}

.date-picker__input {
  width: 100%;
  padding-right: calc(var(--space-12) + var(--icon-size-s));
  cursor: pointer;
}

.date-picker__icon {
  position: absolute;
  right: var(--space-12);
  color: var(--text-muted);
  font-size: var(--icon-size-s);
  pointer-events: none;
}

.date-picker__panel {
  position: fixed;
  top: calc(100% + var(--space-4));
  left: 0;
  /* Portalled to document.body while open (see date-picker.js) - a sibling
     of .modal-overlay (z-index 100), so this must clear that to render on
     top of an open modal instead of behind it. */
  z-index: 150;
  width: 264px;
  padding: var(--space-8);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  background: var(--bg-surface);
  box-shadow: var(--shadow-none);
  animation: dropdown-panel-in var(--duration-fast) var(--ease-standard);
}

.date-picker__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-8);
}

.date-picker__label {
  font-size: var(--text-s);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.date-picker__nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--radius-8);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.date-picker__nav:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.date-picker__nav .material-symbols-rounded {
  font-size: var(--icon-size-s);
}

.date-picker__weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.date-picker__weekdays span {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  color: var(--text-muted);
  text-align: center;
}

.date-picker__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--space-4);
}

.date-picker__day {
  height: 30px;
  border: 0;
  border-radius: var(--radius-8);
  background: transparent;
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  color: var(--text-primary);
  cursor: pointer;
}

.date-picker__day:hover {
  background: var(--bg-hover);
}

.date-picker__day.is-adjacent {
  color: var(--text-muted);
}

.date-picker__day.is-today {
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.date-picker__day.is-active {
  background: var(--brand-primary);
  color: var(--text-inverse);
  font-weight: var(--weight-semibold);
}

.date-picker__footer {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin-top: var(--space-8);
  padding-top: var(--space-8);
  border-top: 1px solid var(--border-default);
}

.date-picker__quick,
.date-picker__done {
  flex: 1;
  height: 28px;
  border: 1px solid transparent;
  border-radius: var(--radius-8);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  cursor: pointer;
}

.date-picker__quick {
  background: var(--bg-page);
  border-color: var(--border-default);
  color: var(--text-secondary);
}

.date-picker__quick:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.date-picker__done {
  background: var(--brand-primary);
  color: var(--text-inverse);
}

.date-picker__done:hover {
  filter: brightness(1.05);
}

/* Health check page - a hero banner with the aggregate status, plus a
   grid of small labelled check cards grouped into sections (Application,
   Database, Infrastructure, Automation, Backup & Mail) rather than one
   long vertical table. */
/* Package page's 4 pipeline stages (Build/Download/Upload/Deploy), each
   its own ring card - a fixed identity color per stage (blue/green/red/
   amber), same convention as the Health pillars. */
.package-ring-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-12);
}

.package-ring-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-8);
  padding: var(--space-16);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-12);
  background: var(--bg-surface);
}

.package-ring-card__title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.package-ring-card__status {
  font-size: var(--text-s);
  color: var(--text-secondary);
  min-height: 18px;
}

.package-ring-card .btn {
  width: 100%;
  justify-content: center;
}

/* Health Trend chart (2/3) + Health Status Matrix (1/3) side by side. */
.health-overview-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-12);
  align-items: start;
}

.health-matrix-row__meta {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  margin-left: auto;
  flex-shrink: 0;
}

.health-matrix-row__time {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Health page hero: three pillar cards (Application/Database/System),
   each a real ring of that pillar's own checks-passing % - never one
   combined score split three ways. */
.health-pillar-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-12);
}

.health-pillar {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-16);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-12);
  background: var(--bg-surface);
}

.health-pillar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: var(--space-8);
}

.health-pillar__title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.health-pillar__header .status {
  flex-shrink: 0;
}

.health-pillar__ring {
  margin: var(--space-16) 0 var(--space-8);
}

.health-pillar__caption {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.health-pillar__summary {
  margin-top: var(--space-4);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.health-pillar__footer {
  width: 100%;
  margin-top: var(--space-16);
  padding-top: var(--space-12);
  border-top: 1px solid var(--border-light);
  text-align: left;
}

.health-pillar__footer-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.health-pillar__footer-value {
  margin-top: var(--space-4);
  font-size: var(--text-s);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* Small leading dot on a .status pill (used in the health-pillar header)
   - inherits its color from the pill's own text color, no new token. */
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* Health page detail: three label/value diagnostic panels (Application/
   Database/System), one per pillar above - a dense "spec sheet" list
   rather than another row of icon chips and tags. */
.diagnostic-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-12);
  align-items: start;
}

.diagnostic-panel {
  padding: var(--space-16);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-12);
  background: var(--bg-surface);
}

.diagnostic-panel__title {
  padding-bottom: var(--space-8);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-default);
  font-size: var(--text-m);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  color: var(--text-primary);
}

.diagnostic-list__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-8);
  padding: var(--space-8) 0;
  border-bottom: 1px solid var(--border-light);
}

.diagnostic-list__row:last-child {
  border-bottom: 0;
}

.diagnostic-list__row dt {
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.diagnostic-list__row dd {
  margin: 0;
  min-width: 0;
  font-size: var(--text-s);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* Tone set by health.php: class="is-' . $tone . '" */
.diagnostic-list__row dd.is-success { color: var(--success); }
.diagnostic-list__row dd.is-warning { color: var(--warning); }
.diagnostic-list__row dd.is-danger { color: var(--danger); }

/* KPI cards - one shared design for the whole project via View::kpiCard().
   Borderless white tile: a small colored icon inline with the uppercase
   label (no separate icon-chip column), bold tabular value, trend line,
   and an optional full-bleed sparkline (only pages that pass $sparkId
   get one - currently just the dashboard). */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-12);
}

.kpi-card {
  position: relative;
  padding: var(--card-padding);
  border-radius: var(--radius-8);
  overflow: hidden;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
  min-width: 0;
}

.kpi-card__label {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-card__label .material-symbols-rounded {
  font-size: var(--icon-size-s);
}

.kpi-card--info .kpi-card__label .material-symbols-rounded {
  color: var(--info);
}

.kpi-card--warning .kpi-card__label .material-symbols-rounded {
  color: var(--warning);
}

.kpi-card--danger .kpi-card__label .material-symbols-rounded {
  color: var(--danger);
}

.kpi-card--success .kpi-card__label .material-symbols-rounded {
  color: var(--success);
}

.kpi-card__value {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kpi-card__trend {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
}

.kpi-card__trend .material-symbols-rounded {
  font-size: var(--icon-size-s);
}

.kpi-card__trend--up {
  color: var(--success);
}

.kpi-card__trend--down {
  color: var(--danger);
}

.kpi-card__trend--neutral {
  color: var(--text-muted);
}

/* A neutral caption's icon uses its card's color; only the text stays muted. */
.kpi-card--info .kpi-card__trend--neutral .material-symbols-rounded { color: var(--info); }
.kpi-card--success .kpi-card__trend--neutral .material-symbols-rounded { color: var(--success); }
.kpi-card--danger .kpi-card__trend--neutral .material-symbols-rounded { color: var(--danger); }
.kpi-card--warning .kpi-card__trend--neutral .material-symbols-rounded { color: var(--warning); }

.kpi-card__trend-note {
  color: var(--text-tertiary);
  font-weight: var(--weight-regular);
}

/* No text lives in this svg, so its full-bleed stretch never touches
   font rendering. base.css's global `img, svg { max-width: 100% }`
   reset would otherwise silently clamp the +24px bleed back to 100%. */
.kpi-card__spark {
  display: block;
  max-width: none;
  width: calc(100% + (var(--space-12) * 2));
  height: 30px;
  margin: var(--space-4) calc(var(--space-12) * -1) calc(var(--space-12) * -1);
}

/* Borderless status list - one shared design for any page's "list of
   items with a severity/category icon and a trailing status tag"
   (dashboard's Needs Attention/Recent Activity/Reminders, Counter's
   drawer balances, and any future page needing the same shape). Every
   row's icon chip is colored by severity/category; the trailing tag
   carries the row's status. */
.attention-list {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  overflow: hidden;
}

.attention-row {
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-8) var(--space-12);
  border-top: 1px solid var(--border-light);
}

.attention-row:first-child {
  border-top: 0;
}

.attention-row__icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-8);
  flex-shrink: 0;
}

.attention-row__icon .material-symbols-rounded {
  font-size: var(--icon-size-s);
}

.attention-row--info .attention-row__icon {
  background: var(--info-soft);
  color: var(--info);
}

.attention-row--success .attention-row__icon {
  background: var(--success-soft);
  color: var(--success);
}

.attention-row--warning .attention-row__icon {
  background: var(--warning-soft);
  color: var(--warning);
}

.attention-row--danger .attention-row__icon {
  background: var(--danger-soft);
  color: var(--danger);
}

.attention-row__desc {
  font-size: var(--text-s);
  font-weight: var(--weight-semibold);
  flex-shrink: 0;
}

.attention-row__reason {
  font-size: var(--text-xs);
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Trailing group of small .status pills (e.g. one per checked extension
   or storage path) in place of a single .tag, for attention-rows that
   report on several sub-items at once. */

.tag {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-8);
  border-radius: var(--radius-8);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  flex-shrink: 0;
}

.tag--success {
  background: var(--success-soft);
  color: var(--success);
}

.tag--danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.tag--warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.tag--info {
  background: var(--info-soft);
  color: var(--info);
}

.tag--neutral {
  background: var(--bg-subtle);
  color: var(--text-tertiary);
  font-weight: var(--weight-regular);
  font-variant-numeric: tabular-nums;
}

/* Radial progress ring (e.g. storage/usage percentage) â€” pure CSS, set --value: 0-100 inline */
.radial-progress {
  --value: 0;
  position: relative;
  width: 72px;
  height: 72px;
  min-width: 72px;
  border-radius: 50%;
  background: conic-gradient(var(--brand-primary) calc(var(--value) * 1%), var(--bg-hover) 0);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.radial-progress::before {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--bg-surface);
}

.radial-progress__value {
  position: relative;
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
}

.radial-progress--success {
  background: conic-gradient(var(--success) calc(var(--value) * 1%), var(--bg-hover) 0);
}

.radial-progress--warning {
  background: conic-gradient(var(--warning) calc(var(--value) * 1%), var(--bg-hover) 0);
}

.radial-progress--danger {
  background: conic-gradient(var(--danger) calc(var(--value) * 1%), var(--bg-hover) 0);
}

.radial-progress--lg {
  width: 120px;
  height: 120px;
  min-width: 120px;
}

.radial-progress--lg::before {
  inset: 10px;
}

.radial-progress--lg .radial-progress__value {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

/* Linear progress bar (Package build/upload feedback) - stays visible at 0%
   at rest so the card never looks empty, then fills toward 100% while its
   operation runs. */

.package-action {
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
  padding-top: var(--space-8);
}

.package-action__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-8);
}

/* Charts */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-12);
}

.chart-card--wide {
  grid-column: span 2;
}

.chart-card {
  padding: var(--card-padding);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

.chart-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-8);
}

.chart-card__title {
  font-size: var(--text-m);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

.chart-card__subtitle {
  margin-top: var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
}

.chart-card__body {
  min-height: 220px;
  position: relative;
}

.chart-axis-label {
  font-size: var(--text-xs);
  fill: var(--text-muted);
  font-family: var(--font-primary);
}

.chart-gridline {
  stroke: var(--border-default);
  stroke-width: 1;
}

.chart-card__body--center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.chart-card__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-12);
}

.chart-legend__item {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
}

.chart-legend__swatch {
  width: 14px;
  height: 8px;
  border-radius: var(--radius-4);
  flex-shrink: 0;
}

.chart-legend__value {
  color: var(--text-muted);
}

.chart-legend__item--toggle {
  cursor: pointer;
  align-items: center;
}

.chart-legend__item--toggle input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--brand-primary);
  cursor: pointer;
}

/* Table card */
.table-card {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  background: var(--bg-surface);
  overflow: hidden;
}

.table-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
  flex-wrap: wrap;
  padding: var(--card-padding);
  border-bottom: 1px solid var(--border-default);
}

.table-card__title {
  font-size: var(--text-m);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

.card-subtitle {
  margin-top: var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
}

.table-scroll {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
}

.data-table th,
.data-table td {
  padding: var(--space-8) var(--space-12);
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-default);
}

/* A row's height is just the max of its cells' natural content height, so
   a table whose Action column holds icon-btn--sm buttons (28px, border-box,
   plus this rule's own 2*6px vertical padding = 40px) renders taller rows
   than a table with no action column (plain text or a ~20px .status pill
   only, ~37px total) - e.g. Settlement's own two tables sat at 40.8px vs
   37px side by side. min-height is border-box here (global * reset), so
   this has to state the full target row height, not just the icon's own
   28px - that alone is already smaller than the 37px a plain row renders
   at and has no effect. Giving every cell the same floor makes every
   .data-table's row height match app-wide, action buttons or not. */
.data-table td {
  height: 41px;
}

/* A long free-text column (e.g. a notification message) truncates with an
   ellipsis instead of forcing the whole table wider - full text is still
   available via the row's View action. */
.table-cell--truncate {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.data-table th {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--bg-page);
  text-align: center;
}

.data-table tbody tr {
  transition: background var(--duration-fast) var(--ease-standard);
}

.data-table tbody tr:hover {
  background: var(--bg-page);
}

.data-table .is-numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.data-table th.is-numeric {
  text-align: center;
}

/* A Status pill or a row's action buttons read better centered under
   .data-table th's own centered header text than left-aligned - matched
   by content (every such cell already wraps its contents in .status or
   .row-actions app-wide) rather than a column-index/class the markup
   would otherwise need adding to individually on every table. */
.data-table td:has(.status),
.data-table td:has(.row-actions) {
  text-align: center;
}

.data-table .is-negative {
  color: var(--danger);
  font-weight: var(--weight-semibold);
}

.data-table .transaction-outstanding--unpaid {
  color: var(--danger);
  font-weight: var(--weight-semibold);
}

.data-table .transaction-amount--outflow {
  color: var(--danger);
  font-weight: var(--weight-semibold);
}

.row-actions {
  display: inline-flex;
  gap: var(--space-4);
}

.bulk-select-cell {
  width: var(--control-height-m);
  white-space: nowrap;
}

.bulk-checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--brand-primary);
  cursor: pointer;
}

.data-table tbody tr.is-selected {
  background: var(--bg-hover);
}

.bulk-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
  flex-wrap: wrap;
  padding: var(--space-12) var(--card-padding);
  border-bottom: 1px solid var(--border-default);
  background: var(--bg-page);
}

.bulk-toolbar__count {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
}

.bulk-toolbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  flex-wrap: wrap;
}

.bulk-toolbar__actions [disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.table-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
  flex-wrap: wrap;
  padding: var(--card-padding);
  border-top: 1px solid var(--border-default);
}

.table-card__page-size {
  display: flex;
  align-items: center;
  gap: var(--space-12);
  flex-wrap: wrap;
}

.table-card__page-size-select {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  color: var(--text-muted);
}

.table-card__page-size-select select {
  height: 28px;
  padding: 0 var(--space-8);
  font-size: var(--text-xs);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  background: var(--bg-surface);
  color: var(--text-primary);
}

.table-card__page-size-select .field-icon-wrap {
  width: auto;
}

.table-card__page-size-select select:focus {
  outline: none;
  border-color: var(--border-focus);
}

.table-card__count {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
}

.table-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-8);
  padding: var(--space-12);
  text-align: center;
}

.table-empty .material-symbols-rounded {
  font-size: var(--icon-size-xl);
  color: var(--text-muted);
}

.table-empty__title {
  font-size: var(--text-m);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  color: var(--text-primary);
}

.table-empty__desc {
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
}

/* Error state (404 / 403 / 500 pages) */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-32) var(--space-12);
  text-align: center;
  max-width: 480px;
  margin: 0 auto;
}

.error-state__icon {
  display: grid;
  place-items: center;
  width: 88px;
  height: 88px;
  border-radius: var(--radius-12);
  background: var(--danger-soft);
  color: var(--danger);
}

.error-state__icon .material-symbols-rounded {
  font-size: var(--icon-size-xl);
}

.error-state__code {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.error-state__title {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  color: var(--text-primary);
}

.error-state__desc {
  font-size: var(--text-m);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  line-height: var(--leading-tight);
}

.error-state__actions {
  display: flex;
  gap: var(--space-8);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.pagination__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 var(--space-8);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  background: var(--bg-surface);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-secondary);
}

.pagination__btn:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.pagination__btn.is-active {
  background: var(--brand-primary-soft);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

.pagination__btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination__ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* Status badges */
.status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-8);
  border-radius: var(--radius-8);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  white-space: nowrap;
}

.status--active,
.status--completed,
.status--done,
.status--paid,
.status--approved,
.status--accepted,
.status--posted,
.status--matched,
.status--in-stock,
.status--trusted,
.status--built,
.status--build,
.status--applied,
.status--closed,
.status--success,
.status--healthy,
.status--operational,
.status--uploaded,
.status--upload,
.status--balanced,
.status--full-day {
  background: var(--success-soft);
  color: var(--success);
}

.status--inactive,
.status--cancelled,
.status--dismissed,
.status--expired,
.status--removed,
.status--deleted {
  background: var(--danger-soft);
  color: var(--danger);
}

.status--pending,
.status--draft,
.status--due,
.status--unpaid,
.status--unrefunded,
.status--partially-paid,
.status--partially-refunded,
.status--partially-returned,
.status--discrepancy,
.status--low-stock,
.status--degraded,
.status--scheduled,
.status--staged,
.status--deploy,
.status--in-progress,
.status--overage,
.status--over-paid,
.status--due-tomorrow,
.status--due-today,
.status--maintenance {
  background: var(--warning-soft);
  color: var(--warning);
}

.status--error,
.status--reversed,
.status--refunded,
.status--returned,
.status--overdue,
.status--rejected,
.status--out-of-stock,
.status--revoked,
.status--failed,
.status--down,
.status--critical,
.status--shortage,
.status--remains-overdue {
  background: var(--danger-soft);
  color: var(--danger);
}

.status--info,
.status--upcoming,
.status--open,
.status--clocked-in,
.status--processed,
.status--unread,
.status--sent,
.status--downloaded,
.status--download,
.status--commission,
.status--upcoming-due {
  background: var(--info-soft);
  color: var(--info);
}

/* Priority badges (Workflow module) */
.priority {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-8);
  border-radius: var(--radius-8);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  white-space: nowrap;
}

.priority--high {
  background: var(--danger-soft);
  color: var(--danger);
}

.priority--medium {
  background: var(--warning-soft);
  color: var(--warning);
}

.priority--low {
  background: var(--info-soft);
  color: var(--info);
}

/* Subsection (boxed group nested inside a form-card, e.g. Permission Matrix, Bundle Components) */
.subsection {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  background: var(--bg-page);
  padding: var(--card-padding);
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

.subsection__title {
  font-size: var(--text-m);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
}

/* Variant picker (attribute + value multi-select used by Product/Service/Bundle) */
.variant-picker {
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

.variant-picker__values {
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

.variant-picker__group {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.variant-picker__actions {
  display: flex;
  justify-content: flex-start;
  margin-top: var(--space-12);
}

.variant-picker__grid {
  margin-top: var(--space-12);
}

/* Generated combination grid (inline-editable table cells) */
.data-table__input {
  width: 100%;
  min-width: 80px;
  height: 30px;
  padding: 0 var(--space-8);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-4);
  background: var(--bg-surface);
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
}

.data-table__input:focus {
  outline: none;
  border-color: var(--border-focus);
}

.data-table__input:disabled {
  background: var(--bg-page);
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 1279px) {
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .chart-card--wide {
    grid-column: auto;
  }
}

@media (max-width: 1023px) {
  .kpi-row,
  .health-pillar-row,
  .diagnostic-row,
  .package-ring-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .health-overview-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 639px) {
  .kpi-row,
  .health-pillar-row,
  .diagnostic-row,
  .package-ring-row {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
  }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ---------- Title icons (one design system) ----------
   Page, form, table and chart titles carry data-icon="<material symbol>" and
   an optional data-tone. The icon is drawn as a pseudo-element so scripts that
   read or rewrite a title's textContent never see or remove it.
   Palette is limited to blue (info), green (success), red (danger), amber (warning). */
.page-header__title[data-icon],
.form-card__title[data-icon],
.table-card__title[data-icon],
.chart-card__title[data-icon],
.site-section__title[data-icon] {
  display: flex;
  align-items: center;
  gap: var(--space-12);
}

.page-header__title[data-icon]::before,
.form-card__title[data-icon]::before,
.table-card__title[data-icon]::before,
.chart-card__title[data-icon]::before,
.site-section__title[data-icon]::before {
  content: attr(data-icon);
  font-family: 'Material Symbols Rounded';
  font-weight: normal;
  font-style: normal;
  font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 20;
  font-size: var(--icon-size-m);
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-8);
  background: var(--info-soft);
  color: var(--info);
  user-select: none;
}

.page-header__title[data-icon]::before {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-12);
  font-size: var(--icon-size-l);
}

[data-icon][data-tone="success"]::before { background: var(--success-soft); color: var(--success); }
[data-icon][data-tone="danger"]::before  { background: var(--danger-soft);  color: var(--danger); }
[data-icon][data-tone="warning"]::before { background: var(--warning-soft); color: var(--warning); }

/* ---------- Icon tones (applied by public/js/icon-tone.js) ----------
   One color per icon meaning, everywhere. `body` raises specificity above the
   component defaults that grey icons out (sidebar, header menus, footer, empty states). */
body .material-symbols-rounded.icon--info    { color: var(--info); }
body .material-symbols-rounded.icon--success { color: var(--success); }
body .material-symbols-rounded.icon--danger  { color: var(--danger); }
body .material-symbols-rounded.icon--warning { color: var(--warning); }

/* Icon + text pair used for small inline labels (header menus, footers). */
.with-icon {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
}

.with-icon > .material-symbols-rounded {
  font-size: var(--icon-size-s);
}

.header-menu__footer.with-icon,
.header-menu__item[role="status"] .with-icon {
  display: flex;
  justify-content: center;
}

/* ---------- Field lead icons (added by public/js/field-icons.js) ----------
   Each input box shows its label's icon on the left, in the label icon's color. */
.field-icon-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.field-icon-wrap > .field__control {
  width: 100%;
}

.has-lead-icon > .field__lead-icon {
  position: absolute;
  left: var(--space-12);
  top: 50%;
  transform: translateY(-50%);
  font-size: var(--icon-size-s);
  pointer-events: none;
  z-index: 1;
}

.has-lead-icon--textarea > .field__lead-icon {
  top: var(--space-12);
  transform: none;
}

.has-lead-icon .field__control {
  padding-left: calc(var(--space-12) + var(--icon-size-s) + var(--space-8));
}

/* Money boxes: icon, then "Rs.", then the amount. */
.field-prefix.has-lead-icon .field-prefix__symbol {
  left: calc(var(--space-12) + var(--icon-size-s) + var(--space-8));
}

.field-prefix.has-lead-icon .field-prefix__control {
  padding-left: calc(var(--space-12) + var(--icon-size-s) + var(--space-8) + 28px);
}

/* Table content lines up with the card's 24px side padding. */
.data-table th:first-child,
.data-table td:first-child {
  padding-left: var(--card-padding);
}

.data-table th:last-child,
.data-table td:last-child {
  padding-right: var(--card-padding);
}

/* Date and time boxes show their icon once, on the left (field lead icon);
   the decorative right-side calendar/clock is hidden and its space released. */
.date-picker__icon,
.time-picker__icon {
  display: none;
}

.date-picker__input,
.time-picker__input {
  padding-right: var(--space-12);
}

/* ---------- Profile menu (header) ---------- */
button.profile-trigger {
  font: inherit;
  cursor: pointer;
}

.profile-trigger:hover,
.profile-menu.is-open .profile-trigger {
  background: var(--bg-page);
  border-color: var(--border-default);
}

.profile-trigger__caret {
  font-size: var(--icon-size-s);
  color: var(--text-muted);
  transition: transform var(--duration-fast) var(--ease-standard);
}

.profile-menu.is-open .profile-trigger__caret {
  transform: rotate(180deg);
}

.profile-menu__panel {
  width: 300px;
  font-weight: var(--weight-regular);
}

/* Chip card: who is signed in. */
.profile-chip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-12);
  margin-bottom: var(--space-8);
  padding: var(--space-12);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-8);
  background: var(--bg-page);
}

.avatar--lg {
  width: 44px;
  height: 44px;
  font-size: var(--text-l);
  flex-shrink: 0;
}

.profile-chip__text {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}

.profile-chip__name {
  font-size: var(--text-m);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-chip__email {
  font-size: var(--text-s);
  font-weight: var(--weight-regular);
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-chip__tags {
  /* Own row under avatar and name. */
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

/* Menu items rendered as <button> look the same as the link items. */
button.header-menu__item {
  width: 100%;
  border: 0;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.profile-menu__signout {
  margin-top: var(--space-4);
  border-top: 1px solid var(--border-default) !important;
  border-radius: 0 0 var(--radius-8) var(--radius-8);
}

/* Page permissions (data-can-* on <body>, from the role's grants): controls
   for actions the role may not take are not shown. The server refuses them too. */
body[data-can-edit="0"] .row-actions [data-action="edit"],
body[data-can-delete="0"] .row-actions [data-action="delete"],
body[data-can-delete="0"] [data-bulk-delete],
body[data-can-print="0"] .row-actions [data-action="print"],
body[data-can-download="0"] [data-bulk-excel],
body[data-can-approve="0"] .row-actions [data-action="approve"],
body[data-can-reject="0"] .row-actions [data-action="reject"],
body[data-can-create="0"][data-can-edit="0"] .form-card[id$="FormCard"] {
  display: none !important;
}

/* ---------- Rich text editor (public/js/rich-editor.js) ----------
   Toolbar of small icon buttons over an editable area styled like .field__control. */
.rich-editor { display: flex; flex-direction: column; border: 1px solid var(--border-default); border-radius: var(--radius-8); background: var(--bg-surface); overflow: hidden; }
.rich-editor:focus-within { border-color: var(--border-focus); }
.rich-editor.is-loading { opacity: 0.6; pointer-events: none; }
.rich-editor__toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: var(--space-4) var(--space-8); border-bottom: 1px solid var(--border-default); background: var(--bg-subtle); position: sticky; top: 0; z-index: 1; }
.rich-editor__sep { width: 1px; height: 20px; background: var(--border-default); margin: 0 var(--space-4); }
.rich-editor__area { min-height: 280px; max-height: 70vh; overflow-y: auto; padding: var(--space-16); font-weight: var(--weight-regular); line-height: var(--leading-relaxed); color: var(--text-primary); outline: none; }
.rich-editor__area:empty::before { content: attr(data-placeholder); color: var(--text-muted); }
.rich-editor__area > * + * { margin-top: var(--space-12); }
.rich-editor__area h2 { font-size: var(--text-xl); }
.rich-editor__area h3 { font-size: var(--text-l); }
.rich-editor__area ul, .rich-editor__area ol { padding-left: var(--space-24); list-style: revert; }
.rich-editor__area blockquote { border-left: 3px solid var(--brand-primary); padding-left: var(--space-12); color: var(--text-secondary); }
.rich-editor__area img { max-width: 100%; border-radius: var(--radius-8); }
.rich-editor__area a { text-decoration: underline; }

/* ---------- Photo field (public/js/media-field.js): one cover photo or an ordered gallery ---------- */
.media-field.is-loading { opacity: 0.6; pointer-events: none; }
.media-field__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: var(--space-12); }
.media-field__item { position: relative; aspect-ratio: 1 / 1; border-radius: var(--radius-8); overflow: hidden; border: 1px solid var(--border-default); background: var(--bg-subtle); }
.media-field__item img { width: 100%; height: 100%; object-fit: cover; }
.media-field__actions { position: absolute; right: var(--space-4); bottom: var(--space-4); display: flex; gap: 2px; }
.media-field__actions .icon-btn { background: var(--bg-surface); }
.media-field__badge { position: absolute; left: var(--space-4); top: var(--space-4); padding: 2px var(--space-8); border-radius: var(--radius-20); background: var(--brand-primary); color: var(--text-inverse); font-size: var(--text-xs); }
.media-field__add { aspect-ratio: 1 / 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-4); border: 1px dashed var(--border-strong); border-radius: var(--radius-8); background: var(--bg-surface); color: var(--text-secondary); font-size: var(--text-s); }
.media-field__add:hover { border-color: var(--brand-primary); color: var(--brand-primary); }
