:root {
  --ink: #17212f;
  --muted: #667085;
  --line: #d8e0ea;
  --soft: #edf3f8;
  --paper: #ffffff;
  --brand: #0068b7;
  --brand-dark: #0f3f66;
  --bad: #b42318;
  --ok: #14845b;
  --shadow: 0 12px 34px rgba(17, 35, 58, .08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--soft);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
}
.login-card {
  width: min(420px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; font-size: 24px; }
.login-card p { margin: 6px 0 18px; color: var(--muted); }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background: var(--brand-dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 6px 12px;
  border-bottom: 1px solid rgba(255,255,255,.18);
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #0581cf;
  font-weight: 800;
}
.brand strong { display: block; font-size: 16px; }
.brand span { display: block; color: rgba(255,255,255,.72); font-size: 12px; }
.nav { display: grid; gap: 7px; }
.nav button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  color: rgba(255,255,255,.84);
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-weight: 800;
}
.nav button.active, .nav button:hover { color: #fff; background: rgba(255,255,255,.14); }
.content { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 64px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.94);
}
.topbar h1 { margin: 0; font-size: 20px; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.page {
  width: min(1560px, calc(100% - 32px));
  margin: 18px auto 36px;
  display: none;
}
.page.active { display: block; }
.panel, .card, .stat-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.panel-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 14px;
}
.panel-head h2, .card h2 { margin: 0; font-size: 18px; }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
form { padding: 18px 20px 20px; }
form h3 { margin: 14px 0 10px; font-size: 13px; color: #344054; }
label { display: grid; gap: 6px; color: #344054; font-size: 13px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid #c9d4e2;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}
textarea { min-height: 82px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(0,104,183,.14); border-color: var(--brand); }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.wide { grid-column: 1 / -1; }
.check-label {
  display: flex;
  align-items: center;
  gap: 8px;
}
.check-label input[type="checkbox"] {
  width: auto;
  min-height: auto;
  margin: 0;
}
.quick-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, .8fr);
  gap: 18px;
  align-items: start;
}
.quick-grid-wide { display: block; }
.quick-grid-wide #quickForm .form-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.quick-grid-wide #quickForm textarea { min-height: 62px; }
.quick-launch-grid { align-items: end; }
.channel-combobox-label { position: relative; }
.channel-combobox-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: 320px;
  overflow: auto;
  padding: 6px;
  border: 1px solid #c9d4e2;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}
