:root {
  --bg: #f6f8fb;
  --bg-warm: #fff7ed;
  --panel: #ffffff;
  --ink: #152033;
  --muted: #66758a;
  --line: #e1e8f0;
  --nav: #17324d;
  --nav-soft: #214867;
  --blue: #2878d8;
  --green: #10a37f;
  --amber: #f59e0b;
  --red: #dc2626;
  --cyan: #0ea5b7;
  --radius: 8px;
  --shadow: 0 18px 45px rgba(28, 55, 90, .08);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(255,247,237,.82), rgba(240,249,255,.76) 38%, rgba(246,248,251,1) 72%),
    var(--bg);
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 264px 1fr; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  color: #fff;
  background: linear-gradient(180deg, #17324d 0%, #123a45 100%);
  display: flex;
  flex-direction: column;
  gap: 22px;
  box-shadow: 10px 0 36px rgba(15, 42, 71, .16);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 16px; border-bottom: 1px solid rgba(255,255,255,.14); }
.brand strong { display: block; font-size: 18px; }
.brand small { color: #c3d7e8; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f8fafc;
  color: #17324d;
  font-size: 25px;
  font-weight: 900;
  line-height: 1;
  box-shadow: inset 0 -4px 0 rgba(16,185,129,.22), 0 10px 22px rgba(0,0,0,.18);
  text-shadow: 1px 1px 0 rgba(16,185,129,.34);
}
.brand-mark.large { width: 58px; height: 58px; font-size: 22px; }
.nav { display: flex; flex-direction: column; gap: 7px; }
.nav a {
  padding: 11px 12px;
  border-radius: 8px;
  color: #e7f0f8;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid transparent;
  transition: background .16s ease, transform .16s ease, border-color .16s ease;
}
.nav a:hover, .nav a.active {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.16);
  transform: translateX(2px);
}
.nav a small { color: #b9cedf; font-size: 12px; }
.nav-group { color: #9eead7; font-size: 12px; padding: 14px 12px 4px; }
.logout { margin-top: auto; }
.logout button, .button, .primary, .text-button { border: 0; border-radius: 8px; cursor: pointer; }
.logout button {
  width: 100%;
  padding: 11px;
  color: #fff;
  background: rgba(255,255,255,.12);
  transition: background .16s ease;
}
.logout button:hover { background: rgba(255,255,255,.2); }

.main { padding: 26px; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding: 2px 2px 4px;
}
.topbar h1 { margin: 0; font-size: 27px; color: #102033; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
.menu-toggle { display: none; width: 42px; height: 42px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }

.panel {
  background: rgba(255,255,255,.92);
  border: 1px solid rgba(215,226,238,.9);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.grid { display: grid; gap: 18px; margin-bottom: 18px; }
.grid.two { grid-template-columns: minmax(0, 1.6fr) minmax(320px, .8fr); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-title h2 { margin: 0; font-size: 18px; color: #102033; }
.filters, .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
label { display: flex; flex-direction: column; gap: 7px; color: var(--muted); font-size: 13px; margin-bottom: 12px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(40,120,216,.72);
  box-shadow: 0 0 0 3px rgba(40,120,216,.12);
}
input[readonly], textarea[readonly], select:disabled {
  background: #f8fafc;
  color: #64748b;
}
textarea { resize: vertical; }
.checkbox { flex-direction: row; align-items: center; color: var(--ink); }
.checkbox input { width: auto; }
.table-check { margin: 0; }

.primary {
  background: linear-gradient(135deg, var(--blue), #0ea5b7);
  color: #fff;
  padding: 11px 16px;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(40,120,216,.2);
}
.button {
  background: #eef6ff;
  color: #17324d;
  border: 1px solid #d8e9fb;
  padding: 11px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .16s ease, transform .16s ease, border-color .16s ease;
}
.button:hover, .primary:hover { transform: translateY(-1px); }
.button:hover { background: #e0f2fe; border-color: #bae6fd; }
.text-button, .text-link { color: var(--blue); background: transparent; padding: 0; font-weight: 700; }
.text-danger {
  border: 0;
  background: transparent;
  color: var(--red);
  padding: 0;
  font-weight: 700;
  cursor: pointer;
}
.table-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.table-actions form { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.form-section {
  border: 1px solid #edf2f7;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
  background: #fbfdff;
}
.form-section h3 {
  margin: 0 0 12px;
  font-size: 15px;
  color: #17324d;
}
.order-form-grid { align-items: start; }
.batch-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  background: linear-gradient(135deg, #f0f9ff, #fff7ed);
}
.batch-bar label { margin-bottom: 0; min-width: 180px; }
.selected-count {
  display: inline-flex;
  align-items: center;
  min-height: 39px;
  padding: 0 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #dbeafe;
  color: #2878d8;
  font-weight: 700;
}

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.metrics.order-summary { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.dashboard-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 1fr); gap: 18px; align-items: start; }
.dashboard-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.metrics article {
  position: relative;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(218,229,241,.95);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 14px 34px rgba(28, 55, 90, .07);
}
.metrics article::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, #38bdf8, #10b981, #f59e0b);
}
.metrics span, .metrics small { display: block; color: var(--muted); }
.metrics strong { display: block; font-size: 26px; margin: 9px 0 7px; color: #102033; }
.trend-panel {
  min-width: 0;
  overflow: hidden;
}
.trend-panel .section-title {
  align-items: flex-start;
  gap: 12px;
}
.trend-panel .muted {
  font-size: 12px;
  line-height: 1.5;
  text-align: right;
}
.chart-box {
  position: relative;
  width: 100%;
  height: 320px;
  max-height: 320px;
  overflow: hidden;
  padding: 8px 4px 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #f8fcff 0%, #ffffff 100%);
}
.chart-box canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  max-width: 100%;
  max-height: 320px;
}

.rank-list { display: grid; gap: 10px; }
.rank-list.columns { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.rank-list div, .mini-list div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  background: #fbfdff;
}
.rank-list small, .mini-list span { color: var(--muted); }

.data-table { width: 100%; border-collapse: separate; border-spacing: 0; }
.data-table th, .data-table td { padding: 13px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.data-table th { color: var(--muted); font-size: 13px; background: #f8fbff; position: sticky; top: 0; z-index: 1; }
.data-table tbody tr { transition: background .14s ease; }
.data-table tbody tr:hover { background: #f8fcff; }
.data-table td small { display: block; color: var(--muted); margin-top: 4px; }
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #e0f2fe;
  color: #075985;
  padding: 4px 9px;
  font-size: 12px;
  margin: 2px 4px 2px 0;
  white-space: nowrap;
}
.pay-unpaid { background: #fee2e2; color: #991b1b; }
.pay-partial { background: #fef3c7; color: #92400e; }
.pay-paid { background: #dcfce7; color: #166534; }
.receipt-state {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.receipt-state.is-done { background: #ccfbf1; color: #0f766e; }
.receipt-state.is-open { background: #f1f5f9; color: #64748b; }
.mobile-list { display: none; }
.order-card { border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin-bottom: 10px; background: #fff; box-shadow: 0 10px 22px rgba(28,55,90,.06); }
.order-card header, .order-card footer { display: flex; justify-content: space-between; gap: 12px; }
.order-card p { color: var(--muted); }

.split-preview { display: grid; gap: 12px; margin-bottom: 18px; }
.split-preview div { background: linear-gradient(135deg, #f8fcff, #fffaf3); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.split-preview span { color: var(--muted); }
.split-preview strong { display: block; font-size: 24px; margin-top: 6px; color: #102033; }
.stack { display: grid; gap: 10px; margin-bottom: 14px; }
.muted { color: var(--muted); line-height: 1.8; }
.receipt-toggle {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  background: #f8fcff;
  color: #17324d;
  font-weight: 700;
}
.receipt-toggle input { width: 18px; height: 18px; }
.timeline {
  display: grid;
  gap: 10px;
}
.timeline div {
  position: relative;
  padding: 10px 10px 10px 18px;
  border-left: 3px solid #38bdf8;
  background: #f8fcff;
  border-radius: 0 8px 8px 0;
}
.timeline strong { display: block; font-size: 14px; color: #102033; }
.timeline span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.danger-zone {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fff7f7;
}
.danger-zone strong { display: block; color: #991b1b; }
.danger-zone span { display: block; margin-top: 4px; color: #7f1d1d; font-size: 12px; line-height: 1.6; }
.danger-button {
  border: 0;
  border-radius: 8px;
  background: #dc2626;
  color: #fff;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}
.danger-button:hover { background: #b91c1c; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #0f3a4a 0%, #2878d8 52%, #10a37f 100%);
}
.login-panel { width: min(960px, 100%); display: grid; grid-template-columns: 1.1fr .9fr; gap: 24px; align-items: stretch; }
.login-copy { color: #fff; padding: 40px 22px; display: flex; flex-direction: column; justify-content: center; }
.login-copy h1 { font-size: 40px; margin: 22px 0 12px; }
.login-copy p { color: #e0f2fe; font-size: 18px; line-height: 1.8; }
.login-card { background: rgba(255,255,255,.96); border-radius: 8px; padding: 28px; box-shadow: 0 24px 60px rgba(0,0,0,.22); }
.login-card h2 { margin-top: 0; }
.alert { background: #fee2e2; color: #991b1b; border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.toast { position: fixed; top: 18px; right: 18px; z-index: 50; background: #dcfce7; color: #166534; border: 1px solid #86efac; border-radius: 8px; padding: 12px 16px; box-shadow: 0 16px 38px rgba(15,23,42,.18); }
.toast[data-type="error"] { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
}
.modal-shell.is-open { display: block; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 32, 51, .52);
  backdrop-filter: blur(5px);
}
.modal-window {
  position: absolute;
  inset: 4vh 4vw;
  max-width: 1180px;
  margin: 0 auto;
  border-radius: 8px;
  background: #f6f8fb;
  box-shadow: 0 30px 80px rgba(0,0,0,.28);
  overflow: hidden;
}
.modal-window iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: #17324d;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(28,55,90,.16);
}
body.modal-open { overflow: hidden; }
.modal-page {
  min-height: 100vh;
  padding: 18px;
  background: #f6f8fb;
}
.modal-page .grid.two {
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, .8fr);
}
.logs-grid .panel { overflow: auto; }

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; width: 270px; transform: translateX(-100%); transition: transform .2s ease; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .menu-toggle { display: inline-grid; place-items: center; }
  .main { padding: 16px; }
  .grid.two, .login-panel { grid-template-columns: 1fr; }
  .modal-page .grid.two { grid-template-columns: 1fr; }
  .dashboard-split { grid-template-columns: 1fr; }
  .metrics, .metrics.order-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-box { height: 300px; max-height: 300px; }
}
@media (max-width: 640px) {
  .topbar h1 { font-size: 21px; }
  .metrics, .metrics.order-summary, .dashboard-metrics { grid-template-columns: 1fr; }
  .table-panel { overflow: hidden; }
  .data-table { display: none; }
  .mobile-list { display: block; }
  .modal-window { inset: 0; border-radius: 0; }
  .chart-box { height: 260px; max-height: 260px; }
  .trend-panel .section-title { display: block; }
  .trend-panel .muted { display: block; margin-top: 6px; text-align: left; }
  .login-copy { padding: 12px 4px; }
  .login-copy h1 { font-size: 30px; }
}
