:root {
  --bg: #f7f3ea;
  --bg-deep: #efe7da;
  --surface: rgba(255, 253, 248, 0.96);
  --surface-strong: #fffdf8;
  --surface-subtle: #fbf6eb;
  --surface-contrast: #171616;
  --surface-contrast-2: #2b2925;
  --ink: #171616;
  --ink-soft: #3b352f;
  --muted: #6b655e;
  --muted-2: #8a8176;
  --line: #d8d0c2;
  --line-strong: #b9aa93;
  --accent: #5e4212;
  --accent-strong: #4d350d;
  --accent-soft: #ead7b2;
  --accent-border: #dcc7a1;
  --gold: #9a6b11;
  --gold-soft: #f7ead1;
  --red: #9f3f2e;
  --red-soft: #f5ded6;
  --blue: #314a64;
  --blue-soft: #e8eceb;
  --teal: #1d6d67;
  --teal-soft: #e0f0ec;
  --button-surface: #fbf3e2;
  --button-line: #dcc7a1;
  --shadow: none;
  --shadow-soft: none;
  --radius: 0;
  --radius-sm: 0;
  --font: "Aptos", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Book Antiqua", "Palatino Linotype", Georgia, serif;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font);
  background:
    linear-gradient(180deg, rgba(127, 95, 45, 0.08), transparent 24%),
    linear-gradient(180deg, #faf7f1, var(--bg));
}

body::before {
  content: none;
}

a {
  color: inherit;
  text-decoration: none;
}

.shell {
  width: min(1880px, calc(100vw - 14px));
  margin: 14px auto 20px;
}

.app-frame {
  position: relative;
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 0;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.98), rgba(248, 243, 234, 0.96));
  box-shadow: var(--shadow);
}

.app-frame::before {
  content: none;
}

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(255, 253, 248, 0.98), rgba(248, 243, 234, 0.96));
  color: var(--ink);
}

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

.brand-logo {
  display: block;
  height: 82px;
  width: auto;
  max-width: min(240px, 54vw);
}

.brand-copy,
.brand-subtitle {
  display: block;
}

.brand-copy {
  min-width: 0;
}

.brand-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav a,
.button,
.table-link,
.action-link,
.field button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--button-line);
  border-radius: 0;
  background: var(--button-surface);
  color: var(--ink-soft);
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease, background 140ms ease;
}

.nav a {
  border-color: var(--button-line);
  background: var(--button-surface);
  color: var(--accent);
  backdrop-filter: none;
}

.nav a:hover,
.button:hover,
.table-link:hover,
.action-link:hover,
.field button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(23, 22, 22, 0.08);
}

.nav a.active,
.button.primary,
.field button {
  border-color: var(--accent-border);
  background: var(--button-surface);
  color: var(--accent);
}

.mast {
  padding: 22px 20px 20px;
  border-bottom: 1px solid var(--line);
  text-align: center;
  background: linear-gradient(180deg, rgba(255, 253, 248, 0.98), rgba(248, 243, 234, 0.96));
}

.mast h1 {
  margin-top: 12px;
}

.mast-copy {
  margin: 12px auto 0;
  max-width: 58ch;
  color: var(--muted);
  line-height: 1.55;
}

.mast .meta-band {
  justify-content: center;
  margin-top: 16px;
}

.command-bar {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  padding: 24px 22px 18px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.98), rgba(248, 243, 234, 0.96));
}

.page-title-row,
.section-head,
.subgroup-head,
.chart-head,
.record-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title,
h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 3.4vw, 3rem);
  line-height: 0.95;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-kicker,
.section-kicker,
.label,
.field label,
th {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.page-meta,
.muted,
.section-copy,
.summary,
.record-subtitle,
.chart-subtitle {
  color: var(--muted);
  line-height: 1.5;
}

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

.segment-group {
  display: grid;
  gap: 8px;
  min-width: 0;
}

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

.segment-tab {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--button-surface);
  color: var(--ink-soft);
  padding: 8px 14px;
  font-size: 0.82rem;
  font-weight: 800;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.segment-tab:hover {
  transform: translateY(-1px);
  border-color: var(--accent-border, var(--button-line));
}

.segment-tab.active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--surface-strong);
  box-shadow: none;
}

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

.metric-grid.metric-grid-six,
.facts {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.facts {
  display: grid;
  gap: 12px;
}

.metric,
.fact {
  min-width: 0;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface-strong);
  box-shadow: var(--shadow-soft);
}

.metric-value,
.fact .value {
  margin-top: 8px;
  font-size: 1.08rem;
  font-weight: 900;
  color: var(--ink);
}

.metric-copy {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.79rem;
  line-height: 1.45;
}

.content {
  display: grid;
  gap: 22px;
  padding: 22px;
}

.layout-rail {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 22px;
  padding: 22px;
}

.stack {
  display: grid;
  gap: 22px;
  align-content: start;
}

.section {
  display: grid;
  gap: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 18px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: none;
}