.channel-combobox-list button {
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.channel-combobox-list button:hover, .channel-combobox-list button:focus {
  outline: 0;
  background: #e9f4ff;
}
.empty-option { padding: 10px; color: var(--muted); font-size: 13px; }
.quick-summary {
  min-height: 128px;
  margin: 16px 0 0;
}
.policy-add-form textarea { min-height: 220px; }
.policy-add-form .status { margin-top: 10px; }
.mode-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 0;
  margin: 0;
  border: 0;
}
.mode-picker legend {
  grid-column: 1 / -1;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 13px;
}
.mode-picker label {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 9px;
  align-items: center;
  min-height: 56px;
  padding: 10px 12px;
  border: 1px solid #c9d4e2;
  border-radius: 8px;
  background: #fff;
}
.mode-picker input {
  width: auto;
  min-height: auto;
  margin: 0;
}
.mode-picker span { font-weight: 700; }
.mode-picker small {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
}
.mode-picker label:has(input:checked) {
  border-color: var(--brand);
  background: #f3f9ff;
}
.mail-grid {
  display: grid;
  grid-template-columns: minmax(360px, .45fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.mail-grid + .panel { margin-top: 18px; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card { padding: 16px; }
.stat-card span { display: block; color: var(--muted); font-size: 12px; }
.stat-card strong { display: block; margin-top: 6px; font-size: 24px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.card { padding: 18px; }
.summary {
  margin: 18px 20px;
  min-height: 280px;
  padding: 14px;
  border: 1px dashed #b9d5eb;
  border-radius: 8px;
  background: #f8fbfe;
  color: #344054;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.actions, .toolbar, .doc-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.orders-controls {
  padding: 16px 20px;
  display: grid;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}
.orders-sync-settings {
  padding: 10px 12px;
  border: 1px solid #c9d4e2;
  border-radius: 8px;
  background: #f8fbfe;
}
.orders-sync-settings summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  color: #344054;
  font-size: 13px;
  font-weight: 800;
}
.orders-sync-settings summary::marker { content: ""; }
.orders-sync-settings summary strong { color: var(--brand-dark); }
.orders-sync-row {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
  align-items: end;
}
.orders-filter-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}
.orders-search-field { grid-column: span 2; }
.orders-filter-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 800;
}
.button.primary { color: #fff; background: var(--brand); }
.button.secondary { color: var(--brand-dark); border: 1px solid #b9d5eb; background: #f5fbff; }
.button.danger { color: var(--bad); border: 1px solid #f2b8b5; background: #fff7f6; }
.button.ghost { margin-top: auto; color: #fff; border: 1px solid rgba(255,255,255,.25); background: transparent; }
.button:disabled { opacity: .55; cursor: not-allowed; }
.selection-count {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.order-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 0 20px 16px;
}
.order-summary-grid div {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfe;
}
.order-summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.order-summary-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}
.status { min-height: 22px; margin-top: 12px; color: var(--muted); font-size: 13px; }
.status.bad { color: var(--bad); }
.status.ok { color: var(--ok); }
.helper-note {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #b9d5eb;
  border-radius: 8px;
  color: #344054;
  background: #f8fbfe;
  font-size: 12px;
  line-height: 1.55;
}
.helper-note strong { margin-right: 8px; color: var(--brand-dark); }
.helper-note code {
  padding: 1px 5px;
  border-radius: 5px;
  background: #e7f2fb;
  color: var(--brand-dark);
}
.limit-pills {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.limit-pills span {
  padding: 5px 9px;
  border: 1px solid #b9d5eb;
  border-radius: 999px;
  color: var(--brand-dark);
  background: #f5fbff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.upload-zone {
  display: grid;
  gap: 14px;
}
.product-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 0 20px 18px;
}
.product-summary div {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfe;
}
.product-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.product-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
}
.product-preview-wrap {
  margin: 0 20px 20px;
}
.risk-alerts {
  margin: 0 20px 18px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff7f7;
  overflow: hidden;
}
.risk-alert-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid #fecaca;
  color: #991b1b;
}
.risk-alert-head strong {
  font-size: 14px;
}
.risk-alert-head span {
  font-size: 12px;
  font-weight: 800;
}
.customer-message {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid #fecaca;
  background: #fff;
}
.customer-message p {
  margin: 0;
  color: #7f1d1d;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.6;
}
.button.small {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
}
.product-risk-table {
  min-width: 920px;
}
.risk-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}
.risk-badge.danger {
  color: #991b1b;
  background: #fee2e2;
}
.risk-badge.warn {
  color: #92400e;
  background: #fef3c7;
}
.product-preview-table {
  min-width: 520px;
}
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; line-height: 1.45; }
th { color: #344054; background: #f7fbfe; white-space: nowrap; }
td { color: #475467; }
.orders-table { min-width: 1040px; }
.documents-table { min-width: 1180px; }
.mail-table { min-width: 980px; }
.channels-table { min-width: 880px; }
.empty { padding: 18px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }
.orders-pagination {
  min-height: 54px;
  padding: 12px 2px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}
.orders-pagination-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.orders-pagination-actions label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}
.orders-pagination-actions select {
  width: auto;
  min-width: 68px;
  min-height: 36px;
  padding: 6px 8px;
}
.orders-pagination-actions .button {
  min-height: 36px;
}
.hint { color: var(--muted); font-size: 12px; }
.table-select { min-height: 34px; padding: 5px 8px; font-size: 12px; }
.inline-input { min-height: 34px; padding: 6px 8px; border-radius: 6px; font-size: 12px; }
.inline-input.short { min-width: 96px; }
.table-checkbox {
  width: 16px;
  min-height: 16px;
  margin: 2px 0 0;
  padding: 0;
  accent-color: var(--brand);
}
.doc-cell { display: grid; gap: 7px; min-width: 170px; }
.apply-cell { display: grid; gap: 8px; min-width: 180px; }
.file-upload { display: inline-flex; gap: 7px; color: var(--brand-dark); cursor: pointer; font-size: 12px; font-weight: 800; }
.file-upload input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.mail-link {
  width: fit-content;
  color: var(--ok);
  font-size: 12px;
  font-weight: 800;
}
.mail-source {
  font-size: 12px;
  color: var(--brand-dark);
  font-weight: 800;
}
.sync-log {
  color: var(--muted);
  font-size: 12px;
}
.text-button { border: 0; padding: 0; color: var(--brand-dark); background: transparent; cursor: pointer; font-size: 12px; font-weight: 800; }
.text-button.danger { color: var(--bad); }
.external-links, .detail-links { display: grid; gap: 6px; min-width: 150px; }
.detail-links { display: flex; flex-wrap: wrap; }
.order-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
}
.order-modal[hidden] { display: none; }
.order-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 63, 102, .38);
}
.order-modal-panel {
  position: relative;
  width: min(980px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 20px 60px rgba(17, 35, 58, .24);
}
.order-detail-body { padding: 18px 20px 24px; }
.order-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.order-detail-grid > div {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.order-detail-grid > div > span { color: var(--muted); font-size: 12px; }
.order-detail-grid strong { overflow-wrap: anywhere; }
.order-detail-grid pre {
  max-height: 220px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7fbfe;
  color: #344054;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.order-detail-grid details { min-width: 0; }
.order-detail-grid summary { cursor: pointer; color: var(--brand-dark); font-weight: 800; }
.site-footer {
  width: 100%;
  padding: 14px 20px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.login-view .site-footer {
  position: absolute;
  left: 0;
  bottom: 0;
}
.site-footer a:hover { color: var(--brand-dark); }
.app-footer { margin-top: -22px; }
.bar-list, .todo-list { display: grid; gap: 12px; }
.channel-stat {
  display: grid;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.channel-stat:last-child { border-bottom: 0; padding-bottom: 0; }
.bar-row { display: grid; grid-template-columns: 120px minmax(0, 1fr) 46px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row.primary { font-weight: 800; color: var(--ink); }
.bar-row.child { padding-left: 18px; color: var(--muted); }
.bar-track { height: 10px; border-radius: 999px; background: #e8eef5; overflow: hidden; }
.bar-fill { height: 100%; min-width: 2px; background: var(--brand); }
.todo-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.channel-form { display: grid; grid-template-columns: minmax(150px, .8fr) minmax(190px, 1fr) minmax(150px, .7fr) minmax(160px, .7fr) auto; gap: 12px; align-items: end; }
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(360px, calc(100% - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: .18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); }
  .quick-grid, .mail-grid, .two-col { grid-template-columns: 1fr; }
  .mail-grid + .panel { margin-top: 18px; }
  .quick-grid-wide #quickForm .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .orders-filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .orders-sync-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .order-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .product-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
  .topbar { padding: 12px 14px; align-items: flex-start; flex-direction: column; }
  .page { width: min(100% - 24px, 1280px); margin-top: 16px; }
  .nav, .form-grid, .stats-grid, .channel-form, .mode-picker, .orders-filter-grid, .quick-grid-wide #quickForm .form-grid { grid-template-columns: 1fr; }
  .orders-search-field { grid-column: auto; }
  .actions .button, .toolbar .button, .toolbar a { width: 100%; }
  .orders-filter-actions .button, .orders-filter-actions a { width: 100%; }
  .orders-pagination { align-items: flex-start; flex-direction: column; }
  .orders-pagination-actions { width: 100%; justify-content: space-between; }
  .product-summary { grid-template-columns: 1fr; }
  .order-summary-grid { grid-template-columns: 1fr; }
  .order-detail-grid { grid-template-columns: 1fr; }
}
