:root {
  --blue: #1677ff;
  --blue-dark: #0b5ed7;
  --green: #12b76a;
  --amber: #f79009;
  --red: #f04438;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f4f6f9;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: 40px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error-text { color: var(--red); font-size: 13px; min-height: 18px; margin: 8px 0 0; }

.login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #1677ff 0%, #0b3fa8 100%); padding: 24px; z-index: 50;
}
.login-card {
  background: #fff; border-radius: 20px; padding: 28px 24px; width: 100%; max-width: 360px;
  text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.login-card .logo { font-size: 30px; font-weight: 800; letter-spacing: 2px; color: var(--blue); }
.login-card h1 { font-size: 20px; margin: 10px 0 4px; }
.login-card input { margin: 16px 0 12px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: #fff; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 800; font-size: 18px; }
.brand span { font-weight: 500; font-size: 12px; color: var(--muted); margin-left: 8px; }
.topbar-right { display: flex; gap: 8px; }

.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; padding: 14px 16px 0; }
.summary .card {
  background: var(--card); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); text-align: center;
}
.summary .card .num { font-size: 22px; font-weight: 800; line-height: 1.2; }
.summary .card .label { font-size: 12px; color: var(--muted); }
.summary .card.alert .num { color: var(--red); }
.summary .card.warn .num { color: var(--amber); }
.summary .card.ok .num { color: var(--green); }

.tabs { display: flex; gap: 6px; padding: 14px 16px 0; }
.tab {
  border: none; background: transparent; padding: 10px 14px; border-radius: 10px 10px 0 0;
  font-size: 15px; color: var(--muted); cursor: pointer; position: relative;
}
.tab.active { background: #fff; color: var(--blue); font-weight: 700; box-shadow: var(--shadow); }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff;
  font-size: 11px; line-height: 18px; text-align: center; margin-left: 4px;
}

.content { padding: 12px 16px 0; }
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: #fff; color: var(--muted);
  padding: 7px 14px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.chip.active { background: var(--blue); border-color: var(--blue); color: #fff; }

.list { display: flex; flex-direction: column; gap: 12px; }
.order-card, .product-card, .refund-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; flex-wrap: wrap; }
.status-badge {
  font-size: 12px; padding: 3px 10px; border-radius: 999px; background: #eef4ff; color: var(--blue); font-weight: 600;
}
.status-badge.s1 { background: #fff4e5; color: #b54708; }
.status-badge.s2 { background: #eef4ff; color: var(--blue); }
.status-badge.s3 { background: #e7f6ff; color: #0a6e9c; }
.status-badge.s4 { background: #e8f8ef; color: #027a48; }
.status-badge.s5 { background: #f2f4f7; color: var(--muted); }
.status-badge.s6 { background: #fef3f2; color: var(--red); }
.status-badge.s7 { background: #f2f4f7; color: var(--muted); }
.order-time { font-size: 12px; color: var(--muted); }

.line-item { display: flex; justify-content: space-between; font-size: 14px; padding: 3px 0; color: #374151; }
.line-item .qty { color: var(--muted); margin-left: 6px; }
.receiver {
  margin-top: 10px; padding: 10px; background: #f9fafb; border-radius: 10px; font-size: 13px; line-height: 1.7;
}
.receiver .name { font-weight: 700; }
.totals { display: flex; justify-content: space-between; align-items: baseline; margin-top: 10px; }
.totals .amount { font-size: 18px; font-weight: 800; color: var(--red); }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 auto; min-width: 96px; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; cursor: pointer; font-weight: 600; transition: transform 0.06s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; }
.head-actions { display: flex; gap: 8px; }
.toolbar { display: flex; gap: 8px; margin-bottom: 6px; }
.toolbar input { flex: 1; }
.toolbar-hint { font-size: 12px; color: var(--muted); margin: 0 0 12px; line-height: 1.5; }
.import-actions { display: flex; gap: 10px; margin-bottom: 10px; align-items: center; }
.file-btn {
  position: relative; overflow: hidden; display: inline-block; padding: 7px 12px; font-size: 13px;
  border: 1px dashed var(--blue); color: var(--blue); border-radius: 8px; cursor: pointer;
}
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
#import-text { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 12px; line-height: 1.6; }
.import-result { margin-top: 10px; font-size: 13px; background: #f9fafb; border-radius: 10px; padding: 10px 12px; line-height: 1.7; }
.import-result .ok { color: var(--green); font-weight: 600; }
.import-result .err { color: var(--red); }
.import-result ul { margin: 6px 0 0; padding-left: 18px; }
.panel-title { font-size: 16px; margin: 0 0 12px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px; }

.product-card { display: flex; gap: 12px; align-items: flex-start; }
.product-card.low { border: 1px solid #fde68a; background: #fffdf3; }
.product-card img { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: #f3f4f6; }
.product-main { flex: 1; min-width: 0; }
.product-title { font-weight: 700; font-size: 15px; }
.product-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.price { color: var(--red); font-weight: 800; }
.stock-edit { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.stock-edit input { width: 76px; }
.off { opacity: 0.55; }

input, textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px;
  font-family: inherit; background: #fff; color: var(--text);
}
input:focus, textarea:focus { outline: 2px solid rgba(22, 119, 255, 0.25); border-color: var(--blue); }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.92); color: #fff; padding: 11px 20px; border-radius: 999px;
  font-size: 14px; z-index: 60; max-width: 88vw; text-align: center;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.alert-popup {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  width: calc(100% - 32px); max-width: 480px; background: #fff; border-radius: 16px; padding: 14px 16px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.24); display: flex; align-items: center; gap: 12px; z-index: 70;
  border: 2px solid var(--blue); animation: pop-in 0.25s ease;
}
@keyframes pop-in { from { opacity: 0; transform: translate(-50%, -12px); } to { opacity: 1; transform: translate(-50%, 0); } }
.alert-icon { font-size: 26px; animation: ring 0.9s ease infinite; }
@keyframes ring { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-14deg); } 40% { transform: rotate(12deg); } 60% { transform: rotate(-8deg); } 80% { transform: rotate(6deg); } }
.alert-body { flex: 1; }
.alert-body p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: flex; align-items: center; justify-content: center; z-index: 80; padding: 16px; }
.modal-card { background: #fff; border-radius: 18px; padding: 20px; width: 100%; max-width: 460px; max-height: 88vh; overflow: auto; }
.modal-card h2 { margin: 0 0 14px; font-size: 17px; }
.modal-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.modal-card label input, .modal-card label textarea { margin-top: 4px; }
.modal-card .row { display: flex; gap: 10px; }
.modal-card .row > label { flex: 1; }
.modal-card label.inline { display: flex; align-items: center; gap: 8px; color: var(--text); }
.modal-card label.inline input { width: auto; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn { flex: 1; }
.image-row { display: flex; gap: 10px; margin-top: 6px; align-items: flex-start; }
.preview { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: #f3f4f6; }
.image-actions { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.image-actions input[type="file"] { padding: 6px; font-size: 12px; }

@media (max-width: 480px) {
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar .brand span { display: none; }
}
.settings-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  max-width: 520px;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 12px;
}
.setting-row input { width: 140px; }
