:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #666;
  --line: #d8d8d8;
  --panel: #fff;
  --soft: #f5f5f3;
  --accent: #f96302;
  --accent-strong: #c84d00;
  --ok: #217346;
  --error: #b00020;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #f0f1ef;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

body.modal-open {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.shell {
  min-height: 100vh;
  padding: 16px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  max-width: 1120px;
  margin: 0 auto;
}

.app-footer {
  display: flex;
  justify-content: flex-end;
  max-width: 1120px;
  min-height: 44px;
  margin: 2px auto 0;
  padding: 0 2px;
  align-items: center;
  font-size: 13px;
}

.app-footer a {
  color: var(--muted);
  text-underline-offset: 3px;
}

.app-footer a:hover {
  color: var(--accent-strong);
}

.app-footer a:focus-visible {
  outline: 3px solid #1a73e8;
  outline-offset: 3px;
}

.store-pane,
.product-pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  min-width: 0;
}

.store-pane {
  padding: 14px;
  position: sticky;
  top: 16px;
  z-index: 10;
}

.product-pane {
  padding: 14px;
}

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

.pane-header > div:first-child {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.store-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.secondary-button {
  min-height: 34px;
  border-color: var(--line);
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
}

.secondary-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: #fff6ef;
}

.search-form,
.product-search {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

input {
  width: 100%;
  min-height: 42px;
  font-size: 16px;
  border: 1px solid #aaa;
  border-radius: 4px;
  padding: 0 11px;
  color: var(--ink);
  background: #fff;
}

button {
  min-height: 42px;
  border: 1px solid var(--accent-strong);
  border-radius: 4px;
  padding: 0 13px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button:disabled {
  border-color: #bbb;
  color: #f4f4f4;
  background: #999;
  cursor: not-allowed;
}

button:focus-visible,
input:focus-visible,
.store-row:focus-visible,
.product-main a:focus-visible {
  outline: 3px solid #1a73e8;
  outline-offset: 2px;
}

.store-results {
  display: grid;
  gap: 8px;
  max-height: min(430px, 56svh);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
}

.product-search {
  margin-bottom: 8px;
}

.store-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 66px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}

.store-dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: min(720px, calc(100svh - 32px));
  margin: auto;
  padding: 0;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .22);
  overflow: hidden;
}

.store-dialog::backdrop {
  background: rgba(0, 0, 0, .34);
}

.store-dialog-shell {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.store-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.store-dialog h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.15;
}

.store-row:hover,
.store-row.selected {
  border-color: var(--accent);
  background: #fff6ef;
}

.store-row strong,
.store-row small,
.store-meta {
  display: block;
}

.store-row small {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.25;
}

.store-meta {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.store-meta b {
  display: block;
  margin-top: 4px;
  color: var(--ink);
}

.result-summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 26px;
  margin: 4px 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.product-results {
  display: grid;
  gap: 8px;
}

.product-row {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) minmax(140px, 190px);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 98px;
  padding: 10px;
  background: #fff;
}

.product-row img {
  width: 76px;
  height: 76px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.product-main {
  min-width: 0;
}

.product-main a {
  color: var(--ink);
  font-weight: 700;
  line-height: 1.25;
  text-decoration-color: var(--accent);
}

.product-details {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.product-details span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--muted);
  font-size: 12px;
}

.inventory {
  border-left: 1px solid var(--line);
  padding-left: 12px;
}

.inventory strong,
.inventory span {
  display: block;
}

.inventory strong {
  color: var(--ok);
  font-size: 16px;
}

.inventory span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.empty,
.error,
.suggestions {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  color: var(--muted);
  background: var(--soft);
}

.error {
  border-color: #efb6c1;
  color: var(--error);
  background: #fff5f7;
}

.suggestions {
  font-size: 13px;
}

.skeleton {
  height: 74px;
  border-radius: 6px;
  background: linear-gradient(90deg, #eeeeee, #fafafa, #eeeeee);
  background-size: 220% 100%;
  animation: pulse 1.1s linear infinite;
}

@keyframes pulse {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}

@media (max-width: 820px) {
  body {
    min-height: 100svh;
  }

  .shell {
    min-height: 100svh;
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(14px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .app-footer {
    justify-content: center;
  }

  .store-pane {
    top: 10px;
  }

  .store-pane,
  .product-pane {
    padding: 12px;
  }

  h1 {
    font-size: 18px;
  }

  input,
  button {
    min-height: 46px;
  }

  .product-search {
    scroll-margin-top: 10px;
  }

  .result-summary {
    flex-direction: column;
    gap: 3px;
  }

  .product-row {
    grid-template-columns: 64px minmax(0, 1fr);
    align-items: start;
  }

  .product-row img {
    width: 64px;
    height: 64px;
  }

  .inventory {
    grid-column: 1 / -1;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 9px 0 0;
  }
}

@media (max-width: 430px) {
  .shell {
    padding:
      env(safe-area-inset-top)
      env(safe-area-inset-right)
      max(10px, env(safe-area-inset-bottom))
      env(safe-area-inset-left);
  }

  .store-pane,
  .product-pane {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .pane-header {
    gap: 8px;
  }

  h1 {
    font-size: 17px;
  }

  .status {
    display: none;
  }

  .field-row {
    gap: 6px;
  }

  button {
    padding: 0 10px;
  }

  .store-row {
    gap: 8px;
  }

  .store-dialog {
    width: 100vw;
    max-width: none;
    max-height: min(88svh, 720px);
    margin: auto 0 0;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 14px 14px 0 0;
  }

  .store-dialog-shell {
    padding:
      14px
      max(12px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  .store-results {
    max-height: 58svh;
  }
}

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