:root {
  color-scheme: light;
  --bg: #f6f3ef;
  --ink: #181512;
  --muted: #716b64;
  --line: #d8d0c7;
  --panel: #fffdfa;
  --accent: #0d766e;
  --accent-ink: #ffffff;
  --danger: #a33a2b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Noto Sans JP", system-ui, sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--accent-ink);
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent);
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
  transform: none;
}

button:disabled:hover {
  background: var(--ink);
  border-color: var(--ink);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.65fr);
  min-height: 100vh;
}

.catalog-pane {
  padding: 32px;
  border-right: 1px solid var(--line);
}

.chat-pane {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  width: max(360px, 32vw);
  height: 100vh;
  max-height: 100vh;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow: hidden;
  z-index: 10;
}

.chat-tools {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 2;
  display: flex;
  gap: 6px;
}

.chat-collapse,
.login-button {
  width: 34px;
  min-height: 30px;
  padding: 0;
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
}

.login-button {
  width: auto;
  padding: 0 10px;
  font-size: 12px;
  white-space: nowrap;
}

.login-button.is-logged-in {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.topbar,
.chat-header,
.search-row,
.actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: clamp(32px, 5vw, 64px);
}

h1 a {
  color: inherit;
  text-decoration: none;
}

h1 a:hover {
  color: var(--accent);
}

h2 {
  font-size: 24px;
}

.search-row {
  margin: 28px 0;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 12px;
  outline-color: var(--accent);
}

.product-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}

.product {
  display: grid;
  grid-template-rows: 180px auto;
  min-height: 360px;
  background: #fff;
  border: 1px solid var(--line);
  overflow: hidden;
  cursor: pointer;
}

.product-image-link {
  display: block;
  min-width: 0;
}

.product img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  background: #e8e1d8;
  display: block;
}

.product-body {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.product h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.3;
}

.product h3 a {
  color: inherit;
  text-decoration: none;
}

.product h3 a:hover {
  color: var(--accent);
}

.product p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

.meta button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
  white-space: nowrap;
}

.chat-header {
  padding: 24px;
  border-bottom: 1px solid var(--line);
}

#statusBadge,
#conversationBadge {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.badges {
  display: grid;
  gap: 6px;
  justify-items: end;
  white-space: nowrap;
}

#conversationBadge {
  color: var(--ink);
}

.selected-products {
  min-height: 46px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.selected-label {
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.selected-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
}

.selected-chip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px;
  align-items: stretch;
  min-width: 0;
  border: 1px solid var(--line);
  background: #fff;
}

.selected-list a {
  display: block;
  min-width: 0;
  color: var(--ink);
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1.25;
  overflow: hidden;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-list a:hover {
  color: var(--accent);
}

.selected-chip:hover {
  border-color: var(--accent);
}

.selected-remove {
  min-height: 0;
  width: 24px;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  background: #fff;
  color: var(--danger);
  font-size: 16px;
  line-height: 1;
}

.selected-remove:hover {
  background: #f7e9e5;
  border-color: var(--line);
  color: var(--danger);
  transform: none;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  min-height: 0;
  padding: 20px 24px;
}

.message {
  max-width: 88%;
  padding: 12px 14px;
  line-height: 1.5;
  background: #f1ede8;
  white-space: pre-line;
}

.message.customer {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
}

.message.loading {
  color: var(--muted);
}

.chat-form {
  display: grid;
  gap: 8px;
  flex-shrink: 0;
  padding: 12px 24px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.chat-form textarea {
  min-height: 76px;
  max-height: 110px;
  resize: vertical;
}

.login-dialog {
  width: min(360px, calc(100vw - 28px));
  border: 1px solid var(--line);
  padding: 0;
  background: var(--panel);
  color: var(--ink);
}

.login-dialog::backdrop {
  background: rgba(24, 21, 18, 0.38);
}

.login-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
}

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

.login-header h3,
.login-panel p {
  margin: 0;
}

.login-header h3 {
  font-size: 18px;
}

.login-panel p {
  color: var(--muted);
  line-height: 1.5;
  font-size: 13px;
}

.login-header button,
.login-panel > button {
  min-height: 36px;
}

.actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.actions button {
  min-width: 104px;
}

.order-action[hidden] {
  display: none;
}

.primary-order {
  min-width: 92px;
  background: #256f54;
  color: #fff;
  border-color: #256f54;
}

.primary-order:disabled {
  display: none;
}

.help-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  padding: 0;
  background: var(--panel);
  color: var(--ink);
}

