:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1a1a1a;
  --ink-soft: #5b6470;
  --line: #e3e6ea;
  --primary: #c8102e;
  --primary-dark: #9d0a23;
  --accent: #1a3a5c;
  --ok: #1f7a3a;
  --ok-bg: #e6f4ea;
  --err: #b3261e;
  --err-bg: #fce8e6;
  --warn: #8a6d1c;
  --warn-bg: #fff4d4;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
  --mono: 'SF Mono', 'Consolas', 'Monaco', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  display: inline-grid;
  place-items: center;
  width: 44px; height: 44px;
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  font-size: 22px;
  font-weight: 700;
}
.brand h1 { margin: 0; font-size: 18px; letter-spacing: 0.3px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); }

.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #c7cdd4; transition: background .2s; }
.dot.on, .dot.ok { background: var(--ok); }
.dot.off, .dot.err { background: var(--err); }
.dot.warn { background: var(--warn); }

main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 20px 40px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.tab {
  background: none;
  border: none;
  padding: 12px 22px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all .15s;
}
.tab:hover { color: var(--ink); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 6px; font-size: 18px; }
.card .hint { margin: 0 0 22px; font-size: 13px; color: var(--ink-soft); }
.card .hint code {
  font-family: var(--mono);
  background: #f0f2f5;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
}
.card .hint a { color: var(--accent); text-decoration: none; margin-left: 10px; }
.card .hint a:hover { text-decoration: underline; }
.hint-small { font-size: 12px; color: var(--ink-soft); }

.form {
  display: grid;
  gap: 14px;
  max-width: 460px;
}
.form label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  gap: 6px;
}
.form .req { color: var(--primary); }
.form input, .form select {
  font: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.form input:focus, .form select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(200,16,46,0.12);
}

.btn-primary, .btn-secondary, .btn-danger {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 22px;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  transition: all .15s;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-primary:disabled { background: #c7cdd4; cursor: not-allowed; }
.btn-secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn-secondary:hover { background: #f0f2f5; }
.btn-danger {
  background: var(--err);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: #8b1e18; }

.link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  font: inherit;
  padding: 0;
}

.result {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
}
.result.ok { background: var(--ok-bg); color: var(--ok); }
.result.err { background: var(--err-bg); color: var(--err); }
.result.warn { background: var(--warn-bg); color: var(--warn); }
.result strong { display: block; margin-bottom: 4px; }

.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 50px 20px;
  text-align: center;
  color: var(--ink-soft);
  transition: all .2s;
  cursor: pointer;
}
.dropzone:hover, .dropzone.drag {
  border-color: var(--primary);
  background: #fff5f6;
  color: var(--ink);
}
.dropzone p { margin: 0; font-size: 14px; }
.dropzone strong { color: var(--ink); }

#previewBox { margin-top: 20px; }
#previewBox h3 {
  font-size: 14px;
  margin: 0 0 12px;
  color: var(--ink-soft);
  font-weight: 500;
}
#previewBox h3 span { color: var(--ink); font-weight: 600; }

.tableWrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  max-height: 500px;
  overflow-y: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table th {
  background: #f5f6f8;
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
}
table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table tr:last-child td { border-bottom: none; }

#queueTable th:last-child,
#queueTable td:last-child {
  width: 50px;
  text-align: center;
  padding-right: 14px;
  padding-left: 8px;
  white-space: nowrap;
}
.del-btn {
  background: var(--err-bg);
  color: var(--err);
  border: 1px solid var(--err);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  min-width: 28px;
}
.del-btn:hover { background: var(--err); color: #fff; }

.row-status.ok { color: var(--ok); font-weight: 600; }
.row-status.err { color: var(--err); font-weight: 600; }

.actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
  flex-wrap: wrap;
}

footer {
  padding: 18px 20px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
}

.autocomplete-wrap { position: relative; }
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-top: none;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
  max-height: 320px;
  overflow-y: auto;
  z-index: 50;
}
.ac-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  transition: background .1s;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.active { background: #f5f6f8; }
.ac-item strong { font-family: var(--mono); }
.ac-name { color: var(--ink-soft); font-size: 12px; margin-left: 8px; }
.ac-stock {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--ok-bg);
  color: var(--ok);
  margin-left: 8px;
}
.ac-stock.zero { background: var(--err-bg); color: var(--err); }
.ac-warn {
  font-size: 11px;
  color: var(--warn);
  background: var(--warn-bg);
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 6px;
}

@media (max-width: 600px) {
  .topbar { flex-direction: column; gap: 10px; align-items: flex-start; }
  .form { max-width: 100%; }
  .card { padding: 18px; }
}

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal[hidden] { display: none !important; }
.modal-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  max-width: 500px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal-card h3 { margin: 0 0 8px; font-size: 18px; }