:root {
  --bg: #f7f7f9;
  --bg-accent: #eff2f8;
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --ink: #20222a;
  --muted: #69707d;
  --line: #e7e9ef;
  --accent: #315cff;
  --accent-deep: #2446c8;
  --accent-soft: rgba(49, 92, 255, 0.1);
  --success: #218765;
  --warning: #f5a13a;
  --danger: #bf394c;
  --shadow: 0 18px 56px rgba(32, 34, 42, 0.08);
  --shadow-soft: 0 10px 28px rgba(32, 34, 42, 0.06);
  --radius-lg: 16px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --sans: "Avenir Next", "Segoe UI", sans-serif;
  --serif: "Baskerville", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --mono: "SFMono-Regular", "Menlo", monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(49, 92, 255, 0.08), transparent 28%),
    radial-gradient(circle at top right, rgba(66, 196, 155, 0.1), transparent 28%),
    linear-gradient(180deg, #fbfbfd 0%, var(--bg) 100%);
  font-family: var(--sans);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(32, 34, 42, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 34, 42, 0.025) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
  opacity: 0.6;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  gap: 20px;
  width: min(1600px, calc(100vw - 32px));
  margin: 16px auto 40px;
  align-items: start;
}

.page-shell {
  min-width: 0;
}

body.auth-route .page-shell {
  width: min(760px, calc(100vw - 32px));
  margin-top: 48px;
}

body.auth-route .app-shell {
  display: block;
  width: min(760px, calc(100vw - 32px));
}

.app-sidebar {
  position: sticky;
  top: 16px;
  display: flex;
  min-height: calc(100vh - 32px);
  flex-direction: column;
  gap: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(247, 247, 249, 0.92);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 6px 12px;
  border-bottom: 1px solid var(--line);
}

.sidebar-brand strong,
.sidebar-brand span {
  display: block;
}

.sidebar-brand strong {
  font-size: 1rem;
  line-height: 1.1;
}

.sidebar-brand span:not(.sidebar-logo) {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.sidebar-logo {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 10px 20px rgba(49, 92, 255, 0.22);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(17, 24, 39, 0.34);
}

.sidebar-toggle {
  display: none;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
}

.sidebar-toggle span[aria-hidden="true"],
.sidebar-toggle span[aria-hidden="true"]::before,
.sidebar-toggle span[aria-hidden="true"]::after {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 99px;
  background: var(--ink);
}

.sidebar-toggle span[aria-hidden="true"] {
  position: relative;
}

.sidebar-toggle span[aria-hidden="true"]::before,
.sidebar-toggle span[aria-hidden="true"]::after {
  content: "";
  position: absolute;
  left: 0;
}

.sidebar-toggle span[aria-hidden="true"]::before {
  top: -6px;
}

.sidebar-toggle span[aria-hidden="true"]::after {
  top: 6px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hero,
.filters-panel,
.table-panel,
.detail-panel,
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.hero {
  display: flex;
  gap: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  align-items: center;
  justify-content: space-between;
}

.topbar-main {
  display: flex;
  min-width: 240px;
  align-items: center;
  gap: 12px;
}

.topbar-title-block {
  min-width: 0;
}

.topbar-status {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 10px;
  min-width: 320px;
  max-width: 460px;
}

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

.hero-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.7rem;
  color: var(--accent-deep);
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--serif);
  line-height: 0.98;
}

h1 {
  font-family: var(--sans);
  font-size: clamp(1.1rem, 1.8vw, 1.45rem);
  font-weight: 640;
  max-width: 28ch;
  line-height: 1.08;
}

h2 {
  font-size: clamp(1.45rem, 2.3vw, 2.1rem);
  font-weight: 620;
}

h3 {
  font-size: 1.15rem;
}

.title-link {
  color: inherit;
  text-decoration: none;
}

