:root {
  color-scheme: dark;
  --ink: #121510;
  --muted: #667060;
  --line: #d9ded2;
  --panel: #ffffff;
  --page: #f4f6f1;
  --soft: #edf3e8;
  --green: #16795f;
  --green-2: #2aa980;
  --amber: #b76b14;
  --red: #b33b37;
  --shadow: 0 16px 40px rgba(22, 31, 19, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --ink: #f4f2e9;
  --muted: #a7b0a0;
  --line: #344136;
  --panel: #151a16;
  --page: #0d100e;
  --soft: #20281f;
  --green: #59c99f;
  --green-2: #7ad8b3;
  --amber: #e2a646;
  --red: #f07d74;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
}

:root[data-theme="light"] {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(42, 169, 128, 0.35);
  outline-offset: 2px;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1480px;
  margin: 0 auto 14px;
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid #a7b89d;
  background: #172018;
  color: #f0c46a;
  font-weight: 800;
  border-radius: 8px;
}

:root[data-theme="dark"] .brand-mark {
  border-color: #55624f;
  background: #242019;
  color: #f0c46a;
}

.brand h1,
.brand p,
.toolbar h2,
.toolbar p,
.panel-heading h2 {
  margin: 0;
}

.brand h1 {
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  letter-spacing: 0;
}

.eyebrow {
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.top-actions,
.toolbar-controls,
.segmented,
.item-actions,
.meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ghost-button,
.text-button,
.icon-button,
.segmented button,
.tab,
.favorite-button,
.drawer-tabs button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  border-radius: 8px;
}

.ghost-button {
  min-height: 40px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  font-weight: 700;
}

.text-button {
  border: 0;
  padding: 0;
  color: var(--green);
  background: transparent;
  font-weight: 800;
}

.icon-button {
  width: 36px;
  height: 36px;
  font-weight: 900;
}

.stats-strip {
  max-width: 1480px;
  margin: 0 auto 18px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.stats-strip article {
  min-width: 0;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats-strip span,
.metric-label,
.listing-meta,
.source-note,
.muted {
  color: var(--muted);
  font-size: 0.82rem;
}

.stats-strip strong {
  display: block;
  margin-top: 3px;
  font-size: 1.2rem;
}

.workspace {
  max-width: 1480px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 294px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.filters-panel,
.main-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.filters-panel {
  position: sticky;
  top: 14px;
  padding: 16px;
}

.panel-heading,
.toolbar,
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.filters-panel label,
.compact-label {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--ink);
}

.filters-panel input,
.filters-panel select,
.compact-label select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: color-mix(in srgb, var(--panel) 88%, var(--page));
  color: var(--ink);
}

.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toggle-line {
  grid-template-columns: auto 1fr;
  align-items: center;
  font-weight: 700;
}

.toggle-line input {
  width: 18px;
  min-height: 18px;
}

.range-value {
  color: var(--green);
  font-size: 0.86rem;
}

.source-note {
  margin-top: 16px;
  padding: 10px;
  background: var(--soft);
  border-radius: 8px;
  line-height: 1.4;
}

.main-panel {
  overflow: hidden;
}

.tabs {
  display: flex;
  padding: 10px;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  min-height: 38px;
  padding: 0 14px;
  font-weight: 800;
  white-space: nowrap;
}

.tab.is-active,
.segmented button.is-active,
.drawer-tabs button.is-active {
  background: var(--ink);
  color: var(--page);
  border-color: var(--ink);
}

.toolbar {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.segmented {
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.segmented button {
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  font-weight: 800;
}

.notice {
  margin: 14px 16px 0;
  padding: 10px 12px;
  border: 1px solid #edc17e;
  background: color-mix(in srgb, var(--amber) 14%, var(--panel));
  color: var(--ink);
  border-radius: 8px;
  font-size: 0.88rem;
}

.state-box {
  margin: 16px;
  padding: 24px;
  text-align: center;
  background: var(--soft);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
}

.state-box.is-error {
  background: color-mix(in srgb, var(--red) 14%, var(--panel));
  color: var(--red);
}

.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  padding: 16px;
}

.item-card {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, var(--page));
  border-radius: 8px;
  padding: 12px;
  text-align: left;
  cursor: pointer;
  min-width: 0;
  display: grid;
  gap: 10px;
}

.item-card:hover,
.table-row:hover,
.activity-row:hover,
.insight-row:hover {
  border-color: var(--green);
  background: color-mix(in srgb, var(--green) 8%, var(--panel));
}

.item-top {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.table-item {
  grid-template-columns: 46px minmax(0, 1fr) auto;
}

.item-icon {
  width: 46px;
  height: 46px;
  object-fit: contain;
  image-rendering: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--soft) 82%, var(--panel));
  padding: 5px;
}

.item-name,
.detail-title h2 {
  min-width: 0;
  margin: 0;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.item-type {
  color: var(--muted);
  font-size: 0.76rem;
  overflow-wrap: anywhere;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 90%, var(--page));
}

.metric strong {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.score-pill {
  display: inline-flex;
  min-width: 44px;
  min-height: 28px;
  justify-content: center;
  align-items: center;
  padding: 0 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--green) 20%, var(--panel));
  color: var(--green-2);
  font-weight: 900;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--amber) 18%, var(--panel));
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
  padding: 12px 16px 16px;
}