.panel.flat {
  box-shadow: none;
}

.section-title,
h2,
h3 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.14rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.filter-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.rail-form {
  grid-template-columns: 1fr;
}

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

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 9px 12px;
  font: inherit;
  font-size: 0.89rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.field input:focus,
.field select:focus {
  outline: 2px solid rgba(94, 66, 18, 0.10);
  border-color: var(--accent);
}

.setup-grid,
.chart-grid,
.record-grid {
  display: grid;
  gap: 12px;
}

.setup-group,
.chart-card,
.record-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.subgroup-head,
.record-head,
.chart-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 253, 248, 0.98), rgba(251, 246, 235, 0.98));
}

.subgroup-title,
.chart-title,
.record-title {
  font-weight: 900;
}

.pick-row {
  display: grid;
  grid-template-columns: 52px minmax(220px, 1.3fr) minmax(200px, 0.7fr) minmax(240px, 0.9fr);
  gap: 16px;
  padding: 16px;
  border-top: 1px solid var(--line);
  align-items: start;
}

.pick-row:first-of-type {
  border-top: 0;
}

.rank-box {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  background: transparent;
  color: #d9c294;
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1;
  box-shadow: none;
}

.symbol,
.pick-symbol {
  font-weight: 900;
}

.security-name,
.pick-name {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.87rem;
}

.pick-summary,
.company-summary {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.87rem;
  line-height: 1.52;
}

.tag-row,
.metric-strip,
.pick-links,
.downloads,
.action-links,
.meta-band {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.tag,
.chip,
.badge,
.quality-badge,
.direction-badge,
.state-badge,
.stat-chip,
.meta-chip,
.pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 0;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  padding: 5px 10px;
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.meta-chip {
  background: var(--surface-strong);
}

.quality-strict,
.strict,
.side-long,
.direction-long {
  border-color: rgba(29, 109, 103, 0.24);
  background: var(--teal-soft);
  color: var(--teal);
}

.quality-loose,
.loose {
  border-color: rgba(154, 107, 17, 0.24);
  background: var(--gold-soft);
  color: var(--gold);
}

.side-short,
.direction-short {
  border-color: rgba(182, 65, 58, 0.22);
  background: var(--red-soft);
  color: var(--red);
}

.side-neutral,
.direction-neutral,
.state-badge {
  border-color: var(--line);
  background: var(--blue-soft);
  color: var(--blue);
}

.action-link,
.chart-link-internal,
.chart-link-external,
.downloads a,
.pick-links a,
.actions a,
.table-link {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  border-radius: 0;
  border: 1px solid var(--button-line);
  background: var(--button-surface);
  color: var(--accent);
  padding: 7px 12px;
  font-size: 0.8rem;
  font-weight: 800;
}

.chart-link-internal,
.button.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface-strong);
}

.chart-link-external {
  background: var(--surface-strong);
  color: var(--accent);
  border-color: var(--button-line);
}

.empty-state {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 251, 244, 0.96);
  color: var(--muted);
  padding: 24px;
}

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

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

th,
td {
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  font-size: 0.86rem;
}

th {
  background: rgba(251, 246, 235, 0.96);
}

tbody tr {
  transition: background 120ms ease;
}

tbody tr:hover td {
  background: rgba(251, 243, 226, 0.72);
}

.details {
  max-width: 340px;
  color: var(--muted);
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.38;
}

.chart svg {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface-strong);
}

.chart-panel {
  padding: 14px;
}

.trendline-context-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 8px 16px 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.35;
}

.trendline-context-strip span:first-child {
  color: var(--ink);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-body {
  padding: 0 14px 14px;
}

.note-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.note-item {
  border: 1px solid var(--line);
  border-radius: 0;
  background: rgba(255, 251, 244, 0.96);
  padding: 12px;
}

.note-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.compact-title {
  display: flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
}

.mt-7 {
  margin-top: 7px;
}

.mt-8 {
  margin-top: 8px;
}

.mt-9 {
  margin-top: 9px;
}

@media (max-width: 1180px) {
  .segment-groups,
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-grid.metric-grid-six,
  .facts {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .pick-row {
    grid-template-columns: 52px minmax(0, 1fr);
  }

  .pick-row > :nth-child(3),
  .pick-row > :nth-child(4) {
    grid-column: 2;
  }
}

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

  .layout-rail,
  .filter-form {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 14px, 1560px);
    margin-top: 10px;
  }

  .app-frame {
    border-radius: 0;
  }

  .topbar,
  .mast,
  .command-bar,
  .content,
  .layout-rail {
    padding-left: 14px;
    padding-right: 14px;
  }

  .segment-groups,
  .metric-grid,
  .facts {
    grid-template-columns: 1fr;
  }

  .brand-logo {
    height: 68px;
  }

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

  .pick-row > :nth-child(3),
  .pick-row > :nth-child(4) {
    grid-column: auto;
  }
}
