:root {
  color-scheme: light;
  --page: #f3f5f6;
  --surface: #ffffff;
  --surface-muted: #e9eff1;
  --text: #17212b;
  --muted: #52636c;
  --border: #c9d3d8;
  --border-strong: #aebcc2;
  --brand: #164c50;
  --brand-action: #146c70;
  --brand-soft: #eef8f7;
  --success: #146c43;
  --success-soft: #e6f4ec;
  --danger: #b42318;
  --danger-soft: #fbe9e7;
  --warning: #8a4b0f;
  --warning-soft: #fff0dc;
  --unknown: #6b5d22;
  --unknown-soft: #f5f0dc;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 Arial, Helvetica, sans-serif;
}

a {
  color: var(--brand-action);
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  min-height: 58px;
  background: var(--brand);
  color: #ffffff;
}

.site-header__inner {
  display: flex;
  width: min(1220px, calc(100% - 48px));
  min-height: 58px;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.site-header__brand {
  color: #ffffff;
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}

.site-header__actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.site-header__user {
  max-width: 280px;
  overflow: hidden;
  color: #dcebec;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-header form {
  margin: 0;
}

.header-button,
.header-link {
  min-height: 40px;
  border: 0;
  padding: 9px 0;
  background: transparent;
  color: #ffffff;
  font-weight: 600;
  text-decoration: none;
}

.header-button:hover,
.header-link:hover,
.site-header__brand:hover {
  text-decoration: underline;
}

.page-shell {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: 30px 0 48px;
}

.page-shell--medium {
  width: min(1060px, calc(100% - 48px));
}

.page-shell--narrow {
  width: min(720px, calc(100% - 48px));
}

.auth-shell {
  display: grid;
  min-height: calc(100vh - 58px);
  place-items: center;
  padding-top: 32px;
}

.auth-panel {
  width: min(380px, 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px;
  background: var(--surface);
}

.page-heading {
  margin-bottom: 22px;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0 0 6px;
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  margin: 30px 0 12px;
  font-size: 19px;
  line-height: 1.3;
}

h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

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

.page-heading .muted,
.empty-state {
  margin: 0;
}

.section-band {
  margin-top: 28px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.section-band h2 {
  margin-top: 0;
}

.button,
.filter-form button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--brand-action);
  border-radius: 4px;
  padding: 9px 13px;
  background: var(--brand-action);
  color: #ffffff;
  font-weight: 700;
  text-decoration: none;
}

.button:hover,
.filter-form button:hover {
  background: var(--brand);
}

.button--secondary {
  background: var(--surface);
  color: var(--brand-action);
}

.button--secondary:hover {
  background: var(--brand-soft);
}

.action-bar,
.area-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.area-links {
  margin-top: 18px;
}

.area-links .button {
  min-width: 150px;
}

.filter-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 22px;
}

.filter-form--compact {
  grid-template-columns: minmax(220px, 2fr) repeat(
      auto-fit,
      minmax(145px, 1fr)
    );
}

.filter-field {
  display: grid;
  min-width: 0;
  gap: 6px;
  font-weight: 700;
}

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

.filter-field input,
.filter-field select,
.auth-panel input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--text);
}

