:root {
  color-scheme: light;
  --text: #1f2933;
  --muted: #5f6b7a;
  --line: #d9e2ec;
  --panel: #ffffff;
  --band: #f5f7fa;
  --accent: #1f6f8b;
  --accent-dark: #17577a;
  --ok: #1f7a4d;
  --bad: #b42318;
  --warn: #b54708;
  --plan: #1f7a4d;
  --purchase: #9a6700;
  --soft-blue: #e8f3fb;
  --soft-red: #fff0ed;
  --soft-green: #eef8f0;
  --soft-yellow: #fff6d6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--band);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 32px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.brand-block {
  min-width: 220px;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  flex: 1;
}

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

.logout-form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.logout-form span {
  color: var(--muted);
  font-size: 13px;
}

.logout-form button {
  min-width: 64px;
  height: 34px;
  background: #344054;
}

.topbar nav a,
.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: #243447;
  font-size: 13px;
  font-weight: 650;
}

.button-link.disabled {
  color: #98a2b3;
  background: #f8fafc;
  pointer-events: none;
}

.topbar nav a.active {
  border-color: #9cc9e5;
  background: var(--soft-blue);
  color: var(--accent-dark);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 700;
}

h2 {
  font-size: 16px;
  margin-bottom: 14px;
}

p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

button {
  min-width: 108px;
  height: 38px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.secondary-button {
  background: #ffffff;
  color: #243447;
  border: 1px solid var(--line);
}

.secondary-button:hover {
  background: #f8fafc;
}

.inline-form {
  display: inline-flex;
  margin: 0;
}

.action-cell {
  display: flex;
  align-items: center;
  gap: 6px;
}

.table-action {
  min-width: 56px;
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.table-action.danger {
  background: var(--bad);
}

input[type="file"],
input[type="search"],
input[type="text"],
input:not([type]) {
  min-height: 36px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd5df;
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  color: var(--text);
  background: #ffffff;
}

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

button:disabled {
  cursor: not-allowed;
  background: #9aa6b2;
}

.login-page {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(31, 111, 139, 0.08), rgba(31, 41, 51, 0.02)),
    #f5f7fa;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 420px;
  align-items: center;
  gap: 56px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 48px 32px;
}

.login-brand {
  display: grid;
  gap: 18px;
}

.login-logo {
  width: 260px;
  height: auto;
}

.login-brand h1 {
  font-size: 38px;
}

.login-brand p {
  max-width: 520px;
  font-size: 16px;
  line-height: 1.7;
}

.login-panel {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 45px rgba(31, 41, 51, 0.08);
}

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

.login-panel button {
  width: 100%;
  margin-top: 4px;
}

.captcha-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 112px;
  height: 34px;
  margin: 6px 0 8px;
  padding: 0 12px;
  border: 1px solid #9cc9e5;
  border-radius: 6px;
  background: var(--soft-blue);
  color: var(--accent-dark);
  font-weight: 750;
  letter-spacing: 0;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.permission-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.permission-item input,
.field-checkbox input {
  width: auto;
}

.permission-item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.permission-chip {
  display: inline-flex;
  align-items: center;
  margin: 2px 4px 2px 0;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--soft-blue);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 650;
}

@media (max-width: 860px) {
  .login-shell {
    grid-template-columns: 1fr;
    gap: 28px;
  }

  .topbar,
  .topbar-right {
    align-items: flex-start;
    flex-direction: column;
  }
}

