:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #e5eaf1;
  --text: #182230;
  --muted: #728096;
  --navy: #0f172a;
  --blue: #2563eb;
  --blue-soft: #eaf1ff;
  --green: #138a5b;
  --green-soft: #e7f8ef;
  --orange: #bd6a10;
  --orange-soft: #fff4df;
  --red: #d44747;
  --red-soft: #fff0f0;
  --shadow: 0 10px 30px rgba(31, 49, 78, 0.06);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: flex; }
.sidebar { width: 244px; flex: 0 0 244px; background: var(--navy); color: #c6d0df; padding: 24px 16px; display: flex; flex-direction: column; }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 10px 34px; color: white; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: linear-gradient(135deg, #60a5fa, #2563eb); color: white; font-size: 20px; font-weight: 800; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; letter-spacing: .02em; }
.brand span { margin-top: 4px; color: #8291aa; font-size: 12px; }
.nav-list { display: grid; gap: 6px; }
.nav-item { border: 0; background: transparent; color: #9eabc0; text-align: left; border-radius: 9px; padding: 12px 14px 12px 42px; position: relative; }
.nav-item::before { content: "·"; position: absolute; left: 20px; color: #6d7e98; font-size: 24px; line-height: 12px; }
.nav-item:hover { background: rgba(255,255,255,.07); color: white; }
.nav-item.is-active { background: #1e2b44; color: white; box-shadow: inset 3px 0 0 #60a5fa; }
.nav-item.is-active::before { content: "◆"; font-size: 8px; color: #60a5fa; top: 16px; }
.sidebar-footer { margin-top: auto; border-top: 1px solid rgba(255,255,255,.08); padding: 18px 10px 0; color: #71809a; font-size: 12px; display: flex; gap: 7px; align-items: center; }
.status-dot { width: 7px; height: 7px; background: #42d392; border-radius: 50%; box-shadow: 0 0 0 4px rgba(66,211,146,.12); }

.main-content { min-width: 0; flex: 1; padding: 30px 38px 50px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 30px; }
.eyebrow { color: var(--blue); font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; margin: 0 0 7px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 28px; line-height: 1.1; margin-bottom: 0; letter-spacing: -.03em; }
h2 { font-size: 23px; letter-spacing: -.025em; margin-bottom: 6px; }
h3 { font-size: 16px; margin-bottom: 6px; }
.topbar-actions, .form-actions, .date-range { display: flex; gap: 10px; align-items: center; }
.button { border: 1px solid transparent; border-radius: 8px; padding: 10px 15px; font-weight: 700; transition: .2s ease; }
.button-primary { background: var(--blue); color: white; box-shadow: 0 6px 14px rgba(37,99,235,.18); }
.button-primary:hover { background: #1d4ed8; transform: translateY(-1px); }
.button-secondary { background: var(--surface); color: #3b4a60; border-color: var(--line); }
.button-secondary:hover { border-color: #b8c4d5; background: var(--surface-soft); }
.text-button, .table-action { border: 0; color: var(--blue); background: transparent; font-weight: 700; padding: 4px 0; }
.table-action.danger { color: var(--red); }
.icon-button { border: 0; background: transparent; color: var(--muted); font-size: 28px; line-height: 1; }
.icon-button:hover { color: var(--text); }
.view-panel { display: none; }
.view-panel.is-visible { display: block; }
.page-intro { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 22px; }
.page-intro p { margin-bottom: 0; color: var(--muted); }
.page-intro.compact { align-items: center; }
.date-badge { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; color: var(--muted); padding: 9px 13px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.stat-card { border-radius: 12px; padding: 19px 20px; border: 1px solid transparent; box-shadow: var(--shadow); background: var(--surface); min-height: 125px; position: relative; overflow: hidden; }
.stat-card::after { content: ""; position: absolute; width: 80px; height: 80px; border-radius: 50%; right: -27px; bottom: -27px; background: currentColor; opacity: .05; }
.stat-neutral { color: #516174; border-color: #e1e8f1; }
.stat-blue { color: #2563eb; background: #f8fbff; border-color: #dbe8ff; }
.stat-orange { color: var(--orange); background: #fffaf1; border-color: #f8e6c5; }
.stat-green { color: var(--green); background: #f6fdf9; border-color: #d9f2e5; }
.stat-red { color: var(--red); background: #fff8f8; border-color: #f8dcdc; }
.stat-label, .stat-hint { display: block; color: var(--muted); }
.stat-value { display: block; color: var(--text); font-size: 25px; line-height: 1.2; margin: 13px 0 5px; }
.stat-hint { font-size: 12px; }

.content-grid { display: grid; grid-template-columns: 1.25fr .75fr; gap: 20px; }
.content-grid-wide { grid-template-columns: 1.45fr .55fr; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.settings-card-wide { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 22px 16px; }
.inline-form input { min-width: 0; flex: 1 1 130px; }
.inline-form .button { flex: 0 0 auto; }
.shipping-form { padding: 0 22px 16px; }
.shipping-form .inline-form { padding: 0 0 10px; }
.shipping-editor-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 15px; border-top: 1px solid #edf0f4; padding: 16px 0 10px; }
.shipping-editor-toolbar strong, .shipping-editor-toolbar small { display: block; }
.shipping-editor-toolbar small { color: var(--muted); margin-top: 4px; font-size: 11px; }
.toolbar-actions { display: flex; gap: 8px; }
.shipping-matrix-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.shipping-matrix { min-width: 760px; }
.shipping-matrix th, .shipping-matrix td { padding: 9px; vertical-align: middle; }
.shipping-matrix th { background: var(--surface-soft); border-bottom: 1px solid var(--line); }
.shipping-matrix th small { display: block; color: var(--muted); font-size: 10px; font-weight: 400; margin-top: 3px; text-transform: none; letter-spacing: 0; }
.shipping-matrix td { background: white; }
.shipping-matrix input { width: 100%; min-width: 82px; padding: 7px 8px; }
.shipping-tier-header { min-width: 110px; position: relative; }
.shipping-tier-header > span { display: block; color: var(--text); margin-bottom: 5px; }
.shipping-tier-header input { min-width: 72px; }
.mini-button { border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 3px 5px; }
.mini-button.danger:hover { color: var(--red); }
.tier-delete-button { display: block; margin: 4px auto 0; padding: 2px 4px; font-size: 11px; }
.config-list { border-top: 1px solid #edf0f4; padding: 0 22px; }
.config-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 13px 0; border-bottom: 1px solid #edf0f4; }
.config-row:last-child { border-bottom: 0; }
.config-row strong { color: var(--text); }
.config-row small { color: var(--muted); display: block; margin-top: 4px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; padding: 21px 22px 14px; gap: 15px; }
.section-heading p { color: var(--muted); font-size: 12px; margin: 0; }
.table-card { overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th { color: #8a96a8; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
th, td { padding: 14px 18px; border-bottom: 1px solid #edf0f4; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfe; }
td { color: #415067; }
td strong { color: var(--text); font-weight: 700; }
td small { display: block; color: #9aa6b6; font-size: 11px; margin-top: 3px; }
.align-right { text-align: right; }
.money { font-variant-numeric: tabular-nums; }
.positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }
.muted { color: var(--muted) !important; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; font-size: 11px; font-weight: 700; }
.badge-warning { color: #a45a0b; background: var(--orange-soft); }
.badge-info { color: #2563eb; background: var(--blue-soft); }
.badge-success { color: #128052; background: var(--green-soft); }
.badge-danger { color: #c23d3d; background: var(--red-soft); }
.badge-muted { color: #748197; background: #eef1f5; }
.table-footer { border-top: 1px solid var(--line); color: var(--muted); padding: 13px 18px; font-size: 12px; }
.row-actions { display: flex; gap: 10px; align-items: center; justify-content: flex-start; }
.empty-state { color: #98a4b4; padding: 30px 18px; text-align: center; }

.attention-list { padding: 4px 16px 16px; }
.attention-item { width: 100%; display: grid; grid-template-columns: 1fr auto 18px; gap: 12px; align-items: center; border: 0; border-bottom: 1px solid #edf0f4; background: transparent; color: #516174; padding: 16px 6px; text-align: left; }
.attention-item:last-child { border-bottom: 0; }
.attention-item strong { color: var(--text); font-size: 18px; }
.attention-item .arrow { color: #a2afbf; font-size: 18px; }
.attention-item:hover { color: var(--blue); }

.toolbar { display: flex; gap: 10px; padding: 12px; margin-bottom: 16px; align-items: center; }
.search-box { display: flex; align-items: center; gap: 8px; flex: 1; color: #9aa6b6; padding: 0 8px; }
.search-box input { border: 0; outline: 0; width: 100%; color: var(--text); background: transparent; }
select, input, textarea { border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--text); padding: 9px 10px; outline: 0; }
select:focus, input:focus, textarea:focus { border-color: #8db2ff; box-shadow: 0 0 0 3px rgba(37,99,235,.09); }
.toolbar select { min-width: 130px; }
.month-filter { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.month-filter input { padding: 8px 9px; }
.order-summary { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 0 0 16px; }
.mini-stat { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.mini-stat span, .mini-stat small { display: block; color: var(--muted); }
.mini-stat strong { display: block; color: var(--text); font-size: 17px; margin: 6px 0 4px; }
.mini-stat small { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-stat.stat-blue { border-color: #dbe8ff; }
.mini-stat.stat-orange { border-color: #f8e6c5; }
.mini-stat.stat-green { border-color: #d9f2e5; }
.mini-stat.stat-red { border-color: #f8dcdc; }
.date-range label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.date-range input { padding: 8px 9px; }

.recon-list { padding: 0 22px 18px; }
.recon-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 0; border-bottom: 1px solid #edf0f4; }
.recon-row:last-child { border-bottom: 0; }
.recon-row strong { color: var(--text); }
.recon-row small { display: block; color: var(--muted); margin-top: 4px; font-size: 11px; }
.recon-values { text-align: right; }
.recon-row.total { border-top: 2px solid var(--text); margin-top: 8px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(15,23,42,.5); display: grid; place-items: center; padding: 20px; }
.modal-backdrop[hidden] { display: none; }
.modal { width: min(680px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: var(--surface); border-radius: 14px; box-shadow: 0 24px 80px rgba(15,23,42,.25); }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; padding: 24px 26px 10px; }
.modal-header h2 { margin-bottom: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; padding: 12px 26px 26px; }
.form-grid label { display: grid; gap: 7px; color: #536278; font-size: 12px; font-weight: 700; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; font-weight: 400; }
.form-field-label { display: block; color: #536278; font-size: 12px; font-weight: 700; margin-bottom: 7px; }
.order-items-field { min-width: 0; }
.order-items-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: var(--surface-soft); }
.order-item-option { display: grid; grid-template-columns: 22px minmax(0, 1fr); align-items: center; gap: 10px; padding: 8px 9px; border-radius: 6px; background: white; }
.order-item-option:hover { background: var(--blue-soft); }
.order-item-option input[type="checkbox"] { width: 16px; height: 16px; }
.order-item-info strong, .order-item-info small { display: block; }
.order-item-info small { color: var(--muted); font-size: 11px; margin-top: 3px; }
.order-items-empty { color: var(--muted); padding: 12px; border: 1px dashed var(--line); border-radius: 8px; background: var(--surface-soft); }
.aftersale-order-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.full-width { grid-column: 1 / -1; }
.form-actions { justify-content: flex-end; padding-top: 5px; }
.toast-region { position: fixed; right: 25px; top: 25px; z-index: 30; display: grid; gap: 8px; }
.toast { background: #172236; border-radius: 8px; color: white; padding: 12px 15px; box-shadow: 0 10px 30px rgba(15,23,42,.2); animation: toast-in .2s ease-out; }
.toast-error { background: #a93636; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-7px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1050px) {
  .sidebar { width: 205px; flex-basis: 205px; }
  .main-content { padding: 24px; }
  .content-grid, .content-grid-wide { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-card-wide { grid-column: auto; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .app-shell { display: block; }
  .sidebar { width: 100%; padding: 14px 16px; }
  .brand { padding: 0 5px 14px; }
  .nav-list { grid-template-columns: repeat(5, 1fr); }
  .nav-item { padding: 9px 4px; text-align: center; font-size: 12px; }
  .nav-item::before, .nav-item.is-active::before, .sidebar-footer { display: none; }
  .main-content { padding: 20px 14px 35px; }
  .order-items-list { grid-template-columns: 1fr; }
  .aftersale-order-picker { grid-template-columns: 1fr; }
  .topbar, .page-intro, .page-intro.compact { align-items: stretch; flex-direction: column; }
  .topbar-actions { flex-wrap: wrap; }
  .topbar-actions .button { flex: 1; }
  h1 { font-size: 24px; }
  .stat-grid { gap: 10px; }
  .stat-card { min-height: 110px; padding: 14px; }
  .stat-value { font-size: 20px; }
  .toolbar { flex-wrap: wrap; }
  .search-box { flex-basis: 100%; padding: 5px 8px; }
  .toolbar select, .toolbar .button { flex: 1; min-width: 0; }
  .month-filter { flex: 1; }
  .month-filter input { min-width: 0; width: 100%; }
  .order-summary { grid-template-columns: repeat(2, 1fr); }
  .date-range { flex-wrap: wrap; }
  .form-grid { grid-template-columns: 1fr; }
  .full-width { grid-column: auto; }
}

@media print {
  .sidebar, .topbar-actions, .nav-list, .button, .text-button, .toolbar, .page-intro .date-range { display: none !important; }
  .main-content { padding: 0; }
  .view-panel { display: none !important; }
  #view-reconciliation { display: block !important; }
  .card { box-shadow: none; }
}
