:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17202a;
  background: #f5f7f9;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 68px;
  padding: 0 max(22px, calc((100vw - 1260px) / 2));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid #dce2e7;
  backdrop-filter: blur(12px);
}

.brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #17202a;
  text-decoration: none;
  font-size: 18px;
  font-weight: 800;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: #17202a;
  border-radius: 6px;
  font-size: 12px;
}

.main-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.nav-item,
.segmented button {
  min-height: 36px;
  padding: 7px 13px;
  color: #5e6974;
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-weight: 700;
}

.nav-item.active,
.segmented button.active {
  color: #17202a;
  background: #e9eef2;
}

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

.readonly-badge,
.tag {
  padding: 6px 9px;
  color: #197149;
  background: #e7f6ed;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 800;
}

.icon-button,
.primary-button {
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 750;
}

.icon-button {
  color: #37434e;
  background: #ffffff;
  border: 1px solid #ced6dc;
}

.primary-button {
  color: #ffffff;
  background: #17202a;
  border: 1px solid #17202a;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.danger-button {
  min-height: 34px;
  padding: 6px 10px;
  color: #b83731;
  background: #ffffff;
  border: 1px solid #e2aaa6;
  border-radius: 6px;
  font-weight: 700;
}

.app-shell {
  width: min(1260px, calc(100% - 44px));
  margin: 0 auto;
  padding: 34px 0 64px;
}

.page-heading {
  margin-bottom: 22px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.page-heading p,
.panel-heading p,
.hero-copy p {
  margin: 0 0 5px;
  color: #6b7782;
  font-size: 12px;
  font-weight: 760;
}

.page-heading h1 {
  margin: 0 0 8px;
  font-size: 28px;
  letter-spacing: 0;
}

#page-description {
  max-width: 680px;
  margin: 0;
  color: #606d78;
  font-size: 14px;
  font-weight: 400;
}

.freshness {
  max-width: 420px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #66737e;
  background: #eef8f2;
  border-radius: 6px;
  font-size: 13px;
}

.freshness.delayed {
  color: #7f5a15;
  background: #fff7e7;
}

.freshness.stale {
  color: #9a2e27;
  background: #fff0ee;
}

.privacy-notice {
  margin: -4px 0 20px;
  padding: 12px 14px;
  color: #5e5325;
  background: #fff9df;
  border-left: 4px solid #d8ae35;
  font-size: 13px;
  line-height: 1.55;
}

.status-dot {
  width: 9px;
  height: 9px;
  background: #80909c;
  border-radius: 50%;
}

.status-dot.ready,
.status-dot.fresh {
  background: #2e9d66;
}

.status-dot.delayed {
  background: #d89a28;
}

.status-dot.error,
.status-dot.stale,
.status-dot.unknown {
  background: #d9493f;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero-panel {
  min-height: 300px;
  padding: 34px;
  display: grid;
  grid-template-columns: minmax(280px, 0.7fr) minmax(420px, 1.3fr);
  align-items: stretch;
  gap: 30px;
  color: #f8fafb;
  background: #111820;
  border: 1px solid #111820;
  border-radius: 8px;
}

.hero-copy {
  align-self: center;
}

.hero-copy p {
  color: #9eabb5;
}

.hero-copy strong {
  display: block;
  margin: 8px 0 14px;
  font-size: clamp(34px, 5vw, 54px);
  line-height: 1;
}

.hero-copy span {
  color: #aeb9c1;
  font-size: 14px;
}

.hero-panel canvas {
  width: 100%;
  height: 220px;
}

.metric-strip {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: #ffffff;
  border: 1px solid #dce2e7;
  border-radius: 8px;
}

.metric-card {
  min-height: 105px;
  padding: 20px;
  border-right: 1px solid #e2e7eb;
}

.metric-card:last-child {
  border-right: 0;
}

.metric-card span {
  display: block;
  margin-bottom: 12px;
  color: #6b7782;
  font-size: 12px;
  font-weight: 700;
}

.metric-card strong {
  font-size: clamp(20px, 2.5vw, 28px);
}

.metric-card small {
  display: block;
  margin-top: 7px;
  color: #788590;
}

.positive {
  color: #248955;
}

.negative {
  color: #d34238;
}

.dashboard-grid {
  margin-top: 22px;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 20px;
}

.panel {
  min-width: 0;
  padding: 24px;
  background: #ffffff;
  border: 1px solid #dce2e7;
  border-radius: 8px;
}

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

.panel-heading h2 {
  margin: 0;
  font-size: 19px;
}

.panel-heading > span {
  color: #5d6974;
  font-size: 13px;
  font-weight: 700;
}