.items-table {
  min-width: 860px;
}

.table-head,
.table-row {
  display: grid;
  grid-template-columns: minmax(230px, 2fr) 100px 130px 130px 120px 90px;
  gap: 12px;
  align-items: center;
}

.table-head {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.table-row {
  width: 100%;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, var(--page));
  border-radius: 8px;
  padding: 10px;
  margin-top: 8px;
  text-align: left;
  cursor: pointer;
}

.activity-list,
.insights-grid,
.drawer-section {
  padding: 16px;
}

.activity-row,
.insight-row {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 88%, var(--page));
  padding: 12px;
  margin-bottom: 8px;
  text-align: left;
}

.activity-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

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

.insight-section {
  min-width: 0;
}

.insight-section h3 {
  margin: 0 0 8px;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(18, 21, 16, 0.34);
  z-index: 10;
}

.detail-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(520px, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 48px rgba(18, 21, 16, 0.18);
  z-index: 11;
  transform: translateX(105%);
  transition: transform 160ms ease;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.detail-drawer.is-open {
  transform: translateX(0);
}

.drawer-header {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.detail-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  flex: 1;
}

.drawer-body {
  overflow: auto;
}

.drawer-section {
  border-bottom: 1px solid var(--line);
}

.drawer-section h3 {
  margin: 0 0 10px;
}

.chart {
  width: 100%;
  height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel) 88%, var(--page));
}

.sparkline {
  width: 100%;
  height: 100%;
}

.chart-axis {
  stroke: var(--line);
}

.chart-line {
  stroke: var(--green);
}

.chart-point {
  fill: var(--panel);
  stroke: var(--green-2);
  stroke-width: 2;
}

.chart-point:hover {
  fill: var(--amber);
  stroke: var(--amber);
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.legend-line {
  width: 28px;
  height: 3px;
  border-radius: 999px;
  background: var(--green);
}

.favorite-button {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 80%, var(--page));
  font-size: 1.05rem;
  line-height: 1;
}

.favorite-button.is-active {
  color: #f0c46a;
  border-color: color-mix(in srgb, #f0c46a 60%, var(--line));
  background: color-mix(in srgb, #f0c46a 13%, var(--panel));
}

.favorite-button--large {
  width: 40px;
  height: 40px;
  font-size: 1.25rem;
}

.drawer-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.drawer-tabs button {
  min-height: 36px;
  padding: 0 12px;
  font-weight: 800;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
  background: #172018;
}

.login-shell {
  width: min(440px, 100%);
}

.login-panel {
  padding: 24px;
  background: var(--panel);
  border-radius: 8px;
  border: 1px solid #dce4d3;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.25);
}

.login-panel h2 {
  margin: 22px 0 8px;
}

.login-panel p {
  color: var(--muted);
  line-height: 1.5;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.login-form label {
  display: grid;
  gap: 6px;
  font-weight: 800;
}

.login-form input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
}

.login-form button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: white;
  font-weight: 900;
  cursor: pointer;
}

.login-error {
  display: none;
  color: var(--red) !important;
  font-weight: 800;
}

.has-login-error .login-error {
  display: block;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .filters-panel {
    position: static;
  }

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

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

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

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

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

  .top-actions,
  .toolbar-controls {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

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

  .field-pair,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .items-grid {
    grid-template-columns: 1fr;
    padding: 12px;
  }
}
