:root {
  --font-ui: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --blue: #1677ff;
  --download: #17a8e5;
  --upload: #7657d9;
  --success: #3aa76d;
  --warning: #d49327;
  --error: #d84d4d;
  --radius: 7px;
  --radius-large: 9px;
  --sidebar-small: 56px;
  --sidebar-large: 196px;
  --topbar: 56px;
  --fast: 140ms ease;
}

html[data-theme="light"] {
  --background: #f7f8fa;
  --surface: #ffffff;
  --surface-soft: #f2f4f7;
  --text: #20252c;
  --secondary: #68717d;
  --muted: #8a929d;
  --border: #e5e8ec;
  --border-strong: #d9dde3;
  --hover: #f3f5f7;
  --selected: #eaf3ff;
  --shadow: 0 8px 24px rgba(24, 33, 45, .10);
}

html[data-theme="dark"] {
  --background: #16191d;
  --surface: #1c2025;
  --surface-soft: #252a30;
  --text: #e7eaee;
  --secondary: #a8b0ba;
  --muted: #7f8894;
  --border: #30363d;
  --border-strong: #3a414a;
  --hover: #272d34;
  --selected: #1f344d;
  --shadow: 0 10px 28px rgba(0, 0, 0, .30);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background: var(--background);
  font-family: var(--font-ui);
  font-size: 14px;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.loading-view {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  color: var(--secondary);
  background: var(--background);
  font-size: 12px;
}

.loader {
  display: grid;
  grid-template-columns: repeat(2, 8px);
  gap: 5px;
}

.loader i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--blue);
  animation: pulse 1s infinite ease-in-out;
}

.loader i:nth-child(2) {
  animation-delay: .12s;
}

.loader i:nth-child(3) {
  animation-delay: .36s;
}

.loader i:nth-child(4) {
  animation-delay: .24s;
}

@keyframes pulse {
  0%,
  100% {
    opacity: .28;
    transform: scale(.82);
  }

  45% {
    opacity: 1;
    transform: scale(1);
  }
}

.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  padding: clamp(32px, 7vw, 96px);
  background:
    linear-gradient(
      90deg,
      var(--surface) 0,
      var(--surface) 38%,
      var(--background) 38%
    );
}

.login-panel {
  width: min(340px, 100%);
}

.brand,
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  font-weight: 600;
}

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: #fff;
  background: var(--blue);
  border-radius: 6px;
  font-size: 13px;
}

.brand-mark.small {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
}

.login-header {
  margin: 52px 0 28px;
}

.login-header h1 {
  margin: 0 0 6px;
  font-size: 25px;
  line-height: 1.2;
  font-weight: 600;
}

.login-header p {
  margin: 0;
  color: var(--secondary);
}

#login-form {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 7px;
}

.field > span:first-child {
  color: var(--secondary);
  font-size: 12px;
  font-weight: 500;
}

.field input {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}

.field input:focus {
  border-color: var(--blue);
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 42px;
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--secondary);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.icon-button:hover {
  color: var(--text);
  background: var(--hover);
}

.password-field .icon-button {
  position: absolute;
  top: 2px;
  right: 3px;
}

