*,
*::before,
*::after { box-sizing: border-box; }

:root {
  --bg: #070c14;
  --panel: #0e1622;
  --panel-2: #131e2e;
  --line: #1d2b3d;
  --line-soft: #16212f;
  --text: #e6edf7;
  --muted: #8b9db5;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
}

html,
body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1100px 620px at 72% -12%, #14283f 0%, rgba(7, 12, 20, 0) 62%),
    radial-gradient(900px 500px at 0% 0%, #10202f 0%, rgba(7, 12, 20, 0) 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.app {
  max-width: 1640px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

/* ---------------- top bar ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 0 12px;
  margin-bottom: 8px;
  background: linear-gradient(to bottom, rgba(7, 12, 20, 0.96) 60%, rgba(7, 12, 20, 0));
  backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 21px;
  background: linear-gradient(145deg, #1c3557, #0f1d2e);
  border: 1px solid #25476b;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.tabs { display: flex; gap: 6px; background: var(--panel); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }

.tab {
  padding: 8px 16px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}

.tab:hover { color: var(--text); }
.tab.active { color: #04121c; background: linear-gradient(140deg, var(--accent), var(--accent-2)); }

/* ---------------- layout ---------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(320px, 384px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

@media (max-width: 1023px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.sidebar { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.card {
  background: linear-gradient(180deg, rgba(19, 30, 46, 0.9), rgba(14, 22, 34, 0.92));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

.card.wide { max-width: 980px; margin: 8px auto 0; }

.card h2 {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: #b9c9dd;
  display: flex;
  align-items: center;
  gap: 8px;
}

.step {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 800;
  color: #04121c;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
}

.pill {
  margin-left: auto;
  background: #17263a;
  border: 1px solid var(--line);
  color: #a9bdd6;
  font-size: 11.5px;
  padding: 1px 9px;
  border-radius: 99px;
  letter-spacing: 0;
}

.card-foot { margin-top: 10px; display: flex; justify-content: flex-end; }

/* ---------------- controls ---------------- */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  background: #0a1220;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 4px;
}

.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.seg-btn:hover { color: var(--text); background: #14203150; }
.seg-btn.active { color: #04121c; background: linear-gradient(140deg, var(--accent), var(--accent-2)); }
.seg.small .seg-btn { font-size: 12.5px; padding: 8px 6px; }

.specs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 0;
}

.specs div {
  background: #0a1220;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  padding: 7px 10px;
}

.specs dt { font-size: 11px; color: var(--muted); margin: 0; }
.specs dd { margin: 2px 0 0; font-size: 13.5px; font-weight: 650; color: #dbe8f7; }

.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }

input[type="text"],
input[type="number"] {
  width: 100%;
  background: #0a1220;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  padding: 9px 11px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: #2b6d95;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14);
}

input::placeholder { color: #465a72; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: #b6c6d9;
  margin-bottom: 8px;
  cursor: pointer;
}

.check input { margin: 3px 0 0; accent-color: var(--accent-2); width: 15px; height: 15px; flex: 0 0 15px; }

.form-error {
  margin: 4px 0 8px;
  font-size: 12.5px;
  color: #fecaca;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: 9px;
  padding: 8px 10px;
}

.form-actions { display: flex; gap: 8px; margin-top: 4px; }

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 650;
  padding: 10px 16px;
  cursor: pointer;
  transition: transform 0.12s, filter 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.55; cursor: progress; }

.btn.primary {
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #04121c;
  box-shadow: 0 6px 18px rgba(14, 165, 233, 0.28);
}

.btn.primary:hover { filter: brightness(1.08); }

.btn.ghost {
  background: #101b29;
  border-color: var(--line);
  color: #c3d3e6;
}

.btn.ghost:hover { background: #152334; border-color: #29405a; }
.small-btn { padding: 7px 12px; font-size: 12.5px; }

/* ---------------- item list ---------------- */
.item-list { display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; padding-right: 2px; }

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #0a1220;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 9px 10px;
}

.swatch { width: 12px; height: 12px; border-radius: 4px; flex: 0 0 12px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.14); }