main {
  padding: 24px 32px 48px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

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

.toolbar form {
  margin: 0;
}

.search-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.search-form input[type="search"] {
  max-width: 360px;
}

.inline-upload {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.inline-upload input[type="file"] {
  max-width: 220px;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
  flex-wrap: wrap;
}

.page-status {
  color: var(--muted);
  font-size: 13px;
  padding: 0 6px;
}

.row-edit-form {
  display: grid;
  grid-template-columns: 150px 120px minmax(180px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.row-edit-form input {
  min-width: 0;
}

.panel,
.notice,
.alert {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.panel {
  margin-bottom: 16px;
}

.hint {
  margin-top: 4px;
  color: var(--muted);
}

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

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #98a2b3;
}

.legend-dot.ship {
  background: var(--plan);
}

.legend-dot.buy {
  background: var(--purchase);
}

.legend-dot.shortage {
  background: var(--bad);
}

.legend-dot.error-dot {
  background: var(--bad);
}

.legend-dot.warn-dot {
  background: var(--warn);
}

.legend-dot.info-dot {
  background: var(--accent);
}

.legend-swatch {
  width: 16px;
  height: 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #ffffff;
}

.legend-swatch.open {
  background: #f1fbf4;
}

.legend-swatch.purchase {
  background: var(--soft-yellow);
}

.legend-swatch.mixed {
  background: linear-gradient(135deg, #f1fbf4 0%, #f1fbf4 50%, var(--soft-yellow) 50%, var(--soft-yellow) 100%);
}

.legend-swatch.short {
  border: 2px solid #f3b2a8;
}

.notice {
  margin-bottom: 16px;
  border-color: #8ec5a7;
  background: #effaf3;
}

.alert {
  margin-bottom: 16px;
  border-color: #f2a6a0;
  background: #fff4f2;
}

.alert.success {
  border-color: #8ec5a7;
  background: #effaf3;
  color: #17633a;
}

.alert.error {
  color: var(--bad);
}

.alert span {
  display: inline-block;
  margin-left: 8px;
  color: var(--bad);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  color: #344054;
  font-weight: 650;
  white-space: nowrap;
}

td {
  color: #243447;
}

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

a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.ok {
  color: var(--ok);
  font-weight: 700;
}

.bad {
  color: var(--bad);
  font-weight: 700;
}

.bad-text {
  color: var(--bad);
  font-weight: 700;
}

.plan,
.plan-text {
  color: var(--plan);
  font-weight: 700;
}

.purchase,
.purchase-text {
  color: var(--purchase);
  font-weight: 700;
}

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

.secondary {
  background: #ffffff;
}

.import-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.import-grid form {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.import-grid h3 {
  margin: 0;
  font-size: 15px;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  color: var(--muted);
  white-space: nowrap;
}

.checkbox input {
  width: auto;
}

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

.projection-scroll {
  max-height: calc(100vh - 260px);
  min-height: 420px;
  overflow: scroll;
  scrollbar-gutter: stable both-edges;
}

.top-scroll {
  width: 100%;
  height: 38px;
  margin-bottom: 8px;
  padding: 9px 12px;
  overflow-x: hidden;
  overflow-y: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
}

.top-scroll-inner {
  display: none;
}

.top-scroll-track {
  position: relative;
  height: 18px;
  border-radius: 999px;
  background: #e4ebf2;
  box-shadow: inset 0 0 0 1px #d1dbe5;
}

.top-scroll-thumb {
  position: absolute;
  top: 0;
  left: 0;
  height: 18px;
  min-width: 72px;
  border-radius: 999px;
  background: #8b99a8;
  box-shadow: inset 0 0 0 1px #6f7d8b;
  cursor: grab;
  touch-action: none;
}

.top-scroll-thumb:hover,
.top-scroll:focus .top-scroll-thumb {
  background: #6f7d8b;
}

.top-scroll-thumb:active {
  cursor: grabbing;
}

.table-scroll table {
  border-collapse: separate;
  border-spacing: 0;
}

.projection {
  width: max-content;
  min-width: 100%;
  table-layout: fixed;
}

.projection th,
.projection td {
  width: 150px;
  min-width: 150px;
  max-width: 150px;
  border-right: 1px solid var(--line);
  background: #ffffff;
}

.projection thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--line);
}

.projection th:nth-child(1),
.projection td:nth-child(1) {
  width: 168px;
  min-width: 168px;
  max-width: 168px;
}

.projection th:nth-child(2),
.projection td:nth-child(2) {
  width: 180px;
  min-width: 180px;
  max-width: 180px;
}

.projection th:nth-child(3),
.projection td:nth-child(3) {
  width: 180px;
  min-width: 180px;
  max-width: 180px;
}

.projection th:nth-child(4),
.projection td:nth-child(4),
.projection th:nth-child(5),
.projection td:nth-child(5),
.projection th:nth-child(6),
.projection td:nth-child(6) {
  width: 110px;
  min-width: 110px;
  max-width: 110px;
}

.projection td {
  height: 78px;
  overflow: hidden;
}

.projection td:nth-child(2),
.projection td:nth-child(3) {
  color: #344054;
  word-break: break-word;
}

.projection .sticky-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #ffffff;
  box-shadow: 1px 0 0 var(--line);
}

.projection thead .sticky-col {
  z-index: 6;
}

.period-cell {
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

.period-cell.open-cell {
  background: #f1fbf4;
}

.period-cell.purchase-cell {
  background: var(--soft-yellow);
}

.period-cell.mixed-cell {
  background: linear-gradient(135deg, #f1fbf4 0%, #f1fbf4 50%, var(--soft-yellow) 50%, var(--soft-yellow) 100%);
}

.period-cell.short {
  box-shadow: inset 0 0 0 2px #f3b2a8;
}

.period-cell.source-cell {
  cursor: pointer;
}

.period-cell.source-cell:hover,
.period-cell.source-cell:focus {
  outline: 2px solid #9cc9e5;
  outline-offset: -2px;
}

.period-cell .cell-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 18px;
  color: #344054;
}

.period-cell .cell-line span {
  color: var(--muted);
  font-size: 12px;
}

.period-cell .cell-line b {
  font-weight: 650;
  white-space: nowrap;
}

.period-cell .cell-line.plan,
.period-cell .cell-line.plan span {
  color: var(--plan);
}

.period-cell .cell-line.purchase,
.period-cell .cell-line.purchase span {
  color: var(--purchase);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(31, 41, 51, 0.42);
}

.modal-backdrop[hidden] {
  display: none;
}

.source-modal {
  width: min(980px, 100%);
  max-height: min(760px, 92vh);
  overflow: hidden;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 72px rgba(31, 41, 51, 0.28);
}

.source-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.source-modal-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: #344054;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus {
  border-color: #9cc9e5;
  outline: none;
}

.source-modal-summary {
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  color: #344054;
  font-weight: 650;
}

.source-modal-table {
  max-height: 560px;
  overflow: auto;
}

.source-modal-table table {
  min-width: 820px;
  margin: 0;
}

.form-panel form {
  display: grid;
  gap: 16px;
}

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

.form-grid label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 650;
}

.field-label-text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.field-help {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 1px solid #9cc9e5;
  border-radius: 50%;
  background: var(--soft-blue);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  cursor: help;
}

.field-help::after {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 20;
  display: none;
  width: max-content;
  max-width: 320px;
  padding: 9px 10px;
  border: 1px solid #cbd5df;
  border-radius: 6px;
  background: #1f2933;
  color: #ffffff;
  box-shadow: 0 12px 28px rgba(31, 41, 51, 0.22);
  content: attr(data-help);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
  text-align: left;
  transform: translateX(-50%);
  white-space: normal;
}

.field-help:hover::after,
.field-help:focus::after {
  display: block;
}

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

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

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

.bom-diff-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-top: 16px;
}

.bom-diff-form label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 650;
}

