:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --text: #16202a;
  --muted: #657386;
  --accent: #b9272f;
  --accent-weak: #fff4d6;
  --brand-gold: #f5b51b;
  --danger: #9f2d2d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

.login-view {
  align-items: center;
  background: var(--bg);
  display: flex;
  min-height: 100vh;
  justify-content: center;
  padding: 24px;
}

.login-panel {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
  padding: 22px;
  width: min(420px, 100%);
}

.login-panel img {
  height: 72px;
  object-fit: contain;
  object-position: left center;
  width: 280px;
}

.login-panel h1 {
  color: var(--text);
}

.login-panel p {
  color: var(--muted);
  font-size: 13px;
}

.login-panel p.waiting::after {
  animation: waiting-dots 1.2s steps(4, end) infinite;
  content: "";
  display: inline-block;
  min-width: 18px;
  text-align: left;
}

@keyframes waiting-dots {
  0% {
    content: "";
  }
  25% {
    content: ".";
  }
  50% {
    content: "..";
  }
  75%,
  100% {
    content: "...";
  }
}

.login-panel label {
  display: grid;
  gap: 5px;
}

.login-panel label span {
  color: var(--muted);
  font-size: 12px;
}

.login-panel input {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  padding: 9px 10px;
  width: 100%;
}

.login-panel input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(185, 39, 47, 0.12);
}

.topbar {
  align-items: center;
  background: #ffffff;
  border-bottom: 3px solid var(--accent);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  min-height: 84px;
  padding: 10px 18px;
}

.brand {
  align-items: center;
  display: flex;
  gap: 16px;
  min-width: 0;
}

.brand img {
  display: block;
  flex: 0 0 auto;
  height: 64px;
  object-fit: contain;
  width: 260px;
}

h1, h2, p {
  margin: 0;
}

h1 {
  color: var(--accent);
  font-size: 20px;
  line-height: 1.1;
}

h2 {
  font-size: 15px;
}

.topbar p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

button {
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  font-size: 13px;
  padding: 8px 10px;
}

button:hover {
  background: #941f26;
}

.button-link {
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  cursor: pointer;
  display: inline-block;
  font-size: 13px;
  padding: 8px 10px;
  text-decoration: none;
}

.button-link:hover {
  background: #941f26;
}

.button-link.secondary {
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--text);
}

.button-link.secondary:hover {
  background: #f0f3f7;
}

.topnav {
  display: flex;
  gap: 8px;
}

.nav-button,
.secondary-button {
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--text);
}

.nav-button:hover,
.secondary-button:hover {
  background: #f0f3f7;
}

.nav-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.actions {
  display: flex;
  gap: 8px;
}

.document-actions {
  align-items: center;
  display: flex;
  gap: 8px;
}

.link-button {
  background: transparent;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 0;
  text-align: left;
}

.link-button:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

.layout {
  display: grid;
  gap: 12px;
  grid-template-columns: 320px 390px minmax(520px, 1fr);
  height: calc(100vh - 85px);
  padding: 12px;
}

.layout.client-scoped-layout {
  grid-template-columns: 390px minmax(520px, 1fr);
}

.layout.client-scoped-layout .clients-panel {
  display: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  overflow: hidden;
}

.panel-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 44px;
  padding: 10px 12px;
}

.panel-tools {
  border-bottom: 1px solid var(--line);
  padding: 8px;
}

.panel-tools input {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  outline: none;
  padding: 8px 9px;
  width: 100%;
}

.panel-tools input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(185, 39, 47, 0.12);
}

.list {
  height: calc(100% - 92px);
  overflow: auto;
}

.admin-layout {
  display: grid;
  gap: 12px;
  grid-template-columns: 220px 360px minmax(520px, 1fr);
  height: calc(100vh - 85px);
  padding: 12px;
}

.json-viewer-layout {
  display: grid;
  gap: 12px;
  grid-template-columns: 360px minmax(620px, 1fr);
  height: calc(100vh - 85px);
  padding: 12px;
}

