:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --line: #dbe1ea;
  --primary: #1f6feb;
  --primary-hover: #195fc9;
  --accent: #f6b51b;
  --success: #16825d;
  --success-soft: #e9f8f2;
  --danger: #c93636;
  --danger-soft: #fff0f0;
  --shadow: 0 16px 40px rgba(23, 32, 51, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgba(31, 111, 235, 0.22);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.shell { width: min(1080px, calc(100% - 32px)); margin-inline: auto; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.site-header {
  background: #172033;
  color: #fff;
  border-bottom: 4px solid var(--accent);
}
.header-content {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: #fff;
  text-decoration: none;
}
.brand-mark {
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 10px; background: var(--accent); color: #172033;
  font-size: 14px; font-weight: 900; letter-spacing: -0.4px;
}
.brand strong { display: block; font-size: 16px; line-height: 1.2; }
.brand small { display: block; margin-top: 2px; color: #b8c1d1; font-size: 11px; }
.admin-link {
  color: #d9e0eb; text-decoration: none; font-size: 13px; font-weight: 650;
  padding: 8px 10px; border-radius: 8px;
}
.admin-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.header-actions { display: flex; align-items: center; gap: 8px; }

.public-main { padding-block: 54px 70px; }
.hero { max-width: 730px; margin: 0 auto 25px; text-align: center; }
.eyebrow {
  color: #466080; font-size: 11px; font-weight: 800; letter-spacing: 1.2px;
  text-transform: uppercase;
}
.hero h1, .admin-title-row h1, .auth-heading h1 {
  margin: 7px 0 8px; font-size: clamp(26px, 4vw, 38px); line-height: 1.15; letter-spacing: -0.8px;
}
.hero p, .auth-heading p { margin: 0; color: var(--muted); font-size: 15px; }

.search-panel {
  max-width: 850px; margin: 0 auto;
  padding: 18px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.search-form { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 10px; }
.search-field { position: relative; }
.search-field svg {
  position: absolute; top: 50%; left: 16px; transform: translateY(-50%); color: #7d8899;
}
.search-field input {
  width: 100%; height: 54px; padding: 0 46px 0 48px;
  border: 1.5px solid #cfd6e1; border-radius: 11px; background: #fff;
  color: var(--text); font-size: 16px; outline: none;
}
.search-field input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(31,111,235,.10); }
.clear-button {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent;
  color: #7d8899; cursor: pointer; font-size: 23px; line-height: 1;
}
.clear-button:hover { background: #eef1f5; color: var(--text); }
.search-submit { min-width: 112px; }
.search-meta {
  min-height: 21px; margin-top: 9px; padding-inline: 2px;
  display: flex; justify-content: space-between; gap: 16px;
  color: var(--muted); font-size: 11px;
}
.connection-status { color: var(--success); font-weight: 700; }
.connection-status::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: currentColor; }
.connection-status.is-offline { color: var(--danger); }

.button {
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 0 16px; border: 1px solid transparent; border-radius: 10px;
  font-weight: 750; font-size: 14px; cursor: pointer; text-decoration: none;
  transition: background .16s ease, border-color .16s ease, transform .16s ease;
}
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .62; cursor: wait; }
.button-primary { background: var(--primary); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--primary-hover); }
.button-secondary { background: #fff; color: #344054; border-color: var(--line); }
.button-secondary:hover { background: #f7f8fa; }
.button-ghost { color: #fff; background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.13); }
.button-danger { color: var(--danger); background: #fff; border-color: #f0caca; }
.button-danger:hover { background: var(--danger-soft); }
.button-small { min-height: 34px; padding-inline: 11px; font-size: 12px; border-radius: 8px; }

.result-section { max-width: 850px; margin: 35px auto 0; }
.result-heading { display: flex; align-items: end; justify-content: space-between; margin-bottom: 12px; }
.result-heading h2 { margin: 0; font-size: 17px; }
.result-heading p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.state-card {
  min-height: 210px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 30px; text-align: center; background: var(--surface); border: 1px dashed #c9d1dd; border-radius: var(--radius);
}
.state-card .state-icon {
  width: 48px; height: 48px; display: grid; place-items: center; margin-bottom: 12px;
  border-radius: 50%; background: #edf1f6; color: #68768a; font-size: 24px; font-weight: 800;
}
.state-card strong { font-size: 15px; }
.state-card span { margin-top: 5px; color: var(--muted); font-size: 13px; }
.error-state { background: var(--danger-soft); border-color: #efc7c7; }
.error-state .state-icon { color: var(--danger); background: #ffe0e0; }
.loading-state .state-icon { animation: pulse 1s infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); opacity: .55; } }

.result-list { display: grid; gap: 12px; }
.result-card {
  display: grid; grid-template-columns: minmax(0,1fr) 310px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 7px 20px rgba(23,32,51,.045);
}
.result-product { padding: 20px 22px; align-self: center; min-width: 0; }
.product-code {
  display: inline-flex; padding: 4px 8px; border-radius: 6px;
  background: #eef1f5; color: #465369; font-size: 11px; font-weight: 800; letter-spacing: .2px;
}
.product-name { margin: 9px 0 0; font-size: 17px; line-height: 1.35; overflow-wrap: anywhere; }
.product-notes, .inventory-notes { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.location-card { padding: 16px; background: #172033; color: #fff; }
.location-label { display: block; margin-bottom: 8px; color: #d7dfec; font-size: 10px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; }
.location-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 7px; }
.location-cell { min-width: 0; padding: 9px 6px; text-align: center; background: #222e44; border: 1px solid #344057; border-radius: 9px; }
.location-cell small { display: block; color: #aeb8c9; font-size: 9px; text-transform: uppercase; }
.location-cell strong { display: block; margin-top: 2px; font-size: 18px; overflow-wrap: anywhere; }
.site-footer { padding: 20px 0; color: #7a8495; text-align: center; font-size: 11px; }

.admin-main { padding-block: 38px 70px; }
.auth-card {
  width: min(430px, 100%); margin: 35px auto; padding: 28px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.auth-heading { margin-bottom: 22px; }
.auth-heading h1 { font-size: 27px; }
.stack-form, .product-form { display: grid; gap: 15px; }
.field-group { display: grid; gap: 6px; min-width: 0; }
.field-group label, .location-fields legend { color: #344054; font-size: 12px; font-weight: 750; }
.field-group input, .field-group textarea, .admin-search-form input {
  width: 100%; border: 1px solid #cfd6e1; border-radius: 9px; background: #fff;
  color: var(--text); outline: none;
}
.field-group input, .admin-search-form input { height: 43px; padding: 0 12px; }
.field-group textarea { padding: 10px 12px; resize: vertical; }
.field-group input:focus, .field-group textarea:focus, .admin-search-form input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31,111,235,.10);
}
.form-message { min-height: 20px; margin: 0; color: var(--muted); font-size: 12px; }
.form-message.error { color: var(--danger); }
.form-message.success { color: var(--success); }

.admin-workspace { display: block; }
.admin-title-row { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.admin-title-row h1 { margin-bottom: 4px; font-size: 30px; }
.muted-text { margin: 0; color: var(--muted); font-size: 12px; }
.admin-grid { display: grid; grid-template-columns: minmax(350px,.8fr) minmax(430px,1.2fr); gap: 18px; align-items: start; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(23,32,51,.05); }
.editor-card { padding: 22px; position: sticky; top: 18px; }
.inventory-card { overflow: hidden; }
.card-header h2 { margin: 0; font-size: 17px; }
.card-header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.inventory-header { padding: 20px 20px 0; }
.field-row { display: grid; grid-template-columns: 135px minmax(0,1fr); gap: 12px; }
.field-row.three-columns { grid-template-columns: repeat(3,minmax(0,1fr)); }
.field-grow { min-width: 0; }
.location-fields { margin: 0; padding: 13px; border: 1px solid var(--line); border-radius: 10px; }
.location-fields legend { padding: 0 6px; }
.toggle-row { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.toggle-row input { margin-top: 4px; accent-color: var(--primary); }
.toggle-row strong, .toggle-row small { display: block; }
.toggle-row strong { font-size: 13px; }
.toggle-row small { margin-top: 1px; color: var(--muted); font-size: 11px; }
.form-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.admin-search-form { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.inventory-status { padding: 0 20px; color: var(--muted); font-size: 12px; }
.inventory-list { display: grid; }
.inventory-item { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 16px 20px; border-top: 1px solid #ebeff4; }
.inventory-item:first-child { border-top: 0; }
.inventory-main { min-width: 0; }
.inventory-topline { display: flex; align-items: center; gap: 7px; }
.inventory-main h3 { margin: 7px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.inventory-location { margin: 4px 0 0; color: #4b5a70; font-size: 11px; font-weight: 650; }
.status-badge { padding: 3px 7px; border-radius: 999px; font-size: 9px; font-weight: 800; }
.status-badge.active { color: var(--success); background: var(--success-soft); }
.status-badge.inactive { color: #737d8c; background: #edf0f4; }
.inventory-actions { display: flex; flex: 0 0 auto; gap: 7px; }
.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 20; display: grid; gap: 8px; }
.toast { max-width: 330px; padding: 12px 15px; border-radius: 10px; background: #172033; color: #fff; box-shadow: var(--shadow); font-size: 12px; font-weight: 650; }
.toast-error { background: var(--danger); }

@media (max-width: 900px) {
  .admin-grid { grid-template-columns: 1fr; }
  .editor-card { position: static; }
}
@media (max-width: 680px) {
  .shell { width: min(100% - 20px, 1080px); }
  .public-main { padding-block: 35px 50px; }
  .search-form { grid-template-columns: 1fr; }
  .search-submit { width: 100%; }
  .search-meta { flex-direction: column; gap: 2px; }
  .result-card { grid-template-columns: 1fr; }
  .result-product { padding: 18px; }
  .location-card { padding: 14px; }
  .admin-title-row { align-items: flex-start; flex-direction: column; }
  .admin-title-row .button { width: 100%; }
  .field-row, .field-row.three-columns { grid-template-columns: 1fr; }
  .inventory-item { align-items: flex-start; flex-direction: column; }
  .inventory-actions { width: 100%; }
  .inventory-actions .button { flex: 1; }
}
@media (max-width: 430px) {
  .brand small { display: none; }
  .admin-page .admin-link { display: none; }
  .header-content { min-height: 62px; }
  .hero h1 { font-size: 28px; }
  .auth-card { padding: 21px; }
  .location-grid { gap: 5px; }
  .location-cell strong { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
