/* Dense, light "market terminal" look inspired by finviz-style futures/screener
   pages: navy header bars, hairline borders, zebra-striped tables, tabular
   monospace numbers, green/red price deltas. Fonts are self-hosted. */

@font-face {
  font-family: "Figtree";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/vendor/fonts/figtree-400.woff2") format("woff2");
}
@font-face {
  font-family: "Figtree";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/static/vendor/fonts/figtree-500.woff2") format("woff2");
}
@font-face {
  font-family: "Figtree";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/vendor/fonts/figtree-600.woff2") format("woff2");
}
@font-face {
  font-family: "Figtree";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/vendor/fonts/figtree-700.woff2") format("woff2");
}

:root {
  --color-bg: #eef1f5;
  --color-surface: #ffffff;
  --color-text: #1a1f2b;
  --color-divider: #d8dce3;

  --color-neutral-50: #f7f8fa;
  --color-neutral-100: #eef1f5;
  --color-neutral-200: #e2e6ec;
  --color-neutral-300: #d8dce3;
  --color-neutral-400: #b6bcc8;
  --color-neutral-500: #8a92a3;
  --color-neutral-600: #666f82;
  --color-neutral-700: #4a5266;
  --color-neutral-800: #2e3547;
  --color-neutral-900: #161b28;

  --color-accent-100: #e6effe;
  --color-accent-200: #c3d8fc;
  --color-accent-300: #90b6f8;
  --color-accent-400: #5891f0;
  --color-accent-500: #2f6fe0;
  --color-accent-600: #2158bf;
  --color-accent-700: #1b4494;
  --color-accent-800: #142f68;
  --color-accent-900: #0e1e46;
  --color-accent: var(--color-accent-500);

  --color-up: #157a3d;
  --color-up-bg: #e2f5e7;
  --color-down: #ae2a1f;
  --color-down-bg: #fbe6e3;
  --color-danger: var(--color-down);
  --color-danger-bg: var(--color-down-bg);

  --font-heading: "Figtree", system-ui, sans-serif;
  --font-heading-weight: 700;
  --font-body: "Figtree", system-ui, sans-serif;
  --font-mono:
    ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;

  --radius-sm: 3px;
  --radius-md: 5px;
  --radius-lg: 6px;

  --shadow-sm: 0 1px 2px rgba(22, 27, 40, 0.08);
  --shadow-md: 0 2px 6px rgba(22, 27, 40, 0.12);
  --shadow-lg: 0 10px 28px rgba(22, 27, 40, 0.22);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.45;
  font-weight: 400;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-2);
}
h1 {
  font-size: 22px;
}
h2 {
  font-size: 17px;
}
h3 {
  font-size: 15px;
}

a {
  color: var(--color-accent);
  text-underline-offset: 2px;
}
:focus {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--color-accent-500);
  outline-offset: 1px;
}
::selection {
  background: color-mix(in srgb, var(--color-accent-500) 30%, transparent);
}

/* — buttons — */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  text-decoration: none;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 12px;
  line-height: 1.2;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
}
button.btn,
button {
  font: inherit;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--color-accent-600);
  color: #fff;
  border-color: var(--color-accent-600);
}
.btn-primary:hover {
  background: var(--color-accent-700);
  border-color: var(--color-accent-700);
}
.btn-secondary {
  border-color: var(--color-divider);
  background: var(--color-surface);
  color: var(--color-text);
}
.btn-secondary:hover {
  background: var(--color-neutral-100);
}
.btn-danger {
  background: var(--color-down-bg);
  color: var(--color-down);
  border-color: transparent;
}
.btn-danger:hover {
  background: #f6d0cb;
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-accent-600);
  padding-inline: 6px;
}
.btn-ghost:hover {
  background: var(--color-accent-100);
}
.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
}

/* — forms — */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--color-neutral-600);
}
input,
select {
  font: inherit;
  min-height: 30px;
  padding: 5px 10px;
  font-size: 12.5px;
  color: var(--color-text);
  caret-color: var(--color-accent-600);
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-sm);
}
input:hover {
  border-color: var(--color-neutral-500);
}
input:focus-visible {
  border-color: var(--color-accent-500);
  outline-offset: 0;
}
input[type="number"] {
  width: 6.5rem;
}
input[name="unit"] {
  width: 4.5rem;
}

/* — tags / pills — */
.tag {
  display: inline-flex;
  align-items: center;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
}
.tag-accent {
  background: var(--color-accent-100);
  color: var(--color-accent-800);
}
.tag-neutral {
  background: var(--color-neutral-200);
  color: var(--color-neutral-800);
}

