:root {
  --bg: #0e1014;
  --bg-card: #161a22;
  --bg-input: #0b0d12;
  --border: #252a35;
  --text: #e8ecf4;
  --text-dim: #9aa3b2;
  --accent: #8b5cf6;
  --accent-2: #6366f1;
  --ok: #22c55e;
  --err: #ef4444;
  --warn: #f59e0b;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
}
.logo {
  color: var(--accent);
  font-size: 20px;
}

.auth-status {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.pill-on { background: rgba(34, 197, 94, 0.15); color: var(--ok); }
.pill-off { background: rgba(239, 68, 68, 0.15); color: var(--err); }

.layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  min-height: calc(100vh - 56px);
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 56px;
  align-self: start;
  max-height: calc(100vh - 56px);
  overflow-y: auto;
}
.nav-link {
  color: var(--text-dim);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}
.nav-link:hover { background: var(--bg-card); color: var(--text); }
.nav-link.active { background: var(--bg-card); color: var(--text); }

.content {
  padding: 22px 28px;
  max-width: 1100px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  scroll-margin-top: 70px;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.card h3 {
  margin: 10px 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-weight: 600;
}
.card h2 small {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 400;
  margin-left: 6px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 12px;
}
form.inline-form {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: end;
}
form.inline-form h3 {
  flex-basis: 100%;
  margin-bottom: 4px;
}

input, select, button, textarea {
  font: inherit;
}

input, select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 11px;
  border-radius: 6px;
  flex: 1;
  min-width: 0;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
}
button:hover { background: var(--accent-2); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 12px;
}
.btn-ghost:hover { background: var(--bg-input); color: var(--text); }
.btn-danger { background: var(--err); }
.btn-danger:hover { background: #dc2626; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.current {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 10px 0;
  font-size: 13px;
}
.current code {
  color: var(--accent);
  background: transparent;
  flex: 1;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
}

.response {
  margin-top: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 400px;
  overflow-y: auto;
  color: var(--text-dim);
  min-height: 0;
}
.response:empty { display: none; }
.response .status { font-weight: 600; }
.response .status.ok { color: var(--ok); }
.response .status.err { color: var(--err); }

.image-preview {
  margin: 12px 0;
  padding: 16px;
  background: var(--bg-input);
  border: 1px dashed var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 160px;
  justify-content: center;
}
.image-preview img {
  max-width: 100%;
  max-height: 480px;
  min-width: 140px;
  min-height: 140px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #000;
  object-fit: contain;
  image-rendering: auto;
}
.image-preview .meta {
  font-size: 11px;
  color: var(--text-dim);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  word-break: break-all;
  text-align: center;
}
.image-preview .demo-note {
  color: var(--warn);
  font-size: 12px;
  background: rgba(245, 158, 11, 0.1);
  padding: 8px 12px;
  border-radius: 6px;
}
.image-preview:empty { display: none; }

/* chat */
.chat-window {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  height: 380px;
  overflow-y: auto;
  margin: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.chat-msg.user {
  background: var(--accent);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
  background: var(--bg-card);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chat-msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-dim);
  font-style: italic;
  font-size: 11px;
}
.chat-composer {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.chat-composer input { flex: 1; }

.carousel {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 8px 2px;
  margin-top: 8px;
}
.carousel .prod-card {
  min-width: 200px;
  max-width: 200px;
}

.prod-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}
.prod-card img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--bg-input);
}
.prod-card .title {
  font-weight: 500;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 34px;
}
.prod-card .price {
  color: var(--accent);
  font-weight: 600;
}
.prod-card .meta {
  color: var(--text-dim);
  font-size: 11px;
}
.prod-card .pid {
  color: var(--text-dim);
  font-size: 10px;
  font-family: ui-monospace, monospace;
  word-break: break-all;
}
.prod-card .row {
  display: flex;
  gap: 4px;
}
.prod-card button {
  flex: 1;
  padding: 5px 8px;
  font-size: 11px;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

#cart-table {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}
.cart-row {
  display: grid;
  grid-template-columns: 60px 1fr 80px 80px auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.cart-row img { width: 50px; height: 50px; object-fit: cover; border-radius: 4px; }
.cart-row input { padding: 4px 6px; }
.cart-row button { padding: 5px 10px; font-size: 12px; }
.cart-total {
  text-align: right;
  padding: 10px 14px;
  font-weight: 600;
  color: var(--accent);
}
