:root {
  --navy: #16233f;
  --navy-light: #223258;
  --copper: #b5651d;
  --copper-light: #d98a3d;
  --cream: #f6f1e7;
  --green: #28a745;
  --red: #dc3545;
  --amber: #d99a1b;
  --grey: #6c757d;
  --bg: #f3f1ec;
  --panel: #ffffff;
  --border: #e3ddd0;
  --text: #232323;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Login screen ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-screen.hidden { display: none; }
.login-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 36px;
  width: 100%;
  max-width: 360px;
}
.login-logo { text-align: center; margin-bottom: 20px; }
.login-logo .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.login-logo > div:first-child { justify-content: center; margin-bottom: 10px; }
.login-title { font-weight: 700; font-size: 1rem; color: var(--navy); }
.login-subtitle { font-size: 0.85rem; color: #888; margin-top: 2px; }
#loginForm label { display: block; font-size: 0.85rem; font-weight: 600; margin: 14px 0 4px; color: #555; }
.login-btn { width: 100%; justify-content: center; margin-top: 18px; }
.login-error {
  margin-top: 12px;
  padding: 8px 10px;
  background: #fdecec;
  color: var(--red);
  border-radius: 6px;
  font-size: 0.85rem;
  text-align: center;
}
.login-error.hidden { display: none; }
#appRoot.hidden { display: none; }

.current-user-label { font-size: 0.8rem; color: var(--cream); opacity: 0.8; }
.logout-btn { padding: 6px 12px; font-size: 0.8rem; }

/* ---------- Header ---------- */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--navy);
  color: var(--cream);
  padding: 14px 28px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: var(--copper);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.5px;
}
.brand-title { font-weight: 700; font-size: 1.05rem; }
.brand-subtitle { font-size: 0.8rem; opacity: 0.75; }
.conn-status { font-size: 0.8rem; padding: 4px 12px; border-radius: 12px; background: rgba(255,255,255,0.12); }
.conn-status.connected { background: #2f6e42; color: #d9f7de; }
.conn-status.disconnected { background: #7a2f2f; color: #fbdada; }

/* ---------- Tabs ---------- */
.tab-bar {
  display: flex;
  gap: 4px;
  background: var(--navy-light);
  padding: 0 20px;
  overflow-x: auto;
}
.tab-btn {
  background: transparent;
  border: none;
  color: #d8dbe6;
  padding: 12px 18px;
  font-size: 0.95rem;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.tab-btn i { font-size: 16px; }
.tab-btn.active {
  color: white;
  border-bottom-color: var(--copper-light);
  font-weight: 600;
}
.badge {
  display: inline-block;
  background: var(--copper);
  color: white;
  font-size: 0.7rem;
  padding: 1px 7px;
  border-radius: 10px;
  margin-left: 4px;
}
.badge.hidden { display: none; }

main { max-width: 1100px; margin: 0 auto; padding: 20px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.grid-2 { display: grid; grid-template-columns: 340px 1fr; gap: 18px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.card h2 { margin-top: 0; font-size: 1.05rem; color: var(--navy); }
.hint { color: #777; font-size: 0.88rem; margin-top: -6px; }

/* ---------- Scan list ---------- */
.scan-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 460px;
  overflow-y: auto;
  font-family: 'Consolas', monospace;
}
.scan-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 8px;
  border-bottom: 1px solid #f0ede4;
}
.scan-list li.duplicate { color: #444; }
.scan-list li.unique { color: var(--red); font-weight: 600; }
.item-delete-btn {
  background: #f1f1f1;
  color: #888;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  min-width: 22px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
}
.item-delete-btn:hover { background: var(--red); color: white; }

/* ---------- Fields ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; color: #555; }
.inline { display: flex; gap: 8px; }
input, select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  background: #fffdfa;
}
.current-style { margin-top: 6px; font-weight: 600; color: var(--copper); }
.draft-select { margin-top: 8px; }

#styleCodeInput, #printerSelect, #cartonNumberInput, #barcodeInput, #draftSelect {
  width: 30%;
  min-width: 160px;
}

.count-badge {
  display: inline-block;
  background: #f0ece0;
  color: var(--navy);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 700;
  margin: 10px 0;
}
.count-badge.big { font-size: 1.15rem; }
.count-badge.sticky-count {
  position: sticky;
  top: 0;
  z-index: 2;
  width: 100%;
  text-align: center;
  margin: 0 0 10px;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
button {
  padding: 10px 14px;
  border: none;
  border-radius: 6px;
  font-size: 0.92rem;
  cursor: pointer;
  color: white;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
button i { font-size: 16px; }
.btn-primary { background: var(--navy); }
.btn-success { background: var(--green); }
.btn-danger { background: var(--red); }
.btn-warning { background: var(--amber); color: #3b2b00; }
.btn-secondary { background: var(--grey); }

/* ---------- Drafts tab ---------- */
.drafts-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.draft-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fdfcf9;
}
.draft-item .draft-info strong { color: var(--navy); }
.draft-item .draft-info div { font-size: 0.85rem; color: #666; margin-top: 2px; }
.draft-item .draft-actions { display: flex; gap: 8px; }
.empty-state { color: #888; padding: 20px 0; text-align: center; }

/* ---------- Packing list tab ---------- */
.status-banner {
  margin: 10px 0;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
}
.status-banner.hidden { display: none; }
.status-banner.closed { background: #fdf0e6; color: var(--copper); border: 1px solid #f0d9c0; }
.status-banner.confirmed { background: #e8f5ea; color: #1e7a3d; border: 1px solid #cdeccf; }
.search-input { margin: 12px 0; }
.table-wrap { overflow-y: auto; max-height: 460px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.9rem; }
th { background: #f8f7f3; position: sticky; top: 0; }
td button { padding: 4px 8px; font-size: 0.8rem; background: var(--red); }

/* ---------- Reports tab ---------- */
.report-summary {
  background: #f8f7f3;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 6px;
  font-size: 0.9rem;
  min-height: 40px;
}

/* ---------- Sticker modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-content {
  background: white;
  padding: 22px;
  border-radius: 12px;
  width: 90%;
  max-width: 480px;
}
.sticker-label {
  background: #fff;
  border: 2px dashed #999;
  border-radius: 4px;
  padding: 16px 20px;
  font-family: 'Consolas', monospace;
  font-size: 0.95rem;
  line-height: 1.6;
  aspect-ratio: 2 / 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.sticker-label .sl-title { font-weight: 700; }
.sticker-label .sl-total { font-weight: 700; margin-top: 6px; border-top: 1px dashed #ccc; padding-top: 6px; }
.sticker-actions { display: flex; gap: 10px; margin-top: 16px; }
.sticker-print-status { margin-top: 10px; font-size: 0.85rem; color: #555; min-height: 1.2em; }