/* — direction / delta text — */
.dir-up {
  color: var(--color-up);
}
.dir-down {
  color: var(--color-down);
}
.dir-flat {
  color: var(--color-neutral-500);
}
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* — layout shell — */
header.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3) var(--space-4);
  padding: 10px 24px;
  background: var(--color-neutral-900);
  border-bottom: 1px solid var(--color-neutral-900);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: var(--color-accent-500);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 12px;
}
.brand-name {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: #fff;
  text-transform: uppercase;
}
header.site-header nav {
  display: flex;
  align-items: center;
  gap: 14px;
}
header.site-header nav a {
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  color: #cdd6e8;
}
header.site-header nav a:hover {
  color: #fff;
}
header.site-header nav form {
  margin: 0;
}
header.site-header .btn-secondary {
  background: transparent;
  border-color: #3a4256;
  color: #cdd6e8;
}
header.site-header .btn-secondary:hover {
  background: #232b3d;
  color: #fff;
}

/* — import-produce ticker strip — */
.ticker-wrap {
  background: var(--color-neutral-800);
  border-bottom: 1px solid var(--color-neutral-900);
  overflow: hidden;
  white-space: nowrap;
}
.ticker-track {
  display: inline-flex;
  align-items: baseline;
  /* Without an explicit width, the browser's shrink-to-fit sizing clamps
     this box to the (much narrower) visible strip instead of its true
     content width, so the -50% loop transform below lands in the wrong
     place and leaves a gap before the repeated content scrolls in. */
  width: max-content;
  padding: 12px 0;
  animation-name: ticker-scroll;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  will-change: transform;
}
.ticker-wrap:hover .ticker-track {
  animation-play-state: paused;
}
.ticker-item {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  flex-shrink: 0;
  padding: 0 16px;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 18px;
}
.ticker-name {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: #dfe4ee;
}
.ticker-price {
  font-weight: 700;
  color: var(--color-accent-300);
}
.ticker-sep {
  flex-shrink: 0;
  color: #4a5266;
  font-size: 11px;
}
@keyframes ticker-scroll {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-50%);
  }
}
@media (prefers-reduced-motion: reduce) {
  .ticker-track {
    animation: none;
  }
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px;
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.page-heading .meta {
  font-size: 11.5px;
  color: var(--color-neutral-600);
  margin-top: 2px;
}

.empty-state {
  text-align: center;
  color: var(--color-neutral-600);
  padding: 3rem 1rem;
  font-size: 13px;
}

/* — produce sections: plain label + flat grid of ticker tiles (public dashboard) — */
.produce-section {
  margin-bottom: 22px;
}
.produce-section-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-bottom: 6px;
  margin-bottom: 10px;
  border-bottom: 2px solid var(--color-neutral-900);
}
.produce-section-head h2 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.ticker-badge {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  color: var(--color-neutral-900);
  background: var(--color-accent-300);
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.02em;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(120px, 100%), 1fr));
  gap: 8px;
}
.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: 9px 6px 8px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-decoration: none;
}
.tile:hover {
  border-color: var(--color-accent-400);
  box-shadow: var(--shadow-sm);
}
.tile:focus-visible {
  outline: 2px solid var(--color-accent-500);
  outline-offset: 1px;
}
.tile-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--color-neutral-600);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.tile-price {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  margin: 5px 0 3px;
  font-variant-numeric: tabular-nums;
}
.tile-unit {
  font-size: 9.5px;
  font-weight: 400;
  color: var(--color-neutral-500);
}
.tile-delta {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}
.search-row input {
  flex: 1;
  max-width: 280px;
}

/* — admin — */
.admin-card {
  background: var(--color-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.admin-card > h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-neutral-600);
  font-weight: 700;
  margin: 0 0 8px;
}
.admin-produce-block {
  list-style: none;
}
.admin-type-block {
  border-top: 1px solid var(--color-divider);
  padding: 10px 0;
  margin-top: 2px;
}
.admin-type-block:first-of-type {
  border-top: none;
}
.admin-grade-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12.5px;
}
.row-actions {
  display: flex;
  gap: 5px;
  align-items: center;
}
.row-actions .btn {
  padding: 4px 10px;
  font-size: 11px;
}
.inline-form {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  margin: 6px 0;
}

.grade-updated {
  color: var(--color-neutral-500);
  font-size: 10.5px;
  margin-left: 6px;
}

.flash-error {
  background: var(--color-down-bg);
  color: var(--color-down);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin-bottom: 14px;
  font-size: 12.5px;
  font-weight: 600;
}

.login-wrap {
  max-width: 340px;
  margin: 3.5rem auto;
}
.login-wrap .admin-card {
  padding: 22px 24px;
}

