/* Planufac Bin Lookup
   Brand tokens from PLANUFAC CODEBASE LATEST:
   $primary #2f619e · $indigo #346CB0 · $orange #f3c16c · $gray-100 #f6f7f9
   Login shell mirrors app.devvizion.com (Manager IO) OTP layout.
*/

:root {
  --primary: #2f619e;
  --indigo: #346cb0;
  --accent: #2f619e;
  --accent-hover: #346cb0;
  --accent-ink: #ffffff;
  --orange: #f3c16c;
  --bg: #f6f7f9;
  --ink: #1a2332;
  --muted: #5c6b7a;
  --line: #d7dde6;
  --field-bg: #ffffff;
  --field-border: rgba(47, 97, 158, 0.28);
  --field-focus: rgba(47, 97, 158, 0.55);
  --stage-bg: #243f68;
  --stage-bg-deep: #1a3358;
  --stage-ink: #f6f7f9;
  --stage-muted: rgba(246, 247, 249, 0.72);
  --stage-line: rgba(243, 193, 108, 0.35);
  --desk-bg: #f6f7f9;
  --desk-ink: #1a2332;
  --desk-muted: rgba(26, 35, 50, 0.62);
  --desk-border: rgba(47, 97, 158, 0.14);
  --msg-info-bg: rgba(47, 97, 158, 0.08);
  --msg-info-border: rgba(47, 97, 158, 0.22);
  --msg-info-ink: #1e3f6b;
  --msg-ok-bg: rgba(27, 107, 58, 0.1);
  --msg-ok-border: rgba(27, 107, 58, 0.28);
  --msg-ok-ink: #14532d;
  --msg-err-bg: rgba(180, 40, 50, 0.08);
  --msg-err-border: rgba(180, 40, 50, 0.28);
  --msg-err-ink: #8c1d2c;
  --radius: 12px;
  --font: "Manrope", "Segoe UI", system-ui, -apple-system, sans-serif;
  --shadow-btn: 0 10px 24px color-mix(in srgb, var(--primary) 22%, transparent);
  --table-head: #2f619e;
  --table-head-ink: #f6f7f9;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  letter-spacing: 0.005em;
  -webkit-font-smoothing: antialiased;
  color: var(--ink);
  background: var(--bg);
}

.view[hidden],
.hidden {
  display: none !important;
}

/* ── Login shell (Manager IO pattern, Planufac palette) ── */

.login-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
}

.login-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 2rem;
  padding: clamp(1.75rem, 4vw, 3.25rem);
  background: linear-gradient(
    165deg,
    var(--stage-bg) 0%,
    var(--stage-bg-deep) 55%,
    var(--stage-bg) 100%
  );
  color: var(--stage-ink);
  overflow: hidden;
  min-height: 36vh;
}

.login-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 50% at 18% 88%, rgba(243, 193, 108, 0.16), transparent 60%),
    radial-gradient(ellipse 40% 40% at 92% 12%, rgba(52, 108, 176, 0.35), transparent 55%);
  pointer-events: none;
}

.login-stage::after {
  content: "";
  position: absolute;
  right: -8%;
  bottom: -20%;
  width: min(52vw, 28rem);
  height: min(52vw, 28rem);
  border: 1px solid var(--stage-line);
  border-radius: 50%;
  opacity: 0.55;
  pointer-events: none;
}

.stage-top,
.stage-hero,
.stage-meta {
  position: relative;
  z-index: 1;
}

.brand-logo {
  display: block;
  height: auto;
  object-fit: contain;
}

/* Login stage: white mark on navy (restored) */
.brand-logo-stage {
  width: min(180px, 52vw);
  height: auto;
  filter: brightness(0) invert(1);
}

/* App header: medium-blue brand mark (#346cb0) on white — never invert */
.brand-logo-nav {
  width: 132px;
  height: auto;
  filter: none !important;
}

.stage-title {
  margin: 0;
  font-size: clamp(2.75rem, 8vw, 5.25rem);
  font-weight: 800;
  line-height: 0.92;
  letter-spacing: -0.045em;
  color: var(--stage-ink);
}

.stage-title em {
  font-style: normal;
  color: var(--orange);
}

.stage-lede {
  margin: 1.15rem 0 0;
  max-width: 30ch;
  font-size: clamp(0.95rem, 1.6vw, 1.08rem);
  line-height: 1.55;
  font-weight: 500;
  color: var(--stage-muted);
}

.stage-meta {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--stage-muted);
}

.login-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(1.75rem, 4vw, 3.5rem);
  background: var(--desk-bg);
  color: var(--desk-ink);
}

.card-inner {
  width: min(100%, 26rem);
  margin-inline: auto;
}

.card-eyebrow {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--primary);
}

