:root {
  --bg: #f5f6f8;
  --card: #fff;
  --text: #111827;
  --muted: #4b5563;
  --line: #e5e7eb;
  --accent: #0070d1;
  --accent-ink: #fff;
  --badge: #b42318;
  --danger: #b42318;
  --alert-bg: #fff4f2;
  --alert-text: #7a1a14;
  --note-bg: #f5f6f8;
  --pic-a: #e8eef7;
  --pic-b: #cdd9ea;
  --pic-ink: #1b3a6b;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.18);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116;
    --card: #181c23;
    --text: #f3f4f6;
    --muted: #b6bec9;
    --line: #2a303a;
    --accent: #4aa3ff;
    --accent-ink: #062033;
    --danger: #ff8d82;
    --alert-bg: #3a2224;
    --alert-text: #ffd4cf;
    --note-bg: #12161c;
    --pic-a: #222b3a;
    --pic-b: #2d3a50;
    --pic-ink: #a9c7f5;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1116;
  --card: #181c23;
  --text: #f3f4f6;
  --muted: #b6bec9;
  --line: #2a303a;
  --accent: #4aa3ff;
  --accent-ink: #062033;
  --danger: #ff8d82;
  --alert-bg: #3a2224;
  --alert-text: #ffd4cf;
  --note-bg: #12161c;
  --pic-a: #222b3a;
  --pic-b: #2d3a50;
  --pic-ink: #a9c7f5;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

:root[data-theme="light"] {
  color-scheme: light;
}

* { box-sizing: border-box; }

html {
  scroll-padding-top: env(safe-area-inset-top, 0px);
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-top: env(safe-area-inset-top, 0px);
  text-size-adjust: 100%;
}

img { max-width: 100%; }

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

button { cursor: pointer; }

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

a:hover { text-decoration: underline; }

:focus { outline: none; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: 12px;
  top: 0;
  transform: translateY(-120%);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 14px;
  border-radius: 10px;
  z-index: 5;
  text-decoration: none;
}

.skip:focus { transform: none; top: 12px; }

.wrap {
  width: min(1240px, calc(100% - 32px));
  margin-inline: auto;
}

@media (min-width: 768px) {
  .wrap { width: min(1240px, calc(100% - 48px)); }
}

.site-header { padding: 24px 0 8px; }

.header-inner { display: flex; flex-direction: column; gap: 6px; }

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

.brand,
.brand a {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  letter-spacing: -0.03em;
}

h1.brand,
a.brand {
  margin: 0;
  font-size: clamp(1.4rem, 1.15rem + 1vw, 1.85rem);
  font-weight: 700;
  line-height: 1.2;
}

.mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.4px;
  flex: 0 0 auto;
}

.tagline { margin: 0; color: var(--muted); }

.bar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.bar-actions form { margin: 0; }

main { flex: 1; padding: 12px 0 28px; }

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

@media (min-width: 768px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1024px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 1280px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.pic {
  position: relative;
  height: 130px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--pic-a), var(--pic-b));
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.pic-label {
  font-weight: 700;
  font-size: 34px;
  color: var(--pic-ink);
  letter-spacing: 2px;
}

.pic-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
}

.badge {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 14px;
  background: var(--badge);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--card);
}

.badge.zero { background: #4b5563; }

.card h2 { margin: 6px 0 0; font-size: 1.125rem; line-height: 1.3; }

.note, .card .note, .muted { color: var(--muted); }

.card .note { margin: 0; font-size: 0.925rem; }

.price { font-size: 1.375rem; font-weight: 700; margin: 0; }

.stock { margin: 0; color: var(--muted); font-size: 0.925rem; }

.btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
  width: 100%;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  touch-action: manipulation;
}

.btn:hover:not(:disabled) { filter: brightness(1.06); text-decoration: none; }

.btn:disabled {
  background: var(--line);
  color: var(--muted);
  cursor: not-allowed;
  filter: none;
}