.filter-check {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.filter-check input {
  width: 18px;
  min-height: 18px;
  margin: 0;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.metric {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  background: var(--surface);
}

.metric strong {
  display: block;
  margin-bottom: 3px;
  font-size: 25px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

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

.summary-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 18px 34px;
  margin: 16px 0 20px;
}

.summary-inline strong {
  display: block;
  font-size: 24px;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  min-width: 660px;
  border-collapse: collapse;
  background: var(--surface);
}

.data-table--wide {
  min-width: 920px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid #d9e0e3;
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table th {
  background: var(--surface-muted);
  white-space: nowrap;
}

.align-right {
  text-align: right !important;
}

.nowrap {
  white-space: nowrap;
}

.code-text {
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.long-text {
  min-width: 240px;
  max-width: 390px;
  white-space: normal;
}

.link-list,
.detail-list,
.compact-checks {
  display: grid;
  gap: 5px;
}

.link-list a,
.attachment-actions a,
.table-link {
  color: var(--brand-action);
  font-weight: 700;
  text-decoration: none;
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 250px;
}

.attachment-item {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  width: min(100%, 290px);
  min-height: 74px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.attachment-preview {
  display: grid;
  width: 88px;
  height: 72px;
  place-items: center;
  overflow: hidden;
  background: var(--surface-muted);
  color: var(--muted);
  text-decoration: none;
}

.attachment-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-placeholder {
  font-size: 12px;
  font-weight: 800;
}

.attachment-meta {
  display: grid;
  min-width: 0;
  align-content: center;
  gap: 7px;
  padding: 8px 10px;
}

.attachment-meta > span {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-actions {
  display: flex;
  gap: 12px;
  font-size: 13px;
}

.table-link {
  white-space: nowrap;
}

.empty-state {
  padding: 30px 0;
  color: var(--muted);
}

.pagination {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
}

.pagination a {
  color: var(--brand-action);
  font-weight: 700;
  text-decoration: none;
}

.pagination a:last-child {
  text-align: right;
}

.heartbeat {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px;
  background: var(--surface);
}

.heartbeat strong {
  display: block;
  margin-bottom: 4px;
}

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

#map {
  width: 100%;
  height: min(66vh, 680px);
  min-height: 360px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #dde6e8;
}

.diagnostic-summary {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
}

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

.summary-heading h2 {
  margin: 0;
}

.summary-heading > span {
  color: var(--muted);
}

.checks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 1px;
  border: 1px solid var(--border);
  background: var(--border);
}

.diagnostic-check {
  min-width: 0;
  padding: 12px;
  background: var(--surface);
}

.diagnostic-check strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.diagnostic-check span {
  font-weight: 700;
}

.ok span,
.compact-checks .ok b {
  color: var(--success);
}

.issue span,
.compact-checks .issue b,
.detail-list .issue {
  color: var(--danger);
}

.unknown span,
.compact-checks .unknown b,
.detail-list .unknown {
  color: var(--unknown);
}

.status {
  display: inline-block;
  border-radius: 4px;
  padding: 4px 7px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

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

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

.status.unknown {
  background: var(--unknown-soft);
  color: var(--unknown);
}

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

.status.missing {
  background: var(--surface-muted);
  color: #465860;
}

.status.inactive {
  background: #ececef;
  color: #4c4c55;
}

.compact-checks {
  min-width: 240px;
}

.compact-checks span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.compact-checks b {
  font-size: 13px;
}

.detail-list {
  min-width: 210px;
  color: var(--muted);
  font-size: 13px;
}

.detail-list .stale {
  color: var(--warning);
  font-weight: 700;
}

.auth-panel h1 {
  margin-bottom: 22px;
  font-size: 24px;
}

.auth-panel .filter-field {
  margin-top: 15px;
}

.auth-panel .button {
  width: 100%;
  margin-top: 22px;
}

.errorlist {
  margin: 0 0 12px;
  padding: 0;
  color: #a61b1b;
  list-style: none;
}

.site-messages {
  margin-bottom: 18px;
}

.site-message {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  background: var(--surface);
}

.site-message--success {
  border-color: #8dc8a8;
  background: var(--success-soft);
  color: var(--success);
}

.policy-heading,
.policy-editor__title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.policy-heading .button {
  flex: 0 0 auto;
}

.policy-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  border-top: 1px solid var(--border);
}

.policy-sidebar {
  min-width: 0;
  border-right: 1px solid var(--border);
  padding: 0 18px 30px 0;
}

.policy-sidebar h2,
.policy-editor h2 {
  margin-top: 20px;
}

.policy-list {
  display: grid;
  gap: 4px;
}

.policy-list__item {
  display: grid;
  gap: 3px;
  border-left: 3px solid transparent;
  padding: 10px 9px;
  color: var(--text);
  text-decoration: none;
}

.policy-list__item:hover {
  background: var(--surface-muted);
}

.policy-list__item.is-selected {
  border-left-color: var(--brand-action);
  background: var(--brand-soft);
}

.policy-list__item span {
  color: var(--muted);
  font-size: 13px;
}

.policy-editor {
  min-width: 0;
  padding: 0 0 30px 24px;
}

.policy-editor__title > div {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.policy-settings-grid {
  display: grid;
  grid-template-columns: minmax(220px, 2fr) repeat(2, minmax(170px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.policy-editor input[type="text"],
.policy-editor input[type="number"],
.policy-editor input[type="time"] {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--text);
}

.input-with-suffix {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.input-with-suffix input {
  border-radius: 4px 0 0 4px !important;
}

.input-with-suffix > span {
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-left: 0;
  border-radius: 0 4px 4px 0;
  padding: 0 9px;
  background: var(--surface-muted);
  color: var(--muted);
  font-weight: 400;
}

.schedule-editor {
  border-top: 1px solid var(--border);
}

.schedule-row {
  display: grid;
  grid-template-columns: minmax(145px, 1.3fr) repeat(4, minmax(105px, 1fr));
  gap: 10px;
  align-items: end;
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}

.schedule-row.is-disabled .schedule-time {
  opacity: 0.5;
}

.schedule-day {
  display: flex;
  min-height: 42px;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.schedule-day input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.schedule-day .errorlist {
  flex-basis: 100%;
  margin: 0;
  font-size: 13px;
}

.schedule-time {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.device-checklist > div {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px 14px;
}

.device-checklist label {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding: 7px 2px;
}

.device-checklist input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.policy-save-bar {
  position: sticky;
  z-index: 5;
  bottom: 0;
  margin-top: 24px;
  border-top: 1px solid var(--border);
  padding: 14px 0;
  background: var(--page);
}

.policy-empty {
  padding-top: 52px;
  text-align: center;
}

.policy-empty h2 {
  margin: 0 0 6px;
}

.privacy-page article {
  max-width: 720px;
}

.privacy-page section {
  border-top: 1px solid var(--border);
  padding: 4px 0 8px;
}

.privacy-page section:first-of-type {
  border-top: 0;
}

.privacy-page p,
.privacy-page li {
  line-height: 1.65;
}

.privacy-page ul {
  padding-left: 22px;
}

.privacy-page li + li {
  margin-top: 8px;
}

@media (max-width: 760px) {
  .site-header__inner,
  .page-shell,
  .page-shell--medium,
  .page-shell--narrow {
    width: calc(100% - 32px);
  }

  .site-header__user {
    display: none;
  }

  .page-shell {
    padding: 22px 0 36px;
  }

  .filter-form,
  .filter-form--compact {
    grid-template-columns: 1fr 1fr;
  }

  .filter-field--device {
    grid-column: 1 / -1;
  }

  .heartbeat {
    grid-template-columns: 1fr;
  }

  .summary-heading {
    display: block;
  }

  .summary-heading > span {
    display: block;
    margin-top: 6px;
  }

  .data-table th,
  .data-table td {
    padding: 9px 8px;
  }

  .policy-heading,
  .policy-editor__title {
    align-items: stretch;
    flex-direction: column;
  }

  .policy-layout {
    grid-template-columns: 1fr;
  }

  .policy-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 0 0 18px;
  }

  .policy-list {
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  }

  .policy-editor {
    padding: 0 0 30px;
  }

  .policy-settings-grid {
    grid-template-columns: 1fr 1fr;
  }

  .policy-name-field {
    grid-column: 1 / -1;
  }

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

  .schedule-day {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  .site-header__inner {
    gap: 12px;
  }

  .site-header__actions {
    gap: 10px;
  }

  .filter-form,
  .filter-form--compact,
  .checks {
    grid-template-columns: 1fr;
  }

  .filter-field--device {
    grid-column: auto;
  }

  .filter-form button,
  .button {
    width: 100%;
  }

  .action-bar .button,
  .area-links .button {
    flex: 1 1 100%;
  }

  .summary-inline {
    justify-content: space-between;
    gap: 14px;
  }

  .pagination {
    grid-template-columns: 1fr 1fr;
  }

  .pagination > span:nth-child(2) {
    grid-column: 1 / -1;
    grid-row: 1;
    text-align: center;
  }

  #map {
    min-height: 320px;
    height: 58vh;
  }

  .policy-settings-grid {
    grid-template-columns: 1fr;
  }

  .policy-name-field {
    grid-column: auto;
  }
}
