:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #d9dee7;
  --brand: #1769e0;
  --brand-strong: #0f4dab;
  --danger: #b42318;
  --ok: #137333;
  --warn: #a15c07;
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
}

a {
  color: var(--brand);
  text-decoration: none;
}

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

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 12px;
  cursor: pointer;
}

.download-button {
  display: inline-block;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  border-radius: var(--radius);
  padding: 8px 12px;
}

.download-button:hover {
  background: var(--brand-strong);
  color: #fff;
}

button.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

button.primary:hover {
  background: var(--brand-strong);
}

.buy-selected-button,
.buy-one-button {
  border-color: #ea580c;
  background: #f97316;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(249, 115, 22, .22);
}

.buy-selected-button:hover,
.buy-one-button:hover {
  border-color: #c2410c;
  background: #ea580c;
  color: #fff;
}

.buy-one-button {
  padding: 6px 12px;
}

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

button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: #fff;
  min-height: 38px;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
}

.side {
  background: #172033;
  color: #dbe4f2;
  padding: 18px 14px;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 18px;
}

.side button {
  display: block;
  width: 100%;
  text-align: left;
  margin: 4px 0;
  border: 0;
  color: #dbe4f2;
  background: transparent;
}

.side button.active, .side button:hover {
  background: #263654;
}

.main {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 12px 18px;
  min-height: 58px;
}

.content {
  padding: 18px;
  max-width: 1420px;
}

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

.auth-box {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}

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

.grid.two {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.panel h2, .panel h3 {
  margin: 0 0 12px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
}

.field label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  margin-bottom: 5px;
}

.field label em {
  font-style: normal;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 12px;
  line-height: 1.5;
}

.field label em.required {
  background: #fff1f0;
  color: var(--danger);
  border: 1px solid #ffd1ce;
}

.field label em.optional {
  background: #f5f7fb;
  color: var(--muted);
  border: 1px solid var(--line);
}

.date-range-trigger {
  width: 100%;
  justify-content: flex-start;
  min-height: 38px;
  color: var(--text);
  background: #fff;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

#searchForm .actions {
  grid-column: span 3;
  flex-wrap: nowrap;
  align-items: center;
  white-space: nowrap;
}

.select-count-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.select-count-control input {
  width: 76px;
}

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

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

.danger-text {
  color: var(--danger);
}

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

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

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

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

th {
  color: #374151;
  background: #f9fafb;
  font-weight: 600;
}

tr:last-child td {
  border-bottom: 0;
}

.badge {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  background: #fff;
}

.badge.pending {
  color: var(--warn);
  border-color: #f4c27a;
}

.badge.approved, .badge.success {
  color: var(--ok);
  border-color: #92d0a2;
}

.badge.rejected, .badge.failed {
  color: var(--danger);
  border-color: #e3a09a;
}

.badge.open {
  color: var(--warn);
  border-color: #f4c27a;
}

.badge.replied {
  color: var(--ok);
  border-color: #92d0a2;
}

.notice {
  border: 1px solid #b8d7ff;
  background: #eef6ff;
  color: #15436f;
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 12px;
}

.important-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-color: #f4b64b;
  background: #fff8e6;
  color: #7a3b05;
  font-weight: 700;
}

.important-notice button {
  border-color: #d97706;
  background: #d97706;
  color: #fff;
}

.promo-card {
  position: relative;
  overflow: hidden;
  border: 1px solid #f4b64b;
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .22) 0 18%, transparent 18% 30%, rgba(255, 255, 255, .18) 30% 44%, transparent 44%),
    linear-gradient(135deg, #b42318 0%, #d9480f 48%, #f59e0b 100%);
  color: #fff;
  padding: 18px;
  box-shadow: 0 12px 26px rgba(180, 35, 24, .18);
}

.promo-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 28px, rgba(255, 255, 255, .16) 28px 30px),
    repeating-linear-gradient(0deg, transparent 0 32px, rgba(255, 233, 173, .16) 32px 34px);
  pointer-events: none;
}

.promo-ribbon, .promo-title, .promo-grid {
  position: relative;
}

.promo-ribbon {
  display: inline-block;
  background: #fff7d6;
  color: #8a2a12;
  border: 1px solid rgba(255, 255, 255, .65);
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 700;
  margin-bottom: 10px;
}

.promo-title {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 12px;
}

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

.promo-grid div {
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: var(--radius);
  padding: 10px;
}

.promo-grid span, .promo-grid strong {
  display: block;
}

.promo-grid strong {
  color: #fff7d6;
  font-size: 20px;
  margin-top: 3px;
}

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 20;
  background: #17324d;
  color: #fff;
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  max-width: min(360px, calc(100vw - 36px));
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 24, 39, .46);
}

