:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #667085;
  --line: #d8dee7;
  --panel: #ffffff;
  --bg: #f5f7fa;
  --brand: #9b2d20;
  --brand-dark: #5c1f18;
  --steel: #1f5b7a;
  --sage: #526b45;
  --amber: #b96f22;
  --danger: #a53030;
  --shadow: 0 10px 28px rgba(31, 43, 61, 0.08);
}

* {
  box-sizing: border-box;
}

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

body.auth-pending .topbar,
body.auth-pending .workspace-nav,
body.auth-pending .layout,
body.signed-out .topbar,
body.signed-out .workspace-nav,
body.signed-out .layout {
  display: none;
}

.login-screen {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #f5f7fa, #eef2f6);
}

body.signed-out .login-screen {
  display: flex;
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(100%, 420px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-card h1 {
  margin: 0 0 8px;
  color: var(--brand-dark);
  font-size: 30px;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 750;
}

[data-role-hidden="true"] {
  display: none !important;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.file-button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

button:hover,
.file-button:hover {
  background: var(--brand-dark);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px clamp(16px, 4vw, 42px);
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.topbar h1,
.topbar p {
  margin: 0;
}

.topbar h1 {
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.05;
  color: var(--brand-dark);
}

.eyebrow {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.workspace-nav {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(246, 248, 251, 0.95);
  padding: 10px clamp(12px, 3vw, 32px);
  backdrop-filter: blur(8px);
}

.workspace-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
  white-space: nowrap;
}

.workspace-nav a:hover {
  background: #eef2f6;
}

.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost:hover {
  background: #eef2f6;
  color: var(--ink);
}

.file-button input {
  display: none;
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 340px;
  align-items: start;
  gap: 16px;
  padding: 16px clamp(12px, 3vw, 32px) 32px;
}

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

.panel {
  padding: 16px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

h2 {
  margin: 0;
  font-size: 17px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: #eef4f7;
  color: var(--steel);
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

label {
  display: grid;
  gap: 6px;
  color: #3d4652;
  font-size: 13px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

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

.controls,
.entry,
.forecast {
  display: grid;
  align-content: start;
  gap: 12px;
}

.controls {
  grid-column: 1 / 2;
  grid-row: 1 / span 4;
}

.entry {
  grid-column: 3 / 4;
  grid-row: 1 / span 3;
}

.forecast {
  grid-column: 2 / 3;
  grid-row: 2 / 3;
}

.insights-panel {
  grid-column: 2 / 4;
  grid-row: 3;
}

.year-panel {
  grid-column: 2 / 4;
  grid-row: 4;
}

.chart-panel {
  grid-column: 2 / 4;
  grid-row: 5;
}

.table-panel {
  grid-column: 1 / -1;
  grid-row: 6;
}

.map-panel {
  grid-column: 1 / -1;
  grid-row: 7;
}

.news-panel {
  grid-column: 1 / -1;
  grid-row: 8;
}

.source-panel {
  grid-column: 1 / -1;
  grid-row: 9;
}

.restaurant-panel {
  grid-column: 1 / -1;
  grid-row: 10;
}

.command-panel {
  grid-column: 1 / -1;
  grid-row: 11;
}

.copacker-panel {
  grid-column: 1 / -1;
  grid-row: 12;
}

.alerts-panel,
.history-panel,
.quotes-panel,
.customer-panel,
.competitor-panel,
.regional-panel,
.inventory-panel,
.upload-panel {
  grid-column: 1 / -1;
}

.alerts-panel {
  grid-row: 13;
}

.history-panel {
  grid-row: 14;
}

.quotes-panel {
  grid-row: 15;
}

.customer-panel {
  grid-row: 16;
}

.competitor-panel {
  grid-row: 17;
}

.regional-panel {
  grid-row: 18;
}

.inventory-panel {
  grid-row: 19;
}

.upload-panel {
  grid-row: 20;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  grid-column: 2 / 3;
  grid-row: 1;
}

.summary-strip article {
  min-height: 94px;
  padding: 16px;
}

.metric-label {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.summary-strip strong {
  font-size: 24px;
  color: var(--brand-dark);
}

.state-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
  gap: 8px;
}

.state-cell {
  min-height: 62px;
  border-radius: 6px;
  border: 1px solid rgba(32, 33, 36, 0.1);
  padding: 8px;
  color: #fff;
}

.state-cell span,
.state-cell strong {
  display: block;
}

.state-cell span {
  font-size: 12px;
  opacity: 0.85;
}

.state-cell strong {
  margin-top: 4px;
  font-size: 16px;
}

.chart-wrap {
  position: relative;
}

.chart-note {
  margin: -4px 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.chart-panel canvas {
  display: block;
  width: 100%;
  height: 360px;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  max-width: 230px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--ink);
  padding: 9px 10px;
  pointer-events: none;
  font-size: 12px;
  line-height: 1.35;
}

.entry-form {
  display: grid;
  gap: 10px;
}

.entry-form button {
  margin-top: 4px;
}

.advanced-entry {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  padding: 0;
}

.advanced-entry summary {
  cursor: pointer;
  padding: 10px 11px;
  color: var(--steel);
  font-size: 13px;
  font-weight: 850;
}

.advanced-entry[open] {
  padding: 0 11px 11px;
}

.advanced-entry[open] summary {
  margin: 0 -11px 10px;
  border-bottom: 1px solid var(--line);
}

.advanced-entry .field-row {
  margin-bottom: 10px;
}

.copacker-form {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.inline-add-form {
  display: grid;
  grid-template-columns: minmax(180px, 320px) auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
}

.inline-add-form button {
  width: max-content;
}

.copacker-results {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr)) auto;
  align-items: end;
  gap: 12px;
}

.run-results {
  grid-template-columns: repeat(5, minmax(120px, 1fr)) auto;
}

.copacker-results article {
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.copacker-results strong {
  color: var(--brand-dark);
  font-size: 22px;
}

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

.insight-grid article {
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.insight-grid strong {
  color: var(--brand-dark);
  font-size: 22px;
}

.alert-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.alert-hit,
.alert-empty {
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 750;
}

.alert-hit {
  background: #f9eded;
  color: var(--danger);
}

.alert-empty {
  background: #edf6ec;
  color: var(--sage);
}

.alert-form {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.alert-form button {
  justify-self: start;
}

.prediction {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfd;
}

.signal-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.signal-notes {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.sync-status {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.source-summary {
  margin-top: 8px;
  color: #45515f;
  font-size: 13px;
  line-height: 1.4;
}

.source-form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.source-form button {
  justify-self: start;
}

.capture-tool {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.capture-tool h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.bookmarklet {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  margin: 8px 0;
  border-radius: 6px;
  background: var(--steel);
  color: #fff;
  padding: 0 12px;
  font-weight: 850;
  text-decoration: none;
}

.bookmarklet:hover {
  background: #17465e;
}

.paste-capture-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.paste-capture-form button {
  justify-self: start;
}

.source-panel .signal-toolbar {
  margin-bottom: 14px;
}

.collection-results {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.collection-results summary {
  cursor: pointer;
  padding: 10px 11px;
  color: var(--steel);
  font-size: 14px;
  font-weight: 850;
}

.collection-results[open] {
  padding: 0 11px 11px;
}

.collection-results[open] summary {
  margin: 0 -11px 10px;
  border-bottom: 1px solid var(--line);
}

.compact-table table {
  min-width: 760px;
}

.compact-table th,
.compact-table td {
  padding: 8px;
  font-size: 12px;
}

.compact-table td {
  vertical-align: top;
}

.collection-note {
  max-height: 42px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.news-list {
  display: grid;
  gap: 10px;
  max-height: 520px;
  overflow: auto;
}

.news-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 116px;
  gap: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid #b8c6d1;
  border-radius: 6px;
  background: #fff;
  padding: 12px;
}

.news-item a {
  color: var(--ink);
  font-weight: 850;
  text-decoration: none;
}

.news-item a:hover {
  color: var(--steel);
  text-decoration: underline;
}

.news-item p {
  margin: 6px 0 0;
  color: #4f5b69;
  font-size: 13px;
  line-height: 1.4;
}

.news-item aside {
  display: grid;
  justify-items: end;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.news-item aside strong {
  color: var(--brand-dark);
}

.news-up {
  border-left-color: var(--danger);
}

.news-down {
  border-left-color: var(--sage);
}

.news-neutral {
  border-left-color: var(--steel);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 0 8px;
  background: #eef2f6;
  color: var(--muted);
  font-weight: 850;
}

.status-ok {
  background: #edf6ec;
  color: var(--sage);
}

.status-error {
  background: #f9eded;
  color: var(--danger);
}

.status-no_prices,
.status-skipped,
.status-outlier {
  background: #f8f1e8;
  color: var(--amber);
}

.status-dynamic,
.status-blocked {
  background: #eef4f7;
  color: var(--steel);
}

.forecast-headline {
  margin: 0;
  font-size: 25px;
  font-weight: 850;
  color: var(--brand-dark);
}

.forecast-reason {
  margin: 0;
  color: #45515f;
  line-height: 1.45;
}

.range-label {
  color: var(--muted);
  font-weight: 800;
}

.reset-button {
  min-width: 58px;
  padding: 0;
  background: #eef2f6;
  color: var(--ink);
}

.danger {
  background: #fff;
  border: 1px solid #e0b5b5;
  color: var(--danger);
}

.danger:hover {
  background: #f9eded;
  color: var(--danger);
}

.hidden {
  display: none;
}

.row-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  min-width: 72px;
  border: 1px solid #e0b5b5;
  background: #fff;
  color: var(--danger);
  padding: 0 9px;
  white-space: nowrap;
}

.table-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

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

.table-panel .table-wrap,
.competitor-panel .table-wrap {
  max-height: 560px;
  overflow: auto;
}

.source-panel .table-wrap,
.restaurant-panel .table-wrap,
.quotes-panel .table-wrap,
.customer-panel .table-wrap,
.regional-panel .table-wrap,
.inventory-panel .table-wrap,
.upload-panel .table-wrap,
.history-panel .table-wrap,
.alerts-panel .table-wrap {
  max-height: 360px;
  overflow: auto;
}

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

.restaurant-panel table {
  min-width: 1260px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
  overflow-wrap: anywhere;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #f8fafc;
}

.excluded-row {
  background: #fff8ef;
}

.excluded-row:hover {
  background: #fff2df;
}

.excluded-row .notes-cell strong {
  color: var(--amber);
}

th:nth-child(1),
td:nth-child(1) {
  width: 92px;
}

th:nth-child(2),
td:nth-child(2) {
  width: 138px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 120px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 104px;
}

th:nth-child(5),
td:nth-child(5) {
  width: 94px;
}

th:nth-child(6),
td:nth-child(6) {
  width: 150px;
}

th:nth-child(7),
td:nth-child(7) {
  width: 112px;
}

th:nth-child(8),
td:nth-child(8) {
  width: 116px;
}

th:nth-child(10),
td:nth-child(10) {
  width: 104px;
}

.restaurant-panel th:nth-child(1),
.restaurant-panel td:nth-child(1) {
  width: 92px;
}

.restaurant-panel th:nth-child(2),
.restaurant-panel td:nth-child(2) {
  width: 170px;
}

.restaurant-panel th:nth-child(3),
.restaurant-panel td:nth-child(3) {
  width: 64px;
}

.restaurant-panel th:nth-child(4),
.restaurant-panel td:nth-child(4) {
  width: 360px;
}

.restaurant-panel th:nth-child(5),
.restaurant-panel td:nth-child(5),
.restaurant-panel th:nth-child(6),
.restaurant-panel td:nth-child(6),
.restaurant-panel th:nth-child(7),
.restaurant-panel td:nth-child(7) {
  width: 116px;
}

.restaurant-panel th:nth-child(8),
.restaurant-panel td:nth-child(8) {
  width: 136px;
}

.restaurant-panel th:nth-child(9),
.restaurant-panel td:nth-child(9) {
  width: 92px;
}

.restaurant-panel th:nth-child(10),
.restaurant-panel td:nth-child(10) {
  width: 82px;
}

.notes-cell a {
  color: var(--steel);
  font-weight: 750;
}

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

  .controls,
  .entry,
  .forecast,
  .news-panel,
  .source-panel,
  .restaurant-panel,
  .command-panel,
  .copacker-panel,
  .year-panel,
  .insights-panel,
  .alerts-panel,
  .history-panel,
  .quotes-panel,
  .customer-panel,
  .competitor-panel,
  .regional-panel,
  .inventory-panel,
  .upload-panel,
  .summary-strip,
  .map-panel,
  .chart-panel,
  .table-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .summary-strip,
  .restaurant-panel,
  .command-panel,
  .copacker-panel,
  .year-panel,
  .insights-panel,
  .alerts-panel,
  .history-panel,
  .quotes-panel,
  .customer-panel,
  .competitor-panel,
  .regional-panel,
  .inventory-panel,
  .upload-panel,
  .map-panel,
  .chart-panel,
  .table-panel {
    grid-column: 1 / -1;
  }
}

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

  .top-actions {
    width: 100%;
    justify-content: stretch;
  }

  .top-actions > * {
    flex: 1;
  }

  .layout,
  .summary-strip,
  .copacker-results,
  .run-results,
  .insight-grid,
  .inline-add-form,
  .field-row,
  .forecast-grid {
    grid-template-columns: 1fr;
  }
}