.allocation-content {
  min-height: 280px;
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(230px, 1.1fr);
  align-items: center;
  gap: 24px;
}

.allocation-content canvas,
.market-panel canvas {
  width: 100%;
  height: 250px;
}

.legend-list,
.data-list {
  display: grid;
  gap: 2px;
}

.legend-row,
.data-row {
  min-height: 48px;
  padding: 10px 0;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid #edf0f2;
}

.legend-row:last-child,
.data-row:last-child {
  border-bottom: 0;
}

.legend-name {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.row-value {
  text-align: right;
  font-weight: 750;
}

.row-value small {
  display: block;
  margin-top: 3px;
  color: #7a8791;
  font-weight: 500;
}

.compact-metrics {
  margin-bottom: 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid #e1e6ea;
  border-radius: 6px;
}

.compact-metric {
  padding: 13px;
  border-right: 1px solid #e1e6ea;
}

.compact-metric:last-child {
  border-right: 0;
}

.compact-metric span {
  display: block;
  margin-bottom: 7px;
  color: #74808a;
  font-size: 11px;
}

.compact-metric strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.toolbar {
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.segmented {
  padding: 3px;
  display: inline-flex;
  gap: 2px;
  background: #e9eef2;
  border-radius: 7px;
}

.segmented button.active {
  background: #ffffff;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #697680;
  font-size: 12px;
}

.search-field input {
  width: 220px;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid #ced6dc;
  border-radius: 6px;
}

.table-panel {
  margin-top: 20px;
  padding: 0;
  overflow: hidden;
}

.table-panel .panel-heading {
  padding: 22px 24px 0;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

th,
td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid #e6eaed;
  font-size: 13px;
}

th {
  color: #66737e;
  background: #f7f9fa;
  font-size: 12px;
  font-weight: 760;
}

td:first-child {
  font-weight: 760;
}

.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  margin: 0;
  padding: 48px 24px;
  color: #788590;
  text-align: center;
}

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

.risk-grid canvas {
  width: 100%;
  height: 300px;
}

.span-full {
  grid-column: 1 / -1;
}

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

.alert-item {
  padding: 15px 16px;
  border-left: 4px solid #93a0aa;
  background: #f7f9fa;
}

.alert-item.warning {
  border-left-color: #d89a28;
  background: #fff7e7;
}

.alert-item.ok {
  border-left-color: #2e9d66;
  background: #eef8f2;
}

.alert-item strong,
.alert-item span {
  display: block;
}

.alert-item span {
  margin-top: 4px;
  color: #65727d;
  font-size: 13px;
}

.error-banner {
  margin-top: 22px;
  padding: 16px 18px;
  color: #9a2e27;
  background: #fff0ee;
  border-left: 4px solid #d34238;
}

.share-dialog {
  width: min(680px, calc(100% - 28px));
  max-height: min(760px, calc(100vh - 40px));
  padding: 24px;
  color: #17202a;
  background: #ffffff;
  border: 1px solid #cfd7dd;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(23, 32, 42, 0.28);
}

.share-dialog::backdrop {
  background: rgba(17, 24, 32, 0.52);
}

.dialog-heading,
.share-list-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.dialog-heading p {
  margin: 0 0 5px;
  color: #6b7782;
  font-size: 11px;
  font-weight: 800;
}

.dialog-heading h2,
.share-list-heading h3 {
  margin: 0;
}

.dialog-description {
  margin: 12px 0 20px;
  color: #63707b;
  font-size: 13px;
}

.share-form {
  display: grid;
  gap: 16px;
  padding: 18px;
  background: #f7f9fa;
  border: 1px solid #dce2e7;
  border-radius: 8px;
}

.share-form > label,
.auth-form label {
  display: grid;
  gap: 7px;
  color: #5f6c77;
  font-size: 12px;
  font-weight: 700;
}

.share-form input[type="text"],
.share-form input:not([type]),
.share-form select,
.share-result input,
.auth-form input {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  background: #ffffff;
  border: 1px solid #cbd4db;
  border-radius: 6px;
}

.share-form fieldset {
  margin: 0;
  padding: 0;
  display: flex;
  gap: 18px;
  border: 0;
}

.share-form legend {
  margin-bottom: 9px;
  color: #5f6c77;
  font-size: 12px;
  font-weight: 700;
}

.share-form fieldset label,
.toggle-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(150px, 0.55fr) minmax(240px, 1.45fr);
  align-items: end;
  gap: 18px;
}

.form-grid > label:first-child {
  display: grid;
  gap: 7px;
  color: #5f6c77;
  font-size: 12px;
  font-weight: 700;
}

.share-result {
  margin-top: 16px;
  padding: 14px;
  background: #eef8f2;
  border-left: 4px solid #2e9d66;
}

