:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-muted: #f8faf9;
  --text: #20272b;
  --muted: #68747b;
  --line: #dce2e5;
  --primary: #13795b;
  --primary-dark: #0d5d46;
  --accent: #d38b18;
  --danger: #c33c36;
  --info: #2563a6;
  --sidebar: #202a2e;
  --sidebar-active: #314148;
  --shadow: 0 8px 24px rgba(26, 38, 44, .08);
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #e9eef0;
}
.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 32px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  background: var(--primary);
  color: white;
  font-weight: 700;
}
.brand h1 { margin: 0; font-size: 22px; }
.login-panel .brand { margin-bottom: 28px; }
.login-panel #login-submit { display: block; margin-left: auto; }

.shell { min-height: 100vh; display: grid; grid-template-rows: 58px 1fr; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
  padding: 0 18px;
  color: white;
  background: #182125;
  border-bottom: 1px solid #334047;
}
.topbar .brand h1 { font-size: 18px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.layout { min-width: 0; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar {
  min-height: calc(100vh - 58px);
  background: var(--sidebar);
  color: #dce4e7;
  padding: 20px 12px;
}
.profile { text-align: center; padding: 10px 8px 22px; border-bottom: 1px solid #3a474d; }
.profile img { width: 58px; height: 58px; border-radius: 50%; background: white; }
.profile strong { display: block; margin-top: 10px; overflow-wrap: anywhere; }
.nav { display: grid; gap: 4px; margin-top: 18px; }
.nav button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 12px;
  border: 0;
  border-radius: 6px;
  color: inherit;
  background: transparent;
  text-align: left;
}
.nav button:hover, .nav button.active { color: white; background: var(--sidebar-active); }
.nav-icon { width: 20px; text-align: center; font-size: 16px; }
.main { min-width: 0; padding: 26px clamp(16px, 3vw, 38px) 48px; }
.page-head {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.page-head h2 { margin: 0; font-size: 22px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.status-card {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 112px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(26, 38, 44, .05);
}
button.status-card { width: 100%; color: inherit; text-align: left; }
button.status-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.status-name { color: var(--muted); margin-bottom: 8px; }
.status-value { font-size: 28px; font-weight: 700; }
.status-symbol {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 6px;
  color: white;
  background: var(--primary);
  font-size: 20px;
}
.status-symbol.amber { background: var(--accent); }
.status-symbol.blue { background: var(--info); }
.status-symbol.red { background: var(--danger); }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: #526067; background: var(--surface-muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td { overflow-wrap: anywhere; }
.empty { padding: 54px 20px; color: var(--muted); text-align: center; }
.actions { display: flex; align-items: center; gap: 4px; white-space: nowrap; }

.btn {
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
}
.btn:hover { border-color: #9ba8ae; background: #f7f9fa; }
.btn-primary { color: white; border-color: var(--primary); background: var(--primary); }
.btn-primary:hover { border-color: var(--primary-dark); background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #e4b3b0; }
.btn-text { min-height: 30px; padding: 4px 7px; border-color: transparent; color: var(--info); background: transparent; }
.btn-text.danger { color: var(--danger); }
.icon-btn { width: 36px; padding: 6px; font-size: 19px; }

.badge { display: inline-flex; padding: 3px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap; }
.badge.success { color: #07583f; background: #d8f2e8; }
.badge.warning { color: #7a4b00; background: #fff0c9; }
.badge.muted { color: #526067; background: #e9edef; }
.badge.danger { color: #8c2622; background: #f8dddb; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(18, 27, 31, .55);
}
.modal {
  width: min(620px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 20px 55px rgba(0, 0, 0, .22);
}
.modal.wide { width: min(820px, 100%); }
.modal-head, .modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; }
.modal-head { border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-body { padding: 20px; }
.modal-foot { justify-content: flex-end; border-top: 1px solid var(--line); }
.date-picker-backdrop { position: fixed; inset: 0; z-index: 110; display: grid; place-items: center; padding: 20px; background: rgba(18, 27, 31, .35); }
.date-picker { width: min(360px, 100%); padding: 16px; border-radius: 8px; background: var(--surface); box-shadow: 0 20px 55px rgba(0, 0, 0, .22); }
.date-picker-head { display: grid; grid-template-columns: 36px 1fr 36px; align-items: center; text-align: center; }
.date-picker-week, .date-picker-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.date-picker-week { margin: 14px 0 6px; color: var(--muted); font-size: 12px; }
.date-picker-days button, .date-picker-days span { aspect-ratio: 1; display: grid; place-items: center; border: 0; border-radius: 6px; background: transparent; }
.date-picker-days button { color: var(--text); }
.date-picker-days button:hover { background: #e8efec; }
.date-picker-days button.selected { color: white; background: var(--primary); }
.date-picker-days button:disabled { color: #b7c0c4; background: transparent; }
.date-picker-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px 18px; }
.field { min-width: 0; display: grid; align-content: start; gap: 6px; }
.field.toggle-field { align-content: end; }
.field.full { grid-column: 1 / -1; }
.field label { color: #3f4b50; font-weight: 600; }
.required::after { content: " *"; color: var(--danger); }
.input, .select {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #bec8cc;
  border-radius: 6px;
  color: var(--text);
  background: white;
}
.input:focus, .select:focus { outline: 2px solid rgba(19, 121, 91, .18); border-color: var(--primary); }
.input::placeholder { color: #8a969c; opacity: 1; }
.input.mutually-exclusive-disabled { border-color: #c9d0d3; color: #78848a; background: #edf0f1; cursor: not-allowed; opacity: 1; }
.input.mutually-exclusive-disabled::placeholder { color: #78848a; font-weight: 600; }
.hint { color: var(--muted); font-size: 12px; }
.train-filter-hint { grid-column: 1 / -1; margin-top: -9px; }
.period-hint { grid-column: 1 / -1; margin-top: -9px; }
.toggle-row { display: flex; align-items: center; gap: 9px; min-height: 38px; }
.sale-control-row { display: grid; grid-template-columns: minmax(120px, 0.7fr) auto; align-items: center; gap: 12px; }
.sale-control-row > .toggle-row { justify-self: end; }
.seat-picker { display: grid; gap: 10px; }
.seat-options { display: flex; flex-wrap: wrap; gap: 7px; }
.seat-option.selected { color: white; border-color: var(--primary); background: var(--primary); }
.seat-order { display: flex; flex-wrap: wrap; gap: 7px; min-height: 36px; padding: 8px; border: 1px dashed #bdc7cb; border-radius: 6px; }
.seat-chip { display: inline-flex; align-items: center; gap: 3px; padding: 4px 6px; border-radius: 5px; background: #e8efec; }
.seat-chip button { border: 0; color: #526067; background: transparent; padding: 0 3px; }

.qr-box { min-height: 300px; display: grid; place-items: center; text-align: center; }
.qr-box img { width: min(260px, 80vw); height: min(260px, 80vw); image-rendering: pixelated; }
.spinner { width: 30px; height: 30px; border: 3px solid #d7dedf; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.log-main { height: calc(100vh - 58px); display: flex; flex-direction: column; overflow: hidden; }
.log-main .page-head { flex: 0 0 auto; }
.log-panel { min-height: 0; flex: 1 1 auto; overflow: auto; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: #161e22; color: #cde7dc; font: 13px/1.65 Consolas, monospace; white-space: pre-wrap; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 200; max-width: min(420px, calc(100vw - 36px)); padding: 12px 15px; border-radius: 6px; color: white; background: #26343a; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--primary); }
.mobile-only { display: none; }

@media (max-width: 1050px) {
  .status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .mobile-only { display: inline-grid; place-items: center; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 58px auto 0 0; z-index: 30; width: 220px; transform: translateX(-100%); transition: transform .2s ease; }
  .shell.sidebar-open .sidebar { transform: translateX(0); }
  .main { padding: 20px 14px 36px; }
  .status-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .sale-control-row { grid-template-columns: 1fr; gap: 4px; }
  .sale-control-row > .toggle-row { justify-self: start; }
  .field.full { grid-column: auto; }
  .page-head { align-items: flex-start; }
  .topbar { padding: 0 12px; }
  .topbar .brand h1 { font-size: 16px; }
  .hide-mobile { display: none; }
  th, td { padding: 11px 10px; }
  .mobile-stack-table { overflow: visible; border: 0; background: transparent; }
  .mobile-stack-table table, .mobile-stack-table tbody, .mobile-stack-table tr, .mobile-stack-table td { display: block; width: 100%; }
  .mobile-stack-table thead { display: none; }
  .mobile-stack-table tr { margin-bottom: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 4px 14px rgba(26, 38, 44, .05); }
  .mobile-stack-table td { display: grid; grid-template-columns: 92px minmax(0, 1fr); align-items: center; gap: 10px; min-height: 46px; padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: center; overflow-wrap: anywhere; }
  .mobile-stack-table td::before { content: attr(data-label); color: #526067; font-weight: 600; text-align: center; }
  .mobile-stack-table td:last-child { border-bottom: 0; }
  .mobile-stack-table td > * { justify-self: center; }
  .mobile-stack-table .actions { justify-content: center; flex-wrap: wrap; }
  .date-picker-backdrop { padding: 12px; }
  .modal-backdrop { padding: 10px; }
  .modal { max-height: calc(100vh - 20px); }
}
