:root {
  color-scheme: light;
  --ink: #18231f;
  --muted: #61716c;
  --line: #dce6e0;
  --paper: #f7f8f4;
  --panel: #ffffff;
  --forest: #21695b;
  --berry: #a33e62;
  --gold: #b27316;
  --cyan: #237485;
  --lime: #cfe57a;
  --soft: #eef4ec;
  --danger: #9f2f42;
  --shadow: 0 18px 45px rgba(28, 38, 35, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  min-width: 0;
  padding: 24px 18px;
  background: #10251f;
  color: #f6fbf7;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--lime);
  color: #10251f;
  font-weight: 900;
}

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

.brand span {
  color: #b7c9c2;
  font-size: 0.86rem;
}

.nav-list {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.nav-item {
  color: #d8e7e1;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 7px;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.data-card {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.data-card strong {
  margin: 6px 0;
  overflow-wrap: anywhere;
}

.main-panel {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

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

.eyebrow,
.label {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 3vw, 3.15rem);
  line-height: 1.04;
  max-width: 900px;
}

h2 {
  margin-top: 4px;
  font-size: 1.05rem;
}

.file-button,
.ghost-button {
  min-height: 42px;
  border: 1px solid #16382f;
  border-radius: 7px;
  background: #16382f;
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0 14px;
  white-space: nowrap;
}

.file-button {
  position: relative;
}

.file-button input {
  position: absolute;
  inset: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.ghost-button {
  min-height: 36px;
  background: white;
  color: #16382f;
}

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

.danger-button {
  border-color: #d9b1ba;
  color: var(--danger);
}

.control-strip {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.check-control {
  min-height: 54px;
  grid-template-columns: auto 1fr;
  align-items: center;
  align-content: center;
  color: var(--ink);
  text-transform: none;
}

input,
select {
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  padding: 0 10px;
}

input[type="checkbox"] {
  min-height: auto;
  width: 18px;
  height: 18px;
  padding: 0;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  min-width: 0;
  min-height: 126px;
  padding: 17px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  border-top: 5px solid var(--forest);
  display: grid;
  align-content: space-between;
  gap: 10px;
}

.kpi-card span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi-card strong {
  font-size: 1.9rem;
  line-height: 1;
  overflow-wrap: anywhere;
}

.kpi-card small {
  color: var(--muted);
}

.accent-berry {
  border-top-color: var(--berry);
}

.accent-gold {
  border-top-color: var(--gold);
}

.accent-cyan {
  border-top-color: var(--cyan);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 18px;
}

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

.panel.wide {
  grid-column: 1 / -1;
}

.priority-panel {
  border-color: #bfd1c9;
}

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

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

.pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--forest);
  font-size: 0.78rem;
  font-weight: 850;
  white-space: nowrap;
}

.pill.good {
  background: #e6f4df;
  color: #275b35;
}

.pill.warn {
  background: #fff2d6;
  color: #70440d;
}

.pill.bad {
  background: #ffe3e8;
  color: #843044;
}

.table-frame {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.compact-frame {
  max-height: 430px;
}

.data-table {
  overflow-x: auto;
  max-width: 100%;
}

.empty-state {
  padding: 22px;
  color: var(--muted);
  font-weight: 750;
}

table.forecast-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  font-size: 0.9rem;
}

table.forecast-table th,
table.forecast-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

table.forecast-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f4f7f2;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

table.forecast-table tr:hover td {
  background: #fbfcfa;
}

td strong,
td small {
  display: block;
}

td small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.num {
  text-align: right;
  white-space: nowrap;
}

.strong {
  font-weight: 900;
}

.num-input {
  width: 96px;
  text-align: right;
}

td input,
td select {
  width: 100%;
}

.mapping-grid {
  min-width: 1120px;
}

.signal-list {
  display: grid;
  gap: 10px;
}

.signal-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.signal-item strong,
.signal-item span {
  display: block;
}

.signal-item span {
  margin-top: 4px;
  color: var(--muted);
}

.loading {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  background: rgba(247, 248, 244, 0.88);
}

.loading.is-hidden {
  display: none;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
  background: #10251f;
}

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

.auth-panel {
  padding: 24px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-brand {
  margin-bottom: 22px;
  color: var(--ink);
}

.auth-brand span:not(.brand-mark) {
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-submit {
  width: 100%;
  margin-top: 4px;
}

.auth-status {
  min-height: 22px;
  color: var(--danger);
  font-weight: 800;
}

.setup-secret {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.setup-secret strong {
  overflow-wrap: anywhere;
  font-family: "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.04em;
}

.setup-secret a {
  color: var(--forest);
  font-weight: 850;
}

.loader {
  width: 42px;
  height: 42px;
  border: 4px solid #d5e1dc;
  border-top-color: var(--forest);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

  .primary-strip,
  .kpi-grid,
  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
  }

  .dashboard-grid .wide {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .main-panel {
    padding: 16px;
  }

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

  .file-button {
    width: 100%;
  }

  .nav-list {
    display: flex;
    overflow-x: auto;
  }

  .nav-item {
    white-space: nowrap;
  }

  .primary-strip,
  .kpi-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .table-frame {
    max-height: 620px;
    border: 0;
  }

  table.forecast-table,
  table.forecast-table thead,
  table.forecast-table tbody,
  table.forecast-table tr,
  table.forecast-table th,
  table.forecast-table td {
    display: block;
  }

  table.forecast-table {
    min-width: 0;
  }

  table.forecast-table thead {
    display: none;
  }

  table.forecast-table tr {
    padding: 12px;
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfa;
  }

  table.forecast-table td {
    display: grid;
    grid-template-columns: 118px minmax(0, 1fr);
    gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: normal;
  }

  table.forecast-table td:last-child {
    border-bottom: 0;
  }

  table.forecast-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 850;
    text-transform: uppercase;
  }

  table.forecast-table td.num {
    text-align: left;
    white-space: normal;
  }
}
