:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --line: #dfe3e6;
  --text: #1e252b;
  --muted: #68717a;
  --blue: #1d6fb8;
  --green: #168157;
  --red: #b42318;
  --amber: #a15c00;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}
body.logged-out { grid-template-columns: 1fr; }
body.logged-out .sidebar, body.logged-out header { display: none; }
body.logged-out main { min-height: 100vh; display: grid; }
body.logged-out #app { padding: 24px; display: grid; }

.sidebar {
  background: #17202a;
  color: white;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.brand { padding: 8px 10px 20px; display: grid; gap: 4px; }
.brand span { color: #aab4bf; font-size: 13px; }
.nav {
  border: 0;
  background: transparent;
  color: #d7dee5;
  text-align: left;
  padding: 11px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
}
.nav.active, .nav:hover { background: #263545; color: white; }

main { min-width: 0; }
header {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: white;
  padding: 0 24px;
}
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 0 0 10px; }
#app { padding: 22px 24px 40px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.panel, dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.metric { background: white; border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { display: block; font-size: 24px; margin-top: 5px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
button, input, select, textarea {
  font: inherit;
}
input, select, textarea {
  width: 100%;
  border: 1px solid #cfd6dd;
  border-radius: 6px;
  padding: 9px 10px;
  background: white;
}
textarea { min-height: 140px; resize: vertical; }
button.primary, button.secondary, button.danger {
  border: 0;
  border-radius: 6px;
  padding: 9px 13px;
  cursor: pointer;
  white-space: nowrap;
}
button.primary { background: var(--blue); color: white; }
button.secondary { background: #eef2f5; color: #25313b; border: 1px solid var(--line); }
button.danger { background: #fff1f0; color: var(--red); border: 1px solid #ffd0cc; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.copy-success {
  background: var(--green) !important;
  border-color: var(--green) !important;
  color: white !important;
  box-shadow: 0 3px 10px rgb(22 129 87 / .28);
  transform: translateY(-1px);
  transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: end; }
.form .wide { grid-column: 1 / -1; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
label span { color: var(--muted); }
table { width: 100%; border-collapse: collapse; background: white; }
th, td { border-bottom: 1px solid var(--line); padding: 10px 8px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; background: #fafbfc; }
td.num, th.num { text-align: right; }
.tag { display: inline-flex; border-radius: 999px; padding: 2px 8px; font-size: 12px; background: #eef2f5; }
.tag.green { background: #e8f6ef; color: var(--green); }
.tag.red { background: #fff1f0; color: var(--red); }
.tag.amber { background: #fff5df; color: var(--amber); }
.bill, .cards-out {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #f8fafb;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  line-height: 1.6;
}
#toast { color: var(--green); font-size: 14px; min-height: 20px; }
dialog { width: min(760px, calc(100vw - 30px)); }
dialog::backdrop { background: rgb(23 32 42 / .35); }
.icon-close { float: right; border: 0; background: transparent; font-size: 24px; cursor: pointer; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.warn { color: var(--red); font-weight: 600; }
.search-results { display: grid; gap: 6px; margin-top: 6px; }
.search-results button { text-align: left; border: 1px solid var(--line); background: white; padding: 8px; border-radius: 6px; cursor: pointer; }
.inventory-filters input { flex: 2 1 260px; }
.inventory-filters select { flex: 1 1 150px; width: auto; }
.order-filters input { flex: 2 1 220px; }
.order-filters select { flex: 1 1 145px; width: auto; }
.inventory-actions { justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 14px; }
.inventory-actions strong { margin-right: auto; }
.table-scroll { overflow-x: auto; }
.check-cell { width: 42px; text-align: center; }
.check-cell input { width: 16px; height: 16px; }
.card-content { min-width: 220px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }
.metric-status { font-size: 17px !important; }
.negative { color: var(--red); }
.login-shell { width: 100%; min-height: calc(100vh - 48px); display: grid; place-items: center; }
.login-panel { width: min(400px, 100%); padding: 24px; }
.login-brand { display: grid; gap: 5px; margin-bottom: 24px; }
.login-brand strong { font-size: 22px; }
.login-brand span { color: var(--muted); font-size: 13px; }
.login-form { display: grid; gap: 14px; }
.login-error { color: var(--red); background: #fff1f0; border: 1px solid #ffd0cc; border-radius: 6px; padding: 9px 10px; }
.logout-button { margin-left: auto; }
.field-label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.refund-card-list { border: 1px solid var(--line); border-radius: 6px; max-height: 240px; overflow: auto; }
.refund-card { display: flex; grid-template-columns: none; align-items: center; gap: 10px; padding: 9px 10px; border-bottom: 1px solid var(--line); color: var(--text); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.refund-card:last-child { border-bottom: 0; }
.refund-card input { width: 16px; height: 16px; flex: 0 0 auto; }
.refund-card span { color: inherit; overflow-wrap: anywhere; }

@media (max-width: 900px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 2; flex-direction: row; overflow-x: auto; }
  .brand { display: none; }
  .cols-2, .cols-3, .cols-4, .cols-5, .form { grid-template-columns: 1fr; }
  header { padding: 0 16px; }
  #app { padding: 16px; }
}
