:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #d7dee8;
  --soft: #f7f9fc;
  --accent: #3370ff;
  --accent-strong: #245bdb;
  --accent-soft: #eaf0ff;
  --blue: #2563eb;
  --amber: #b7791f;
  --red: #b42318;
  --green: #16803c;
  --sidebar: #172033;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

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

button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

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

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

textarea {
  resize: vertical;
}

.hidden {
  display: none !important;
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 22px 48px rgba(16, 24, 40, 0.12);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

.auth-card h1 {
  margin-bottom: 12px;
  font-size: 1.75rem;
}

.auth-card p {
  color: var(--muted);
  line-height: 1.7;
}

.login-form {
  display: grid;
  gap: 12px;
}

.message,
.notice {
  color: var(--red);
  font-weight: 800;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--sidebar);
  color: #fff;
  padding: 18px;
}

.brand {
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand strong,
.brand span,
.shop-picker span {
  display: block;
}

.brand strong {
  font-size: 1.18rem;
}

.brand span,
.shop-picker span {
  margin-top: 7px;
  color: #b4c8c1;
  font-size: 0.82rem;
  font-weight: 800;
}

.shop-picker select {
  margin-top: 8px;
}

#nav {
  display: grid;
  gap: 7px;
  overflow: auto;
}

#nav button,
.ghost-button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

#nav button {
  background: transparent;
  color: #dce7e3;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#nav button.active {
  background: #f6fffb;
  color: #12382f;
}

.ghost-button {
  margin-top: auto;
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

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

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

.topbar h2 {
  margin-bottom: 6px;
  font-size: 1.45rem;
}

.topbar p {
  color: var(--muted);
}

.filters {
  min-width: min(720px, 100%);
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto auto auto auto;
  gap: 8px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.date-field {
  display: grid;
  gap: 5px;
}

.date-field span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
}

.range-only {
  display: none;
}

.range-only.active {
  display: grid;
}

.muted-field {
  opacity: 0.55;
}

.notice {
  margin-bottom: 12px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  padding: 12px 14px;
}

.page {
  display: none;
}

.page.active {
  display: grid;
  gap: 16px;
}

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

.metric-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.05);
}

.metric-card {
  min-height: 96px;
  padding: 14px;
}

.metric-grid.compact .metric-card {
  min-height: 88px;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.metric-card strong {
  display: block;
  margin-top: 9px;
  font-size: 1.45rem;
  line-height: 1.1;
}

.metric-card em {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-style: normal;
  font-size: 0.8rem;
}

.ops-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.55fr);
  gap: 16px;
}

.panel {
  padding: 16px;
}

.panel.wide {
  min-width: 0;
}

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

.panel-head h3 {
  margin-bottom: 4px;
  font-size: 1.02rem;
}

.panel-head span {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

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

.core-grid article,
.summary-grid article {
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 12px;
}

.core-grid span,
.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.core-grid strong,
.summary-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 1rem;
  word-break: break-word;
}

.compact-list,
.suggestion-list {
  display: grid;
  gap: 10px;
}

.compact-list article,
.suggestion-list article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--soft);
}

.compact-list strong,
.suggestion-list strong {
  display: block;
  margin-bottom: 5px;
}

.compact-list p,
.suggestion-list p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

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

.upload-grid label,
.rule-grid label {
  display: grid;
  gap: 7px;
}

.upload-grid label span,
.rule-grid label span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.upload-grid textarea,
.wide-field {
  grid-column: 1 / -1;
}

.rule-grid textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.86rem;
  line-height: 1.55;
}

.form-actions,
.template-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
}

.form-actions {
  min-height: 70px;
}

.secondary-button,
.table-action {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.secondary-button:hover,
.table-action:hover {
  background: var(--soft);
}

.table-action {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.78rem;
  white-space: nowrap;
}

.file-field,
.check-line {
  min-height: 70px;
}

.check-line {
  display: flex !important;
  align-items: center;
  grid-template-columns: none !important;
  gap: 10px !important;
}

.check-line input {
  width: auto;
}

.toolbar,
.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.toolbar button,
.export-actions button {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.toolbar button:hover,
.export-actions button:hover {
  background: var(--soft);
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: #fff;
}

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

th {
  position: sticky;
  top: 0;
  background: #f3f7fa;
  color: #344054;
  font-size: 0.78rem;
  font-weight: 900;
  z-index: 1;
}

td {
  color: #344054;
}

.trace-grid {
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
}

.trace-grid table {
  min-width: 680px;
}

.tag {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 0 8px;
  background: #eef4ff;
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 900;
}

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

.tag.warn {
  background: #fffaeb;
  color: var(--amber);
}

.tag.good {
  background: #ecfdf3;
  color: var(--green);
}

.section-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  padding: 5px;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.section-tabs button {
  min-height: 34px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}

.section-tabs button:hover {
  background: var(--soft);
  color: var(--ink);
}

.section-tabs button.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: #b7dfd3;
}

.cost-tab-panel {
  display: grid;
  gap: 14px;
}

.panel-copy {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.filter-grid label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.filter-grid .wide-filter {
  grid-column: span 2;
}

.quote-shortcuts {
  margin-top: 12px;
}

.management-metrics {
  margin: 0;
}

.management-toolbar {
  justify-content: flex-end;
  margin: 14px 0 0;
}

.management-toolbar input {
  max-width: 420px;
}

.cost-quote-table-wrap table {
  min-width: 1480px;
}

.sku-cost-table-wrap table {
  min-width: 1160px;
}

.freight-table-wrap table {
  min-width: 820px;
}

.cell-stack {
  display: grid;
  gap: 4px;
  min-width: 180px;
}

.cell-stack strong {
  color: var(--ink);
}

.cell-stack span {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.sku-cost-editor {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) auto;
  gap: 8px;
  min-width: 220px;
}

.sku-cost-editor input,
.freight-table-wrap input {
  min-height: 36px;
  padding: 7px 9px;
}

.sku-cost-editor button,
.freight-table-wrap button {
  min-height: 36px;
}

.freight-table-wrap th:nth-child(2),
.freight-table-wrap td:nth-child(2) {
  width: 190px;
}

.freight-table-wrap th:nth-child(3),
.freight-table-wrap td:nth-child(3),
.freight-table-wrap th:nth-child(4),
.freight-table-wrap td:nth-child(4) {
  width: 100px;
}

.freight-table-wrap input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

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

.danger-button:hover {
  background: #fef3f2;
  color: var(--red);
}

.report-template {
  margin-top: 18px;
}

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

  .ops-grid,
  .trace-grid,
  .upload-grid,
  .rule-grid,
  .filter-grid {
    grid-template-columns: 1fr;
  }

  .filter-grid .wide-filter {
    grid-column: auto;
  }
}

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

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

  .topbar {
    display: grid;
  }

  .filters {
    grid-template-columns: 1fr;
    min-width: 100%;
  }
}

@media (max-width: 560px) {
  .main {
    padding: 14px;
  }

  .metric-grid,
  .core-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }
}