.notice-modal {
  width: min(460px, 100%);
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 14px;
  border-radius: var(--radius);
  background: #fff;
  border: 1px solid var(--line);
  padding: 20px;
  box-shadow: 0 22px 58px rgba(0, 0, 0, .28);
}

.modal-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 999px;
  color: #fff;
  font-size: 30px;
  font-weight: 800;
}

.notice-modal.success .modal-icon {
  background: var(--ok);
}

.notice-modal.danger .modal-icon {
  background: var(--danger);
}

.notice-modal.info .modal-icon {
  background: var(--brand);
}

.busy-modal .modal-icon {
  background: var(--brand);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.modal-body h3 {
  margin: 0 0 8px;
  font-size: 20px;
}

.modal-body p {
  margin: 0 0 14px;
  line-height: 1.6;
}

.purchase-result-modal {
  width: min(600px, 100%);
}

.purchase-result-modal .modal-body {
  min-width: 0;
}

.copy-waybills-box {
  min-height: 240px;
  max-height: 50vh;
  margin-bottom: 14px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  line-height: 1.6;
  white-space: pre;
}

.wrap-cell {
  min-width: 220px;
  max-width: 420px;
  white-space: normal;
  line-height: 1.5;
}

.replied-row {
  background: #fbfffb;
}

.error {
  border: 1px solid #f0b8b3;
  background: #fff4f2;
  color: var(--danger);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 12px;
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

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

.metric strong {
  display: block;
  font-size: 24px;
  margin-top: 4px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.tabs button.active {
  border-color: var(--brand);
  color: var(--brand);
  background: #edf5ff;
}

.match-table {
  min-width: 1160px;
}

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

.match-table .select-cell {
  width: 54px;
  min-width: 54px;
  max-width: 54px;
  padding-left: 6px;
  padding-right: 6px;
  text-align: center;
}

.select-check {
  width: 16px;
  height: 16px;
  min-height: 0;
  padding: 0;
}

.select-all-head {
  min-height: 28px;
  padding: 4px 6px;
  font-size: 13px;
}

.date-picker {
  width: min(420px, 100%);
  display: block;
}

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

.date-picker-tip {
  margin-bottom: 10px;
  color: var(--muted);
}

.date-week,
.date-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.date-week span {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.date-cell {
  min-height: 36px;
  padding: 0;
  justify-content: center;
}

.date-cell.empty {
  visibility: hidden;
}

.date-cell.in-range {
  background: #e9f2ff;
  border-color: #b7d5ff;
}

.date-cell.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.date-picker-actions {
  margin-top: 14px;
  justify-content: flex-end;
}

.carrier-tag {
  display: inline-block;
  border: 1px solid #c9d8ef;
  background: #f3f7fc;
  color: #19436f;
  border-radius: 999px;
  padding: 2px 8px;
  font-weight: 600;
}

.waybill-cell {
  font-weight: 600;
}

.place-cell {
  min-width: 190px;
  white-space: normal;
}

.place-cell div {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 6px;
  line-height: 1.45;
}

.place-cell span {
  color: var(--muted);
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 96px;
}

.attachment-list a {
  display: inline-flex;
  align-items: center;
  border: 1px solid #bcd3f4;
  border-radius: var(--radius);
  padding: 4px 8px;
  background: #f3f7fc;
  color: var(--brand);
  text-decoration: none;
  font-weight: 600;
}

.batch-title-row,
.batch-section-head {
  justify-content: space-between;
}

.batch-title-row h2,
.batch-section-head h3 {
  margin: 0;
}

.batch-section {
  margin-top: 14px;
}

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

.batch-summary div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f5f7fb;
  padding: 16px;
  text-align: center;
}

.batch-summary strong {
  display: block;
  font-size: 28px;
  line-height: 1;
  margin-bottom: 8px;
}

.batch-summary span {
  color: var(--muted);
}

.batch-summary .success {
  background: #f0faec;
  border-color: #d5efcc;
  color: #45b82e;
}

.batch-summary .failed {
  background: #fff1f0;
  border-color: #ffd1ce;
  color: var(--danger);
}

.batch-summary .money {
  background: #fff8ed;
  border-color: #ffe1b8;
  color: #df8b12;
}

.batch-start-button {
  width: 100%;
  margin: 14px 0;
  justify-content: center;
  min-height: 42px;
  font-weight: 700;
}

.batch-failed-row {
  background: #fff1f0;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 10px;
}

.mobile-only {
  display: none;
}

@media (max-width: 860px) {
  .shell {
    display: block;
  }
  .side {
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .side button {
    display: inline-block;
    width: auto;
  }
  .grid, .grid.two, .summary, .form-row {
    grid-template-columns: 1fr;
  }
  #searchForm .actions {
    grid-column: auto;
    flex-wrap: wrap;
  }
  .content {
    padding: 12px;
  }
  .promo-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .batch-summary {
    grid-template-columns: 1fr;
  }
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
