:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --text: #172033;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-weak: #dbeafe;
  --green: #15803d;
  --green-weak: #dcfce7;
  --amber: #b45309;
  --amber-weak: #fef3c7;
  --red: #b91c1c;
  --red-weak: #fee2e2;
  --cyan: #0e7490;
  --cyan-weak: #cffafe;
  --violet: #6d28d9;
  --violet-weak: #ede9fe;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 1180px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

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

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: #0f172a;
  color: #e5edf7;
  padding: 18px 14px;
}

.brand {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 16px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.14);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: linear-gradient(135deg, #38bdf8, #2563eb);
  font-weight: 800;
  color: #fff;
}

.brand-title {
  font-weight: 760;
  line-height: 1.25;
}

.brand-subtitle {
  color: #9fb1c9;
  font-size: 12px;
  margin-top: 3px;
}

.nav-group {
  margin-top: 16px;
}

.nav-group-title {
  color: #94a3b8;
  font-size: 12px;
  padding: 0 10px 7px;
}

.nav-item {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  color: #d7e3f4;
  background: transparent;
  text-align: left;
}

.nav-item:hover {
  background: rgba(148, 163, 184, 0.14);
}

.nav-item.active {
  background: #1d4ed8;
  color: #fff;
}

.nav-icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
}

.main-shell {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 66px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
}

.topbar-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.company-title {
  font-weight: 750;
  margin-right: 8px;
}

.search {
  width: min(360px, 32vw);
  min-width: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 9px 12px;
}

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

.content {
  padding: 22px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-title {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.page-kicker {
  margin: 6px 0 0;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.filter-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-title {
  font-size: 13px;
  color: #64748b;
  font-weight: 500;
  margin-right: 4px;
}

.filter-select {
  padding: 4px 8px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  font-size: 13px;
  background: white;
  color: #172033;
  cursor: pointer;
}

.filter-select:hover {
  border-color: #2563eb;
}

.filter-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  background: #dbeafe;
  color: #2563eb;
  border-radius: 4px;
  font-size: 12px;
}

.section {
  margin-top: 16px;
}

.section-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e2e8f0;
}

.section-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #1e293b;
}

.section-header .subtle {
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 14px;
}

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

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

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

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

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-title {
  font-size: 16px;
  font-weight: 740;
}

.panel-body {
  padding: 16px;
}

.metric-card {
  min-height: 112px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  margin-top: 12px;
  font-size: 26px;
  line-height: 1.05;
  font-weight: 800;
}

.metric-note {
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}

.card-link {
  border-color: #bfdbfe;
}

.card-link:hover {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.badge,
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
  border: 1px solid transparent;
}

.pill {
  border-color: var(--line);
  background: #fff;
  color: var(--muted);
}

.badge.blue {
  background: var(--primary-weak);
  color: #1d4ed8;
}

.badge.green {
  background: var(--green-weak);
  color: var(--green);
}

.badge.amber {
  background: var(--amber-weak);
  color: var(--amber);
}

.badge.red {
  background: var(--red-weak);
  color: var(--red);
}

.badge.cyan {
  background: var(--cyan-weak);
  color: var(--cyan);
}

