:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #7a8499;
  --line: #e4e8f0;
  --accent: #2f6fed;
  --accent-dark: #1f5ad6;
  --green: #18a058;
  --red: #d93025;
  --orange: #e8890c;
  --gray: #8a93a6;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 30, 60, .07);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1 { font-size: 20px; } h2 { font-size: 17px; margin-bottom: 12px; } h3 { font-size: 15px; }
a { color: var(--accent); text-decoration: none; }

/* ---- login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  padding: 36px; width: 340px; text-align: center; display: flex; flex-direction: column; gap: 12px;
}
.login-logo { font-size: 40px; }
.login-card input { text-align: center; }
.login-error { color: var(--red); font-size: 13px; min-height: 18px; }

/* ---- layout ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--card); border-right: 1px solid var(--line);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-size: 17px; font-weight: 700; padding: 0 8px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  padding: 9px 12px; border-radius: 8px; color: var(--text); font-weight: 500;
}
.sidebar nav a:hover { background: #eef2fb; }
.sidebar nav a.active { background: var(--accent); color: #fff; }
.content { flex: 1; padding: 26px 30px; max-width: 1180px; }

/* ---- cards & grid ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.stat-num { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat-num.green { color: var(--green); } .stat-num.red { color: var(--red); } .stat-num.orange { color: var(--orange); }
.section { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
.row-click { cursor: pointer; }
.row-click:hover { background: #f7f9fd; }

/* ---- badges ---- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.free, .badge.delivered, .badge.on { background: #e3f6ec; color: var(--green); }
.badge.sold { background: #e8effe; color: var(--accent); }
.badge.uploaded { background: #f0e9fd; color: #7a3ff2; }
.badge.error { background: #fdecea; color: var(--red); }
.badge.no_stock, .badge.warn { background: #fdf3e3; color: var(--orange); }
.badge.pending, .badge.info { background: #eef1f6; color: var(--gray); }
.badge.skipped, .badge.disabled, .badge.off { background: #eef1f6; color: var(--gray); }

/* ---- forms ---- */
input, select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47, 111, 237, .25); border-color: var(--accent); }
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
label.inline { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 8px 0; }
label.inline input { width: auto; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ---- buttons ---- */
.btn {
  display: inline-block; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: #f4f7fd; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { color: var(--red); border-color: #f3c5c1; }
.btn-danger:hover { background: #fdecea; }
.btn-ghost { border: none; background: none; color: var(--muted); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* ---- modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 22, 40, .45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal { background: #fff; border-radius: 14px; padding: 24px; width: 480px; max-width: 94vw; max-height: 88vh; overflow: auto; }

/* ---- toast ---- */
#toast { position: fixed; top: 18px; right: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1c2333; color: #fff; padding: 11px 18px; border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.25); font-size: 13px; max-width: 360px; animation: slidein .2s ease;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }

/* ---- misc ---- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }
.expand-panel { background: #f8fafd; border-radius: 10px; padding: 16px; margin-top: 8px; }
.pager { display: flex; gap: 10px; align-items: center; margin-top: 12px; font-size: 13px; color: var(--muted); }
.code-text { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; white-space: pre-wrap; word-break: break-all; }
.help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.on { background: var(--green); } .status-dot.off { background: var(--gray); }
.mp-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.divider { border: none; border-top: 1px solid var(--line); margin: 18px 0; }
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .content { padding: 16px; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
}

/* ---- dashboard ---- */
.dash-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.dash-head h1 { margin: 0; }
.dash-status { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.chip-online {
  display: inline-flex; align-items: center; gap: 6px; background: #e3f6ec; color: var(--green);
  font-size: 12px; font-weight: 600; padding: 3px 12px; border-radius: 999px;
}
.chip-online .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.chip-sync { font-size: 12px; color: var(--muted); background: var(--card); padding: 3px 12px; border-radius: 999px; box-shadow: var(--shadow); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.stat-card { border-radius: 14px; padding: 14px 18px 16px; position: relative; min-height: 92px; }
.stat-card .sc-label { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; opacity: .8; }
.stat-card .sc-num { font-size: 27px; font-weight: 700; margin-top: 12px; }
.stat-card .sc-icon { position: absolute; top: 12px; right: 14px; opacity: .5; font-size: 17px; }
.stat-card.blue { background: #e8f1fe; color: #1d4ed8; }
.stat-card.pink { background: #fdeaeb; color: #dc2626; }
.stat-card.yellow { background: #fdf3dc; color: #b45309; }
.stat-card.purple { background: #f1eafe; color: #7c3aed; }

.chart-card { padding: 18px 18px 12px; }
.cc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; background: #f1f3f8; border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 4px 12px; border-radius: 7px; font-size: 12px; cursor: pointer; color: var(--gray); font-weight: 600; font-family: inherit; }
.seg button.on { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.top-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.top-card { border-radius: 14px; padding: 16px 18px; }
.top-card.blue { background: #eaf2fe; }
.top-card.yellow { background: #fdf4e0; }
.top-card h3 { margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.tc-chip { margin-left: auto; font-size: 11px; background: rgba(255,255,255,.75); padding: 2px 10px; border-radius: 999px; font-weight: 600; color: var(--gray); }
.top-row { display: flex; align-items: center; gap: 12px; background: rgba(255,255,255,.8); border-radius: 10px; padding: 9px 12px; margin-bottom: 8px; }
.top-row:last-child { margin-bottom: 0; }
.top-num { width: 26px; height: 26px; border-radius: 50%; background: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--gray); flex: none; }
.top-name { flex: 1; min-width: 0; font-size: 13px; line-height: 1.35; }
.top-name .sku { display: block; font-size: 11px; color: var(--muted); }
.top-cnt { font-weight: 700; font-size: 13px; white-space: nowrap; color: var(--accent); }
.top-card.yellow .top-cnt { color: #b45309; }
.top-cnt.red { color: var(--red); }

@media (max-width: 980px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .top-grid { grid-template-columns: 1fr; }
}
