:root {
  color-scheme: light;
  --ink: #18212f;
  --muted: #647084;
  --line: #dfe5ee;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --blue: #2563eb;
  --green: #14804a;
  --amber: #b7791f;
  --red: #c24135;
  --teal: #0f766e;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: linear-gradient(180deg, #f8fbff 0, var(--bg) 260px);
  color: var(--ink);
  font-size: 14px;
}

.auth-gate {
  align-items: center;
  background: rgba(248, 250, 252, 0.92);
  backdrop-filter: blur(12px);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 24px;
  position: fixed;
  z-index: 20;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.18);
  display: grid;
  gap: 14px;
  max-width: 420px;
  padding: 24px;
  width: min(100%, 420px);
}

.auth-copy {
  color: var(--muted);
  line-height: 1.6;
}

.auth-fields {
  display: grid;
  gap: 12px;
}

.auth-error {
  color: var(--red);
  min-height: 20px;
}

.topbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.04);
  display: grid;
  gap: 24px;
  grid-template-columns: 1fr auto 1fr;
  padding: 18px 28px;
  position: sticky;
  top: 0;
  z-index: 4;
}

.topbar > div:first-child {
  grid-column: 2;
  text-align: center;
}

.eyebrow {
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
}

main {
  margin: 0 auto;
  max-width: none;
  padding: 14px 24px 36px;
}

button,
.upload {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font-size: 14px;
  font-weight: 650;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
}

button:hover,
.upload:hover {
  border-color: #b9c4d6;
}

.upload {
  background: var(--blue);
  border-color: var(--blue);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.18);
  color: #fff;
}

.upload input {
  display: none;
}

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

.user-chip {
  background: #eef6ff;
  border: 1px solid #cfe2ff;
  border-radius: 999px;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 750;
  padding: 7px 10px;
  white-space: nowrap;
}

.summary {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  margin-bottom: 12px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.03);
  padding: 13px 14px;
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-bottom: 8px;
}

.metric strong {
  display: block;
  font-size: 24px;
  white-space: nowrap;
}

.tabs {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.03);
  display: inline-flex;
  gap: 4px;
  margin-bottom: 10px;
  padding: 4px;
}

.tabs button {
  border: 0;
  border-radius: 6px;
  min-height: 34px;
  padding: 0 14px;
}

.tabs button.active {
  background: #eaf1ff;
  color: #1645ad;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

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

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
}

.filters button.active {
  background: #eaf1ff;
  border-color: #9ebcff;
  color: #1645ad;
}

.facet-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.03);
  margin-bottom: 14px;
  padding: 12px;
}

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

.facet-head strong {
  font-size: 14px;
}

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

.global-search {
  align-items: center;
  display: flex;
  gap: 8px;
}

.global-search span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.global-search input {
  min-width: 280px;
  min-height: 32px;
  padding: 7px 10px;
}

.facet-head button {
  min-height: 30px;
  padding: 0 10px;
}

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

.facet {
  border: 1px solid #e6ebf3;
  border-radius: 7px;
  min-width: 0;
  position: relative;
}

.facet summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  min-height: 38px;
  padding: 0 10px;
}

.facet summary span {
  color: #334155;
  font-weight: 700;
}

.facet summary strong {
  color: var(--blue);
  font-size: 12px;
}

.facet-tools {
  border-top: 1px solid #edf1f6;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
}

.facet-tools button {
  font-size: 12px;
  min-height: 28px;
  padding: 0 9px;
}

.facet-options {
  display: grid;
  gap: 4px;
  max-height: 210px;
  overflow: auto;
  padding: 0 8px 8px;
}

.facet-search {
  border: 0;
  border-top: 1px solid #edf1f6;
  border-radius: 0;
  font-size: 12px;
  min-height: 34px;
  padding: 8px 10px;
}

.facet-option {
  align-items: start;
  color: var(--ink);
  display: grid;
  font-size: 12px;
  gap: 7px;
  grid-template-columns: 14px 1fr;
  line-height: 1.35;
  padding: 5px 3px;
}

.facet-option input {
  margin: 2px 0 0;
}

.facet-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 8px 3px;
}

.risk-panel {
  align-items: start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.03);
  display: grid;
  gap: 16px;
  grid-template-columns: 210px minmax(280px, 0.85fr) 1.15fr;
  margin-bottom: 12px;
  padding: 12px;
}

#riskHint {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  margin-top: 8px;
}

.plain-link {
  background: transparent;
  border: 0;
  color: var(--blue);
  font-size: 13px;
  font-weight: 700;
  min-height: 0;
  padding: 8px 0 0;
}

.risk-rules {
  border-left: 3px solid #c7d7fe;
  display: grid;
  gap: 7px;
  padding-left: 12px;
}

.risk-rules p {
  color: #334155;
  font-size: 12px;
  line-height: 1.55;
}

#riskList {
  display: grid;
  gap: 6px;
  list-style-position: inside;
  margin: 0;
  padding: 0;
}

#riskList li {
  border-bottom: 1px solid #edf1f6;
  line-height: 1.5;
  padding: 0 0 8px;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.045);
  max-height: calc(100vh - 330px);
  overflow: auto;
}

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

