* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: #f4f5f7;
  color: #1a1a2e;
  font-size: 14px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: #fff;
  border-bottom: 1px solid #e5e7ef;
}

header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 0.75rem;
  padding: 0.75rem;
  min-height: calc(100vh - 56px);
}

.chat-panel,
.draft-panel {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e5e7ef;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f0f1f4;
  gap: 0.5rem;
}

.toolbar-label {
  font-weight: 600;
  color: #444;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.panel-title {
  margin: 0;
  font-size: 1rem;
}

.message-feed {
  flex: 1;
  height: calc(100vh - 200px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
}

.message {
  max-width: 88%;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  background: #eef1ff;
  line-height: 1.4;
}

.message.mine {
  align-self: flex-end;
  background: #fff3e6;
}

.message.system {
  background: #f3f4f6;
  align-self: stretch;
  max-width: 100%;
  font-size: 0.8rem;
  color: #555;
}

.message.debug {
  display: none;
  background: #fafafa;
  border: 1px dashed #ddd;
  font-size: 0.75rem;
  font-family: ui-monospace, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

body.show-debug .message.debug {
  display: block;
}

.message .meta {
  font-size: 0.7rem;
  color: #888;
  margin-bottom: 0.2rem;
}

.message .sender {
  font-weight: 600;
  color: #333;
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid #f0f1f4;
}

.chat-form input {
  flex: 1;
}

.draft-panel {
  padding-bottom: 0;
}

.draft-section {
  padding: 0 1rem;
  overflow-y: auto;
  flex: 1;
}

.draft-section.hidden {
  display: none;
}

.section-label {
  margin: 0.75rem 0 0.5rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #888;
  font-weight: 600;
}

.subtotal {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: #666;
}

.cart-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}

.cart-list li {
  padding: 0.6rem 0;
  border-bottom: 1px solid #f0f1f4;
}

.cart-list li:last-child {
  border-bottom: none;
}

.cart-row-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: flex-start;
}

.cart-name {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.3;
}

.cart-price {
  font-weight: 600;
  color: #fc8019;
  white-space: nowrap;
  font-size: 0.85rem;
}

.cart-meta {
  color: #888;
  font-size: 0.75rem;
  margin-top: 0.15rem;
}

.cart-tag {
  display: inline-block;
  background: #f0f1f4;
  color: #555;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.7rem;
  margin-right: 0.25rem;
}

.attention-item .cart-name {
  color: #555;
}

.option-btn {
  display: block;
  width: 100%;
  text-align: left;
  margin-top: 0.35rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid #e5e7ef;
  background: #fafafa;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
}

.option-btn:hover {
  background: #fff3e6;
  border-color: #fc8019;
}

.option-btn.ghost {
  color: #888;
  border-style: dashed;
}

.empty-state {
  color: #aaa;
  font-size: 0.85rem;
  text-align: center;
  padding: 2rem 0.5rem;
  margin: 0;
}

.empty-state.hidden {
  display: none;
}

.checkout-block {
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid #f0f1f4;
  margin-top: auto;
}

.badge {
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
}

.badge-ok {
  background: #dcfce7;
  color: #166534;
}

.badge-warn {
  background: #fef3c7;
  color: #92400e;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
}

.btn-primary {
  background: #fc8019;
  color: #fff;
  width: 100%;
}

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

.btn-secondary {
  background: #eef1ff;
  color: #1a1a2e;
  text-decoration: none;
}

.btn-accent {
  background: #fc8019;
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: #666;
  border: 1px solid #e0e0e0;
}

.btn-ghost:hover {
  background: #f5f5f5;
}

.toggle-debug {
  font-size: 0.75rem;
  color: #888;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
}

.note {
  font-size: 0.75rem;
  color: #888;
  margin: 0.4rem 0 0;
  text-align: center;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #fff;
  padding: 1.25rem;
  border-radius: 12px;
  width: min(420px, 90vw);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

select,
input[type="text"] {
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  font-size: 0.85rem;
}

#address-select {
  max-width: 220px;
  font-size: 0.78rem;
}

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

  .message-feed {
    height: 45vh;
  }
}
