:root {
  --bg: #fbf7f0; --ink: #1f1b16; --muted: #6b6257; --card: #ffffff; --line: #e8dfd2;
  --accent: #c2410c; --accent-ink: #ffffff; --stripe: #f4c95d; --ok: #15803d; --bad: #b91c1c;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 Inter, system-ui, sans-serif; }
main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 48px; }
h1, h2, h3 { font-family: Fraunces, Georgia, serif; line-height: 1.15; margin: 0 0 .5em; }
h1 { font-size: clamp(1.9rem, 4vw, 3rem); }
h1 em { color: var(--accent); font-style: normal; }
a { color: var(--accent); }
code, pre { font-family: ui-monospace, Menlo, monospace; font-size: .9em; }
pre { background: #1f1b16; color: #fbf7f0; padding: 12px 14px; border-radius: 10px; overflow-x: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--card); }
.topbar nav a { margin-left: 18px; color: var(--ink); text-decoration: none; font-weight: 500; }
.brand { font-family: Fraunces, serif; font-weight: 700; font-size: 1.35rem; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 10px; }
.awning { width: 28px; height: 18px; border-radius: 0 0 8px 8px;
  background: repeating-linear-gradient(90deg, var(--accent) 0 7px, var(--stripe) 7px 14px); }
.banner { background: #fff4d6; border-bottom: 1px solid #f1d58a; padding: 8px 20px; font-size: .9rem; text-align: center; }
footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px; border-top: 1px solid var(--line); }
.hero { display: grid; grid-template-columns: 1.3fr 1fr; gap: 32px; align-items: center; padding: 24px 0 40px; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; color: var(--accent); font-weight: 600; margin: 0 0 8px; }
.lead { font-size: 1.12rem; color: var(--muted); max-width: 60ch; }
.cta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; counter-reset: s; }
.steps li { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px 14px 54px; position: relative; }
.steps li::before { counter-increment: s; content: counter(s); position: absolute; left: 16px; top: 14px; width: 26px; height: 26px;
  border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: .85rem; }
.steps strong { display: block; }
.steps span { color: var(--muted); font-size: .95rem; }
.btn { display: inline-block; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 10px 16px;
  border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .6; cursor: wait; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px; margin: 16px 0; }