.login-title {
  margin: 0.55rem 0 0;
  font-size: clamp(1.5rem, 3vw, 1.8rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.login-copy {
  margin: 0.75rem 0 0;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--desk-muted);
}

.divider {
  height: 1px;
  margin: 1.4rem 0;
  background: linear-gradient(90deg, var(--desk-border), transparent 90%);
  border: 0;
}

.field {
  margin-top: 1rem;
}

.field-label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--desk-ink);
}

.field-input {
  width: 100%;
  min-height: 3rem;
  border-radius: var(--radius);
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  color: var(--desk-ink);
  padding: 0.8rem 1rem;
  font: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field-input::placeholder {
  color: color-mix(in srgb, var(--desk-muted) 70%, transparent);
}

.field-input:focus {
  border-color: var(--field-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

.primary-button {
  width: 100%;
  min-height: 3rem;
  margin-top: 1.05rem;
  border: 0;
  border-radius: var(--radius);
  padding: 0.8rem 1.1rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  background: var(--primary);
  color: var(--accent-ink);
  box-shadow: var(--shadow-btn);
  transition: background 0.15s ease, transform 0.15s ease;
}

.primary-button:hover {
  background: var(--indigo);
  transform: translateY(-1px);
}

.primary-button:active {
  transform: translateY(0) scale(0.99);
}

.text-button {
  display: block;
  width: 100%;
  margin-top: 0.75rem;
  border: 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  padding: 0.4rem;
}

.text-button:hover {
  color: var(--indigo);
  text-decoration: underline;
}

.message {
  margin-top: 1.15rem;
  border-radius: var(--radius);
  border: 1px solid var(--msg-info-border);
  padding: 0.85rem 1rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.message.info {
  background: var(--msg-info-bg);
  border-color: var(--msg-info-border);
  color: var(--msg-info-ink);
}

.message.success,
.message.ok {
  background: var(--msg-ok-bg);
  border-color: var(--msg-ok-border);
  color: var(--msg-ok-ink);
}

.message.error,
.message.err {
  background: var(--msg-err-bg);
  border-color: var(--msg-err-border);
  color: var(--msg-err-ink);
}

@media (min-width: 900px) {
  .login-shell {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
  }

  .login-stage {
    min-height: 100dvh;
    padding: clamp(2.5rem, 5vw, 4.5rem);
  }

  .login-card {
    min-height: 100dvh;
    padding: clamp(2.5rem, 5vw, 4.5rem);
    border-left: 1px solid var(--desk-border);
  }

  .card-inner {
    margin-inline: 0;
    margin-left: clamp(0rem, 4vw, 2rem);
  }
}

/* ── App shell ─────────────────────────────────── */

.app-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.app-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.01em;
  padding-left: 14px;
  border-left: 1px solid var(--line);
}

.app-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-chip {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.08s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 22%, transparent);
}

.btn.primary:hover {
  background: var(--indigo);
  border-color: var(--indigo);
}

.btn.ghost {
  background: transparent;
}

.btn.ghost:hover {
  background: var(--bg);
  border-color: color-mix(in srgb, var(--primary) 35%, var(--line));
}

.btn.sm {
  padding: 0.4rem 0.7rem;
  font-size: 0.78rem;
}

.sort-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink);
}

.sort-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.sort-toggle-ui {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: #cfd6e0;
  border: 1px solid var(--line);
  transition: background 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}

.sort-toggle-ui::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(26, 35, 50, 0.2);
  transition: transform 0.15s ease;
}

.sort-toggle input:checked + .sort-toggle-ui {
  background: var(--primary);
  border-color: var(--primary);
}

.sort-toggle input:checked + .sort-toggle-ui::after {
  transform: translateX(16px);
}