.title-link:hover,
.title-link:focus-visible {
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

.table-sort-button {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.table-sort-button .sort-arrow {
  display: inline-block;
  min-width: 0.9rem;
  color: #9aa1ae;
  transition: color 160ms ease;
}

.table-sort-button:hover .sort-arrow,
.table-sort-button.is-active .sort-arrow,
.table-sort-button:focus-visible .sort-arrow {
  color: var(--accent);
}

.inline-detail-title {
  margin: 6px 0 0;
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.15;
}

.hero-text,
.panel-copy,
.detail-placeholder p,
.history-item p,
.metric-caption,
#health-meta,
#freshness-meta {
  color: var(--muted);
}

.hero-text {
  max-width: 72ch;
  margin: 3px 0 0;
  font-size: 0.86rem;
  line-height: 1.35;
}

.hero-actions,
.filters-actions,
.pagination-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 14px;
}

.language-switcher {
  display: inline-flex;
  padding: 4px;
  border-radius: 12px;
  background: #f7f8fb;
  border: 1px solid var(--line);
}

.lang-button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 999px;
  font: 600 0.82rem/1 var(--sans);
  cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease;
}

.lang-button.active {
  background: var(--accent);
  color: #fff;
}

.primary-button,
.secondary-button,
.ghost-button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  padding: 9px 13px;
  font: 650 0.88rem/1 var(--sans);
  text-decoration: none;
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 20px rgba(49, 92, 255, 0.16);
}

.secondary-button,
.ghost-button {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.danger-button {
  border-color: rgba(191, 57, 76, 0.3);
  color: var(--danger);
}

.danger-button:hover {
  background: rgba(191, 57, 76, 0.08);
}

.clear-data-guard {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.clear-data-guard-form {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.clear-data-guard-form input {
  min-width: 112px;
  width: 112px;
  border-radius: 10px;
  border: 1px solid rgba(191, 57, 76, 0.3);
  background: #fff;
  padding: 9px 14px;
  color: var(--ink);
  font: inherit;
}

.clear-data-guard-error {
  color: var(--danger);
  font-size: 0.8rem;
  line-height: 1.2;
}

.meta-filter-link {
  appearance: none;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent-deep);
  font: inherit;
  text-align: left;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
}

.meta-filter-link:hover {
  color: var(--accent);
}

.hero-status {
  display: grid;
  gap: 10px;
  align-content: start;
}

.status-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #f7f8fb;
  border: 1px solid var(--line);
}

.status-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.status-card strong {
  font-size: 0.9rem;
  line-height: 1.1;
}

#health-meta,
#freshness-meta {
  font-size: 0.74rem;
  line-height: 1.25;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.stat-card {
  padding: 16px;
  border-radius: var(--radius-md);
  min-height: 132px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat-card.has-details {
  justify-content: flex-start;
  gap: 10px;
}

.stat-value {
  font: 650 clamp(1.75rem, 3.4vw, 2.65rem) / 1 var(--sans);
  max-width: 100%;
  overflow-wrap: anywhere;
}

.stat-card.has-details .stat-value {
  font-size: clamp(1.15rem, 2.2vw, 1.6rem);
  line-height: 1.15;
}

.stat-card.long-value .stat-value {
  font-size: clamp(1.45rem, 3vw, 2.3rem);
  line-height: 1.04;
}

.stat-card.has-details .metric-caption {
  margin-top: 2px;
}

.metric-caption {
  font-size: 0.92rem;
  line-height: 1.5;
}

.metric-details {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.metric-detail-row {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--ink);
}

.metric-compare {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 10px;
}

.metric-compare-bar {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: #edf0f6;
  overflow: hidden;
}

.metric-compare-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #42c49b, var(--accent));
}

.metric-compare-text {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--muted);
}

.filters-panel,
.table-panel,
.detail-panel {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: visible;
}

.filters-panel:has(.custom-select.is-open),
.table-panel:has(.custom-select.is-open),
.detail-panel:has(.custom-select.is-open) {
  z-index: 60;
}

.filters-panel {
  margin-top: 16px;
  padding: 18px;
}

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

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