.share-result > span {
  display: block;
  margin-bottom: 9px;
  color: #47705a;
  font-size: 12px;
}

.share-result > div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.share-list-heading {
  margin: 24px 0 10px;
  align-items: baseline;
}

.share-list-heading h3 {
  font-size: 16px;
}

.share-list-heading span {
  color: #74808a;
  font-size: 12px;
}

.share-list {
  display: grid;
  gap: 8px;
}

.share-list-item {
  padding: 13px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid #dce2e7;
  border-radius: 6px;
}

.share-list-item strong,
.share-list-item span,
.share-list-item small {
  display: block;
}

.share-list-item span,
.share-list-item small {
  margin-top: 4px;
  color: #6d7983;
  font-size: 12px;
}

.empty-state.compact {
  padding: 20px;
}

.auth-page {
  min-height: 100vh;
  background: #f5f7f9;
}

.auth-shell {
  min-height: 100vh;
  padding: 28px;
  display: grid;
  place-items: center;
}

.auth-panel {
  width: min(430px, 100%);
  padding: 30px;
  background: #ffffff;
  border: 1px solid #d6dde2;
  border-radius: 8px;
}

.auth-copy {
  margin: 42px 0 24px;
}

.auth-copy p {
  margin: 0 0 7px;
  color: #687580;
  font-size: 11px;
  font-weight: 800;
}

.auth-copy h1 {
  margin: 0 0 9px;
  font-size: 26px;
}

.auth-copy span,
.auth-note {
  color: #6b7782;
  font-size: 13px;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-note {
  margin: 20px 0 0;
}

.form-error {
  padding: 11px 12px;
  color: #9a2e27;
  background: #fff0ee;
  border-left: 4px solid #d34238;
  font-size: 13px;
}

footer {
  width: min(1260px, calc(100% - 44px));
  min-height: 74px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  color: #77838d;
  border-top: 1px solid #dce2e7;
  font-size: 12px;
}

body.privacy [data-private],
body.privacy .private-value {
  filter: blur(7px);
  user-select: none;
}

@media (max-width: 920px) {
  .app-header {
    grid-template-columns: 1fr auto;
  }

  .main-nav {
    position: fixed;
    right: 14px;
    bottom: max(14px, env(safe-area-inset-bottom));
    left: 14px;
    z-index: 30;
    justify-content: space-around;
    padding: 7px;
    background: #ffffff;
    border: 1px solid #ccd5dc;
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(23, 32, 42, 0.16);
  }

  .nav-item {
    min-height: 44px;
  }

  .header-actions .readonly-badge {
    display: none;
  }

  .hero-panel,
  .dashboard-grid,
  .risk-grid {
    grid-template-columns: 1fr;
  }

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

  .metric-card:nth-child(2) {
    border-right: 0;
  }

  .metric-card:nth-child(-n + 2) {
    border-bottom: 1px solid #e2e7eb;
  }

  footer {
    padding-bottom: calc(86px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 620px) {
  .app-header {
    min-height: 62px;
    padding: 0 14px;
  }

  .brand {
    font-size: 15px;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .icon-button {
    padding-inline: 9px;
  }

  .primary-button {
    padding-inline: 10px;
  }

  .app-shell {
    width: min(100% - 28px, 1260px);
    padding: 22px 0 calc(82px + env(safe-area-inset-bottom));
  }

  .page-heading,
  .toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .freshness {
    align-self: stretch;
  }

  .hero-panel {
    min-height: 360px;
    padding: 20px;
    grid-template-columns: 1fr;
  }

  .hero-panel canvas {
    height: 180px;
  }

  .metric-strip {
    grid-template-columns: 1fr;
  }

  .metric-card {
    border-right: 0;
    border-bottom: 1px solid #e2e7eb;
  }

  .metric-card:last-child {
    border-bottom: 0;
  }

  .allocation-content {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 18px;
  }

  .table-panel {
    padding: 0;
  }

  .table-panel .panel-heading {
    padding: 18px 18px 0;
  }

  table {
    min-width: 760px;
  }

  th:first-child,
  td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: #ffffff;
    box-shadow: 1px 0 0 #e6eaed;
  }

  th:first-child {
    z-index: 2;
    background: #f7f9fa;
  }

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

  .compact-metric:nth-child(2) {
    border-right: 0;
  }

  .compact-metric:nth-child(-n + 2) {
    border-bottom: 1px solid #e1e6ea;
  }

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

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }

  .share-dialog {
    padding: 18px;
  }

  .share-form fieldset,
  .form-grid {
    align-items: stretch;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  footer {
    width: min(100% - 28px, 1260px);
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
  }
}