/* — modal — */
[x-cloak] {
  display: none !important;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: rgba(14, 18, 28, 0.55);
}
.modal-box {
  position: relative;
  width: min(600px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 22px 24px 20px;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-divider);
  background: var(--color-neutral-100);
  color: var(--color-neutral-700);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.modal-close:hover {
  background: var(--color-neutral-200);
}
.modal-head {
  margin-bottom: 12px;
  padding-right: 34px;
}
.modal-head .meta {
  font-size: 12px;
  color: var(--color-neutral-600);
  margin-top: 2px;
}

/* — price history chart — */
.price-chart-wrap {
  position: relative;
  max-width: 560px;
  margin: 0 auto;
}
.price-chart {
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
}
.chart-grid {
  stroke: var(--color-divider);
  stroke-width: 1;
}
.chart-axis-label {
  font: 600 10px var(--font-mono);
  fill: var(--color-neutral-600);
}
.chart-area {
  fill: var(--color-accent-500);
  opacity: 0.1;
  stroke: none;
}
.chart-line {
  fill: none;
  stroke: var(--color-accent-600);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chart-marker {
  fill: var(--color-accent-600);
  stroke: var(--color-surface);
  stroke-width: 2;
}
.chart-marker-last {
  fill: var(--color-accent-800);
}
.chart-end-label {
  font: 700 12px var(--font-mono);
  fill: var(--color-text);
  font-variant-numeric: tabular-nums;
}
.chart-crosshair {
  stroke: var(--color-neutral-500);
  stroke-width: 1;
  pointer-events: none;
}
.chart-tooltip {
  position: absolute;
  top: 8px;
  transform: translateX(-50%);
  pointer-events: none;
  background: var(--color-neutral-900);
  color: #fff;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}
.chart-tooltip-value {
  font-weight: 700;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.chart-tooltip-date {
  opacity: 0.75;
  font-size: 10.5px;
  margin-top: 1px;
}
.chart-table-wrap {
  overflow-x: auto;
}
.chart-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  font-size: 12px;
}
.chart-table th {
  text-align: left;
  font: 700 10px var(--font-body);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-neutral-600);
  padding: 5px 4px;
  border-bottom: 1px solid var(--color-divider);
}
.chart-table td {
  padding: 5px 4px;
  border-bottom: 1px solid var(--color-neutral-100);
  font-family: var(--font-mono);
}

/* — grade detail page — */
.detail-breadcrumb {
  font-size: 11.5px;
  color: var(--color-neutral-600);
  margin-bottom: 14px;
}
.detail-breadcrumb a {
  color: var(--color-neutral-600);
  text-decoration: none;
}
.detail-breadcrumb a:hover {
  color: var(--color-accent-600);
}
.detail-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.detail-price-block {
  margin-left: auto;
  text-align: right;
}
.detail-price {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
}
.detail-unit {
  font-size: 12px;
  color: var(--color-neutral-600);
}
.detail-delta {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  margin-top: 4px;
}
.detail-specs {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  margin: 0;
  font-size: 13px;
}
.detail-specs dt {
  color: var(--color-neutral-600);
}
.detail-specs dd {
  margin: 0;
  font-weight: 600;
  font-family: var(--font-mono);
}

/* — small screens — */
@media (max-width: 640px) {
  header.site-header {
    padding: 10px 14px;
    gap: 8px 12px;
  }
  header.site-header nav {
    gap: 8px;
    flex-wrap: wrap;
  }

  main {
    padding: 16px 14px;
  }
  h1 {
    font-size: 19px;
  }
  h2 {
    font-size: 15px;
  }
  .page-heading {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 14px;
  }

  .search-row input {
    max-width: none;
  }

  .tile-grid {
    gap: 6px;
    grid-template-columns: repeat(auto-fill, minmax(min(100px, 100%), 1fr));
  }
  .tile {
    padding: 7px 4px 6px;
  }

  .admin-card {
    padding: 12px 14px;
  }
  .row-actions {
    flex-wrap: wrap;
    row-gap: 6px;
  }
  .admin-grade-row {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .inline-form {
    flex-direction: column;
    align-items: stretch;
  }
  .inline-form input,
  .inline-form select {
    width: 100%;
  }

  .login-wrap {
    margin: 2.5rem auto;
    max-width: none;
  }
  .login-wrap .admin-card {
    padding: 18px 16px;
  }

  .modal-backdrop {
    padding: 10px;
    align-items: flex-end;
  }
  .modal-box {
    width: 100%;
    max-height: 92vh;
    padding: 18px 16px 16px;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
  }
  .modal-close {
    top: 10px;
    right: 10px;
  }
  .modal-head {
    padding-right: 32px;
  }

  .chart-tooltip {
    font-size: 10.5px;
    padding: 4px 7px;
  }
}