.filters-form label {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 68px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 8px 18px rgba(32, 34, 42, 0.035);
  font-size: 0.88rem;
  color: var(--muted);
}

.filters-form input,
.filters-form select {
  width: 100%;
  min-height: 26px;
  border: 0;
  border-radius: 0;
  background-color: transparent;
  padding: 0;
  color: var(--ink);
  font: inherit;
  outline: none;
}

.native-select-enhanced {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  min-height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.custom-select {
  position: relative;
  width: 100%;
  color: var(--ink);
}

.custom-select-trigger {
  display: flex;
  width: 100%;
  min-height: 28px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0 24px 0 0;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.custom-select-trigger::after {
  content: "";
  position: absolute;
  right: 2px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-65%) rotate(45deg);
  transition: transform 140ms ease, border-color 140ms ease;
}

.custom-select.is-open .custom-select-trigger::after {
  transform: translateY(-35%) rotate(225deg);
  border-color: var(--accent);
}

.custom-select-menu {
  position: absolute;
  z-index: 90;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 22px 50px rgba(32, 34, 42, 0.16);
}

.custom-select-option {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  padding: 9px 10px;
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.custom-select-option:hover,
.custom-select-option:focus-visible {
  background: #f4f6fb;
  outline: none;
}

.custom-select-option[aria-selected="true"] {
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 700;
}

.custom-select-option:disabled {
  color: #a3a9b5;
  cursor: not-allowed;
}

.filters-form textarea,
.niche-form textarea,
.niche-form select,
.niche-form input {
  width: 100%;
  border: 0;
  border-radius: 0;
  background-color: transparent;
  padding: 0;
  color: var(--ink);
  font: inherit;
  outline: none;
}

.filters-form select,
.niche-form select,
.keyword-toolbar select {
  appearance: none;
  padding-right: 24px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 12px) 54%,
    calc(100% - 7px) 54%;
  background-size:
    5px 5px,
    5px 5px;
  background-repeat: no-repeat;
}

.filters-form label:focus-within,
.niche-form label:focus-within,
.keyword-toolbar label:focus-within {
  border-color: rgba(49, 92, 255, 0.46);
  box-shadow: 0 0 0 4px rgba(49, 92, 255, 0.08);
}

.filters-form select[multiple],
.niche-form select[multiple] {
  min-height: 180px;
  padding-right: 0;
  background-image: none;
}

.checkbox-field {
  justify-content: center;
}

.checkbox-field input {
  width: 20px;
  height: 20px;
}

.filters-actions {
  align-items: end;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.85fr);
  gap: 16px;
  margin-top: 16px;
}

.route-nav {
  display: flex;
  gap: 8px;
}

.sidebar-nav {
  flex-direction: column;
  margin-top: 0;
}

.route-link {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-width: 0;
  width: 100%;
  padding: 10px 11px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: #333842;
  font-weight: 650;
  text-decoration: none;
  transition: transform 180ms ease, background-color 180ms ease, border-color 180ms ease;
}

.route-link.active {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  box-shadow: var(--shadow-soft);
}

.route-link:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.72);
}

.route-icon {
  display: inline-grid;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: #eef2ff;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
}

.route-link.active .route-icon {
  background: var(--accent);
  color: #fff;
}

.account-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.account-card h2 {
  margin: 2px 0 8px;
  font-family: var(--sans);
  font-size: 0.95rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.account-card .panel-copy {
  margin: 0;
  font-size: 0.78rem;
}

.account-actions {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.account-actions .secondary-button,
.account-actions .ghost-button {
  width: 100%;
  justify-content: center;
}

.single-column {
  grid-template-columns: 1fr;
}

.niche-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.niche-form label {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 68px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 8px 18px rgba(32, 34, 42, 0.035);
  font-size: 0.88rem;
  color: var(--muted);
}

.autosuggest-form {
  grid-template-columns: minmax(240px, 1.4fr) minmax(160px, 0.45fr);
}

.form-field-title {
  display: block;
  margin-bottom: 8px;
  font-size: 0.88rem;
  color: var(--muted);
}

.autosuggest-token-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.autosuggest-token {
  border: 0;
  cursor: pointer;
}

.autosuggest-modifier-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.autosuggest-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 252, 247, 0.78);
  color: var(--ink);
}