.sort-toggle input:focus-visible + .sort-toggle-ui {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.sort-toggle input:disabled + .sort-toggle-ui,
.sort-toggle:has(input:disabled) {
  opacity: 0.45;
  cursor: not-allowed;
}

.sort-toggle-label {
  white-space: nowrap;
}

.btn.danger {
  color: var(--msg-err-ink);
  border-color: color-mix(in srgb, var(--msg-err-ink) 30%, var(--line));
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.app-main {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  min-height: calc(100dvh - 61px);
}

.query-block,
.results-block {
  min-width: 0;
  padding: 16px 18px;
}

.query-block {
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.results-block {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.block-head-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.results-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 16px;
}

.block-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.hint {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.sku-limit-note {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.35;
}

.duplicate-panel {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, #e6b800 55%, var(--line));
  border-radius: 10px;
  background: #fff8d6;
}

.duplicate-panel.hidden {
  display: none !important;
}

.duplicate-panel-title {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #8a6d00;
  margin-bottom: 6px;
}

.duplicate-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 140px;
  overflow: auto;
}

.duplicate-list li {
  font-size: 0.78rem;
  font-weight: 700;
  color: #5c4a00;
  font-variant-numeric: tabular-nums;
}

.duplicate-list .dup-count {
  color: #8a6d00;
  font-weight: 800;
}

/* Result rows for SKUs that appeared more than once in the paste */
tbody tr.row-duplicate td {
  background: #fff3a3 !important;
}

tbody tr.row-duplicate:hover td:not(.cell-selected) {
  background: #ffe978 !important;
}

tbody tr.row-duplicate td.cell-selected {
  background: color-mix(in srgb, #fff3a3 55%, rgba(47, 97, 158, 0.28)) !important;
}

.sku-editor {
  position: relative;
  min-height: 220px;
  border-radius: var(--radius);
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  overflow: hidden;
}

.sku-editor:focus-within {
  border-color: var(--field-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.sku-highlight,
#sku-input {
  margin: 0;
  width: 100%;
  min-height: 220px;
  padding: 0.85rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  letter-spacing: normal;
  tab-size: 4;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-sizing: border-box;
  border: 0;
  border-radius: 0;
}

.sku-highlight {
  position: absolute;
  inset: 0;
  overflow: auto;
  pointer-events: none;
  color: transparent;
  background: transparent;
  z-index: 0;
}

.sku-highlight .sku-line {
  display: block;
  min-height: 1.5em;
  border-radius: 4px;
}

.sku-highlight .sku-line.is-dup {
  background: #fff3a3;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #e6b800 35%, transparent);
}

#sku-input {
  position: relative;
  z-index: 1;
  resize: vertical;
  background: transparent;
  color: var(--ink);
  caret-color: var(--ink);
  outline: none;
}

textarea:not(#sku-input) {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border-radius: var(--radius);
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  color: var(--ink);
  padding: 0.85rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  outline: none;
}

textarea:not(#sku-input):focus {
  border-color: var(--field-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.query-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.run-status {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}

.run-status.busy {
  color: var(--primary);
}

.run-status.err {
  color: var(--msg-err-ink);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  max-height: calc(100dvh - 160px);
  box-shadow: 0 1px 2px rgba(26, 35, 50, 0.04);
  outline: none;
  user-select: none;
  -webkit-user-select: none;
}

.table-wrap:focus {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

thead th {
  position: sticky;
  top: 0;
  background: var(--table-head);
  color: var(--table-head-ink);
  text-align: left;
  padding: 10px 9px;
  white-space: nowrap;
  font-weight: 700;
  z-index: 1;
  border-right: 1px solid rgba(246, 247, 249, 0.18);
}

tbody td {
  padding: 9px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid #eef1f5;
  white-space: nowrap;
  vertical-align: top;
  cursor: cell;
}

tbody tr:nth-child(even) td {
  background: rgba(47, 97, 158, 0.03);
}

tbody tr:hover td:not(.cell-selected) {
  background: rgba(243, 193, 108, 0.12);
}

tbody td.cell-selected {
  background: rgba(47, 97, 158, 0.22) !important;
  outline: 1px solid color-mix(in srgb, var(--primary) 55%, transparent);
  outline-offset: -1px;
}

.cell-menu {
  position: fixed;
  z-index: 60;
  min-width: 140px;
  padding: 4px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(26, 35, 50, 0.16);
}

.cell-menu button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}

.cell-menu button:hover {
  background: rgba(47, 97, 158, 0.1);
  color: var(--primary);
}

td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.item {
  white-space: normal;
  min-width: 150px;
  max-width: 260px;
}

.empty-row td {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
}

.miss {
  color: var(--msg-err-ink);
  font-weight: 700;
}

/* ── Allowlist modal ───────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 35, 50, 0.45);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 520px);
  max-height: min(88dvh, 720px);
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(26, 35, 50, 0.18);
  padding: 18px 18px 20px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.modal-copy {
  margin: 8px 0 14px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.allowlist-form {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
}

.allowlist-table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.allowlist-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.allowlist-table th,
.allowlist-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.allowlist-table th {
  background: var(--bg);
  font-weight: 700;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.allowlist-table tr:last-child td {
  border-bottom: 0;
}

.role-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(47, 97, 158, 0.1);
  color: var(--primary);
}

.role-pill.user {
  background: rgba(92, 107, 122, 0.12);
  color: var(--muted);
}

@media (max-width: 900px) {
  .app-main {
    grid-template-columns: 1fr;
  }

  .query-block {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .table-wrap {
    max-height: 55dvh;
  }

  .app-title {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .primary-button,
  .btn {
    transition: none;
  }

  .primary-button:hover,
  .btn:active {
    transform: none;
  }
}