.help-dialog::backdrop {
  background: rgba(24, 21, 18, 0.38);
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.help-header h3 {
  margin: 0;
  font-size: 20px;
}

.help-header button {
  min-height: 34px;
  padding: 0 10px;
}

.help-body {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.help-body h4,
.help-body p {
  margin: 0;
}

.help-body h4 {
  font-size: 15px;
}

.help-body p {
  color: var(--muted);
  line-height: 1.6;
}

@media (max-width: 920px) {
  .workspace {
    display: block;
    min-height: 100svh;
  }

  .catalog-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px 14px;
    padding-bottom: calc(56svh + 16px);
  }

  .chat-pane {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 56svh;
    max-height: 56svh;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .chat-pane.is-collapsed {
    height: 170px;
    max-height: 170px;
  }

  .chat-pane.is-collapsed .selected-products,
  .chat-pane.is-collapsed .messages {
    display: none;
  }

  .chat-tools {
    position: fixed;
    top: auto;
    bottom: 58svh;
    right: 14px;
    z-index: 40;
  }

  .chat-collapse,
  .login-button {
    width: auto;
    min-height: 38px;
    padding: 0 14px;
    border-color: var(--ink);
    background: var(--ink);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 -2px 12px rgba(24, 21, 18, 0.22);
  }

  .chat-collapse {
    min-width: 96px;
  }

  .login-button {
    min-width: 76px;
  }

  .chat-pane.is-collapsed .chat-tools {
    bottom: 170px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar .eyebrow,
  #syncBtn,
  h1,
  .chat-header {
    display: none;
  }

  h2 {
    font-size: 18px;
  }

  .search-row {
    position: sticky;
    top: 0;
    z-index: 8;
    margin: 12px 0;
    padding: 8px 0;
    background: var(--bg);
  }

  .product-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .product {
    grid-template-rows: 132px auto;
    min-height: 218px;
  }

  .product img,
  .product-image-link {
    width: 100%;
    height: 132px;
  }

  .product-body {
    gap: 7px;
    padding: 8px;
    min-width: 0;
  }

  .product h3 {
    font-size: 12px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .product p {
    display: none;
  }

  .meta {
    display: flex;
    gap: 6px;
    font-size: 12px;
  }

  .meta button {
    min-height: 26px;
    min-width: 48px;
    padding: 0 8px;
    font-size: 12px;
  }

  .selected-products {
    min-height: 34px;
    padding: 7px 12px;
    font-size: 13px;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 6px;
  }

  .selected-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  .selected-chip {
    grid-template-columns: minmax(0, 1fr) 22px;
  }

  .selected-list a {
    padding: 5px 6px;
    font-size: 11px;
  }

  .selected-remove {
    width: 22px;
    font-size: 14px;
  }

  .messages {
    gap: 6px;
    padding: 8px 12px;
  }

  .message {
    max-width: 94%;
    padding: 6px 8px;
    font-size: 12px;
    line-height: 1.4;
  }

  .chat-form {
    gap: 6px;
    padding: 8px 12px 10px;
  }

  .chat-form textarea {
    min-height: 42px;
    max-height: 70px;
    resize: none;
    padding: 8px;
    font-size: 12px;
    line-height: 1.35;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .actions button {
    width: 100%;
    min-width: 0;
    padding: 0 4px;
    white-space: nowrap;
    min-height: 34px;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .catalog-pane {
    padding: 10px;
    padding-bottom: calc(58svh + 16px);
  }

  .chat-pane {
    height: 60svh;
    max-height: 60svh;
  }

  .search-row {
    gap: 8px;
  }

  .search-row button {
    min-width: 64px;
  }
}