.autosuggest-check-row input {
  width: auto;
}

.autosuggest-check-row small {
  margin-left: auto;
  color: var(--muted);
}

.autosuggest-results-table {
  min-width: 720px;
}

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

.panel-head.compact {
  grid-column: 1 / -1;
  margin-bottom: 0;
}

.table-panel,
.detail-panel {
  padding: 18px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.table-shell table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.table-shell th,
.table-shell td {
  padding: 13px 14px;
  border-bottom: 1px solid #eef0f4;
  text-align: left;
  vertical-align: top;
}

.table-shell th {
  background: #fbfcff;
  color: var(--muted);
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.books-table-wrap {
  position: relative;
  overflow-x: auto;
  overflow-y: visible;
}

.table-scrollbar-top {
  display: none;
  overflow-x: auto;
  overflow-y: hidden;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  scrollbar-width: thin;
}

.table-scrollbar-top.active {
  display: block;
  position: sticky;
  top: 0;
  z-index: 5;
}

.table-scrollbar-top > div {
  height: 10px;
}

.books-sticky-header {
  display: none;
  position: fixed;
  top: 12px;
  left: 0;
  z-index: 20;
  border: 1px solid var(--line);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 12px 32px rgba(32, 34, 42, 0.12);
  backdrop-filter: blur(14px);
}

.books-sticky-header.active {
  display: block;
}

.books-sticky-header-scroll {
  overflow-x: auto;
  overflow-y: hidden;
}

.books-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 980px;
}

.books-table th,
.books-table td {
  padding: 13px 14px;
  border-bottom: 1px solid #eef0f4;
  text-align: left;
  vertical-align: top;
}

.books-table th {
  background: #fbfcff;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  box-shadow: inset 0 -1px 0 #eef0f4;
}

.books-table tr:hover td {
  background: rgba(49, 92, 255, 0.035);
}

.books-table tr[data-asin] {
  cursor: pointer;
}

.books-table tr[data-asin]:focus-visible td {
  outline: 2px solid rgba(49, 92, 255, 0.28);
  outline-offset: -2px;
  background: rgba(49, 92, 255, 0.04);
}

.categories-index-table {
  min-width: 1280px;
}

.categories-index-table th:first-child,
.categories-index-table td:first-child {
  min-width: 320px;
}

.categories-index-table th:nth-child(2),
.categories-index-table td:nth-child(2) {
  min-width: 90px;
  text-align: center;
}

.categories-index-table th:nth-child(3),
.categories-index-table td:nth-child(3),
.categories-index-table th:nth-child(4),
.categories-index-table td:nth-child(4),
.categories-index-table th:nth-child(5),
.categories-index-table td:nth-child(5) {
  min-width: 140px;
  text-align: center;
}

.categories-index-table th:nth-child(6),
.categories-index-table td:nth-child(6) {
  min-width: 210px;
  white-space: nowrap;
}

.categories-index-table th:nth-child(7),
.categories-index-table td:nth-child(7) {
  min-width: 180px;
}

.categories-index-table th:nth-child(2) .table-sort-button,
.categories-index-table th:nth-child(3) .table-sort-button,
.categories-index-table th:nth-child(4) .table-sort-button,
.categories-index-table th:nth-child(5) .table-sort-button {
  justify-content: center;
  width: 100%;
}

.categories-index-table .book-title {
  min-width: 0;
}

.categories-index-table .book-title strong,
.categories-index-table .book-title span {
  overflow-wrap: anywhere;
}

.categories-index-table .row-action {
  white-space: normal;
}

.categories-index-table .row-action-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.book-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.book-title.book-title-has-thumb {
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
}

.book-title-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
}

.book-title strong {
  font-size: 1rem;
  font-family: var(--sans);
  font-weight: 640;
}