.col-risk {
  width: 76px;
}

.col-id {
  width: 44px;
}

.col-warehouse {
  width: 86px;
}

.col-material {
  width: 170px;
}

.col-qty {
  width: 54px;
}

.col-person {
  width: 68px;
}

.col-buyer {
  width: 78px;
}

.col-required {
  width: 96px;
}

.col-ship {
  width: 128px;
}

.col-date {
  width: 72px;
}

.confirmed-date {
  color: #0f766e;
  font-weight: 750;
}

.col-arrived {
  width: 68px;
}

.col-progress {
  width: 520px;
}

th,
td {
  border-bottom: 1px solid #edf1f6;
  font-size: 12px;
  line-height: 1.45;
  padding: 10px 10px;
  text-align: left;
  vertical-align: middle;
  word-break: break-word;
}

th {
  background: var(--surface-soft);
  color: #435066;
  font-weight: 750;
  height: 42px;
  line-height: 1.25;
  padding: 0 8px;
  position: sticky;
  text-align: center;
  top: 0;
  vertical-align: middle;
  z-index: 2;
}

td {
  height: 52px;
}

tbody tr:hover {
  background: #f8fbff;
}

.progress {
  white-space: pre-wrap;
}

.date-cell,
.num {
  white-space: nowrap;
}

.ship-cell,
.material-cell {
  overflow-wrap: anywhere;
}

.date-cell,
.ship-cell,
.num,
tbody td:nth-child(1),
tbody td:nth-child(2),
tbody td:nth-child(3),
tbody td:nth-child(5),
tbody td:nth-child(6),
tbody td:nth-child(7),
tbody td:nth-child(8),
tbody td:nth-child(10),
tbody td:nth-child(11),
tbody td:nth-child(12),
tbody td:nth-child(13) {
  text-align: center;
}

tbody td:nth-child(4),
tbody td:nth-child(9),
tbody td:nth-child(14) {
  text-align: left;
}

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

.badge {
  border-radius: 999px;
  display: inline-flex;
  font-weight: 760;
  justify-content: center;
  min-width: 58px;
  padding: 4px 8px;
}

.badge.high {
  background: #fdeceb;
  color: var(--red);
}

.badge.medium {
  background: #fff4dc;
  color: var(--amber);
}

.badge.low {
  background: #e8f4ff;
  color: #1d5ca8;
}

.badge.done {
  background: #e5f7ee;
  color: var(--green);
}

.update-row {
  background: transparent;
  border: 0;
  color: var(--blue);
  font-weight: 700;
  font-size: 12px;
  min-height: 0;
  margin-top: 2px;
  padding: 0;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(23, 31, 44, 0.24);
  max-width: 760px;
  width: min(92vw, 760px);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

dialog form {
  display: grid;
  gap: 16px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 8px;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  font: inherit;
  padding: 10px;
  width: 100%;
}

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

.invite-result {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  color: var(--ink);
  font-weight: 750;
  min-height: 44px;
  padding: 12px;
  word-break: break-all;
}

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

#applyEdit {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.03);
  padding: 14px;
}

.panel h2 {
  margin-bottom: 12px;
}

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

.panel-head h2 {
  margin: 0;
}

.panel-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin-top: 6px;
}

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

.weekly-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  margin-bottom: 12px;
}

.table-wrap.compact {
  max-height: calc(100vh - 250px);
}

.stats-table,
.history-table,
.buyer-table,
.oa-table {
  min-width: 980px;
}

.stats-table th,
.stats-table td,
.history-table th,
.history-table td,
.buyer-table th,
.buyer-table td,
.oa-table th,
.oa-table td {
  font-size: 13px;
  padding: 10px 12px;
}

.buyer-table {
  min-width: 1260px;
}

.oa-table {
  min-width: 1880px;
}

.oa-table-wrap {
  max-height: calc(100vh - 300px);
}

.oa-table th:first-child,
.oa-table td:first-child {
  text-align: center;
  width: 54px;
}

.oa-confirm-date {
  min-width: 160px;
}

.sync-action,
.flow-pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 760;
  justify-content: center;
  padding: 4px 8px;
  white-space: nowrap;
}

.sync-action.update,
.flow-pill.ok {
  background: #eaf1ff;
  color: #1645ad;
}

.sync-action.create {
  background: #fff4dc;
  color: var(--amber);
}

.muted-pill {
  background: #eef2f7;
  color: var(--muted);
}

.empty {
  color: var(--muted);
  padding: 28px;
  text-align: center;
}

@media (max-width: 900px) {
  .topbar,
  .controls,
  .risk-panel {
    align-items: stretch;
    display: flex;
    flex-direction: column;
  }

  .topbar > div:first-child,
  .actions {
    grid-column: auto;
    text-align: left;
  }

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

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

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

  .facet-head {
    align-items: stretch;
    flex-direction: column;
  }

  .facet-head-actions,
  .global-search {
    align-items: stretch;
    flex-direction: column;
  }

  .global-search input {
    min-width: 0;
  }

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

  th {
    top: 0;
  }
}
