:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --border: #dde3ea;
  --text: #15202b;
  --muted: #5b6876;
  --brand: #103a57;
  --brand-ink: #ffffff;
  --accent: #1667a8;
  --accent-hover: #11558b;
  --focus: rgba(22, 103, 168, 0.28);
  --in: #12753c;
  --in-bg: #e5f5eb;
  --low: #8a5a00;
  --low-bg: #fff3d6;
  --out: #a2302b;
  --out-bg: #fbe9e7;
  --demo-bg: #fff3d6;
  --demo-ink: #6b4a00;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #171e26;
    --surface-2: #1c242e;
    --border: #2b3542;
    --text: #e6ebf0;
    --muted: #9aa7b4;
    --brand: #0c2b41;
    --accent: #4a9be0;
    --accent-hover: #6aaee8;
    --focus: rgba(74, 155, 224, 0.35);
    --in: #5fd18e;
    --in-bg: rgba(95, 209, 142, 0.12);
    --low: #f0c060;
    --low-bg: rgba(240, 192, 96, 0.13);
    --out: #f08a80;
    --out-bg: rgba(240, 138, 128, 0.12);
    --demo-bg: #3a2f12;
    --demo-ink: #f3d68a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

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

html,
body {
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

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

/* ---------- Buttons & inputs ---------- */

.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0 18px;
  height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.btn:focus-visible,
input:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.primary:disabled {
  opacity: 0.6;
  cursor: progress;
}

.btn.ghost {
  background: transparent;
  color: inherit;
  border-color: var(--border);
}

.btn.ghost:hover {
  background: var(--surface-2);
}

.btn.small {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  border-radius: 8px;
}

.btn.block {
  width: 100%;
}

.btn svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

input[type="text"],
input[type="password"],
input[type="search"] {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  height: 44px;
  padding: 0 14px;
  width: 100%;
  min-width: 0;
}

/* ---------- Top bar ---------- */

.topbar {
  background: var(--brand);
  color: var(--brand-ink);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.brand img {
  flex: none;
  border-radius: 8px;
}

.brand-name {
  font-weight: 700;
  line-height: 1.2;
}

.brand-sub {
  font-size: 13px;
  opacity: 0.8;
  line-height: 1.2;
}

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

.user-name {
  font-size: 13px;
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .btn.ghost {
  color: var(--brand-ink);
  border-color: rgba(255, 255, 255, 0.35);
}

.topbar .btn.ghost:hover {
  background: rgba(255, 255, 255, 0.1);
}

.demo-banner {
  background: var(--demo-bg);
  color: var(--demo-ink);
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
}

/* ---------- Main ---------- */

.wrap {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 16px 40px;
  flex: 1;
}

.search-panel {
  margin-bottom: 18px;
}

.search-title {
  font-size: 26px;
  line-height: 1.2;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.search-lede {
  margin: 0 0 16px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--in);
  box-shadow: 0 0 0 0 var(--in);
  animation: pulse 2.4s ease-out infinite;
  flex: none;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--in) 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none; }
}

.search {
  position: relative;
  display: flex;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  box-shadow: var(--shadow);
}

.search input {
  border: none;
  height: 48px;
  font-size: 18px;
  padding-left: 40px;
  background: transparent;
  font-family: var(--mono);
  letter-spacing: 0.01em;
}

.search input::placeholder {
  font-family: "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0;
  color: var(--muted);
}

.search .btn {
  height: 48px;
  padding: 0 24px;
}

.search-icon {
  position: absolute;
  left: 20px;
  top: 50%;
  width: 20px;
  height: 20px;
  transform: translateY(-50%);
  fill: none;
  stroke: var(--muted);
  stroke-width: 2.2;
  stroke-linecap: round;
  pointer-events: none;
}

.tip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 10px 12px 10px 14px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 32px;
  margin-bottom: 10px;
}

.status {
  color: var(--muted);
  font-size: 14px;
}

.status.error {
  color: var(--out);
  font-weight: 600;
}

.status.busy::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  vertical-align: -1px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Results ---------- */

.results-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
}

.results-table th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: var(--surface-2);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.results-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.results-table tr:last-child td {
  border-bottom: none;
}

.results-table .num {
  text-align: right;
  white-space: nowrap;
}

.part-number {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}

.exact-tag {
  display: inline-block;
  margin-left: 8px;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0 7px;
  vertical-align: 2px;
}

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

.wh-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.wh {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  line-height: 1.6;
  white-space: nowrap;
}

.wh-name {
  font-weight: 600;
  color: var(--muted);
}

.wh-qty {
  font-weight: 700;
  color: var(--in);
  font-variant-numeric: tabular-nums;
}

.wh.none {
  background: transparent;
  border-style: dashed;
}

.wh.none .wh-qty {
  color: var(--muted);
  font-weight: 600;
}

.qty {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 96px;
  padding: 6px 12px;
  border-radius: 10px;
  line-height: 1.15;
}

.qty-value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.qty-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.qty.in { background: var(--in-bg); color: var(--in); }
.qty.out { background: var(--out-bg); color: var(--out); }

.onhand {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.more-note {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--muted);
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}

.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty strong {
  display: block;
  color: var(--text);
  font-size: 16px;
  margin-bottom: 4px;
}

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 16px;
}

/* ---------- Login ---------- */

.login-page {
  justify-content: center;
}

.login-wrap {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 40px 16px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.login-brand img {
  border-radius: 10px;
}

.login-brand .brand-name {
  font-size: 18px;
}

.login-brand .brand-sub {
  color: var(--muted);
  opacity: 1;
  font-size: 14px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.login-card {
  padding: 26px 24px 24px;
}

.login-card h1 {
  font-size: 22px;
  margin: 0 0 16px;
}

.note {
  background: var(--demo-bg);
  color: var(--demo-ink);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin: -4px 0 16px;
}

.note:empty {
  display: none;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
  margin: 4px 0 18px;
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  margin: 0;
}

.error {
  color: var(--out);
  background: var(--out-bg);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 14px;
}

.login-help {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-top: 18px;
}

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  .user-name { display: none; }
  .wrap { padding-top: 20px; }
  .search-title { font-size: 22px; }
  .search { padding: 6px; gap: 6px; }
  .search .btn { padding: 0 16px; }
  .search input { font-size: 16px; }

  .results-table thead { display: none; }
  .results-table,
  .results-table tbody,
  .results-table tr,
  .results-table td { display: block; width: 100%; }
  .results-table tr {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
  }
  .results-table tr:last-child { border-bottom: none; }
  .results-table td { padding: 0; border: none; }
  .results-table td.col-part { grid-column: 1; grid-row: 1; align-self: center; }
  .results-table td.col-desc { grid-column: 1 / span 2; grid-row: 2; font-size: 13px; }
  .results-table td.col-avail { grid-column: 2; grid-row: 1; align-self: start; }
  .results-table td.col-onhand { grid-column: 1; grid-row: 3; text-align: left; font-size: 13px; }
  .results-table td.col-onhand::before { content: "On hand: "; }
  .part-number { white-space: normal; word-break: break-all; }
  .qty { min-width: 84px; }
}