.btn.alt {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn.slim { width: auto; padding-inline: 14px; }

.page-note { margin: 16px 0 0; }

.note {
  font-size: 0.925rem;
  background: var(--note-bg);
  border-radius: 10px;
  padding: 10px 12px;
}

.card .note { background: transparent; padding: 0; }

.login-grid { display: grid; gap: 28px; align-items: start; }

@media (min-width: 1024px) {
  .login-grid { grid-template-columns: minmax(280px, 420px) minmax(0, 1fr); gap: 40px; }
}

.gate {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.gate h2, .prose h2, .page h2, .admin-layout h2 { font-size: 1.15rem; margin: 0; }

.gate form, .stack { display: flex; flex-direction: column; gap: 12px; }

.or {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin: 2px 0;
}

.or::before, .or::after {
  content: "";
  height: 1px;
  background: var(--line);
  flex: 1;
}

.prose { max-width: 68ch; }

.prose p, .page p { margin: 0.45rem 0; }

.prose h2, .page h2 { margin-top: 1.25rem; }

.page h1, .admin-head h1 {
  margin: 0;
  font-size: clamp(1.6rem, 1.2rem + 1.2vw, 2rem);
  letter-spacing: -0.03em;
}

.admin-head { margin-bottom: 16px; }

.admin-layout { display: grid; gap: 28px; align-items: start; }

@media (min-width: 1024px) {
  .admin-layout { grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr); }
}

#shop-form, .gate form { display: flex; flex-direction: column; gap: 12px; }

label {
  font-size: 0.925rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

input, select, textarea {
  font-weight: 400;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  width: 100%;
  min-height: 44px;
}

textarea { min-height: 76px; resize: vertical; }

input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 112, 209, 0.28);
  outline: none;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px 10px;
  margin: 0;
  min-width: 0;
}

legend { font-size: 0.925rem; font-weight: 600; padding: 0 6px; }

.opt {
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: center;
  font-weight: 400;
  min-height: 44px;
  padding: 4px 0;
}

