:root {
  --ink: #17212b;
  --muted: #68727d;
  --line: #dde3ea;
  --panel: #ffffff;
  --bg: #f6f8fb;
  --navy: #18344f;
  --teal: #0f766e;
  --gold: #b7791f;
  --red: #b42318;
  --green: #28724a;
  --shadow: 0 20px 50px rgba(24, 52, 79, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(24, 52, 79, 0.08), transparent 320px),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  padding: 18px 0 28px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 4rem);
  line-height: 1;
  letter-spacing: 0;
}

.intro {
  max-width: 740px;
  margin: 16px 0 0;
  color: #40505f;
  font-size: 1.03rem;
  line-height: 1.65;
}

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 750;
  text-decoration: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary {
  color: #fff;
  background: var(--navy);
}

.secondary {
  color: var(--navy);
  background: #fff;
  border-color: var(--line);
}

.danger {
  color: #fff;
  background: var(--red);
}

.text-link {
  color: var(--navy);
  font-weight: 800;
  text-decoration: none;
}

.account-strip {
  margin: -8px 0 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px;
  color: #40505f;
  background: #fff;
  box-shadow: 0 10px 28px rgba(24, 52, 79, 0.08);
  line-height: 1.45;
}

.workspace {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.upload-panel,
.dashboard {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.upload-panel {
  border-radius: 8px;
  padding: 18px;
  position: sticky;
  top: 18px;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 24px;
  border: 2px dashed #a8b7c6;
  border-radius: 8px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  background: #fbfcfe;
  transition:
    border-color 150ms ease,
    background 150ms ease,
    transform 150ms ease;
}

.drop-zone:hover,
.drop-zone.dragging {
  border-color: var(--teal);
  background: #eefaf8;
  transform: translateY(-1px);
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.drop-zone strong {
  color: var(--ink);
  margin-top: 12px;
  font-size: 1.05rem;
}

.drop-zone small {
  display: block;
  margin-top: 8px;
  line-height: 1.4;
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  color: #fff;
  background: var(--teal);
  font-weight: 900;
}

.field-help {
  padding: 18px 2px 10px;
}

.upload-actions {
  display: flex;
  justify-content: stretch;
  margin-top: 12px;
}

.upload-actions button {
  width: 100%;
}

.field-help h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.field-help p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.helper-copy {
  margin-top: 8px !important;
  font-size: 0.92rem;
}

.column-mapping {
  border-top: 1px solid var(--line);
  margin-top: 8px;
}

.column-mapping summary {
  color: var(--navy);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 800;
}

.mapping-fields {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

code {
  color: var(--navy);
  background: #edf2f7;
  border-radius: 4px;
  padding: 2px 5px;
}

.status-card {
  border-top: 1px solid var(--line);
  margin-top: 10px;
  padding-top: 14px;
  color: var(--muted);
  line-height: 1.45;
}

.dashboard {
  border-radius: 8px;
  overflow: hidden;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.metrics article {
  padding: 18px;
  border-right: 1px solid var(--line);
}

.metrics article:last-child {
  border-right: 0;
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.metrics strong {
  display: block;
  margin-top: 8px;
  font-size: 1.8rem;
}

.controls {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.8fr 1fr;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: #4b5966;
  font-size: 0.82rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #bfccd8;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 96px;
  padding: 10px 12px;
  line-height: 1.45;
  resize: vertical;
}

.allocation-layout {
  display: grid;
  gap: 22px;
}

.guide-layout {
  display: grid;
  gap: 22px;
}

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

.guide-table table {
  min-width: 640px;
}

.membership-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px;
  align-items: start;
}

.compact-grid {
  grid-template-columns: minmax(320px, 520px);
}

.auth-page-grid {
  display: grid;
  grid-template-columns: minmax(320px, 520px);
  gap: 22px;
  align-items: start;
}

.account-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.account-actions[hidden] {
  display: none;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px;
  align-items: start;
}

.auth-form {
  align-content: start;
}

.membership-status {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  color: #40505f;
  background: #fbfcfe;
  line-height: 1.45;
}

.membership-status strong,
.membership-status span,
.membership-status small {
  display: block;
}

.membership-status span,
.membership-status small {
  margin-top: 6px;
  color: var(--muted);
}

.turnstile-box {
  min-height: 65px;
}

.muted-box {
  display: grid;
  align-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  background: #fbfcfe;
  line-height: 1.45;
}

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

.tier-list article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.tier-list strong,
.tier-list span {
  display: block;
}

.tier-list span {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
}

.panel-body p {
  margin: 0;
  color: #40505f;
  line-height: 1.6;
}

.allocation-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.tool-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.danger-panel {
  border-color: #f7b4a6;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.08rem;
}

.panel-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panel-actions select {
  width: 160px;
}

.panel-actions input {
  width: 190px;
}

.saved-status {
  margin: 0;
  padding: 12px 18px;
}

.panel-body {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.order-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.order-table {
  min-width: 620px;
}

.order-table th,
.order-table td {
  padding: 10px;
}

.order-table input {
  min-height: 38px;
}

.allocation-edit {
  min-width: 110px;
  min-height: 36px;
}

.icon-button {
  width: 46px;
  min-width: 46px;
  padding: 0;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.summary-strip article {
  padding: 16px 18px;
  border-right: 1px solid var(--line);
}

.summary-strip article:last-child {
  border-right: 0;
}

.summary-strip span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.summary-strip strong {
  display: block;
  margin-top: 6px;
  font-size: 1.5rem;
}

input:disabled,
select:disabled {
  color: #8a96a3;
  background: #f0f3f7;
}

.messages {
  display: grid;
  gap: 10px;
  padding: 14px 18px 0;
}

.message {
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.45;
  font-size: 0.94rem;
}

.message.error {
  color: #7a271a;
  background: #fff1ed;
  border: 1px solid #f7b4a6;
}

.message.warning {
  color: #7a4f01;
  background: #fffaeb;
  border: 1px solid #f6d78a;
}

.message.success {
  color: #175c40;
  background: #ecfdf3;
  border: 1px solid #a6e9c3;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 340px);
  min-height: 360px;
}

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

.allocation-table table {
  min-width: 1120px;
}

th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #344252;
  background: #eef3f8;
  font-size: 0.78rem;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #f7fafc;
}

.empty-row td {
  height: 240px;
  color: var(--muted);
  text-align: center;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 800;
}

.pill.expired {
  color: #fff;
  background: var(--red);
}

.pill.expiring {
  color: #4d3300;
  background: #f6c453;
}

.pill.valid {
  color: #fff;
  background: var(--green);
}

.pill.noExpiry {
  color: var(--navy);
  background: #dbeafe;
}

.fifo-rank {
  color: var(--teal);
  font-weight: 900;
}

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

  .hero,
  .workspace {
    grid-template-columns: 1fr;
  }

  .hero,
  .hero-actions {
    display: grid;
    justify-content: stretch;
  }

  .upload-panel {
    position: static;
  }

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

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

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

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

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

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

  .metrics,
  .controls,
  .summary-strip {
    grid-template-columns: 1fr;
  }

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

  .metrics article {
    border-right: 0;
  }

  .table-wrap {
    max-height: none;
  }
}