.book-thumb {
  width: 52px;
  min-width: 52px;
  height: 74px;
  border-radius: 10px;
  object-fit: cover;
  background: #eef0f4;
  box-shadow: 0 10px 24px rgba(32, 34, 42, 0.1);
}

.book-thumb-button {
  display: inline-flex;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}

.book-title span,
.asin-link,
.mono-chip,
.detail-meta dd {
  font-family: var(--mono);
}

.asin-link {
  color: var(--muted);
  font-size: 0.84rem;
  text-decoration: underline;
  text-decoration-color: rgba(49, 92, 255, 0.26);
  text-underline-offset: 2px;
}

.asin-link:hover {
  color: var(--ink);
  text-decoration-color: currentColor;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 0.76rem;
  font-weight: 650;
  white-space: nowrap;
}

.pill-link {
  text-decoration: none;
}

.pill-link:hover {
  filter: brightness(0.97);
  text-decoration: underline;
}

.keyword-search-link {
  color: var(--accent-deep);
  text-decoration: none;
}

.keyword-search-link:hover {
  text-decoration: underline;
}

.pill.success {
  background: rgba(66, 196, 155, 0.14);
  color: var(--success);
}

.pill.opportunity-signal.strong {
  background: rgba(66, 196, 155, 0.14);
  color: var(--success);
}

.pill.opportunity-signal.medium {
  background: rgba(245, 161, 58, 0.16);
  color: #99610d;
}

.pill.opportunity-signal.weak {
  background: rgba(191, 57, 76, 0.12);
  color: var(--danger);
}

.is-muted-row td {
  opacity: 0.78;
}

.pill.ranking-badge.bestseller {
  background: rgba(245, 161, 58, 0.16);
  color: #99610d;
}

.pill.ranking-badge.movers {
  background: rgba(191, 57, 76, 0.12);
  color: var(--danger);
}

.pill.ranking-badge.hot-new {
  background: rgba(66, 196, 155, 0.14);
  color: var(--success);
}

.row-action {
  white-space: nowrap;
  cursor: default;
}

.row-action-stack {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
}

.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.detail-panel {
  min-height: 780px;
  position: sticky;
  top: 16px;
  align-self: start;
}

#detail-title {
  font-size: clamp(1.2rem, 1.7vw, 1.6rem);
  line-height: 1.08;
}

.detail-placeholder {
  display: grid;
  place-items: center;
  min-height: 320px;
  padding: 24px;
  border-radius: var(--radius-md);
  border: 1px dashed #d7dce7;
  background: #fbfcff;
  text-align: center;
}

.detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

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

.compact-detail-meta {
  grid-template-columns: 1fr;
  margin-bottom: 18px;
}

.detail-meta dt {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--muted);
}

.detail-meta dd {
  margin: 4px 0 0;
  font-size: 0.95rem;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.detail-meta dd a {
  color: var(--accent-deep);
  text-decoration: none;
}

.detail-meta dd a:hover {
  text-decoration: underline;
}

.meta-multiline {
  white-space: pre-wrap;
  line-height: 1.45;
}

.meta-disclosure {
  margin: 0;
}

.meta-disclosure summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--accent-deep);
  list-style: none;
  user-select: none;
}

.meta-disclosure summary::-webkit-details-marker {
  display: none;
}

.meta-disclosure summary::before {
  content: '▸';
  display: inline-block;
  transition: transform 120ms ease;
}

.meta-disclosure[open] summary::before {
  transform: rotate(90deg);
}

.meta-disclosure .meta-multiline {
  margin-top: 10px;
}

.keyword-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
  margin-top: 20px;
}

.category-detail-toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1.2fr) repeat(4, minmax(180px, 1fr));
  gap: 12px;
  align-items: stretch;
}

.category-detail-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.category-detail-toolbar-actions .ghost-button,
.category-detail-toolbar-actions .pill {
  min-height: 56px;
}

