:root {
  --bg: #0e0b10;
  --panel: #17131b;
  --panel-2: #201a26;
  --line: #2e2636;
  --text: #f4eff6;
  --muted: #a79fb0;
  --accent: #e11d48;
  --accent-2: #fb7185;
  --star: #fbbf24;
  --ok: #34d399;
  --warn: #fbbf24;
  --info: #60a5fa;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  --tabbar: 64px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f4f8; --panel: #ffffff; --panel-2: #f1ecf3; --line: #e3dbe7;
    --text: #1b1420; --muted: #6f6578; --shadow: 0 8px 30px rgba(40, 10, 40, .08);
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Vazirmatn", Tahoma, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; }
[dir=auto] { unicode-bidi: plaintext; }

/* ---------- layout */
.shell { display: flex; min-height: 100vh; }
.side { display: none; }
.main { flex: 1; min-width: 0; padding: 0 16px calc(var(--tabbar) + 24px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: 14px 0 12px; background: linear-gradient(var(--bg) 75%, transparent);
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { border: 0; background: var(--panel-2); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 18px; }
.brand { font-weight: 800; letter-spacing: .08em; font-size: 14px; }
.brand b { color: var(--accent); }
.content { max-width: 860px; margin: 0 auto; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-weight: 600;
}
.tab .ico { font-size: 20px; line-height: 1; }
.tab.active { color: var(--text); }
.tab.active .ico { filter: drop-shadow(0 0 8px var(--accent)); }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; display: inline-grid; place-items: center;
}
.tab .badge { position: absolute; top: 6px; left: calc(50% + 6px); }

@media (min-width: 900px) {
  .side {
    display: flex; flex-direction: column; gap: 4px; width: 230px; padding: 22px 14px; position: sticky; top: 0;
    height: 100vh; border-right: 1px solid var(--line); background: var(--panel);
  }
  .side .brand { padding: 4px 12px 18px; font-size: 15px; }
  .side .tab { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 11px 12px; border-radius: 10px; font-size: 14px; }
  .side .tab.active { background: var(--panel-2); }
  .side .tab .badge { position: static; margin-left: auto; }
  .tabbar { display: none; }
  .main { padding: 0 32px 40px; }
}

/* ---------- surfaces */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card, .stack > * + * { margin-top: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; }
.card h3 { font-size: 14px; margin: 14px 0 8px; color: var(--muted); font-weight: 600; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .grid2.stack-sm { grid-template-columns: 1fr; } }

.kpi { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 700px) { .kpi { grid-template-columns: repeat(4, 1fr); } }
.kpi .card { padding: 14px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 800; margin-top: 2px; }
.kpi a.card { display: block; color: inherit; }
.kpi .hot { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }

.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: flex; gap: 12px; align-items: center; padding: 14px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); color: inherit; cursor: pointer;
}
.item:active { transform: scale(.995); }
.item .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #7c3aed); color: #fff;
}
.stars { color: var(--star); font-weight: 700; white-space: nowrap; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .big { font-size: 40px; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.pill.pending { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.delivering, .pill.refunding { background: color-mix(in srgb, var(--info) 18%, transparent); color: var(--info); }
.pill.delivered, .pill.on { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.refunded, .pill.off { background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--muted); }
.pill.bad { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.pill.accent { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent-2); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 7px 14px; cursor: pointer;
  white-space: nowrap; font-weight: 600; font-size: 13px;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- forms */
label.field { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 6px; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 16px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; font-weight: 650; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ok { background: #059669; border-color: #059669; color: #fff; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: wait; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; cursor: pointer; }
.toggle input { display: none; }
.toggle .sw { width: 46px; height: 28px; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: .2s; }
.toggle .sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; }
.toggle input:checked + .sw { background: var(--accent); }
.toggle input:checked + .sw::after { left: 21px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 1px 0 0; flex: none; }

/* ---------- chat */
.thread { display: flex; flex-direction: column; gap: 6px; padding: 4px 0 12px; }
.bubble { max-width: 82%; padding: 9px 12px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.in { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 5px; }
.bubble.out { align-self: flex-end; background: color-mix(in srgb, var(--accent) 80%, #000); color: #fff; border-bottom-right-radius: 5px; }
.bubble.system { align-self: center; background: transparent; color: var(--muted); font-size: 12px; text-align: center; padding: 4px 8px; }
.bubble .meta { font-size: 11px; opacity: .65; margin-top: 4px; text-align: end; }
.bubble img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-bottom: 6px; background: rgba(255,255,255,.06); min-height: 60px; }
.bubble .file { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; background: rgba(0,0,0,.18); margin-bottom: 6px; color: inherit; }
.composer {
  position: sticky; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 8px); display: flex; gap: 8px; align-items: flex-end;
  padding: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
@media (min-width: 900px) { .composer { bottom: 16px; } }
.composer textarea { min-height: 44px; max-height: 160px; padding: 10px 12px; }
.icon-btn { width: 44px; height: 44px; border-radius: 11px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; font-size: 19px; flex: none; }
.icon-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.attach-chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 99px; background: var(--panel-2); font-size: 13px; margin: 0 0 8px; }
.attach-chip button { border: 0; background: none; cursor: pointer; color: var(--muted); }

/* ---------- modal & toasts */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.modal { width: 100%; max-width: 520px; max-height: 85vh; overflow: auto; background: var(--panel); border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 600px) { .modal-back { align-items: center; } .modal { border-radius: 20px; } }
.modal h2 { margin: 0 0 12px; font-size: 17px; }
#toasts { position: fixed; z-index: 60; left: 50%; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 84px); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { padding: 12px 14px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 600; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); color: #fff; }
@media (min-width: 900px) { #toasts { bottom: 24px; } }

.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(100%, 380px); padding: 24px; }
.login .logo { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 22px; margin-bottom: 14px; }
.setup li { margin: 6px 0; }
.setup .done { color: var(--ok); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.preview { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; font-size: 14px; max-height: 160px; overflow: auto; }
.codes { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.codes .r { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.codes .r:last-child { border-bottom: 0; }
.codes .used { color: var(--muted); text-decoration: line-through; }

/* ---------- product pictures (Mini App shop) */
.thumb { width: 46px; height: 46px; flex: none; border-radius: 10px; object-fit: cover; background: var(--panel-2); }
.thumb.none { display: grid; place-items: center; font-size: 18px; opacity: .5; }
.product-pic { display: block; width: 100%; max-width: 260px; aspect-ratio: 1; object-fit: cover; border-radius: 12px; background: var(--panel-2); }
.product-pic.none { display: grid; place-items: center; color: var(--muted); font-size: 13px; border: 1px dashed var(--line); }