.primary-button,
.secondary-button {
  height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.primary-button {
  color: #fff;
  background: var(--blue);
  border: 1px solid var(--blue);
}

.secondary-button {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
}

.error-box {
  padding: 9px 10px;
  color: var(--error);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 300;
  display: flex;
  width: var(--sidebar-small);
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transition: width var(--fast);
}

.sidebar.expanded {
  width: var(--sidebar-large);
}

.sidebar-brand {
  height: var(--topbar);
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-label {
  opacity: 0;
  transition: opacity 80ms ease;
}

.sidebar.expanded .sidebar-label {
  opacity: 1;
}

.nav {
  padding: 10px 8px;
}

.nav-item {
  display: flex;
  width: 100%;
  min-height: 38px;
  align-items: center;
  gap: 12px;
  padding: 0 10px;
  color: var(--secondary);
  background: transparent;
  border: 0;
  border-radius: 6px;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.nav-item:hover {
  color: var(--text);
  background: var(--hover);
}

.nav-item.active {
  color: var(--blue);
  background: var(--selected);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
}

.sidebar-toggle {
  margin-top: auto;
  border-top: 1px solid var(--border);
  border-radius: 0;
}

.sidebar.expanded .sidebar-toggle svg {
  transform: rotate(180deg);
}

.workspace {
  min-height: 100vh;
  margin-left: var(--sidebar-small);
  transition: margin-left var(--fast);
}

.sidebar.expanded + .drawer-backdrop + .workspace {
  margin-left: var(--sidebar-large);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  min-height: var(--topbar);
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-left,
.topbar-actions,
.account-button,
.content-header,
.date-control,
.foundation-card {
  display: flex;
  align-items: center;
}

.topbar-left {
  min-width: 0;
  gap: 10px;
}

.page-context {
  min-width: 0;
}

.page-context small {
  color: var(--muted);
  font-size: 10px;
}

.page-context h1 {
  max-width: 44vw;
  margin: 2px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 600;
}

.topbar-actions {
  gap: 9px;
}

.theme-toggle {
  display: flex;
  padding: 2px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.theme-option {
  height: 27px;
  padding: 0 9px;
  color: var(--secondary);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
}

.theme-option.active {
  color: var(--text);
  background: var(--surface);
}

.account {
  position: relative;
}

.account-button {
  height: 34px;
  gap: 6px;
  padding: 0 7px 0 4px;
  color: var(--secondary);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.account-button:hover {
  background: var(--hover);
}

#account-initial {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  color: var(--blue);
  background: var(--selected);
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
}

.account-menu {
  position: absolute;
  top: 40px;
  right: 0;
  width: 210px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.account-name {
  display: grid;
  gap: 2px;
  padding: 9px 10px;
}

.account-name small {
  color: var(--muted);
  font-size: 10px;
}

.account-name strong {
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
  font-weight: 500;
}

.account-menu hr {
  height: 1px;
  margin: 4px 0;
  background: var(--border);
  border: 0;
}

.account-menu button {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.account-menu button:hover {
  background: var(--hover);
}

.mobile-menu {
  display: none;
}

.content {
  width: min(100%, 1560px);
  margin: 0 auto;
  padding: 24px;
}

.content-header {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.content-header h2 {
  margin: 3px 0 0;
  font-size: 24px;
  font-weight: 600;
}

.date-control {
  gap: 10px;
}

.date-control > span {
  display: grid;
  gap: 2px;
  text-align: right;
}

.date-control small {
  color: var(--muted);
  font-size: 10px;
}

.date-control strong {
  font-size: 12px;
  font-weight: 500;
}

.foundation-card,
.table-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-large);
}

.foundation-card {
  justify-content: space-between;
  padding: 17px 18px;
  margin-bottom: 14px;
}

.foundation-card h3 {
  margin: 3px 0 0;
  font-size: 14px;
  font-weight: 600;
}

.chip {
  padding: 3px 7px;
  color: var(--blue);
  background: var(--selected);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
}

.table-shell {
  overflow: hidden;
}

.table-head {
  display: grid;
  grid-template-columns:
    minmax(54px, .6fr)
    minmax(150px, 2fr)
    minmax(72px, .8fr)
    minmax(72px, .8fr)
    minmax(90px, 1fr)
    minmax(90px, 1fr)
    minmax(90px, 1fr);
  min-width: 760px;
  min-height: 38px;
  align-items: center;
  padding: 0 14px;
  color: var(--muted);
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 600;
}

.table-head span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  display: grid;
  min-height: 220px;
  place-content: center;
  justify-items: center;
  gap: 6px;
  padding: 30px;
  text-align: center;
  color: var(--secondary);
}

.empty-state strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}

.empty-state span {
  max-width: 440px;
  font-size: 11px;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(0, 0, 0, .32);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 900;
  max-width: calc(100vw - 36px);
  padding: 10px 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  font-size: 12px;
}

@media (max-width: 760px) {
  .login-view {
    align-items: flex-start;
    padding: 64px 24px 32px;
    background: var(--background);
  }

  .sidebar {
    width: min(280px, 82vw);
    transform: translateX(-100%);
    transition: transform var(--fast);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar .sidebar-label {
    opacity: 1;
  }

  .sidebar-toggle {
    display: none;
  }

  .workspace,
  .sidebar.expanded + .drawer-backdrop + .workspace {
    margin-left: 0;
  }

  .mobile-menu {
    display: inline-grid;
    place-items: center;
  }

  .theme-toggle {
    display: none;
  }

  .topbar {
    padding: 0 12px;
  }

  .content {
    padding: 15px 12px 22px;
  }

  .content-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .date-control {
    width: 100%;
    justify-content: space-between;
  }

  .date-control > span {
    text-align: left;
  }

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}

/* Phase 16 Sites dashboard */

.sites-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.site-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.filter-button {
  min-height: 30px;
  padding: 0 9px;
  color: var(--secondary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
}

.filter-button:hover:not(:disabled) {
  color: var(--text);
  background: var(--hover);
}

.filter-button.active {
  color: var(--blue);
  background: var(--selected);
  border-color: var(--border);
}

.filter-button:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.filter-button span {
  color: var(--muted);
}

.sites-data-state {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.sites-grid {
  grid-template-columns:
    44px
    minmax(170px, 2fr)
    72px
    72px
    100px
    100px
    100px
    90px
    90px
    110px
    82px !important;
  min-width: 1080px !important;
}

.sites-grid button {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-start;
  height: 100%;
  padding: 0 12px 0 0;
  overflow: hidden;
  color: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-weight: inherit;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sites-grid button:hover:not(:disabled) {
  color: var(--text);
}

.sites-grid button[data-direction="asc"]::after {
  content: " ↑";
  margin-left: 4px;
  color: var(--blue);
}

.sites-grid button[data-direction="desc"]::after {
  content: " ↓";
  margin-left: 4px;
  color: var(--blue);
}

.sites-grid button:disabled {
  cursor: default;
}

.site-row {
  display: grid;
  grid-template-columns:
    44px
    minmax(170px, 2fr)
    72px
    72px
    100px
    100px
    100px
    90px
    90px
    110px
    82px;
  min-width: 1080px;
  min-height: 43px;
  align-items: center;
  padding: 0 14px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}

.site-row:last-child {
  border-bottom: 0;
}

.site-row:hover {
  background: var(--hover);
}

.site-row > * {
  min-width: 0;
  padding-right: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-name {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.site-name:hover {
  color: var(--blue);
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  padding: 0;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.online {
  background: var(--success);
}

.status-dot.partial_offline {
  background: var(--warning);
}

.status-dot.offline {
  background: var(--error);
}

.traffic-download {
  color: var(--download);
}

.traffic-upload {
  color: var(--upload);
}

.value-partial::after {
  content: " *";
  color: var(--warning);
}

.value-unavailable {
  color: var(--muted);
}

.live-value {
  transition: opacity var(--fast);
}

.live-value.updated {
  opacity: .64;
}

@media (max-width: 760px) {
  .sites-controls {
    align-items: flex-start;
    flex-direction: column;
  }

  .site-filters {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  .filter-button {
    flex: 0 0 auto;
  }
}

/* Phase 16 Site Detail core */

.site-detail-page {
  display: grid;
  gap: 14px;
}

.site-detail-state {
  min-height: 20px;
  color: var(--muted);
  font-size: 11px;
}

.site-summary-grid,
.traffic-summary-grid,
.detail-charts-grid {
  display: grid;
  gap: 10px;
}

.site-summary-grid {
  grid-template-columns:
    repeat(4, minmax(0, 1fr));
}

.traffic-summary-grid {
  grid-template-columns:
    repeat(5, minmax(0, 1fr));
}

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

.detail-card,
.detail-section,
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-large);
}

.detail-card {
  display: grid;
  min-width: 0;
  gap: 5px;
  padding: 14px;
}

.detail-card small,
.detail-card span {
  color: var(--muted);
  font-size: 10px;
}

.detail-card strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 7px;
  text-transform: capitalize;
}

.detail-section,
.chart-card {
  padding: 16px;
}

.detail-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.detail-section-head h3 {
  margin: 3px 0 0;
  font-size: 14px;
  font-weight: 600;
}

.freshness-indicator {
  color: var(--muted);
  font-size: 10px;
}

.partial-warning {
  margin-bottom: 12px;
  padding: 9px 10px;
  color: var(--warning);
  background: color-mix(
    in srgb,
    var(--warning) 8%,
    transparent
  );
  border: 1px solid color-mix(
    in srgb,
    var(--warning) 28%,
    var(--border)
  );
  border-radius: 6px;
  font-size: 11px;
}

.chart-empty {
  display: grid;
  min-height: 150px;
  place-items: center;
  padding: 18px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 6px;
  font-size: 11px;
}

@media (max-width: 1080px) {
  .site-summary-grid {
    grid-template-columns:
      repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 760px) {
  .site-summary-grid,
  .traffic-summary-grid,
  .detail-charts-grid {
    grid-template-columns:
      minmax(0, 1fr);
  }

  .detail-section-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* Phase 16 Site Detail charts */

.chart-stage {
  display: grid;
  gap: 9px;
  min-height: 150px;
}

.chart-stage svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 10px;
}

.chart-legend > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chart-legend-swatch {
  width: 15px;
  height: 2px;
  border-radius: 2px;
  background: var(--muted);
}

.chart-legend-swatch.download {
  background: var(--download);
}

.chart-legend-swatch.upload {
  background: var(--upload);
}

.chart-legend-swatch.total {
  background: var(--secondary);
}

.chart-grid-line {
  stroke: var(--border);
  stroke-width: 1;
}

.chart-line {
  fill: none;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.chart-line.download {
  stroke: var(--download);
}

.chart-line.upload {
  stroke: var(--upload);
}

.chart-line.total {
  stroke: var(--secondary);
}

.chart-hit-point {
  fill: transparent;
  stroke: transparent;
  cursor: pointer;
}

.chart-hit-point:focus {
  stroke: var(--blue);
  stroke-width: 2;
  outline: none;
}

.status-segment {
  cursor: pointer;
  stroke: var(--surface);
  stroke-width: 1;
}

.status-segment.online {
  fill: var(--success);
}

.status-segment.partial-offline {
  fill: var(--warning);
}

.status-segment.offline {
  fill: var(--error);
}

.status-segment.unknown {
  fill: var(--muted);
}

.status-segment:focus {
  stroke: var(--blue);
  stroke-width: 2;
  outline: none;
}

.chart-tooltip {
  min-height: 30px;
  padding: 7px 9px;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 10px;
  line-height: 1.45;
}

@media (max-width: 760px) {
  .chart-legend {
    gap: 8px;
  }

  .chart-tooltip {
    font-size: 9px;
  }
}

/* Phase 16 Site Detail AP list */

.ap-list-section {
  min-width: 0;
}

.ap-list-shell {
  overflow-x: auto;
}

.ap-list-head,
.ap-list-row {
  display: grid;
  grid-template-columns:
    minmax(150px, 1.7fr)
    minmax(110px, 1.2fr)
    minmax(92px, .9fr)
    minmax(112px, 1fr)
    minmax(130px, 1.15fr)
    minmax(86px, .8fr)
    minmax(132px, 1.25fr)
    minmax(104px, 1fr)
    minmax(112px, 1fr)
    minmax(70px, .65fr)
    minmax(92px, .9fr)
    minmax(92px, .9fr)
    minmax(92px, .9fr);
  min-width: 1455px;
  align-items: center;
}

.ap-list-head {
  min-height: 38px;
  padding: 0 12px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
}

.ap-list-head button {
  min-width: 0;
  padding: 0 6px;
  color: var(--muted);
  background: transparent;
  border: 0;
  text-align: left;
  font: inherit;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ap-list-head button[data-direction="asc"]::after {
  content: " ↑";
  color: var(--blue);
}

.ap-list-head button[data-direction="desc"]::after {
  content: " ↓";
  color: var(--blue);
}

.ap-list-row {
  min-height: 42px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}

.ap-list-row:last-child {
  border-bottom: 0;
}

.ap-list-row > * {
  min-width: 0;
  padding: 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ap-name-link {
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
}

.ap-name-link:hover,
.ap-name-link:focus-visible {
  color: var(--blue);
  text-decoration: underline;
}

.ap-status-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-transform: capitalize;
}

.ap-mono {
  font-variant-numeric: tabular-nums;
}

.ap-list-empty {
  display: grid;
  min-width: 1210px;
  min-height: 112px;
  place-items: center;
  padding: 18px;
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 760px) {
  .ap-list-head,
  .ap-list-row,
  .ap-list-empty {
    min-width: 1365px;
  }
}

/* Phase 16 Access Point Detail */

.ap-detail-page {
  min-width: 0;
}

.ap-client-section {
  min-width: 0;
}

.ap-client-shell {
  overflow-x: auto;
}

.ap-client-grid {
  display: grid;
  grid-template-columns:
    minmax(160px, 1.6fr)
    minmax(132px, 1.25fr)
    minmax(90px, .85fr)
    minmax(112px, 1fr)
    minmax(92px, .85fr)
    minmax(92px, .85fr)
    minmax(92px, .85fr);
  min-width: 820px;
  align-items: center;
}

.ap-client-head {
  min-height: 38px;
  padding: 0 12px;
  color: var(--muted);
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 600;
}

.ap-client-head > *,
.ap-client-row > * {
  min-width: 0;
  padding: 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ap-client-row {
  min-height: 42px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}

.ap-client-row:last-child {
  border-bottom: 0;
}

.ap-client-empty {
  display: grid;
  min-width: 820px;
  min-height: 112px;
  place-items: center;
  padding: 18px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

@media (max-width: 760px) {
  .ap-client-grid,
  .ap-client-empty {
    min-width: 760px;
  }
}

/* Phase 16 Site Detail client inventory */

.site-client-list-section {
  min-width: 0;
}

.site-client-list-shell {
  overflow-x: auto;
}

.site-client-grid {
  display: grid;
  grid-template-columns:
    minmax(170px, 1.6fr)
    minmax(132px, 1.2fr)
    minmax(94px, .85fr)
    minmax(112px, 1fr)
    minmax(180px, 1.6fr)
    minmax(92px, .85fr)
    minmax(92px, .85fr)
    minmax(92px, .85fr);
  min-width: 1010px;
  align-items: center;
}

.site-client-head {
  min-height: 38px;
  padding: 0 12px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
}

.site-client-head button {
  min-width: 0;
  padding: 0 6px;
  color: var(--muted);
  background: transparent;
  border: 0;
  text-align: left;
  font: inherit;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-client-head button[data-direction="asc"]::after {
  content: " ↑";
  color: var(--blue);
}

.site-client-head button[data-direction="desc"]::after {
  content: " ↓";
  color: var(--blue);
}

.site-client-row {
  min-height: 42px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}

.site-client-row:last-child {
  border-bottom: 0;
}

.site-client-row > * {
  min-width: 0;
  padding: 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-client-empty {
  display: grid;
  min-width: 1010px;
  min-height: 112px;
  place-items: center;
  padding: 18px;
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 760px) {
  .site-client-grid,
  .site-client-empty {
    min-width: 940px;
  }
}

/* Phase 16 Client Detail */

.client-detail-page {
  min-width: 0;
}

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

#client-detail-aps-range {
  white-space: normal;
}

@media (max-width: 760px) {
  .client-traffic-summary-grid {
    grid-template-columns:
      minmax(0, 1fr);
  }
}

/* Phase 16 custom historical date range */

.date-control {
  position: relative;
  gap: 10px;
}

.date-control-summary {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.date-control-summary small {
  color: var(--muted);
  font-size: 10px;
}

.date-control-summary strong {
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.date-control-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: 5px;
}

.custom-date-panel {
  position: absolute;
  z-index: 40;
  top: calc(100% + 7px);
  right: 0;
  width: 320px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.custom-date-panel[hidden] {
  display: none;
}

.custom-date-fields {
  display: grid;
  grid-template-columns:
    repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.custom-date-fields label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.custom-date-fields label > span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
}

.custom-date-fields input {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  color: var(--text);
  color-scheme: light;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  font: inherit;
  font-size: 11px;
  outline: none;
}

html[data-theme="dark"] .custom-date-fields input {
  color-scheme: dark;
}

.custom-date-fields input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--selected);
}

.custom-date-error {
  margin: 9px 0 0;
  color: var(--red);
  font-size: 10px;
  line-height: 1.4;
}

.custom-date-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 11px;
}

@media (max-width: 760px) {
  .date-control {
    align-items: center;
    gap: 8px;
  }

  .date-control-actions {
    flex-shrink: 0;
  }

  .custom-date-panel {
    position: fixed;
    top: auto;
    right: 12px;
    bottom: 16px;
    left: 12px;
    width: auto;
    max-width: none;
  }

  .custom-date-fields {
    grid-template-columns:
      minmax(0, 1fr);
  }
}

/* Phase 16 monthly period selector */

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.period-select-wrap {
  display: block;
  min-width: 0;
}

.period-select {
  width: 190px;
  max-width: 34vw;
  height: 32px;
  padding: 0 28px 0 9px;
  color: var(--text);
  color-scheme: light;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  font: inherit;
  font-size: 11px;
  outline: none;
  cursor: pointer;
}

html[data-theme="dark"] .period-select {
  color-scheme: dark;
}

.period-select:hover {
  border-color: var(--border-strong);
}

.period-select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--selected);
}

@media (max-width: 760px) {
  .period-select {
    width: min(48vw, 210px);
    max-width: 48vw;
  }
}

/* Phase 16 AP selected-period traffic ranking */

.ap-list-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
}

.ap-rank-button {
  height: 30px;
  padding: 0 10px;
  font-size: 11px;
  white-space: nowrap;
}

.ap-rank-button.active,
.ap-rank-button[aria-pressed="true"] {
  color: var(--blue);
  background: var(--selected);
  border-color: var(--blue);
}

@media (max-width: 760px) {
  .ap-list-controls {
    width: 100%;
    justify-content: space-between;
  }
}

/* Phase 16 selected-period AP client-count ranking */

.ap-list-controls {
  flex-wrap: wrap;
}

@media (max-width: 760px) {
  .ap-list-controls {
    justify-content: flex-end;
  }

  .ap-list-controls .freshness-indicator {
    flex-basis: 100%;
    text-align: right;
  }
}

/* Phase 16 Item 14 — client hourly usage */

.client-hourly-wrap {
  margin-top: 14px;
  min-width: 0;
}

.client-hourly-title {
  margin-bottom: 8px;
}

.client-hourly-title h4 {
  margin: 2px 0 0;
  font-size: 13px;
}

.client-hourly-table {
  overflow-x: auto;
}

.client-hourly-grid {
  display: grid;
  grid-template-columns:
    minmax(190px, 1.4fr)
    repeat(3, minmax(100px, .8fr));
  min-width: 560px;
  align-items: center;
}

.client-hourly-row {
  min-height: 34px;
  border-top: 1px solid var(--border);
  font-size: 11px;
}

.client-hourly-row > * {
  min-width: 0;
  padding: 7px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-hourly-hour {
  font-variant-numeric: tabular-nums;
}

.client-hourly-empty {
  min-width: 560px;
  padding: 18px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

@media (max-width: 760px) {
  .client-hourly-wrap {
    margin-top: 12px;
  }
}

.ap-restart-shell {
  overflow-x: auto;
}

.ap-restart-grid {
  display: grid;
  grid-template-columns:
    minmax(160px, 1.4fr)
    minmax(130px, 1fr)
    minmax(120px, 0.9fr)
    minmax(120px, 0.9fr)
    minmax(110px, 0.8fr);
  gap: 12px;
  align-items: center;
  min-width: 720px;
}

.ap-restart-head {
  padding: 0 12px 8px;
  font-weight: 600;
}

.ap-restart-body {
  display: grid;
  gap: 4px;
}

.ap-restart-row {
  padding: 10px 12px;
}

.ap-restart-row > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.ap-restart-empty {
  padding: 16px 12px;
}

@media (max-width: 760px) {
  .ap-restart-grid {
    min-width: 660px;
  }
}


/* Phase 16 manually configured site map */

.sites-map-section {
  min-width: 0;
  overflow: hidden;
}

.sites-map-frame {
  display: block;
  width: 100%;
  min-height: 340px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-soft);
}

.coordinate-section {
  min-width: 0;
}

.coordinate-form {
  display: grid;
  grid-template-columns:
    minmax(0, 1fr)
    minmax(0, 1fr)
    auto;
  align-items: end;
  gap: 10px;
}

.coordinate-field {
  display: grid;
  min-width: 0;
  gap: 5px;
  color: var(--secondary);
  font-size: 10px;
}

.coordinate-field input {
  width: 100%;
  min-height: 34px;
  padding: 0 9px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  font: inherit;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.coordinate-field input:focus {
  border-color: var(--blue);
  outline: 2px solid color-mix(
    in srgb,
    var(--blue) 18%,
    transparent
  );
}

.coordinate-actions {
  display: flex;
  gap: 6px;
}

.coordinate-state {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 10px;
}

.coordinate-state.coordinate-error {
  color: var(--error);
}

@media (max-width: 760px) {
  .sites-map-frame {
    min-height: 285px;
  }

  .coordinate-form {
    grid-template-columns:
      minmax(0, 1fr);
  }

  .coordinate-actions {
    width: 100%;
  }

  .coordinate-actions button {
    flex: 1 1 0;
  }

  .sites-map-section
  .detail-section-head,
  .coordinate-section
  .detail-section-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* Phase 17 customer usage report */

.site-report-section {
  display: grid;
  gap: 12px;
}

.site-report-help {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.site-report-period {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
}

.site-report-period span {
  color: var(--muted);
}

.site-report-period strong {
  font-weight: 600;
}

.site-report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.site-report-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.site-report-error {
  margin: 0;
}

.site-report-actions button:disabled {
  cursor: wait;
  opacity: .62;
}

@media (max-width: 760px) {
  .site-report-period {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .site-report-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .site-report-actions > * {
    width: 100%;
  }
}