.category-detail-toolbar-actions .ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.keyword-toolbar label {
  position: relative;
  display: grid;
  gap: 7px;
  min-width: 200px;
  min-height: 68px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 8px 18px rgba(32, 34, 42, 0.035);
  color: var(--muted);
}

.keyword-toolbar input,
.keyword-toolbar select {
  width: 100%;
  min-height: 26px;
  border: 0;
  background-color: transparent;
  padding: 0;
  color: var(--ink);
  font: inherit;
  outline: none;
}

.category-detail-filters-form {
  margin-top: 12px;
}

.category-detail-filters-form label {
  min-height: 74px;
}

.keyword-detail-grid {
  align-items: start;
}

.keyword-side-panel {
  min-height: auto;
}

.pill-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.pill small {
  font: inherit;
  opacity: 0.72;
}

.suggestion-group + .suggestion-group {
  margin-top: 18px;
}

.suggestion-group strong,
.diff-grid h4 {
  display: block;
  margin: 0 0 10px;
  font-family: var(--serif);
}

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

.chart-card,
.history-card {
  margin-top: 22px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #fff;
  padding: 18px;
}

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

.chart-header p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.chart-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-axis {
  font-size: 11px;
  fill: var(--muted);
  font-family: var(--mono);
}

.history-hover-trigger {
  color: inherit;
}

.history-hover-trigger-available {
  cursor: help;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 4px;
}

.history-hover-trigger-disabled {
  cursor: default;
  text-decoration: none;
}

.history-hover-trigger:focus-visible {
  outline: 2px solid rgba(49, 92, 255, 0.5);
  outline-offset: 4px;
  border-radius: 6px;
}

.history-hover-popover {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 22px 60px rgba(32, 34, 42, 0.16);
  padding: 14px;
}

.history-hover-popover-title {
  margin: 0 0 10px;
  color: var(--accent-deep);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.history-hover-popover-body svg {
  width: 100%;
  height: auto;
  display: block;
}

.history-hover-popover .metric-caption {
  margin: 8px 0 0;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-item {
  padding: 14px;
  border-radius: var(--radius-sm);
  background: #fbfcff;
  border: 1px solid #eef0f4;
}

.history-item strong,
.history-item p {
  display: block;
}

.history-item strong {
  margin-bottom: 6px;
}

.empty-state {
  margin-top: 18px;
  padding: 28px;
  border-radius: var(--radius-md);
  border: 1px dashed #d7dce7;
  background: #fbfcff;
}

.hidden {
  display: none !important;
}

.auth-standalone {
  max-width: 680px;
  margin-inline: auto;
}

.auth-standalone .panel-head {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.auth-standalone #auth-flow-message {
  max-width: 36rem;
  margin: 0;
  font-size: 0.98rem;
}

.auth-flow {
  gap: 14px;
}

.auth-flow-email {
  grid-template-columns: minmax(280px, 420px) auto;
  align-items: end;
  justify-content: flex-start;
}

.auth-flow-code,
.auth-flow-stack {
  grid-template-columns: minmax(0, 1fr);
}

.auth-flow-code {
  grid-template-columns: 180px minmax(0, 1fr);
  align-items: center;
}

.auth-flow-code .auth-code-caption {
  grid-column: 1 / -1;
}

.auth-field {
  min-height: 84px;
  padding: 12px 16px;
  border-radius: 20px;
}

.auth-field-email {
  min-height: 48px !important;
  height: 48px;
  max-height: 48px;
  justify-content: center;
  padding: 0 20px;
  box-sizing: border-box;
}

.auth-field span {
  font-size: 0.9rem;
  font-weight: 600;
  color: #737b89;
}

.auth-field input {
  min-height: 30px;
  font-size: clamp(1rem, 1.05vw, 1.2rem);
  line-height: 1.2;
}

.auth-field-email input {
  min-height: 100%;
  height: 100%;
  line-height: 48px;
}

.auth-field-code {
  min-height: 48px !important;
  height: 48px;
  max-height: 48px;
  justify-content: center;
  padding: 0 20px;
  box-sizing: border-box;
}

.auth-field-code input {
  min-height: 100%;
  height: 100%;
  line-height: 48px;
}

.auth-field input::placeholder {
  color: #a0a7b4;
}

.auth-field-code input {
  letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
}

.auth-code-caption {
  margin: 0 0 -4px;
  font-size: 0.95rem;
}

.auth-actions {
  margin-top: 0;
  gap: 12px;
}

.auth-actions-inline {
  align-self: end;
}

.auth-actions-inline .auth-primary-action {
  min-width: 168px;
  height: 48px;
}

.auth-primary-action {
  min-height: 48px;
  padding-inline: 22px;
  border-radius: 16px;
  font-size: 0.95rem;
}

.auth-flow-code .auth-actions,
.auth-flow-stack .auth-actions {
  justify-content: flex-start;
}

.auth-actions-code {
  align-items: center;
  flex-wrap: nowrap;
}

#auth-change-email-btn,
#auth-resend-code-btn,
#auth-pending-change-email-btn {
  min-height: 46px;
  padding-inline: 16px;
  border-radius: 16px;
}

#auth-flow-message.auth-error {
  color: var(--danger);
}