.system-health-layout {
  height: calc(100vh - 85px);
  padding: 12px;
}

.system-health-panel {
  height: 100%;
}

.system-health-panel .panel-header {
  align-items: flex-start;
}

.system-health-panel .panel-header p {
  color: var(--muted);
  font-size: 12px;
  margin: 3px 0 0;
}

.system-health-body {
  display: grid;
  gap: 12px;
  height: calc(100% - 57px);
  overflow: auto;
  padding: 12px;
}

.health-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.health-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 12px;
}

.health-card-title {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.health-card h3 {
  font-size: 14px;
  margin: 0;
}

.health-card dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.health-card dl div {
  display: grid;
  gap: 3px;
}

.health-card dt {
  color: var(--muted);
  font-size: 11px;
}

.health-card dd {
  font-size: 13px;
  font-weight: 700;
  margin: 0;
  overflow-wrap: anywhere;
}

.health-card-actions {
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  padding-top: 10px;
}

.status-badge {
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
}

.status-badge.ok {
  background: #e4f6e9;
  color: #17622d;
}

.status-badge.bad {
  background: #fde7e9;
  color: #941f26;
}

.health-list,
.health-log {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 7px;
  padding-top: 10px;
}

.health-list div,
.health-log div {
  font-size: 12px;
  overflow-wrap: anywhere;
}

.health-list strong,
.health-list span {
  display: block;
}

.health-list span {
  color: var(--muted);
  margin-top: 2px;
}

.json-table-panel .panel-header {
  align-items: flex-start;
}

.json-table-panel .panel-header p {
  color: var(--muted);
  font-size: 12px;
  margin: 3px 0 0;
}

.json-table {
  height: calc(100% - 92px);
  overflow-x: scroll;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.json-table table {
  min-width: 100%;
  width: max-content;
}

.json-table th,
.json-table td {
  max-width: 340px;
  white-space: nowrap;
}

.json-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.json-sort-button {
  background: transparent;
  border: 0;
  border-radius: 0;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 0;
  text-align: left;
  white-space: nowrap;
}

.json-sort-button:hover,
.json-sort-button.active {
  color: var(--accent);
}

.json-limit-notice {
  background: #fff4d6;
  border-bottom: 1px solid var(--line);
  color: #5b4a16;
  font-size: 12px;
  padding: 8px 10px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.admin-menu {
  display: grid;
  gap: 6px;
  padding: 8px;
}

.admin-tab {
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--text);
  text-align: left;
}

.admin-tab:hover {
  background: #f0f3f7;
}

.admin-tab.active {
  background: var(--accent-weak);
  border-color: var(--brand-gold);
  box-shadow: inset 4px 0 0 var(--brand-gold);
}

.admin-form {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.admin-form label {
  display: grid;
  gap: 5px;
}

.admin-form label span {
  color: var(--muted);
  font-size: 12px;
}

.admin-form input,
.admin-form select {
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  min-width: 0;
  outline: none;
  padding: 8px 9px;
  width: 100%;
}

.admin-form input:focus,
.admin-form select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(185, 39, 47, 0.12);
}

.form-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.checkbox-field {
  align-items: center;
  display: flex !important;
  gap: 8px !important;
}

.checkbox-field input {
  width: auto;
}

.checkbox-field span {
  color: var(--text) !important;
}

.form-actions {
  display: flex;
  gap: 8px;
}

.company-users-section {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  margin-top: 4px;
  padding-top: 12px;
}

.section-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.section-header-actions {
  align-items: center;
  display: flex;
  gap: 8px;
}

.compact-button {
  font-size: 12px;
  padding: 5px 8px;
}

.section-header h3 {
  font-size: 14px;
  margin: 0;
}

.section-header span,
.muted-text {
  color: var(--muted);
  font-size: 12px;
}

.company-users-list {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.company-user-row {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 9px 10px;
}

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

.company-user-row strong,
.company-user-row span {
  display: block;
}

.company-user-row span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.company-user-meta {
  text-align: right;
  white-space: nowrap;
}

.detail-panel .detail-body {
  height: calc(100% - 45px);
}

.item {
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  padding: 10px 12px;
}

.item:hover,
.item.active {
  background: var(--accent-weak);
}

.item.active {
  box-shadow: inset 4px 0 0 var(--brand-gold);
}

.item-title {
  display: flex;
  font-size: 13px;
  font-weight: 700;
  gap: 6px;
  justify-content: space-between;
}

.client-card-main {
  align-items: flex-start;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) max-content;
}

.client-item .item-title {
  display: block;
  line-height: 1.25;
}

.client-doc-count {
  align-self: center;
  font-size: 13px;
  font-weight: 700;
  justify-self: end;
  line-height: 1.1;
  text-align: right;
}

.item-name {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  margin-top: 5px;
}

.item-meta {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  gap: 3px;
  margin-top: 6px;
}

.metrics {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  margin: 12px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 11px;
}

.metric strong {
  display: block;
  font-size: 14px;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.metric-wide {
  grid-column: span 2;
}

.detail-body {
  height: calc(100% - 45px);
  overflow: auto;
}

table {
  border-collapse: collapse;
  font-size: 12px;
  min-width: 1500px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f0f3f7;
  color: #344152;
  position: sticky;
  top: 0;
  z-index: 1;
}

.support-documents-section {
  border-top: 1px solid var(--line);
  margin: 12px;
  padding-top: 12px;
}

.statement-view {
  display: grid;
  gap: 12px;
}

.statement-toolbar {
  align-items: flex-end;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px;
}

.statement-toolbar h3 {
  font-size: 16px;
  margin: 0;
}

.statement-toolbar p {
  color: var(--muted);
  font-size: 12px;
  margin: 4px 0 0;
}

.statement-filters {
  align-items: flex-end;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.statement-filters label {
  display: grid;
  gap: 4px;
}

.statement-filters span {
  color: var(--muted);
  font-size: 11px;
}

.statement-filters input {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
  padding: 7px 8px;
}

.statement-body {
  display: grid;
  gap: 10px;
}

.statement-metrics {
  margin-bottom: 0;
}

.statement-table {
  min-width: 980px;
}

.support-documents-header {
  align-items: flex-start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.support-documents-header h3 {
  font-size: 14px;
  margin: 0 0 4px;
}

.support-documents-header p {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

.support-documents-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.support-document-item {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 8px 10px;
}

.support-document-item span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 3px;
}

.support-document-actions {
  align-items: center;
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.support-upload-modal {
  max-width: min(620px, 92vw);
  padding: 0;
  width: min(620px, 92vw);
}

.support-upload-dialog {
  margin: 0;
}

.support-upload-dialog-body {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.support-upload-dialog-body label {
  display: grid;
  gap: 5px;
}

.support-upload-dialog-body span {
  color: var(--muted);
  font-size: 12px;
}

.support-upload-dialog-body input,
.support-upload-dialog-body select {
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  padding: 8px;
}

.support-upload-dialog-body p {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 12px;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: min(900px, 90vw);
  width: 760px;
}

.pdf-modal {
  height: min(880px, 92vh);
  max-width: min(1180px, 94vw);
  padding: 0;
  width: min(1180px, 94vw);
}

.pdf-modal-header,
.pdf-modal-actions {
  align-items: center;
  background: #ffffff;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  padding: 10px 12px;
}

.pdf-modal-header {
  border-bottom: 1px solid var(--line);
}

.pdf-modal-actions {
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}

.pdf-modal iframe {
  border: 0;
  display: block;
  height: calc(92vh - 104px);
  max-height: 776px;
  width: 100%;
}

pre {
  max-height: 70vh;
  overflow: auto;
  white-space: pre-wrap;
}

@media (max-width: 1180px) {
  .layout,
  .admin-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .topbar {
    align-items: flex-start;
    gap: 12px;
  }

  .brand img {
    height: 48px;
    width: 196px;
  }

  .panel {
    min-height: 320px;
  }

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