/* Dashboard composition: an operational workspace, not an admin table. */
.dashboard-screen { min-width: 0; }
body.app-shell-sidebar-active #screen-dashboard .dashboard-app-header { display: flex !important; }
.dashboard-app-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 72px; padding: 12px 16px; background: rgba(255,255,255,.9); }
.dashboard-header__copy { min-width: 0; }
.dashboard-header__eyebrow, .dashboard-section-kicker { display: block; color: var(--ink-muted); font-size: 10px; font-weight: 800; letter-spacing: .11em; line-height: 1.3; text-transform: uppercase; }
.dashboard-header__title-row { display: flex; align-items: baseline; gap: 8px; margin-top: 2px; }
.dashboard-header__title-row h1 { margin: 0; color: var(--ink); font-size: 20px; font-weight: 800; letter-spacing: -.025em; }
.dashboard-header__company { overflow: hidden; color: var(--ink-muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.dashboard-header__time { display: block; margin-top: 2px; color: var(--ink-soft); font-size: 10px; }
.dashboard-header__actions { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.dashboard-auto-refresh { display: inline-flex; align-items: center; gap: 7px; padding: 8px 10px; color: var(--ink-soft); background: var(--surface-soft); border-radius: 12px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.dashboard-auto-refresh input { width: 16px; height: 16px; accent-color: var(--coral); }

/* The filter bar owns refresh and filtering. Removing their second entry in
   the app bar keeps the dashboard chrome concise without changing actions. */
#btn-dashboard-refresh,
.dashboard-overview__secondary-action { display: none !important; }

.dashboard-filter-shell { flex: 0 0 auto; width: min(100%, 1440px); margin: 0 auto; padding: 0 16px; }
.dashboard-filter-bar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 10px 0 0; padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-card); }
.dashboard-filter-bar__period { min-width: 0; flex: 1; }
.dashboard-filter-bar__label, .dashboard-filter-field > span:first-child { display: block; margin-bottom: 5px; color: var(--ink-muted); font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.dashboard-filter-bar__period .filter-select { width: min(100%, 260px); }
.dashboard-filter-bar__actions { display: flex; align-items: center; gap: 6px; }
.dashboard-filter-trigger { min-height: 44px; display: inline-flex; align-items: center; gap: 7px; padding: 8px 12px; color: var(--navy); background: var(--surface-blue); border: 0; border-radius: 12px; font: inherit; font-size: 12px; font-weight: 800; white-space: nowrap; }
.dashboard-filter-trigger svg { width: 18px; height: 18px; }
.dashboard-filter-count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding-inline: 5px; color: #fff; background: var(--coral); border-radius: 999px; font-size: 10px; }
.dashboard-filter-refresh { width: 44px; height: 44px; }
.dashboard-filter-panel { margin-top: 10px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-card); }
.dashboard-filter-panel__heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.dashboard-filter-panel__heading strong { display: block; margin-top: 3px; color: var(--ink); font-size: 15px; }
.dashboard-text-action { color: var(--coral); font: inherit; font-size: 12px; font-weight: 800; }
.dashboard-filter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.dashboard-filter-field { min-width: 0; }
.dashboard-filter-field--location { grid-column: 1 / -1; }
.dashboard-filter-field :is(input, select) { width: 100%; }
.dashboard-date-inputs { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 7px; }
.dashboard-date-inputs > span { margin: 0; color: var(--ink-muted); font-size: 12px; text-transform: none; }

.dashboard-main { flex: 1; width: min(100%, 1440px); margin: 0 auto; padding: 16px; overflow-y: auto; }
.dashboard-overview { display: grid; gap: 14px; padding: 22px; overflow: hidden; color: #fff; background: linear-gradient(135deg, var(--navy-dark), var(--navy)); border-radius: var(--radius-large); box-shadow: 0 18px 36px rgba(53,83,111,.18); }
.dashboard-overview__intro { min-width: 0; }
.dashboard-overview .dashboard-section-kicker { color: #c8d9e6; }
.dashboard-overview h2 { max-width: 680px; margin: 5px 0 0; color: #fff; font-size: clamp(23px, 4vw, 31px); font-weight: 800; line-height: 1.18; letter-spacing: -.03em; }
.dashboard-overview p { max-width: 690px; margin: 9px 0 0; color: #dce9f2; font-size: 13px; line-height: 1.6; }
.dashboard-overview__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.dashboard-overview__primary-action { min-width: 170px; }
.dashboard-overview__primary-action svg { width: 18px; height: 18px; }
.dashboard-overview__secondary-action { min-height: 48px; display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; color: #fff; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.19); border-radius: 14px; font: inherit; font-size: 13px; font-weight: 800; }
.dashboard-overview__secondary-action svg { width: 18px; height: 18px; }
.dashboard-attention-card { display: grid; align-content: start; gap: 13px; padding: 16px; color: var(--ink); background: #fff; border-radius: 20px; box-shadow: 0 12px 24px rgba(34,58,80,.14); }
.dashboard-attention-card__header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.dashboard-attention-card__header .dashboard-section-kicker { color: var(--ink-muted); }
.dashboard-attention-card__header strong { display: block; margin-top: 3px; color: var(--ink); font-size: 15px; }
.dashboard-attention-card__status { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 30px; padding: 4px 8px; border: 0; border-radius: 999px; font-size: 12px; font-weight: 800; cursor: pointer; }
.dashboard-attention-card__status.is-urgent { color: #fff; background: var(--coral); }
.dashboard-attention-card__status.is-clear { color: #27834f; background: #e5f6ec; }
.dashboard-attention-card__metric { display: grid; gap: 1px; padding: 0; text-align: inherit; background: transparent; border: 0; cursor: pointer; }
.dashboard-attention-card__metric strong { color: var(--ink); font-size: 34px; line-height: 1; }
.dashboard-attention-card__metric span { color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.dashboard-attention-card__split { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.dashboard-attention-card__split > :is(div, button) { min-width: 0; padding: 9px 7px; text-align: inherit; background: var(--surface-soft); border: 0; border-radius: 10px; cursor: pointer; }
.dashboard-attention-card__split span { display: block; min-height: 25px; color: var(--ink-muted); font-size: 9px; font-weight: 700; line-height: 1.3; }
.dashboard-attention-card__split strong { display: block; margin-top: 2px; color: var(--ink); font-size: 14px; }
.dashboard-attention-card__alert { display: flex; width: 100%; align-items: flex-start; gap: 7px; padding: 9px 10px; color: #ae473d; text-align: inherit; background: #fff0ed; border: 0; border-radius: 10px; font-size: 11px; font-weight: 700; line-height: 1.4; cursor: pointer; }
.dashboard-attention-card__alert--clear { color: #27834f; background: #eaf8ef; }
.dashboard-attention-card__alert-dot { width: 7px; height: 7px; flex: 0 0 7px; margin-top: 4px; background: currentColor; border-radius: 50%; }
.dash-widget[data-dashboard-drill] { cursor: pointer; }
.dash-widget[data-dashboard-drill]:focus-visible { outline: 3px solid var(--clr-primary); outline-offset: 3px; }

.dash-kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.dashboard-kpi-card { min-width: 0; min-height: 186px; display: grid; grid-template-rows: auto 1fr auto; gap: 15px; padding: 16px; color: var(--ink); text-align: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card); box-shadow: var(--shadow-card); }
.dashboard-kpi-card:hover { transform: translateY(-2px); border-color: #d2e0e9; box-shadow: var(--shadow-raised); }
.dashboard-kpi-card__top { display: grid; grid-template-columns: 34px minmax(0, 1fr) 18px; align-items: center; gap: 9px; }
.dashboard-kpi-card__icon { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; color: var(--coral); background: var(--coral-soft); border-radius: 11px; }
.dashboard-kpi-card__icon svg { width: 18px; height: 18px; }
.dashboard-kpi-card__copy { display: grid; min-width: 0; gap: 1px; }
.dashboard-kpi-card__title { overflow: hidden; color: var(--ink); font-size: 11px; font-weight: 800; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.dashboard-kpi-card__context { color: var(--ink-muted); font-size: 10px; }
.dashboard-kpi-card__chevron { width: 17px; height: 17px; color: var(--ink-muted); }
.dashboard-kpi-card__value-row { display: flex; align-items: end; justify-content: space-between; gap: 8px; }
.dashboard-kpi-card__value { min-width: 0; color: var(--navy); font-size: clamp(29px, 7vw, 36px); font-weight: 800; line-height: 1; }
.dashboard-kpi-card__sparkline { width: 70px; flex: 0 1 80px; color: var(--coral); }
.dashboard-kpi-card__sparkline svg { width: 100%; height: auto; }
.dashboard-kpi-card__trend { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 11px; }
.dashboard-kpi-card__trend-value { flex: 0 0 auto; font-weight: 800; }
.dashboard-kpi-card__trend-label { overflow: hidden; color: var(--ink-muted); text-overflow: ellipsis; white-space: nowrap; }

.dashboard-workspace-section { margin-top: 30px; }
.dashboard-section-heading--workspace { display: flex; align-items: end; justify-content: space-between; gap: 14px; margin-bottom: 12px; }
.dashboard-section-heading--workspace h2 { margin: 3px 0 0; color: var(--ink); font-size: 18px; font-weight: 800; letter-spacing: -.015em; }
.dashboard-section-heading--workspace p { max-width: 370px; margin: 0; color: var(--ink-soft); font-size: 12px; line-height: 1.5; text-align: end; }
.dash-widgets-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.widget-grid-item { min-width: 0; display: flex; }
.dash-widget { width: 100%; min-height: 350px; display: flex; flex-direction: column; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card); box-shadow: var(--shadow-card); }
.dash-widget-header { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; background: var(--surface-blue); border-bottom: 1px solid var(--line); }
.dash-widget-heading { min-width: 0; }
.dash-widget-heading__eyebrow { display: block; color: var(--ink-muted); font-size: 9px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.dash-widget-heading h3 { margin: 3px 0 0; overflow: hidden; color: var(--ink); font-size: 14px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.dash-widget-actions { display: flex; gap: 3px; }
.dash-widget-actions .btn-icon { width: 34px; height: 34px; min-height: 34px; border-radius: 10px; }
.dash-widget-body { min-height: 0; flex: 1; padding: 14px; }
.dashboard-chart { width: 100%; height: 270px; display: flex; align-items: center; justify-content: center; }
.dash-widget.fullscreen { position: fixed; inset: 16px; z-index: 7000; min-height: 0; }
.dash-widget.fullscreen .dashboard-chart { height: min(72vh, 660px); }

@media (min-width: 620px) {
  .dashboard-main, .dashboard-filter-shell { padding-inline: 20px; }
  .dashboard-overview { grid-template-columns: minmax(0, 1fr) minmax(260px, .68fr); align-items: stretch; }
  .dashboard-attention-card { min-height: 100%; }
  .dash-kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
  .dash-widgets-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
  .widget-grid-item--small { grid-column: span 4; }
  .widget-grid-item--medium { grid-column: span 6; }
  .widget-grid-item--large { grid-column: span 8; }
  .widget-grid-item--full { grid-column: 1 / -1; }
}
@media (min-width: 1120px) {
  .dashboard-main, .dashboard-filter-shell { padding-inline: 28px; }
  .dash-kpi-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .dashboard-kpi-card { min-height: 190px; }
}
@media (max-width: 600px) {
  .dashboard-app-header { min-height: 64px; padding: 9px 12px; }
  .dashboard-header__eyebrow, .dashboard-header__company, .dashboard-auto-refresh, .dashboard-header__actions .btn-icon:nth-of-type(2) { display: none; }
  .dashboard-header__title-row h1 { font-size: 18px; }
  .dashboard-header__time { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .dashboard-filter-shell, .dashboard-main { padding-inline: 12px; }
  .dashboard-filter-bar { align-items: stretch; padding: 10px; }
  .dashboard-filter-bar__period .filter-select { width: 100%; }
  .dashboard-filter-trigger span:not(.dashboard-filter-count) { display: none; }
  .dashboard-filter-trigger { width: 44px; justify-content: center; padding: 0; }
  .dashboard-filter-grid { grid-template-columns: 1fr; }
  .dashboard-filter-field--location { grid-column: auto; }
  .dashboard-date-inputs { grid-template-columns: 1fr; }
  .dashboard-date-inputs > span { display: none; }
  .dashboard-overview { padding: 18px; border-radius: 22px; }
  .dashboard-attention-card__split { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dashboard-kpi-card { min-height: 164px; padding: 14px; }
  .dashboard-kpi-card__sparkline { display: none; }
  .dashboard-kpi-card__trend-label { display: none; }
  .dashboard-section-heading--workspace { display: block; }
  .dashboard-section-heading--workspace p { margin-top: 6px; text-align: start; }
  .dash-widget { min-height: 326px; }
  .dashboard-chart { height: 246px; }
}
@media (max-width: 360px) {
  .dash-kpi-grid { grid-template-columns: 1fr; }
  .dashboard-kpi-card { min-height: 145px; }
}

/*
 * Layout stability pass
 *
 * The desktop rail can remove a sizeable portion of the viewport, so the
 * dashboard responds to its own usable inline size instead of promoting six
 * compressed cards just because the browser window is wide. Keeping six KPI
 * cards in a three-by-two grid also makes every card genuinely equal.
 */
.dashboard-screen {
  container-type: inline-size;
  container-name: dashboard;
}

.dashboard-main {
  container-type: inline-size;
  container-name: dashboard-content;
  scrollbar-gutter: stable;
}

/* Overrides the legacy global dashboard padding so the spacing scales with
   the workspace rather than remaining fixed at 16px on every desktop. */
#dashboard-content.dashboard-main {
  padding: clamp(16px, 2vw, 28px) !important;
}

/* Dashboard keeps a compact utility bar beside the desktop rail because
   refresh, export, and layout controls do not belong in navigation. */
@media (min-width: 769px) {
  body.app-shell-sidebar-active #screen-dashboard .dashboard-app-header {
    min-height: 68px;
    padding-inline: clamp(16px, 2.2vw, 30px);
    background: rgba(255,255,255,.86);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 8px 20px rgba(47,76,101,.055);
  }
}

/* A predictable 3 x 2 desktop arrangement is more legible than six narrow
   columns. The condition intentionally uses available dashboard space, which
   changes when the desktop sidebar is opened or collapsed. */
.dash-kpi-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  align-items: stretch;
  gap: 12px;
}

.dashboard-kpi-card {
  min-height: 174px;
  height: 100%;
  gap: 14px;
  padding: 16px;
  border-color: var(--line);
  transform: translateZ(0);
}

.dashboard-kpi-card:focus-visible {
  position: relative;
  z-index: 1;
}

.dashboard-kpi-card__title {
  display: -webkit-box;
  overflow: hidden;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.dashboard-kpi-card__value-row { min-height: 42px; }
.dashboard-kpi-card__value { font-size: clamp(30px, 4.4cqi, 40px); }
.dashboard-kpi-card__sparkline { width: min(28%, 86px); flex: 0 1 86px; }

/* Equal cards retain a calm visual rhythm on very narrow phones. */
@container dashboard-content (max-width: 359px) {
  .dash-kpi-grid { grid-template-columns: minmax(0, 1fr); }
  .dashboard-kpi-card { min-height: 150px; }
}

@container dashboard-content (max-width: 510px) {
  .dashboard-kpi-card { min-height: 166px; padding: 14px; }
  .dashboard-kpi-card__context,
  .dashboard-kpi-card__sparkline,
  .dashboard-kpi-card__trend-label { display: none; }
  .dashboard-kpi-card__value { font-size: clamp(29px, 10cqi, 38px); }
  .dashboard-kpi-card__trend { min-height: 16px; }
}

@container dashboard-content (min-width: 700px) {
  .dash-kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
  .dashboard-kpi-card { min-height: 192px; padding: 18px; }
  .dashboard-kpi-card__value { font-size: clamp(31px, 4.2cqi, 42px); }
}

/* The overview becomes a two-column composition only after there is enough
   room for a useful attention panel beside the introduction. */
.dashboard-overview {
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
}

.dashboard-attention-card { min-height: 0; }

@container dashboard-content (min-width: 780px) {
  .dashboard-overview {
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, .74fr);
    gap: 18px;
    padding: 24px;
  }
  .dashboard-attention-card { min-height: 100%; }
}

@container dashboard-content (min-width: 1160px) {
  .dashboard-overview {
    grid-template-columns: minmax(0, 1.65fr) minmax(310px, .72fr);
    padding: 28px;
  }
}

/* KPI and widget areas share one section-heading language, so the statistics
   do not look detached from the rest of the operations workspace. */
.dashboard-kpi-section { margin-top: 30px; }

.dashboard-section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.dashboard-section-heading > div { min-width: 0; }

.dashboard-section-heading h2 {
  margin: 4px 0 0;
  color: var(--ink);
  font-size: clamp(19px, 2.2cqi, 24px);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -.02em;
}

.dashboard-section-heading p {
  max-width: 390px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.55;
  text-align: end;
}

@container dashboard-content (max-width: 510px) {
  .dashboard-kpi-section { margin-top: 24px; }
  .dashboard-section-heading { display: block; margin-bottom: 12px; }
  .dashboard-section-heading p { margin-top: 6px; text-align: start; }
}

/* One-column widgets on compact space; two balanced cards are introduced
   only once each has a practical working width. */
.dash-widgets-grid {
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
}

.widget-grid-item { align-self: stretch; }
.dash-widget { min-height: 338px; height: 100%; }
.dash-widget-body { display: flex; flex-direction: column; min-width: 0; }
.dash-widget-body > :only-child { min-width: 0; }

@container dashboard-content (min-width: 700px) {
  .dash-widgets-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
  .widget-grid-item--small { grid-column: span 4; }
  .widget-grid-item--medium,
  .widget-grid-item--large { grid-column: span 6; }

  /* Default widget order is deliberately paired for even rows. */
  .dashboard-workspace-section--projects .widget-grid-item--project_status { grid-column: span 4; }
  .dashboard-workspace-section--projects .widget-grid-item--project_progress { grid-column: span 8; }
  .dashboard-workspace-section--projects .widget-grid-item--project_budget { grid-column: 1 / -1; }
  .dashboard-workspace-section--assets .widget-grid-item--maint_costs { grid-column: span 8; }
  .dashboard-workspace-section--assets .widget-grid-item--inventory_status { grid-column: span 4; }
}

@container dashboard-content (min-width: 1080px) {
  .dash-widget { min-height: 360px; }
  .dashboard-chart { height: 286px; }
}

/* Loading, error, and empty analytics fill the content region consistently
   instead of appearing as a loose line of text at the top of the dashboard. */
#dashboard-content > .dashboard-state,
#dashboard-content > .pg-loading {
  width: 100%;
  min-height: clamp(320px, 50dvh, 540px);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  margin: 0;
  padding: 28px;
  color: var(--ink-soft);
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow-card);
  box-sizing: border-box;
}

#dashboard-content > .dashboard-state--error { justify-items: center; }
#dashboard-content > .dashboard-state--error .btn { margin-top: 4px !important; }

.dash-widget-body > .rp-empty,
.dash-widget-body .dashboard-chart > .rp-empty {
  width: 100%;
  min-height: 210px;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--ink-soft);
  text-align: center;
  background: var(--surface-soft);
  border: 1px dashed #cbd9e4;
  border-radius: 14px;
}

/* Header and filters use the same available-width rules. This prevents the
   sidebar from forcing controls out of view on a mid-width desktop. */
@container dashboard (max-width: 620px) {
  .dashboard-app-header { min-height: 64px; padding: 9px 12px; gap: 8px; }
  .dashboard-header__eyebrow,
  .dashboard-header__company { display: none; }
  .dashboard-header__title-row h1 { font-size: 18px; }
  .dashboard-header__time { max-width: 132px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .dashboard-auto-refresh { display: inline-flex; width: 42px; height: 42px; justify-content: center; padding: 0; }
  .dashboard-auto-refresh > span { display: none; }
  .dashboard-auto-refresh input { width: 18px; height: 18px; }
  .dashboard-header__actions { gap: 3px; }
  .dashboard-header__actions .btn-icon { width: 42px; height: 42px; min-height: 42px; }
  /* Export remains reachable; the dashboard header has no generic action
     sheet because it is a custom utility bar. */
  .dashboard-header__actions .btn-icon:nth-of-type(2) { display: inline-flex; }
}

@container dashboard (max-width: 520px) {
  .dashboard-filter-shell { padding-inline: 12px; }
  .dashboard-filter-bar { padding: 10px; }
  .dashboard-filter-trigger span:not(.dashboard-filter-count) { display: none; }
  .dashboard-filter-trigger { width: 44px; justify-content: center; padding: 0; }
  .dashboard-filter-grid { grid-template-columns: minmax(0, 1fr); }
  .dashboard-filter-field--location { grid-column: auto; }
  .dashboard-date-inputs { grid-template-columns: minmax(0, 1fr); }
  .dashboard-date-inputs > span { display: none; }
}

@container dashboard (max-width: 390px) {
  .dashboard-header__time { display: none; }
  .dashboard-overview__primary-action { width: 100%; justify-content: space-between; }
}

/* Fallback for browsers that have not enabled container queries yet. */
@media (max-width: 600px) {
  .dashboard-auto-refresh { display: inline-flex; }
  .dashboard-header__actions .btn-icon:nth-of-type(2) { display: inline-flex; }
}

/* Keep the final widget and its actions clear of the fixed mobile navigation. */
@media (max-width: 768px) {
  #dashboard-content.dashboard-main {
    padding-bottom: calc(24px + var(--nav-h) + env(safe-area-inset-bottom, 0px)) !important;
  }
}

@media (max-width: 360px) {
  .dash-kpi-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Phone and portrait-tablet application mode --------------------------------
 * A narrow device must never inherit the desktop navigation rail.  At the
 * intermediate widths used by many phones/PWAs the old rail consumed the
 * left side of the screen and covered the dashboard.  This mode deliberately
 * keeps one clear reading column and the fixed bottom navigation.
 */
@media (max-width: 1023px) {
  body.app-shell-sidebar-active {
    --shell-sidebar-width: 0px;
  }

  body.app-shell-sidebar-active .app-sidebar,
  body.app-shell-sidebar-active .app-sidebar__reopen {
    display: none !important;
  }

  body.app-shell-sidebar-active .bottom-nav:not(.app-sidebar__nav).visible {
    display: flex !important;
  }

  body.app-shell-sidebar-active #screen-dashboard {
    width: 100%;
    max-width: none;
    padding: 0 !important;
  }

  #screen-dashboard .dashboard-app-header {
    min-height: 64px;
    padding: 10px max(14px, env(safe-area-inset-left, 0px));
    gap: 8px;
    background: rgba(255,255,255,.96);
    border-bottom: 1px solid var(--line);
  }

  #screen-dashboard .dashboard-header__eyebrow,
  #screen-dashboard .dashboard-header__company,
  #screen-dashboard .dashboard-auto-refresh {
    display: none;
  }

  #screen-dashboard .dashboard-header__title-row h1 { font-size: 20px; }
  #screen-dashboard .dashboard-header__time { max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #screen-dashboard .dashboard-header__actions { gap: 6px; }
  #screen-dashboard .dashboard-header__actions .btn-icon { width: 44px; height: 44px; min-height: 44px; border-radius: 14px; }

  #screen-dashboard .dashboard-filter-shell,
  #screen-dashboard .dashboard-main { padding-inline: 14px; }

  #screen-dashboard .dashboard-filter-bar {
    align-items: stretch;
    margin-top: 8px;
    padding: 10px;
    border-radius: 16px;
  }

  #screen-dashboard .dashboard-filter-bar__period .filter-select { width: 100%; max-width: none; min-height: 44px; }
  #screen-dashboard .dashboard-filter-trigger { width: 44px; justify-content: center; padding-inline: 0; }
  #screen-dashboard .dashboard-filter-trigger > span:not(.dashboard-filter-count) { display: none; }
  #screen-dashboard .dashboard-filter-refresh { width: 44px; flex: 0 0 44px; }
  #screen-dashboard .dashboard-filter-grid { grid-template-columns: minmax(0, 1fr); }
  #screen-dashboard .dashboard-filter-field--location { grid-column: auto; }
  #screen-dashboard .dashboard-date-inputs { grid-template-columns: minmax(0, 1fr); }
  #screen-dashboard .dashboard-date-inputs > span { display: none; }

  #dashboard-content.dashboard-main {
    padding: 14px 14px calc(24px + var(--nav-h) + env(safe-area-inset-bottom, 0px)) !important;
  }

  #screen-dashboard .dashboard-overview {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 14px;
    padding: 18px;
    border-radius: 24px;
  }

  #screen-dashboard .dashboard-overview h2 { font-size: clamp(24px, 5.6vw, 30px); }
  #screen-dashboard .dashboard-overview__primary-action { width: 100%; min-height: 50px; justify-content: space-between; }
  #screen-dashboard .dashboard-attention-card { padding: 15px; border-radius: 18px; }

  #screen-dashboard .dash-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px;
  }

  #screen-dashboard .dashboard-kpi-card { min-height: 158px; padding: 13px; gap: 11px; }
  #screen-dashboard .dashboard-kpi-card__context,
  #screen-dashboard .dashboard-kpi-card__sparkline,
  #screen-dashboard .dashboard-kpi-card__trend-label { display: none; }
  #screen-dashboard .dashboard-kpi-card__value { font-size: clamp(29px, 7vw, 38px); }

  #screen-dashboard .dashboard-section-heading,
  #screen-dashboard .dashboard-section-heading--workspace { display: block; margin-bottom: 12px; }
  #screen-dashboard .dashboard-section-heading p,
  #screen-dashboard .dashboard-section-heading--workspace p { margin-top: 6px; text-align: start; }
  #screen-dashboard .dashboard-workspace-section { margin-top: 26px; }
  #screen-dashboard .dash-widgets-grid { grid-template-columns: minmax(0, 1fr) !important; gap: 12px; }
  #screen-dashboard .widget-grid-item { grid-column: 1 / -1 !important; }
  #screen-dashboard .dash-widget { min-height: 310px; border-radius: 18px; }
  #screen-dashboard .dashboard-chart { height: 230px; }
}

@media (max-width: 390px) {
  #screen-dashboard .dashboard-header__time { display: none; }
  #screen-dashboard .dashboard-attention-card__split { grid-template-columns: 1fr; }
  #screen-dashboard .dashboard-attention-card__split > :is(div, button) { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  #screen-dashboard .dashboard-attention-card__split span { min-height: 0; }
  #screen-dashboard .dash-kpi-grid { grid-template-columns: minmax(0, 1fr) !important; }
}

/* -------------------------------------------------------------------------
   Live Now panel — real-time pulse (online users, active accounts,
   clocked-in-now with location), separate from the period-based widgets.
-------------------------------------------------------------------------- */
.dashboard-live-panel {
  flex: 0 0 auto;
  width: min(100%, 1440px);
  margin: 10px auto 0;
  padding: 14px 16px;
  background: var(--surface, #fff);
  border: 1px solid var(--line, #e4ebf1);
  border-radius: 18px;
  box-shadow: var(--shadow-card, 0 10px 24px rgba(52,79,103,.065));
}
/* Once JS re-parents it into the KPI grid (see positionDashboardLivePanel in
   dashboard.js), it becomes a full-width row that sits among the cards
   rather than a separate banner pinned above/outside them. */
.dash-kpi-grid > .dashboard-live-panel {
  grid-column: 1 / -1;
  width: 100%;
  margin: 0;
}
.dashboard-live-panel__header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 13px;
}
.dashboard-live-panel__header strong { font-size: 14px; }
.dashboard-live-panel__header small { margin-inline-start: auto; color: var(--ink-muted, #9aa9b6); font-size: 11px; }
.dashboard-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 0 rgba(34,197,94,.6);
  animation: dashboardLivePulse 2s infinite;
}
@keyframes dashboardLivePulse {
  0%   { box-shadow: 0 0 0 0 rgba(34,197,94,.5); }
  70%  { box-shadow: 0 0 0 7px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

.dashboard-live-panel__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.dashboard-live-card {
  padding: 12px 14px;
  background: var(--surface-soft, #f5f8fb);
  border-radius: 14px;
}
.dashboard-live-card__num { font-size: 24px; font-weight: 800; color: var(--ink, #1f2d3d); line-height: 1.1; }
.dashboard-live-card__label { font-size: 11px; font-weight: 700; color: var(--ink-muted, #9aa9b6); text-transform: uppercase; letter-spacing: .03em; margin-top: 2px; }
.dashboard-live-card__avatars { display: flex; margin-top: 8px; }

.dashboard-live-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--surface-soft, #f5f8fb);
  margin-inline-start: -8px;
  object-fit: cover;
  background: var(--navy, #426482);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 800;
}
.dashboard-live-avatar:first-child { margin-inline-start: 0; }
.dashboard-live-avatar--more { background: var(--coral, #ff6b57); }

.dashboard-live-panel__list {
  margin-top: 12px;
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dashboard-live-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--surface-soft, #f5f8fb);
}
.dashboard-live-row .dashboard-live-avatar { margin: 0; width: 30px; height: 30px; }
.dashboard-live-row__body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dashboard-live-row__body strong { font-size: 12.5px; }
.dashboard-live-row__body small { font-size: 11px; color: var(--ink-muted, #9aa9b6); }
.dashboard-live-row__map { flex: 0 0 auto; font-size: 16px; text-decoration: none; }
