:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef3f3;
  --line: #d7e0df;
  --text: #1d2527;
  --muted: #627072;
  --strong: #0d3b3e;
  --accent: #0f766e;
  --accent-soft: #dff4ef;
  --warn: #a15c00;
  --warn-soft: #fff1d6;
  --error: #b42318;
  --error-soft: #fde4df;
  --ok: #147447;
  --ok-soft: #dff5e8;
  --chart-secondary: #315c88;
  --brand-gold: #b89136;
  --shadow: 0 12px 30px rgba(29, 37, 39, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

body.locked {
  overflow: hidden;
}

body.locked .app-shell {
  display: none;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 22px;
}

.lock-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background: var(--bg);
}

.lock-screen[hidden] {
  display: none;
}

.lock-panel {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.lock-panel h1 {
  margin: 0 0 20px;
  padding-bottom: 17px;
  border-bottom: 1px solid var(--line);
  font-size: 1.7rem;
  text-align: center;
}

.lock-layout {
  width: min(420px, 100%);
  display: grid;
  justify-items: center;
  gap: 18px;
}

.lock-logo {
  width: 152px;
  height: 93px;
  object-fit: contain;
}

.lock-field {
  margin-bottom: 12px;
}

.lock-field input {
  width: 100%;
  min-height: 44px;
}

.lock-panel button {
  width: 100%;
  min-height: 44px;
}

.lock-error {
  margin: 12px 0 0;
  color: var(--error);
  font-size: 0.86rem;
  font-weight: 700;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin: 0 auto 14px;
  max-width: 1640px;
}

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

.portal-logo {
  width: 47px;
  height: 29px;
  flex: 0 0 47px;
  object-fit: contain;
}

.portal-brand::after {
  content: "";
  align-self: stretch;
  width: 2px;
  order: -1;
  background: var(--brand-gold);
}

.topbar-actions {
  display: grid;
  justify-items: end;
  gap: 7px;
}

.session-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.secondary-button {
  min-height: 30px;
  padding: 0 10px;
  border-color: var(--line);
  color: var(--strong);
  background: var(--surface);
}

.danger-button {
  border-color: #9f2d24;
  color: #ffffff;
  background: var(--error);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: var(--strong);
  letter-spacing: 0;
}

h1 {
  font-size: 1.65rem;
}

h2 {
  font-size: 1rem;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.field {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.field input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  color: var(--text);
  background: #fbfdfd;
}

.field select {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  color: var(--text);
  background: #fbfdfd;
}

.search-field input {
  width: 240px;
}

button {
  min-height: 38px;
  border: 1px solid #0a625d;
  border-radius: 7px;
  padding: 0 14px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 750;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.tabs {
  display: flex;
  gap: 8px;
  max-width: 1640px;
  margin: 0 auto 14px;
  overflow-x: auto;
}

.primary-views {
  display: flex;
  gap: 4px;
  max-width: 1640px;
  margin: 0 auto 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.module-nav {
  display: contents;
}

.primary-view-button,
.admin-tab {
  min-height: 34px;
  border-color: transparent;
  color: var(--muted);
  background: transparent;
}

.primary-view-button.active,
.admin-tab.active {
  border-color: var(--line);
  color: var(--strong);
  background: var(--surface);
}

.tab-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  color: var(--strong);
  background: var(--surface);
  white-space: nowrap;
}

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

main {
  max-width: 1640px;
  margin: 0 auto;
}

.portal-home-view {
  padding: 30px 0 56px;
}

.portal-home-heading {
  margin-bottom: 22px;
}

.portal-home-heading h2 {
  font-size: 1.45rem;
}

.portal-projects {
  display: grid;
  gap: 32px;
}

.portal-project {
  padding: 22px 0 28px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.portal-project-heading {
  margin-bottom: 16px;
}

.portal-project-heading h2 {
  font-size: 1.15rem;
}

.portal-module-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 360px));
  gap: 10px;
}

.portal-module-button {
  min-height: 94px;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 6px;
  padding: 16px;
  border-color: var(--line);
  color: var(--strong);
  background: var(--surface);
  text-align: left;
  box-shadow: 0 5px 16px rgba(29, 37, 39, 0.05);
}

.portal-module-button:hover,
.portal-module-button:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.portal-module-button strong {
  font-size: 0.96rem;
}

.portal-module-button span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.portal-empty {
  padding: 28px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.admin-view {
  display: block;
}

.admin-toolbar {
  min-height: 54px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.admin-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.month-field input {
  min-width: 170px;
}

.admin-section {
  display: block;
}

.admin-metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

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

.analytics-panel {
  min-width: 0;
}

.daily-chart,
.hourly-chart {
  position: relative;
  min-height: 270px;
  padding: 22px 16px 12px 48px;
  background: #ffffff;
}

.chart-scale {
  position: absolute;
  inset: 22px auto 34px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

.daily-bars,
.hourly-bars {
  height: 226px;
  display: grid;
  align-items: end;
  gap: 3px;
}

.daily-bars {
  grid-template-columns: repeat(31, minmax(5px, 1fr));
  overflow-x: auto;
}

.hourly-bars {
  grid-template-columns: repeat(24, minmax(7px, 1fr));
}

.chart-bar-column {
  min-width: 0;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 20px;
  align-items: end;
}

.chart-bar-track {
  position: relative;
  width: 100%;
  height: 100%;
  border-bottom: 1px solid var(--line);
  background: #fbfdfd;
}

.chart-bar-track::before {
  content: "";
  position: absolute;
  inset: 50% 0 auto;
  border-top: 1px solid #eef3f3;
}

.chart-bar {
  position: absolute;
  inset: auto 16% 0;
  min-height: 0;
  background: var(--accent);
}

.chart-bar.secondary {
  background: var(--chart-secondary);
}

.chart-label {
  min-height: 20px;
  display: grid;
  place-items: end center;
  color: var(--muted);
  font-size: 0.65rem;
  font-variant-numeric: tabular-nums;
}

.admin-table-panel {
  margin-top: 14px;
}

.access-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.user-form-panel {
  position: sticky;
  top: 14px;
}

.user-form-fields {
  display: grid;
  gap: 13px;
  padding: 16px;
}

.permission-list {
  display: grid;
  gap: 10px;
}

.permission-project {
  min-width: 0;
  margin: 0;
  padding: 10px 12px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.permission-project legend {
  padding: 0 5px;
  color: var(--strong);
  font-size: 0.78rem;
  font-weight: 800;
}

.permission-project .toggle-field + .toggle-field {
  border-top: 1px solid var(--surface-soft);
}

.permission-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.toggle-field {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
}

.toggle-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.user-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(128px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
}

.metric strong {
  display: block;
  margin-top: 7px;
  color: var(--strong);
  font-size: 1.08rem;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.status-panel {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--strong);
  font-weight: 650;
}

.status-panel.error {
  border-color: #efb0a7;
  background: var(--error-soft);
  color: var(--error);
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.side-stack {
  display: grid;
  gap: 14px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(420px, 0.75fr);
  gap: 14px;
  margin-top: 14px;
  align-items: start;
}

.document-match-panel {
  margin-top: 14px;
}

.match-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  border-bottom: 1px solid var(--line);
}

.match-summary-item {
  min-height: 62px;
  padding: 11px 14px;
  border-right: 1px solid var(--line);
  background: #fbfdfd;
}

.match-summary-item:last-child {
  border-right: 0;
}

.match-summary-item span,
.match-detail-heading span,
.match-source-detail > span {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.match-summary-item strong {
  display: block;
  margin-top: 4px;
  color: var(--strong);
  font-size: 0.96rem;
}

.match-summary-item.ok strong {
  color: var(--ok);
}

.match-summary-item.error strong {
  color: var(--error);
}

.document-match-table-wrap {
  max-height: 560px;
}

.document-match-table {
  min-width: 1800px;
}

.document-match-table .match-reason {
  min-width: 340px;
  white-space: normal;
  line-height: 1.35;
}

.match-detail {
  border-top: 1px solid var(--line);
  background: #fbfdfd;
}

.match-detail:empty {
  display: none;
}

.match-detail-heading {
  display: grid;
  grid-template-columns: minmax(180px, 0.3fr) minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
}

.match-detail-heading strong {
  display: block;
  margin-top: 3px;
  color: var(--strong);
}

.match-detail-heading p {
  margin: 0;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 650;
}

.match-source-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.match-source-detail {
  min-width: 0;
  padding: 14px;
  border-right: 1px solid var(--line);
}

.match-source-detail:last-child {
  border-right: 0;
}

.match-source-detail > strong {
  display: block;
  margin: 3px 0 10px;
  color: var(--strong);
}

.match-source-detail.missing > strong {
  color: var(--muted);
  font-weight: 700;
}

.match-source-detail dl {
  display: grid;
  gap: 7px;
  margin: 0;
}

.match-source-detail dl div {
  display: grid;
  grid-template-columns: minmax(90px, 0.35fr) minmax(0, 1fr);
  gap: 8px;
}

.match-source-detail dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
}

.match-source-detail dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: 0.76rem;
  overflow-wrap: anywhere;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-heading {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfdfd;
}

.panel-heading-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.export-button {
  width: auto;
  min-height: 32px;
  padding: 0 11px;
  border-color: var(--line);
  color: var(--strong);
  background: var(--surface);
  font-size: 0.76rem;
}

.export-button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.export-button:disabled {
  cursor: not-allowed;
}

.count-pill,
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.76rem;
  font-weight: 800;
}

.count-pill {
  color: var(--accent);
  background: var(--accent-soft);
}

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

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

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

.status-badge.muted {
  color: var(--muted);
  background: var(--surface-soft);
}

.table-wrap {
  overflow: auto;
  max-height: 620px;
}

.table-wrap.compact {
  max-height: 410px;
}

.coverage-table {
  max-height: 280px;
}

.sub-table {
  border-top: 1px solid var(--line);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfdfd;
}

.chip-button {
  min-height: 30px;
  border-color: var(--line);
  padding: 0 10px;
  color: var(--strong);
  background: var(--surface);
  font-size: 0.76rem;
}

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

.hint-text {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
  font-size: 0.82rem;
}

th,
td {
  min-height: 36px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f8fbfb;
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td span {
  color: var(--muted);
  font-size: 0.75rem;
}

tr.clickable {
  cursor: pointer;
}

tr.clickable:hover,
tr.selected {
  background: var(--accent-soft);
}

.method-list {
  display: grid;
}

.method-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
}

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

.method-row span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 750;
}

.method-row strong {
  color: var(--strong);
  font-variant-numeric: tabular-nums;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 0;
  border-bottom: 1px solid var(--line);
}

.meta-item {
  min-height: 62px;
  padding: 11px 14px;
  border-right: 1px solid var(--line);
}

.meta-item:last-child {
  border-right: 0;
}

.meta-item span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.meta-item strong {
  display: block;
  margin-top: 4px;
  color: var(--strong);
  font-size: 0.92rem;
}

.amount-warn {
  color: var(--warn);
  font-weight: 800;
}

.amount-info {
  color: var(--accent);
  font-weight: 800;
}

.amount-error {
  color: var(--error);
  font-weight: 850;
}

.empty-row td {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1180px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .topbar-actions {
    justify-items: stretch;
  }

  .session-controls {
    justify-content: flex-end;
  }

  .search-field input {
    width: min(100%, 360px);
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .layout-grid,
  .detail-grid,
  .analytics-grid,
  .access-layout {
    grid-template-columns: 1fr;
  }

  .admin-metric-grid {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }

  .user-form-panel {
    position: static;
  }

  .match-summary {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }

  .match-source-grid {
    grid-template-columns: 1fr;
  }

  .match-source-detail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .match-source-detail:last-child {
    border-bottom: 0;
  }

  .meta-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
  }

  .metric-grid,
  .admin-metric-grid,
  .meta-grid,
  .match-summary {
    grid-template-columns: 1fr;
  }

  .match-detail-heading {
    grid-template-columns: 1fr;
  }

  .toolbar {
    display: grid;
  }

  .admin-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .daily-chart,
  .hourly-chart {
    min-height: 240px;
    padding-left: 42px;
    overflow-x: auto;
  }

  .daily-bars,
  .hourly-bars {
    min-width: 560px;
    height: 196px;
  }

  .field input,
  .field select,
  .search-field input,
  button {
    width: 100%;
  }

  .primary-views {
    overflow-x: auto;
  }

  .primary-view-button {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .portal-module-list {
    grid-template-columns: 1fr;
  }

  .portal-logo {
    width: 40px;
    height: 25px;
    flex-basis: 40px;
  }
}