.reveal {
  animation: fade-up 420ms ease both;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(1180px, calc(100vw - 24px));
  }

  .app-sidebar {
    position: fixed;
    inset: 12px auto 12px 12px;
    z-index: 100;
    width: min(300px, calc(100vw - 32px));
    min-height: auto;
    transform: translateX(calc(-100% - 24px));
    transition: transform 180ms ease;
    visibility: hidden;
    pointer-events: none;
  }

  body.sidebar-open .app-sidebar {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .sidebar-toggle {
    display: inline-grid;
  }

  .hero {
    flex-wrap: wrap;
  }

  .topbar-main {
    flex: 1 1 320px;
  }

  .topbar-status {
    order: 3;
    width: 100%;
    max-width: none;
  }

  .topbar-actions {
    flex: 1 1 320px;
  }

  .stats-grid,
  .filters-form,
  .niche-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .auth-flow-email {
    grid-template-columns: minmax(0, 1fr);
  }

  .auth-flow-code {
    grid-template-columns: minmax(0, 1fr);
  }

  .auth-actions-inline .auth-primary-action {
    min-width: 0;
    width: 100%;
    min-height: 56px;
  }

  .auth-actions-code {
    flex-wrap: wrap;
  }

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

  .detail-panel {
    position: static;
    top: auto;
  }

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

@media (max-width: 700px) {
  .app-shell {
    width: min(100vw - 16px, 100%);
    margin: 8px auto 28px;
  }

  .page-shell {
    width: 100%;
    margin: 0;
  }

  .hero,
  .filters-panel,
  .table-panel,
  .detail-panel {
    padding: 18px;
  }

  .hero {
    align-items: stretch;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .topbar-actions > *,
  .topbar-actions .clear-data-guard,
  .topbar-actions .primary-button,
  .topbar-actions .secondary-button,
  .topbar-actions .ghost-button {
    width: 100%;
  }

  .table-scrollbar-top.active {
    top: 0;
  }

  .books-sticky-header {
    display: none !important;
  }

  .stats-grid,
  .filters-form,
  .niche-form,
  .detail-meta {
    grid-template-columns: 1fr;
  }

  .auth-field {
    min-height: 78px;
    border-radius: 18px;
  }

  .auth-primary-action,
  #auth-change-email-btn,
  #auth-resend-code-btn,
  #auth-pending-change-email-btn {
    width: 100%;
  }

  .panel-head,
  .table-footer,
  .chart-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .hero-topline {
    flex-direction: column;
    align-items: flex-start;
  }

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

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

  .category-detail-toolbar-actions {
    grid-column: 1 / -1;
  }
}

.table-meta-link {
  color: var(--accent-deep);
  text-decoration: none;
  font-size: 0.92em;
  white-space: nowrap;
}

.table-meta-link:hover {
  text-decoration: underline;
}

.reviews-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
}