.opt input {
  width: 22px;
  height: 22px;
  min-height: 22px;
  margin: 0;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.row {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
}

.two { display: grid; grid-template-columns: 1fr; gap: 8px; }

@media (min-width: 600px) {
  .two { grid-template-columns: 1fr 1fr; }
}

.stepper { display: flex; gap: 6px; align-items: stretch; }

.stepper button {
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
}

.stepper input { text-align: center; min-width: 0; }

.danger {
  background: transparent;
  border: 0;
  color: var(--danger);
  text-align: left;
  padding: 8px 0;
  min-height: 44px;
  font-size: 0.925rem;
  font-weight: 600;
  width: fit-content;
}

.total {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
  font-size: 1.125rem;
}

.hide { display: none !important; }

pre {
  white-space: pre-wrap;
  background: var(--note-bg);
  padding: 12px;
  border-radius: 10px;
  font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace;
  overflow-x: auto;
  margin: 0;
}

.alert {
  background: var(--alert-bg);
  color: var(--alert-text);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0;
}

.empty {
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: 18px;
  padding: 22px;
  color: var(--muted);
}

.site-footer {
  color: var(--muted);
  font-size: 0.875rem;
  padding: 8px 0 calc(28px + env(safe-area-inset-bottom, 0px));
}

.site-footer p { margin: 0 0 8px; }

.site-footer nav { display: flex; flex-wrap: wrap; gap: 8px 16px; }

.fine { font-size: 0.8rem; }

code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

dialog {
  border: 0;
  padding: 0;
  color: var(--text);
  background: var(--card);
  width: min(560px, 94vw);
  max-width: calc(100vw - 32px);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

dialog[open] { display: flex; flex-direction: column; }

dialog::backdrop { background: rgba(0, 0, 0, 0.5); }

.sheet {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: min(860px, 92dvh);
}

.sheet-scroll {
  flex: 1 1 auto;
  overflow: auto;
  padding: 22px 22px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.sheet-scroll h2 { margin: 0; }

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 22px calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: var(--card);
}

@media (max-width: 767px) {
  dialog,
  dialog[open] {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    border-radius: 0;
  }

  dialog::backdrop { background: transparent; }

  .sheet {
    height: 100%;
    max-height: none;
  }
}

.orders { display: grid; gap: 12px; }

@media (min-width: 1280px) {
  .admin-layout .orders { grid-template-columns: 1fr; }
}

.order {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.order h3 { margin: 0; font-size: 1rem; }

.order p { margin: 0; }

.order time { color: var(--muted); font-size: 0.85rem; }

.order-top {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  align-items: flex-end;
}

.order-top label { min-width: min(100%, 180px); flex: 1; }

.savebar {
  padding: 4px 0 calc(12px + env(safe-area-inset-bottom, 0px));
}

.ad { margin: 8px 0 16px; min-height: 90px; }

.ad-infeed {
  grid-column: 1 / -1;
  min-height: 120px;
  margin: 0;
}

.ad-wrap { margin-top: 8px; }

ins.adsbygoogle { display: block; min-height: 90px; }

@media (max-width: 599px) {
  .brand-text { max-width: 12rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}

/* Admin chats and FAQ */
.chats {
  margin-bottom: 32px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
}

.chats-head h2 { margin: 0 0 6px; display: flex; align-items: center; gap: 8px; }

.chat-count {
  display: inline-flex;
  min-width: 1.4em;
  height: 1.4em;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--badge);
  color: #fff;
  font-size: 0.75rem;
  align-items: center;
  justify-content: center;
}

.chats-layout {
  display: grid;
  gap: 16px;
  min-height: 280px;
}

@media (min-width: 768px) {
  .chats-layout { grid-template-columns: minmax(200px, 280px) minmax(0, 1fr); align-items: stretch; }
}

.chat-list { display: flex; flex-direction: column; gap: 8px; max-height: min(520px, 60dvh); overflow: auto; }

.chat-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
}

.chat-item.current { border-color: var(--accent); }
.chat-item.unread { box-shadow: inset 3px 0 0 var(--badge); }
.chat-item strong { font-size: 0.95rem; }
.chat-preview, .chat-meta { color: var(--muted); font-size: 0.85rem; }
.chat-preview {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.chat-thread {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  padding: 12px;
  display: flex;
  flex-direction: column;
  min-height: 280px;
  max-height: min(640px, 70dvh);
}

.thread-head { margin-bottom: 8px; }
.thread-head h3 { margin: 0; }
.thread-form, .thread-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
@media (min-width: 640px) {
  .thread-actions { flex-direction: row; flex-wrap: wrap; }
}

.admin-log { flex: 1 1 auto; overflow: auto; min-height: 120px; }

@media (min-width: 960px) {
  .admin-layout {
    grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  }
  .admin-layout #shop-form { grid-column: 1; grid-row: 1; }
  .admin-layout #faqs { grid-column: 1; grid-row: 2; }
  .admin-layout section[aria-labelledby="orders-title"] { grid-column: 2; grid-row: 1 / span 2; }
}

/* Guest chat bubble and panel */
.chat-root { font: inherit; }

.chat-bubble {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 14px 18px;
  box-shadow: var(--shadow);
  font-weight: 650;
}

.chat-badge {
  min-width: 1.25em;
  height: 1.25em;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--badge);
  color: #fff;
  font-size: 0.75rem;
  line-height: 1.25em;
  text-align: center;
}

.chat-panel {
  position: fixed;
  z-index: 31;
  display: flex;
  flex-direction: column;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-panel.hide, .chat-badge.hide, .chat-help.hide, .hide { display: none !important; }

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}

.chat-head h2 { margin: 0; font-size: 1.05rem; }
.chat-status { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }
.chat-x {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
}

.chat-faq {
  padding: 10px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-faq-label { margin: 0; font-size: 0.85rem; color: var(--muted); }

.chat-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chat-chip {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.9rem;
  text-align: left;
}

.chat-chip.all { border-style: dashed; }

.chat-log {
  flex: 1 1 auto;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px;
  min-height: 120px;
}

.chat-bubble-msg {
  max-width: 90%;
  border-radius: 16px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.chat-bubble-msg.from-guest { align-self: flex-end; background: var(--note-bg); }
.chat-bubble-msg.from-owner, .chat-bubble-msg.from-bot { align-self: flex-start; }
.chat-bubble-msg.from-bot { border-style: dashed; }

.chat-who, .chat-bubble-msg time { margin: 0; font-size: 0.75rem; color: var(--muted); }
.chat-text { margin: 2px 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.chat-help {
  margin: 0 16px 4px;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
}

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
}

.chat-contact summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
.chat-contact { display: flex; flex-direction: column; gap: 8px; }

@media (max-width: 767px) {
  .chat-panel,
  .chat-panel:not(.hide) {
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    border-radius: 0;
  }
}

@media (min-width: 768px) {
  .chat-panel {
    right: max(16px, env(safe-area-inset-right));
    bottom: max(76px, env(safe-area-inset-bottom));
    width: min(400px, calc(100vw - 32px));
    height: min(640px, calc(100dvh - 120px));
    border-radius: 20px;
    border: 1px solid var(--line);
  }
}