.stall-card { color: var(--ink); text-decoration: none; margin: 0; transition: transform .15s; }
.stall-card:hover { transform: translateY(-2px); }
.tag, .pill { display: inline-block; white-space: nowrap; font-size: .75rem; padding: 2px 10px; border-radius: 999px; background: #fdebd3; color: #8a3a0b; margin: 2px 4px 2px 0; }
.muted { color: var(--muted); font-size: .92rem; }
.narrow { max-width: 760px; }
label { display: block; font-weight: 500; margin: 10px 0; }
label.check { display: flex; gap: 8px; align-items: center; }
input, textarea, select { width: 100%; font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; margin-top: 4px; }
input[type=checkbox] { width: auto; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.edit-table input { margin: 0; padding: 6px 8px; }
.menu input.qty { width: 80px; }
.hidden { display: none; }
.notice { background: #fff4d6; border: 1px solid #f1d58a; border-radius: 10px; padding: 10px 14px; }
.success { border-color: #9fd5b0; background: #f0fbf3; }
.error { color: var(--bad); }
.actions { white-space: nowrap; }
.status-refunded td, .status-expired td, .status-cancelled td { opacity: .55; }
.agent-layout { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
.chat { display: flex; flex-direction: column; min-height: 460px; margin: 0; }
#messages { flex: 1; overflow-y: auto; max-height: 520px; display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }
.msg { padding: 10px 14px; border-radius: 14px; max-width: 85%; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.bot { align-self: flex-start; background: #f5efe6; }
.msg .btn { margin-top: 8px; }
#chat-form { display: flex; gap: 8px; }
#chat-form input { margin: 0; }
.trace { margin: 0; }
.trace ol { padding-left: 18px; font-size: .9rem; }
.trace li { margin-bottom: 8px; }
.trace .fn { font-family: ui-monospace, monospace; font-weight: 600; }
.trace .blocked { color: var(--bad); }
.events { list-style: none; padding: 0; font-size: .9rem; }
.mock-paypal { border: 2px dashed #0070e0; }
@media (max-width: 760px) {
  .hero, .agent-layout, .row { grid-template-columns: 1fr; }
  .topbar nav a { margin: 0 12px 0 0; }
  table { display: block; overflow-x: auto; }
}

.order-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin: 12px 0; max-width: 420px; white-space: normal; }
.order-card ul { margin: 6px 0; padding-left: 18px; }
.order-card-head, .order-card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.order-card .btn { margin-top: 10px; }
.badge { font-size: .78rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.wait { background: #fff4d6; color: #8a5a00; }
.badge.warn { background: #fee2e2; color: var(--bad); }
.small-link { display: inline-block; margin-top: 8px; font-size: .82rem; }
#order-result .order-card { max-width: none; }

.tracker { list-style: none; padding: 0; margin: 12px 0 6px; display: flex; gap: 0; }
.tracker li { flex: 1; position: relative; text-align: center; font-size: .78rem; color: var(--muted); padding-top: 22px; min-width: 0; }
.tracker li::before { content: ""; position: absolute; top: 8px; left: -50%; width: 100%; height: 3px; background: var(--line); z-index: 0; }
.tracker li:first-child::before { display: none; }
.tracker .dot { position: absolute; top: 2px; left: 50%; transform: translateX(-50%); width: 15px; height: 15px; border-radius: 50%; background: #fff; border: 3px solid var(--line); z-index: 1; }
.tracker .label { display: block; line-height: 1.2; }
.tracker .when { display: block; font-size: .7rem; opacity: .8; margin-top: 2px; }
.tracker li.done { color: var(--ink); }
.tracker li.done .dot { background: var(--ok); border-color: var(--ok); }
.tracker li.done::before, .tracker li.current::before, .tracker li.stopped::before { background: var(--ok); }
.tracker li.current { color: var(--ink); font-weight: 600; }
.tracker li.current .dot { border-color: var(--accent); animation: pulse 1.4s infinite; }
.tracker li.stopped { color: var(--bad); font-weight: 600; }
.tracker li.stopped .dot { background: var(--bad); border-color: var(--bad); }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(194,65,12,.45); } 50% { box-shadow: 0 0 0 6px rgba(194,65,12,0); } }
.order-card.flash { animation: flash 1.5s; }
@keyframes flash { 0% { background: #fff4d6; } 100% { background: var(--card); } }
.track-form { display: flex; gap: 8px; margin: 16px 0; }
.track-form input { margin: 0; flex: 1; }
.track-form .btn { white-space: nowrap; }
#orders .order-card { max-width: none; }

/* ---------- Seller Insights (AG Studio) ---------- */
.insights-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.insights-head h1 { margin: 0 0 2px; font-size: 1.9rem; }
.insights-head p { margin: 0 0 6px; }
.insights-head { margin-bottom: 10px; }
.studio-host { height: calc(100vh - 120px); min-height: 680px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--card); }
.os-widget { height: 100%; overflow: auto; padding: 4px 6px; font: 14px/1.45 Inter, system-ui, sans-serif; color: var(--ink); box-sizing: border-box; }
.os-title { font-weight: 600; margin: 2px 0 10px; }
.os-muted { color: var(--muted); font-size: .88rem; }
.os-day { border-top: 1px solid var(--line); padding: 8px 0; }
.os-day-h { display: flex; gap: 10px; align-items: baseline; margin-bottom: 4px; }
.os-day-h span { color: var(--muted); font-size: .85rem; }
.os-row { display: grid; grid-template-columns: minmax(120px, 1.2fr) 2fr minmax(140px, 1fr); gap: 10px; align-items: center; padding: 3px 0; }
.os-bar { height: 8px; background: #f1ebe2; border-radius: 99px; overflow: hidden; }
.os-bar i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.os-bar i.full { background: var(--accent); }
.os-num { color: var(--muted); font-size: .85rem; text-align: right; }
.os-demand { border-top: 1px solid var(--line); padding: 8px 0; }
.os-pill { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 99px; background: #fdf0e3; color: var(--accent); font-size: .78rem; }
@media (max-width: 640px) { .os-row { grid-template-columns: 1fr; } .os-num { text-align: left; } }

/* ---------- Market run ---------- */
.market-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.market-stall { margin: 0; }
.market-stall h2 { margin: 0 0 4px; font-size: 1.25rem; }
.market-stall.closed { opacity: .55; }
.market-stall .qty { width: 72px; }
.market-bar { position: sticky; bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  box-shadow: 0 6px 24px rgba(31, 27, 22, .12); z-index: 5; }
.market-date { max-width: 520px; }
.market-card { background: var(--card); border: 2px solid var(--stripe); border-radius: 16px; padding: 16px; margin: 12px 0; max-width: 560px; white-space: normal; }
.market-card .pay-all { margin: 6px 0 4px; }
.market-orders .order-card { max-width: none; margin: 10px 0; }
#market-result .market-card, .narrow .market-card { max-width: none; }

.paid-to { font-size: .85rem; color: var(--ok); margin: 4px 0; }
.paid-to code { background: #eef7ef; padding: 1px 6px; border-radius: 6px; }

/* ---------- Orders grid (AG Grid) ---------- */
.orders-head { display: flex; align-items: baseline; gap: 12px; }
.orders-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.orders-tools .ask { display: flex; gap: 6px; flex: 1 1 420px; }
.orders-tools .ask input { flex: 1; min-width: 0; }
#orders-quick { flex: 0 1 240px; }
.orders-tools input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; font: inherit; }
.ask-hints { font-size: .85rem; margin: 2px 0 4px; }
.ask-out { min-height: 1.2em; font-size: .9rem; margin: 2px 0 8px; }
.ask-out.ok { color: var(--ok); } .ask-out.bad { color: #b42318; }
.orders-grid { width: 100%; }
.grid-actions { display: flex; gap: 4px; align-items: center; height: 100%; }
.gpill { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: #f1ebe2; color: #5b5247; line-height: 1.7; }
.gpill.agent { background: #e8f0fe; color: #1d4ed8; } .gpill.web { background: #f1ebe2; }
.gpill.market { background: #fdf0e3; color: #c2410c; }
.gpill.ok { background: #e6f4ea; color: #15803d; } .gpill.done { background: #eef2f6; color: #334155; }
.gpill.wait { background: #fff7e0; color: #a16207; } .gpill.warn { background: #fff1e0; color: #c2410c; } .gpill.bad { background: #fde8e8; color: #b42318; }
@media (max-width: 640px) { .orders-tools .ask { flex-basis: 100%; } }

/* ---------- Markets ---------- */
.mh-hero { display: grid; grid-template-columns: 1fr auto; gap: 28px; align-items: center; }
.mh-qr { margin: 0; text-align: center; padding: 14px; }
.mh-qr svg { width: 200px; height: 200px; display: block; margin: 0 auto 8px; }
.mh-qr figcaption { font-size: .85rem; color: var(--muted); }
.stall-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.stall-card { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; }
.stall-list { list-style: none; padding: 0; } .stall-list li { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); }
.stall-list li button { margin-left: auto; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
@media (max-width: 760px) { .mh-hero { grid-template-columns: 1fr; } }
.os-stall { font-size: .75rem; font-weight: 600; color: #1d4ed8; background: #e8f0fe; padding: 1px 7px; border-radius: 99px; margin-right: 4px; }
.stall-card .tag { align-self: flex-start; }
.note { background: #fdf6ee; border: 1px solid #f1dcc4; border-radius: 10px; padding: 10px 14px; font-size: 14px; color: #5b4a3a; }