.reviews-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.reviews-modal-dialog {
  position: relative;
  width: min(920px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  margin: 24px auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.18);
}

.thumbnail-modal-dialog {
  width: min(760px, calc(100vw - 32px));
}

.thumbnail-modal-frame {
  display: grid;
  place-items: center;
  min-height: min(70vh, 680px);
  padding: 16px;
}

.thumbnail-modal-image {
  display: block;
  max-width: 100%;
  max-height: min(70vh, 720px);
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 18px 56px rgba(15, 23, 42, 0.18);
}

.review-item p {
  margin: 8px 0 0;
}

.table-meta-link.is-static {
  color: var(--muted);
}

.help-anchor-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}

.help-anchor-text {
  min-width: 0;
}

.help-icon-button {
  display: inline-grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border: 1px solid rgba(49, 92, 255, 0.28);
  border-radius: 999px;
  background: rgba(49, 92, 255, 0.08);
  color: #2446c8;
  cursor: help;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  vertical-align: middle;
}

.help-icon-button:hover,
.help-icon-button:focus-visible {
  background: rgba(49, 92, 255, 0.14);
  outline: none;
}

.kb-tooltip {
  position: absolute;
  z-index: 250;
  max-width: 320px;
}

.kb-tooltip.hidden {
  display: none;
}

.kb-tooltip-card {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow-soft);
}

.kb-tooltip-card strong {
  display: block;
  margin-bottom: 6px;
}

.kb-tooltip-card p {
  margin: 0 0 8px;
  color: var(--muted);
  line-height: 1.45;
}

.kb-tooltip-card a {
  color: var(--accent-deep);
  text-decoration: none;
  font-weight: 600;
}
.ama-tour {
  position: fixed;
  inset: 0;
  z-index: 1100;
}

.ama-tour-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 17, 34, 0.56);
}

.ama-tour-spotlight {
  position: absolute;
  border-radius: 18px;
  box-shadow: 0 0 0 9999px rgba(10, 17, 34, 0.56);
  border: 2px solid rgba(72, 110, 255, 0.95);
  pointer-events: none;
}

.ama-tour-popover,
.ama-tour-prompt-card {
  position: absolute;
  width: min(360px, calc(100vw - 24px));
  background: #fff;
  color: #20263a;
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(21, 34, 66, 0.22);
  padding: 18px 18px 16px;
}

.ama-tour-prompt {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.ama-tour.ama-tour-measuring .ama-tour-popover,
.ama-tour.ama-tour-measuring .ama-tour-spotlight {
  visibility: hidden !important;
}

.ama-tour-prompt-card {
  position: relative;
}

.ama-tour-progress {
  font-size: 12px;
  line-height: 1.4;
  color: #5f6981;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.ama-tour-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: #eef2ff;
  color: #31456f;
  font-size: 20px;
  cursor: pointer;
}

.ama-tour-content h3,
.ama-tour-prompt-title {
  margin: 0 34px 8px 0;
  font-size: 20px;
  line-height: 1.2;
}

.ama-tour-content p,
.ama-tour-prompt-body,
.ama-tour-content span {
  margin: 0;
  color: #5f6981;
  line-height: 1.5;
}

.ama-tour-actions,
.ama-tour-prompt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.ama-tour-inline-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
}

.ama-tour-inline-field span {
  font-size: 12px;
  color: #5f6981;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.ama-tour-inline-field input,
.ama-tour-inline-field select {
  width: 100%;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid #d7deef;
  padding: 0 12px;
  font: inherit;
}

.ama-tour-insight-card,
.ama-tour-premium-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-radius: 16px;
  background: #f5f7ff;
  padding: 12px 14px;
  margin-top: 14px;
}

.ama-tour-premium-card {
  background: #f8fbff;
}

.ama-tour-target-active {
  position: relative;
}

body.ama-tour-open {
  overflow: hidden;
}

@media (max-width: 920px) {
  .ama-tour-popover,
  .ama-tour-prompt-card {
    width: min(340px, calc(100vw - 20px));
  }
}