.diff-scroll {
  max-height: calc(100vh - 310px);
  min-height: 360px;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
}

.diff-table {
  width: max-content;
  min-width: 100%;
}

.diff-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--line);
}

.diff-table th,
.diff-table td {
  white-space: nowrap;
}

.diff-table td:nth-child(5),
.diff-table td:nth-child(13) {
  max-width: 280px;
  white-space: normal;
  word-break: break-word;
}

.change-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.change-badge.added {
  border-color: #9dd7b5;
  background: var(--soft-green);
  color: var(--ok);
}

.change-badge.deleted {
  border-color: #f2a6a0;
  background: var(--soft-red);
  color: var(--bad);
}

.change-badge.usage {
  border-color: #e5c36a;
  background: var(--soft-yellow);
  color: var(--purchase);
}

.change-badge.duplicate {
  border-color: #9cc9e5;
  background: var(--soft-blue);
  color: var(--accent-dark);
}

.change-badge.attribute,
.change-badge.other {
  border-color: #cbd5df;
  background: #f6f8fb;
  color: #344054;
}

.quality-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.quality-filter {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 150px 220px auto auto;
  gap: 10px;
  align-items: center;
  width: 100%;
}

.metric-card {
  display: grid;
  gap: 6px;
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid #98a2b3;
  border-radius: 8px;
  background: #ffffff;
}

.metric-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.metric-card strong {
  color: var(--text);
  font-size: 24px;
  font-weight: 760;
  line-height: 1.1;
}

.metric-card em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.metric-card.ok {
  border-left-color: var(--ok);
}

.metric-card.warn {
  border-left-color: var(--warn);
}

.metric-card.bad {
  border-left-color: var(--bad);
}

.quality-scroll {
  max-height: calc(100vh - 330px);
  min-height: 420px;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
}

.quality-table {
  width: max-content;
  min-width: 100%;
}

.quality-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--line);
}

.quality-table th,
.quality-table td {
  min-width: 120px;
}

.quality-table td:nth-child(4),
.quality-table td:nth-child(5) {
  min-width: 320px;
  max-width: 520px;
  white-space: normal;
  word-break: break-word;
}

.level-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 62px;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: #344054;
  font-size: 12px;
  font-weight: 760;
}

.level-badge.error {
  border-color: #f2a6a0;
  background: var(--soft-red);
  color: var(--bad);
}

.level-badge.warn {
  border-color: #e5c36a;
  background: var(--soft-yellow);
  color: var(--warn);
}

.level-badge.info {
  border-color: #9cc9e5;
  background: var(--soft-blue);
  color: var(--accent-dark);
}

.purchase-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.purchase-filter {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(220px, 320px) auto auto;
  gap: 10px;
  align-items: center;
  width: 100%;
}

.purchase-scroll {
  max-height: calc(100vh - 330px);
  min-height: 420px;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
}

.purchase-table {
  width: max-content;
  min-width: 100%;
}

.purchase-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f8fafc;
  box-shadow: 0 1px 0 var(--line);
}

.purchase-table th,
.purchase-table td {
  white-space: nowrap;
}

tr.selected-row td {
  background: #fff7d6;
  box-shadow: inset 0 1px 0 #e5c36a, inset 0 -1px 0 #e5c36a;
}

.purchase-table td:nth-child(2),
.purchase-table td:nth-child(12),
.purchase-table td:nth-child(13),
.purchase-table td:nth-child(14),
.purchase-table td:nth-child(15) {
  max-width: 280px;
  white-space: normal;
  word-break: break-word;
}

.metric-card strong.date-strong {
  font-size: 15px;
  line-height: 1.35;
}

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

  main {
    padding: 18px;
  }

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

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

  .toolbar,
  .search-form,
  .quality-filter,
  .purchase-filter {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .import-grid,
  .form-grid,
  .location-form,
  .bom-diff-form {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 560px) {
  .quality-summary,
  .purchase-summary {
    grid-template-columns: 1fr;
  }
}