.item-main { min-width: 0; flex: 1 1 auto; }
.item-name { font-size: 13.5px; font-weight: 650; color: #e2ecf9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { font-size: 11.5px; color: var(--muted); margin-top: 1px; }

.item-actions { display: flex; gap: 2px; flex: 0 0 auto; }

.icon-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: #93a8c2;
  font-size: 13px;
  line-height: 1;
  padding: 6px 7px;
  border-radius: 8px;
  cursor: pointer;
}

.icon-btn:hover { background: #182739; border-color: #22364d; color: #e6edf7; }

.empty {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  background: #0a1220;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

/* ---------------- stage ---------------- */
.stage { min-width: 0; display: flex; flex-direction: column; gap: 12px; }

@media (min-width: 1024px) {
  .stage { position: sticky; top: 84px; }
}

.stage-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.bins { display: flex; gap: 6px; flex-wrap: wrap; flex: 1 1 auto; min-width: 0; }

.bin-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #0e1622;
  color: #a9bdd6;
  font: inherit;
  font-size: 12.5px;
  font-weight: 650;
  padding: 7px 12px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
}

.bin-btn:hover { border-color: #2b6d95; color: #e6edf7; }
.bin-btn.active { background: linear-gradient(140deg, #1b4a6b, #123147); border-color: #2f8fb5; color: #d9f2ff; }

.stage-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.canvas-wrap {
  position: relative;
  width: 100%;
  height: clamp(300px, 44vh, 560px);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0a1018;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
}

.canvas-wrap canvas { display: block; width: 100%; height: 100%; }

.canvas-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  gap: 4px;
  padding: 24px;
  background: radial-gradient(circle at 50% 40%, rgba(20, 40, 63, 0.65), rgba(10, 16, 24, 0.92));
}

.ce-title { margin: 0; font-size: 15px; font-weight: 700; }
.canvas-empty .muted { margin: 0; font-size: 13px; color: var(--muted); max-width: 340px; }

.canvas-hint {
  position: absolute;
  left: 12px;
  bottom: 10px;
  font-size: 11.5px;
  color: #6f87a1;
  background: rgba(7, 12, 20, 0.6);
  padding: 3px 9px;
  border-radius: 99px;
  pointer-events: none;
}

.canvas-badge {
  position: absolute;
  right: 12px;
  top: 12px;
  font-size: 12px;
  font-weight: 650;
  color: #d9f2ff;
  background: rgba(11, 30, 45, 0.85);
  border: 1px solid #2f5f7d;
  padding: 4px 11px;
  border-radius: 99px;
  pointer-events: none;
}

/* ---------------- summary ---------------- */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; }

.stat {
  background: linear-gradient(180deg, rgba(19, 30, 46, 0.9), rgba(14, 22, 34, 0.92));
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
}

.stat .label { font-size: 11.5px; color: var(--muted); }
.stat .value { font-size: 20px; font-weight: 750; letter-spacing: -0.4px; margin-top: 2px; }
.stat .sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.stat.good .value { color: var(--good); }
.stat.warn .value { color: var(--warn); }
.stat.bad .value { color: var(--bad); }
.stat.info .value { color: var(--accent); }

.bar { height: 5px; border-radius: 99px; background: #16232f; margin-top: 8px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #22d3ee, #34d399); }

.notice {
  margin-top: 10px;
  font-size: 12.5px;
  border-radius: 10px;
  padding: 9px 12px;
  border: 1px solid rgba(251, 191, 36, 0.32);
  background: rgba(251, 191, 36, 0.1);
  color: #fde68a;
}

.notice.err { border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.1); color: #fecaca; }

/* ---------------- breakdown ---------------- */
.breakdown { margin-top: 2px; }

.panel {
  background: linear-gradient(180deg, rgba(19, 30, 46, 0.9), rgba(14, 22, 34, 0.92));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: #b9c9dd;
  font-weight: 700;
}

.table-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 460px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); font-weight: 650; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td.name { font-weight: 600; color: #e2ecf9; white-space: normal; min-width: 140px; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 7px; vertical-align: middle; }

.binlist { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.binlist span { font-size: 11.5px; color: #a9bdd6; background: #10202f; border: 1px solid var(--line-soft); border-radius: 7px; padding: 2px 8px; }

/* ---------------- plans ---------------- */
.plan-list { display: flex; flex-direction: column; gap: 10px; }

.plan {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #0a1220;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 12px 14px;
  flex-wrap: wrap;
}

.plan-main { flex: 1 1 240px; min-width: 0; }
.plan-name { font-size: 14px; font-weight: 700; color: #e6edf7; }
.plan-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.plan-stats { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: #a9bdd6; }
.plan-stats b { color: #e6edf7; font-size: 13.5px; }

.muted { color: var(--muted); }

@media (max-width: 640px) {
  .app { padding: 0 12px 40px; }
  .brand-text h1 { font-size: 15.5px; }
  .brand-text p { font-size: 11.5px; }
  .tabs { width: 100%; }
  .tab { flex: 1 1 0; text-align: center; padding: 8px 10px; }
  .stage-head { flex-direction: column; align-items: stretch; }
  .stage-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .stage-actions .btn:first-child { grid-column: 1 / -1; }
  .canvas-wrap { height: clamp(260px, 38vh, 400px); }
  .stat .value { font-size: 17px; }
  .item-list { max-height: 280px; }
}

/* ---------------- bulk import (Excel / CSV / ảnh) ---------------- */
.small { font-size: 12px; line-height: 1.45; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.card.accent {
  border-color: #1e4463;
  background: linear-gradient(180deg, rgba(20, 42, 63, 0.92), rgba(14, 22, 34, 0.94));
}

.card.accent h2 { color: #cfe3f7; }

.wide-btn { width: 100%; margin-top: 10px; }

body.modal-open { overflow: hidden; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(3, 7, 12, 0.74);
  backdrop-filter: blur(4px);
}

.modal-card {
  width: min(940px, 100%);
  max-height: min(88vh, 920px);
  display: flex;
  flex-direction: column;
  background: #0c1521;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line-soft);
}

.modal-head h3 { margin: 0; font-size: 15px; font-weight: 700; color: #e6edf7; }

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 1px solid var(--line-soft);
  background: #0a1220;
}

.modal-foot-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.import-panel { display: flex; flex-direction: column; gap: 8px; }
.import-panel p { margin: 0; }

#import-text {
  width: 100%;
  min-height: 148px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--text);
  background: #0a1220;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

#import-text::placeholder { color: #566b85; }
#import-text:focus { outline: 2px solid #1e4d70; outline-offset: 1px; }

.import-panel input[type="file"] {
  width: 100%;
  font-size: 12.5px;
  color: var(--muted);
  background: #0a1220;
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 10px;
}

.import-panel input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid #29405a;
  background: #152334;
  color: #dbe8f7;
  font-size: 12.5px;
  cursor: pointer;
}

.import-error {
  margin: 0;
  font-size: 12.5px;
  color: #fecdd3;
  background: #3b0f1c;
  border: 1px solid #7f1d33;
  border-radius: 9px;
  padding: 8px 10px;
}

.import-summary { font-size: 12.5px; color: #a9bdd6; min-height: 18px; }
.import-summary b { color: #e6edf7; }

.import-table-wrap {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: #0a1220;
}

table.import-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }

table.import-table th,
table.import-table td {
  padding: 7px 9px;
  text-align: left;
  border-bottom: 1px solid #14202d;
  white-space: nowrap;
}

table.import-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #101c2b;
  color: #9fb4cd;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

table.import-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.import-table tr.bad td { background: rgba(127, 29, 51, 0.2); }
table.import-table tbody tr:last-child td { border-bottom: 0; }

.import-badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 99px;
  border: 1px solid;
  white-space: nowrap;
}

.import-badge.ok { color: #6ee7b7; border-color: #1c6b4f; background: #052a1f; }
.import-badge.err { color: #fda4af; border-color: #7f1d33; background: #2c0b14; }

.image-preview {
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 8px;
  background: #0a1220;
}

.image-preview img {
  display: block;
  max-width: 100%;
  max-height: 220px;
  margin: 0 auto;
  border-radius: 8px;
}

@media (max-width: 640px) {
  .modal { padding: 8px; }
  .modal-card { max-height: 94vh; }
  .modal-body { padding: 12px; }
  table.import-table th,
  table.import-table td { padding: 6px; font-size: 12px; }
}

.import-summary .bad-text { color: #fda4af; }
