:root {
  --ink: #171716;
  --muted: #686862;
  --line: #d9d7ce;
  --surface: #fbfaf7;
  --surface-strong: #ffffff;
  --teal: #007c74;
  --teal-soft: #d8efec;
  --red: #b33a3a;
  --amber: #c98920;
  --violet: #6157a6;
  --green: #43784a;
  --shadow: 0 18px 50px rgba(28, 27, 23, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--surface);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button,
input,
select {
  font: inherit;
}

.identity-shell {
  display: grid;
  width: min(540px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 40px 0;
  align-content: center;
  gap: 24px;
}

.identity-header,
.identity-brand,
.identity-actions {
  display: flex;
  align-items: center;
}

.identity-header {
  justify-content: space-between;
  gap: 24px;
}

.identity-brand {
  gap: 14px;
}

.identity-actions {
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.auth-card {
  display: grid;
  gap: 22px;
  padding: clamp(24px, 5vw, 40px);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.auth-card form,
.auth-card [data-auth-view],
.auth-heading,
.auth-field,
#challenge-password-fields {
  display: grid;
  gap: 14px;
}

.auth-heading {
  gap: 7px;
}

.auth-heading p,
.admin-card p {
  color: var(--muted);
  line-height: 1.5;
}

.auth-field {
  gap: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.auth-field input {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.auth-field input:focus-visible {
  border-color: var(--teal);
  outline: 2px solid var(--teal-soft);
}

.primary-command,
.secondary-command,
.text-command {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 750;
  text-decoration: none;
}

.primary-command {
  padding: 9px 16px;
  color: #fff;
  background: var(--teal);
  border: 1px solid var(--teal);
}

.secondary-command {
  padding: 9px 16px;
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.text-command {
  padding: 7px;
  color: var(--teal);
  background: transparent;
  border: 0;
}

.primary-command:disabled,
.secondary-command:disabled,
.text-command:disabled {
  cursor: wait;
  opacity: 0.6;
}

.auth-message {
  padding: 10px 12px;
  color: #7a2020;
  background: #fff0f0;
  border: 1px solid #e7b8b8;
  border-radius: 6px;
  line-height: 1.4;
}

.auth-message.is-success {
  color: #28552e;
  background: #edf8ee;
  border-color: #b9d9bd;
}

.totp-setup {
  display: grid;
  gap: 7px;
  padding: 12px;
  background: var(--teal-soft);
  border-radius: 6px;
}

.totp-setup span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.totp-setup code {
  overflow-wrap: anywhere;
  font-size: 1rem;
  font-weight: 750;
  letter-spacing: 0.08em;
}

.admin-card {
  justify-items: start;
}

.status-pill {
  padding: 6px 10px;
  color: #28552e !important;
  background: #edf8ee;
  border: 1px solid #b9d9bd;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 750;
}

.app-shell {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 0 22px;
  border-bottom: 1px solid var(--line);
}

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

.product-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: flex-end;
  gap: 12px;
}

.control-group {
  display: grid;
  gap: 5px;
}

.control-group > span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
}

.product-controls select {
  width: 110px;
  height: 36px;
  padding: 0 9px;
}

.brand-lockup {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  border-radius: 8px;
  outline: none;
}

.brand-lockup:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 4px;
}

.brand-tooltip {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 20;
  width: max-content;
  max-width: min(360px, calc(100vw - 32px));
  padding: 7px 9px;
  color: #fff;
  background: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  box-shadow: 0 8px 20px rgba(28, 27, 23, 0.22);
  font-size: 0.78rem;
  font-weight: 650;
  line-height: 1.3;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-3px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.brand-lockup:hover .brand-tooltip,
.brand-lockup:focus-visible .brand-tooltip {
  opacity: 1;
  transform: translateY(0);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #fff;
  background: var(--ink);
  border-radius: 6px;
  font-weight: 800;
}

.brand-kicker {
  margin: 0;
  color: var(--teal);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.5rem, 2vw, 2rem);
  line-height: 1.05;
}

h2 {
  font-size: 1.05rem;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab {
  min-height: 38px;
  padding: 0 16px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.tab.is-active {
  color: #fff;
  background: var(--teal);
  border-color: var(--teal);
}

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

.filter-bar {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(150px, 190px) minmax(280px, 1fr);
  gap: 14px;
  align-items: start;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

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

.filter-field > span,
.section-head span,
.kpi-card span,
.book-meta,
.bar-meta,
.mix-card span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

select {
  width: 100%;
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.filter-field select:not([multiple]) {
  height: 42px;
  padding: 0 12px;
}

select[multiple] {
  min-height: 9.8rem;
  padding: 6px;
}

select[multiple] option {
  padding: 7px 8px;
  border-radius: 4px;
}

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

.small-command {
  min-height: 30px;
  padding: 0 10px;
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 6px;
}

#publisher-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.78rem;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.status-row span {
  padding: 6px 10px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.status-row .is-stale {
  color: #6f4300;
  background: #fff2d8;
  border-color: #e0b968;
}

.chart-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
  padding: 16px 0;
}

.chart-controls .filter-field {
  width: min(240px, 100%);
}

.chart-summary {
  min-height: 42px;
  padding: 11px 12px;
  color: var(--muted);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 700;
}

.chart-table-wrap {
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.chart-layout {
  display: grid;
  grid-template-columns: 803px minmax(300px, 440px);
  gap: 22px;
  align-items: start;
}

.chart-work-inspector {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 18px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.chart-inspector-empty {
  display: grid;
  min-height: 180px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.chart-inspector-head {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  gap: 16px;
}

.chart-inspector-cover {
  width: 104px;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  background: linear-gradient(135deg, var(--teal-soft), #f1dcb8);
  border-radius: 6px;
}

.chart-inspector-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chart-inspector-title {
  margin: 5px 0 8px;
  overflow-wrap: anywhere;
  font-size: 1.2rem;
  line-height: 1.2;
}

.chart-inspector-rank,
.chart-inspector-byline,
.chart-inspector-meta dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.chart-inspector-byline {
  line-height: 1.4;
}

.chart-inspector-meta {
  display: grid;
  grid-template-columns: minmax(90px, 0.7fr) minmax(0, 1.3fr);
  gap: 10px 14px;
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.chart-inspector-meta dt,
.chart-inspector-meta dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.chart-inspector-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chart-row {
  cursor: pointer;
}

.chart-row:hover td,
.chart-row:focus-visible td,
.chart-row.is-selected td {
  background: var(--teal-soft);
}

.chart-row:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: -2px;
}

.chart-row.is-selected td:first-child {
  box-shadow: inset 4px 0 var(--teal);
}

.chart-table {
  width: 803px;
  min-width: 803px;
  table-layout: fixed;
  border-collapse: collapse;
}

.chart-col-cover {
  width: 72px;
}

.chart-col-title {
  width: 180px;
}

.chart-col-author {
  width: 176px;
}

.chart-col-publisher {
  width: 125px;
}

.chart-col-change {
  width: 125px;
}

.chart-table th,
.chart-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.chart-table th {
  color: var(--muted);
  background: #f4f2eb;
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

.chart-cover {
  width: 48px;
  height: 72px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--teal-soft), #f1dcb8);
  border-radius: 5px;
}

.chart-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chart-rank {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
}

.chart-title {
  display: block;
  max-width: none;
  overflow-wrap: anywhere;
  font-size: 0.92rem;
  line-height: 1.25;
}

.chart-author-cell,
.chart-publisher-cell {
  overflow-wrap: anywhere;
  line-height: 1.3;
}

.chart-change-cell {
  white-space: nowrap;
}

.movement {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 58px;
  font-weight: 800;
}

.movement.is-up {
  color: var(--green);
}

.movement.is-down {
  color: var(--red);
}

.movement.is-same,
.movement.is-new {
  color: var(--muted);
}

.movement-icon {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  font-size: 0.86rem;
  line-height: 1;
}

.movement-icon.is-up::before,
.movement-icon.is-down::before {
  display: block;
  width: 0;
  height: 0;
  border-right: 5px solid transparent;
  border-left: 5px solid transparent;
  content: "";
}

.movement-icon.is-up::before {
  border-bottom: 9px solid var(--green);
}

.movement-icon.is-down::before {
  border-top: 9px solid var(--red);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
  padding: 16px 0 22px;
}

.kpi-card {
  min-height: 108px;
  padding: 16px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi-card strong {
  display: block;
  margin-top: 10px;
  overflow-wrap: anywhere;
  font-size: clamp(1.35rem, 2.3vw, 2rem);
  line-height: 1;
}

.kpi-card p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.83rem;
}

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

.section-block {
  min-width: 0;
  padding: 0;
}

.section-block-wide {
  grid-column: 1 / -1;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  margin-bottom: 6px;
}

.section-note {
  max-width: 980px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

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

.book-card {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 12px;
  min-height: 170px;
  padding: 12px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.cover {
  width: 74px;
  height: 112px;
  overflow: hidden;
  background: linear-gradient(135deg, var(--teal-soft), #f1dcb8);
  border-radius: 5px;
}

.cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.book-title {
  display: -webkit-box;
  overflow: hidden;
  min-height: 2.7rem;
  font-size: 0.94rem;
  font-weight: 800;
  line-height: 1.22;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.book-rank {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}

.rank-pill {
  padding: 5px 8px;
  color: #fff;
  background: var(--ink);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
}

.delta {
  color: var(--green);
  font-weight: 800;
}

.delta.is-down {
  color: var(--red);
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.badge {
  padding: 4px 7px;
  background: var(--teal-soft);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 750;
}

.sparkline {
  width: 100%;
  height: 36px;
  margin-top: 8px;
}

.bar-chart,
.comparison-chart,
.stacked-chart,
.mix-grid,
.scatter-wrap,
.narrator-card-grid,
.pairing-list {
  min-height: 320px;
  padding: 14px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(110px, 180px) 1fr minmax(42px, auto);
  gap: 10px;
  align-items: center;
  min-height: 36px;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.86rem;
  font-weight: 750;
}

.bar-track {
  height: 12px;
  overflow: hidden;
  background: #ece9df;
  border-radius: 999px;
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  background: var(--teal);
  border-radius: 999px;
}

.bar-fill.is-down {
  background: var(--red);
}

.bar-row:nth-child(3n) .bar-fill {
  background: var(--amber);
}

.bar-row:nth-child(3n + 1) .bar-fill {
  background: var(--violet);
}

.bar-row:nth-child(3n) .bar-fill.is-down,
.bar-row:nth-child(3n + 1) .bar-fill.is-down {
  background: var(--red);
}

.bar-meta {
  text-align: right;
}

.comparison-chart,
.stacked-chart {
  display: grid;
  align-content: start;
  gap: 10px;
}

.comparison-row {
  display: grid;
  grid-template-columns: minmax(130px, 190px) 1fr 1fr minmax(86px, auto);
  gap: 10px;
  align-items: center;
  min-height: 36px;
}

.comparison-track,
.stack-track {
  height: 12px;
  overflow: hidden;
  background: #ece9df;
  border-radius: 999px;
}

.comparison-fill {
  height: 100%;
  min-width: 2px;
  border-radius: 999px;
}

.comparison-fill.is-top {
  background: var(--teal);
}

.comparison-fill.is-broad {
  background: var(--violet);
}

.stacked-row {
  display: grid;
  grid-template-columns: minmax(130px, 190px) 1fr minmax(42px, auto);
  gap: 10px;
  align-items: center;
  min-height: 36px;
}

.stack-track {
  display: flex;
}

.stack-segment {
  height: 100%;
}

.stack-segment.is-swedish {
  background: var(--teal);
}

.stack-segment.is-translated {
  background: var(--amber);
}

.stack-segment.is-unknown {
  background: var(--violet);
}

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

.mix-card {
  min-height: 124px;
  padding: 14px;
  background: #f4f2eb;
  border-radius: 8px;
}

.metadata-coverage .mix-card {
  min-height: 118px;
}

.mix-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.65rem;
}

.share-meter {
  height: 8px;
  margin-top: 12px;
  overflow: hidden;
  background: #e3e0d6;
  border-radius: 999px;
}

.share-meter div {
  height: 100%;
  background: var(--teal);
}

.scatter-wrap {
  min-height: 380px;
}

.scatter-svg {
  width: 100%;
  height: 340px;
}

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

.narrator-card {
  min-width: 0;
  min-height: 156px;
  padding: 14px;
  background: #f4f2eb;
  border-radius: 8px;
}

.narrator-card h3 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.98rem;
}

.narrator-card p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.tag-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.tag-chip {
  max-width: 100%;
  overflow: hidden;
  padding: 5px 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--teal-soft);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 750;
}

.pairing-list {
  display: grid;
  align-content: start;
  gap: 10px;
}

.pairing-row {
  display: grid;
  grid-template-columns: minmax(220px, 360px) 1fr;
  gap: 12px;
  align-items: center;
  min-height: 46px;
}

.pairing-label {
  min-width: 0;
}

.pairing-label strong,
.pairing-label span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pairing-label strong {
  font-size: 0.88rem;
}

.pairing-label span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

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

  .chart-work-inspector {
    position: static;
    grid-row: 1;
    max-height: none;
  }
}

@media (max-width: 1100px) {

  .kpi-grid,
  .book-grid,
  .narrator-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 760px) {
  .chart-work-inspector {
    display: none;
  }

  .chart-row {
    cursor: default;
  }

  .app-shell {
    width: min(100% - 20px, 1500px);
    padding-top: 12px;
  }

  .topbar,
  .filter-bar {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

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

  .product-controls {
    justify-content: flex-start;
  }

  .tabs {
    justify-content: flex-start;
  }

  .filter-bar,
  .kpi-grid,
  .book-grid,
  .mix-grid,
  .narrator-card-grid {
    grid-template-columns: 1fr;
  }

  .book-card {
    grid-template-columns: 66px 1fr;
  }

  .cover {
    width: 66px;
    height: 100px;
  }

  .bar-row {
    grid-template-columns: 1fr minmax(32px, auto);
  }

  .bar-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .comparison-row {
    grid-template-columns: 1fr minmax(72px, auto);
  }

  .comparison-track {
    grid-column: 1 / -1;
  }

  .stacked-row {
    grid-template-columns: 1fr minmax(32px, auto);
  }

  .stack-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }

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