:root {
  color-scheme: light;
  --navy: #0b2545;
  --navy-light: #173a64;
  --gold: #e8b64c;
  --gold-light: #f5d78e;
  --ice: #e8f4fb;
  --ink: #172c42;
  --muted: #50677e;
  --line: #dce6ee;
  --surface: #fff;
  --page: #eef3f7;
  --green: #105b3c;
  --red: #9d3333;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--page);
  font-synthesis: none;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; line-height: 1.55; }
h1, h2, h3, p, dl, dd, ul { margin: 0; }
h1, h2, h3 { color: var(--navy); line-height: 1.3; }
h1 { font-size: clamp(1.55rem, 4vw, 2.1rem); letter-spacing: .04em; }
h2 { font-size: 1.13rem; }
h3 { font-size: 1rem; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, a.button { touch-action: manipulation; }
:focus-visible { outline: 3px solid #517cad; outline-offset: 2px; }

.shell { width: min(1340px, 100% - 40px); margin-inline: auto; }
.masthead { background: linear-gradient(105deg, var(--navy), var(--navy-light)); color: white; }
.masthead-inner { min-height: 74px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: .94rem; }
.brand small { font-size: .77rem; color: #ccdeee; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 9px;
  border: 1px solid #e8b64c80;
  color: var(--gold-light);
  font: 750 1.1rem "Songti SC", SimSun, serif;
}
.header-actions, .filter-actions, .pagination-actions, .exports { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.header-actions { justify-content: flex-end; }

.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 39px;
  padding: 6px 12px;
  border: 1px solid #c9d8e4;
  border-radius: 8px;
  background: var(--surface);
  color: var(--navy);
  text-decoration: none;
  white-space: nowrap;
  font-size: .86rem;
  font-weight: 650;
  cursor: pointer;
}
.button:hover:not(:disabled) { background: #edf4f9; }
.button:disabled { color: #5e7489; opacity: .68; cursor: default; }
.button.primary { border-color: var(--navy); background: var(--navy); color: white; }
.button.primary:hover:not(:disabled) { background: #24466c; }
.button.header-button { border-color: #ffffff4a; background: #ffffff12; color: white; }
.button.header-button:hover:not(:disabled) { background: #ffffff28; }
.button.compact { min-height: 36px; padding: 5px 10px; }
.button.secondary-danger { color: var(--red); }

.card { border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: 0 2px 8px #0b254508; }
.login { max-width: 400px; margin: clamp(36px, 12vh, 120px) auto 40px; padding: 30px; border-top: 4px solid var(--gold); }
.login h1 { margin-bottom: 24px; font-size: 1.55rem; }
.login form { display: grid; gap: 14px; }
.login button { margin-top: 6px; }
.dashboard { display: grid; gap: 18px; padding: 27px 0 40px; }
.title-row, .section-heading, .pagination, .dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { min-width: 0; padding: 13px 16px; border-top: 3px solid var(--gold); }
.stat h2 { font-size: .85rem; color: var(--muted); }
.stat-value { font-size: clamp(1.18rem, 3vw, 1.8rem); line-height: 1.23; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--navy); overflow-wrap: anywhere; margin-top: 6px; }
.stat-note { margin-top: 5px; font-size: .81rem; color: var(--muted); }

.orders { min-width: 0; }
.section-heading { padding: 17px 18px; }
.export-hint { padding: 0 18px 12px; color: var(--muted); font-size: .79rem; }
.filters { display: grid; grid-template-columns: minmax(165px, 1.6fr) repeat(3, minmax(115px, 1fr)) auto; gap: 11px; padding: 13px 18px; align-items: end; border-block: 1px solid var(--line); background: #f7fafc; }
label { display: grid; gap: 5px; color: var(--navy); font-size: .86rem; font-weight: 650; }
input, select, textarea {
  width: 100%;
  min-height: 39px;
  padding: 6px 8px;
  border: 1px solid #c7d7e5;
  border-radius: 7px;
  color: var(--ink);
  background: white;
  font-size: 16px;
  font-weight: 400;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
textarea { resize: vertical; min-height: 70px; }
.table-wrap { overflow: auto; }
.table-wrap:focus-visible { outline-offset: -3px; }
table { width: 100%; min-width: 860px; border-collapse: collapse; text-align: left; font-size: .87rem; }
td, th { padding: 11px 10px; border-bottom: 1px solid var(--line); }
td:first-child, th:first-child { padding-left: 18px; }
th { color: var(--muted); font-size: .8rem; background: #f7fafc; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f9fbfd; }
.subtext { display: block; color: var(--muted); font-size: .8rem; margin-top: 2px; overflow-wrap: anywhere; }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.status {
  display: inline-block;
  width: fit-content;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--ice);
  color: #225273;
  font-size: .77rem;
  font-weight: 650;
  white-space: nowrap;
}
.status.good { color: var(--green); background: #e5f6ed; }
.status.alert { color: #795610; background: #fcf1d5; }
.status.bad { color: var(--red); background: #fceaea; }
.status.quiet { color: var(--muted); background: #edf2f6; }
.empty { text-align: center; color: var(--muted); padding: 24px 12px; }
.pagination { padding: 11px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; }

.breakdowns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: start; }
.breakdown { padding: 16px; }
.breakdown h2 { margin-bottom: 8px; }
.list-pairs { list-style: none; padding: 0; font-size: .87rem; }
.list-pairs li { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.list-pairs li:last-child { border-bottom: 0; }
.list-pairs strong { flex: none; font-variant-numeric: tabular-nums; }
.notice { margin: 1px 0; padding: 8px 11px; border-radius: 8px; border: 1px solid #d8e4ee; background: #f4f8fb; color: var(--navy); font-size: .86rem; overflow-wrap: anywhere; }
.notice.error { color: var(--red); background: #fff4f4; border-color: #f3cdcd; }
.notice.success { color: var(--green); background: #ebf7ef; border-color: #cfebd9; }
#startup { margin-top: 26px; }

dialog {
  padding: 0;
  width: min(820px, 100% - 24px);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  border: 1px solid var(--line);
  border-radius: 13px;
  background: white;
  color: var(--ink);
  box-shadow: 0 12px 50px #0b254528;
  overflow: auto;
}
dialog::backdrop { background: #0b254577; }
.small-dialog { width: min(430px, 100% - 24px); }
.dialog-header { position: sticky; top: 0; z-index: 1; padding: 13px 18px; border-bottom: 1px solid var(--line); background: white; }
.dialog-header p { margin-top: 3px; color: var(--muted); font-size: .82rem; }
.dialog-body { display: grid; gap: 11px; padding: 14px 18px 19px; }
#detail { display: grid; gap: 13px; }
.detail-section { padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: #fcfdff; }
.detail-section h3 { margin-bottom: 8px; }
.detail-section .status { margin: 0 0 8px; }
.detail-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 12px; font-size: .86rem; }
.detail-fields dt { color: var(--muted); font-size: .79rem; }
.detail-fields dd { overflow-wrap: anywhere; white-space: pre-wrap; }
.action-form { margin-top: 10px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.action-form.multi { grid-template-columns: repeat(2, minmax(0, 1fr)) auto; }
.detail-action { margin-top: 10px; }
.audit { margin: 0; padding-left: 20px; font-size: .85rem; }
.audit li { margin-block: 5px; overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .filters { grid-template-columns: 1.5fr 1fr 1fr; }
  .breakdowns { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 580px) {
  .shell { width: calc(100% - 24px); }
  .masthead-inner { min-height: 66px; }
  .header-actions { gap: 5px; flex-wrap: nowrap; }
  .header-button { min-height: 36px; padding-inline: 7px; }
  .brand strong { font-size: .84rem; }
  .brand-mark { width: 29px; height: 32px; flex-basis: 29px; }
  .stats { gap: 8px; grid-template-columns: 1fr 1fr; }
  .stat { padding: 10px; }
  .breakdowns { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr 1fr; padding: 10px; gap: 8px; }
  .filters > label:first-child { grid-column: 1 / -1; }
  .section-heading, .export-hint, .pagination, .dialog-header, .dialog-body { padding-inline: 10px; }
  .detail-fields { grid-template-columns: 1fr 1fr; }
  .action-form, .action-form.multi { grid-template-columns: 1fr; }
  .action-form .button { width: fit-content; }
  .table-wrap table, .table-wrap tbody { display: block; min-width: 0; }
  .table-wrap thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table-wrap tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; padding: 12px 10px; border-bottom: 1px solid var(--line); }
  .table-wrap tr:last-child { border-bottom: 0; }
  .table-wrap td { display: block; min-width: 0; padding: 0; border: 0; overflow-wrap: anywhere; }
  .table-wrap td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 2px; color: var(--muted); font-size: .76rem; }
  .table-wrap td.empty { grid-column: 1 / -1; padding: 14px 0; }
  .table-wrap td:last-child:not(.empty) { align-self: end; justify-self: end; }
}