.badge.violet {
  background: var(--violet-weak);
  color: var(--violet);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 7px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.btn:hover:not(:disabled) {
  border-color: #93c5fd;
  color: #1d4ed8;
}

.btn.primary {
  border-color: #1d4ed8;
  background: #2563eb;
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: #1d4ed8;
  color: #fff;
}

.btn.green {
  border-color: #15803d;
  background: #16a34a;
  color: #fff;
}

.btn.danger {
  border-color: #dc2626;
  background: #dc2626;
  color: #fff;
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
}

.btn.icon {
  width: 34px;
  padding: 0;
}

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

.control,
.select,
.textarea {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 7px 10px;
}

.textarea {
  width: 100%;
  min-height: 78px;
  resize: vertical;
}

.table-wrap {
  width: 100%;
  overflow: visible;
}

.table-note {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  background: #f8fafc;
}

.table-note-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

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

th {
  position: sticky;
  top: 66px;
  z-index: 20;
  background: var(--panel-soft);
  color: #475569;
  font-weight: 720;
  font-size: 12px;
  box-shadow: 0 1px 0 var(--line);
}

tr:hover td {
  background: #f8fbff;
}

.amount {
  font-variant-numeric: tabular-nums;
  font-weight: 720;
}

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

.subtle {
  color: var(--muted);
  font-size: 12px;
}

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

.success-text {
  color: var(--green);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(340px, 0.8fr);
  gap: 14px;
}

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

.kv {
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.kv-label {
  color: var(--muted);
  font-size: 12px;
}

.kv-value {
  margin-top: 6px;
  font-weight: 720;
}

.steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}

.step {
  position: relative;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.step.done {
  border-color: #86efac;
  background: #f0fdf4;
}

.step.current {
  border-color: #93c5fd;
  background: #eff6ff;
}

.step-title {
  font-weight: 740;
}

.step-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.timeline {
  display: grid;
  gap: 9px;
}

.log-item {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.list {
  display: grid;
  gap: 9px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.risk-high {
  border-left: 4px solid #dc2626;
}

.risk-medium {
  border-left: 4px solid #f59e0b;
}

.risk-low {
  border-left: 4px solid #0ea5e9;
}

.chart {
  width: 100%;
  min-height: 210px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f8fafc);
}

.bar-chart {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 84px;
  gap: 10px;
  align-items: center;
}

.bar-row.profit-row {
  grid-template-columns: 150px 1fr 120px;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0ea5e9, #22c55e);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.38);
}

.modal {
  width: min(760px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal.wide {
  width: min(980px, 100%);
}

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

.modal-footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-end;
}

.modal-title {
  font-size: 18px;
  font-weight: 780;
}

.modal-body {
  padding: 18px;
}

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

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

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: #475569;
  font-size: 12px;
  font-weight: 720;
}

.drawer-note {
  padding: 12px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e3a8a;
}

.toast-stack {
  position: fixed;
  right: 18px;
  top: 78px;
  z-index: 200;
  display: grid;
  gap: 9px;
  width: min(420px, calc(100vw - 36px));
}

.toast {
  padding: 12px 14px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.toast.success {
  border-color: #bbf7d0;
}

.toast.warn {
  border-color: #fde68a;
}

.toast.error {
  border-color: #fecaca;
}

.empty {
  padding: 26px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: #fff;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.tab {
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.tab.active {
  border-color: #2563eb;
  background: #eff6ff;
  color: #1d4ed8;
}

.stat-band {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mini-flow {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.mini-node {
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  color: #475569;
  font-size: 12px;
}

.mini-node.on {
  background: #ecfeff;
  border-color: #67e8f9;
  color: #0e7490;
}

.inline-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.compact-input {
  width: 100%;
  min-width: 86px;
}

.line-select {
  min-width: 360px;
}

.drawer-note.warn {
  border-color: #f59e0b;
  background: #fffbeb;
  color: #92400e;
}

.btn.linklike {
  border: 0;
  padding: 0;
  background: transparent;
  color: #2563eb;
  font-weight: 800;
}

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

.voucher-uploader {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 14px;
  align-items: center;
  min-height: 126px;
  padding: 18px;
  border: 1.5px dashed #93c5fd;
  border-radius: 8px;
  background: #f8fbff;
  color: #172033;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.voucher-uploader:hover,
.voucher-uploader:focus,
.voucher-uploader.dragging {
  border-color: #2563eb;
  background: #eff6ff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
  outline: none;
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #dbeafe;
  color: #1d4ed8;
  font-size: 24px;
  font-weight: 900;
}

.upload-title {
  font-weight: 800;
}

.upload-hint {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.upload-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
}

.upload-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
}

.upload-chip.success {
  background: #dcfce7;
  color: #15803d;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

.branch-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.branch-card.active {
  border-color: #22c55e;
  background: #f0fdf4;
}

.branch-card-title {
  font-size: 16px;
  font-weight: 900;
  color: var(--text);
}

.branch-card .kv {
  padding: 0;
  border: 0;
  background: transparent;
}

.branch-action {
  margin-top: auto;
}

@media (max-width: 1180px) {
  .branch-grid {
    grid-template-columns: repeat(2, minmax(220px, 1fr));
  }
}

@media (max-width: 720px) {
  .branch-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  body {
    min-width: 0;
  }

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

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

  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-4,
  .grid.cols-5,
  .split,
  .detail-grid,
  .form-grid,
  .form-grid.three {
    grid-template-columns: 1fr;
  }

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

  .topbar-right {
    justify-content: flex-start;
  }

  .search {
    width: 100%;
  }
}

.order-select-container {
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 8px;
  background: #fafafa;
}

.order-type-tabs {
  display: flex;
  gap: 4px;
  margin: 8px 0;
}

.order-type-tabs .tab-btn {
  flex: 1;
  padding: 6px 12px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.order-type-tabs .tab-btn.active {
  background: #07c160;
  color: white;
  border-color: #07c160;
}

.order-list {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 4px;
}

.order-item {
  display: flex;
  padding: 8px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  align-items: center;
}

.order-item:last-child {
  border-bottom: none;
}

.order-item:hover {
  background: #f5f5f5;
}

.order-item.selected {
  background: #e8f8ee;
}

.order-item-id {
  font-weight: 600;
  font-size: 13px;
  flex: 1;
}

.order-item-info {
  font-size: 12px;
  color: #666;
  flex: 2;
}

.order-item-check {
  width: 20px;
  color: #07c160;
  font-weight: bold;
}

.order-empty {
  padding: 20px;
  text-align: center;
  color: #999;
}

.selected-orders {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.order-tag {
  background: #07c160;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.order-tag span {
  cursor: pointer;
  margin-left: 4px;
  font-weight: bold;
}

.ai-btn {
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.18);
}
.ai-btn:hover { filter: brightness(1.05); }
.ai-panel { display: grid; gap: 16px; }
.ai-header {
  padding: 18px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(37, 99, 235, .10), rgba(124, 58, 237, .12));
  border: 1px solid rgba(37, 99, 235, .16);
}
.ai-header h2 { margin: 8px 0 4px; font-size: 22px; }
.ai-header p { margin: 0; color: #64748b; }
.ai-badge {
  display: inline-flex;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(37, 99, 235, .12);
  color: #2563eb;
  font-weight: 700;
  font-size: 12px;
}
.ai-summary {
  padding: 14px;
  border-radius: 12px;
  background: #eff6ff;
  color: #1e3a8a;
  font-weight: 650;
  line-height: 1.7;
}
.ai-section h3 { margin: 0 0 10px; font-size: 15px; color: #0f172a; }
.ai-finding,
.ai-risk,
.ai-suggestion,
.ai-plan,
.ai-copy-block {
  padding: 10px 12px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  margin-bottom: 8px;
  line-height: 1.65;
}
.ai-risk {
  background: #fff1f2;
  border-color: #fecdd3;
  color: #9f1239;
}
.ai-suggestion {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
}
.ai-plan { margin-bottom: 0; }
.ai-plan p { margin: 6px 0 0; color: #475569; }
.ai-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }
.ai-copy-block { background: #fffbeb; border-color: #fde68a; color: #92400e; }
