:root {
  --bg: #0b0d12;
  --panel: #12161f;
  --panel-2: #171c28;
  --border: #232a3a;
  --border-2: #2c3548;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --muted-2: #6b7383;
  --accent: #6ea8fe;
  --accent-2: #4b86f0;
  --accent-ink: #0a1020;
  --good: #3ecf8e;
  --warn: #f0b429;
  --bad: #f0616d;
  --bubble-me: #2a4a7f;
  --bubble-them: #1b2130;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
#app { min-height: 100%; display: flex; flex-direction: column; }
.boot { margin: auto; color: var(--muted); padding: 40px; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border-2);
  border-radius: 10px;
  padding: 11px 12px;
  width: 100%;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent-2); }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 5px; }
.field { margin-bottom: 12px; }

.btn {
  background: var(--accent-2);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 600;
  transition: filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; border: 1px solid var(--border-2); color: var(--text); }
.btn.subtle { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); }
.btn.danger { background: #3a2029; border: 1px solid #5a2b34; color: var(--bad); }
.btn.sm { padding: 7px 11px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.center { text-align: center; }
.hidden { display: none !important; }

/* ---- Auth ---- */
.auth-wrap { margin: auto; width: 100%; max-width: 380px; padding: 24px; }
.brand-logo { display:flex; align-items:center; gap:10px; justify-content:center; margin-bottom: 18px; }
.brand-logo img { width: 38px; height: 38px; }
.brand-logo b { font-size: 18px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card h1 { margin: 0 0 4px; font-size: 20px; }
.card p.sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }

/* ---- App shell ---- */
.shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.topbar .title { font-weight: 700; }
.topbar .spacer { flex: 1; }
.iconbtn {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 9px; padding: 7px 10px; font-size: 13px;
  position: relative;
}
.badge-dot {
  position: absolute; top: -5px; right: -5px;
  background: var(--bad); color: #fff; border-radius: 999px;
  min-width: 17px; height: 17px; font-size: 10px; line-height: 17px; text-align: center;
  padding: 0 4px; font-weight: 700;
}
.tabbar {
  display: flex; flex: 0 0 auto;
  background: var(--panel); border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; text-align: center; padding: 10px 4px; color: var(--muted);
  font-size: 12px; font-weight: 600; position: relative;
}
.tabbar a.active { color: var(--accent); }
.tabbar .b { position: absolute; top: 4px; right: 22%; background: var(--bad); color:#fff;
  border-radius: 999px; min-width: 16px; height: 16px; line-height: 16px; font-size: 10px; padding: 0 4px; }

.view { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: 16px; }
.stack > * + * { margin-top: 12px; }

/* ---- Chat ---- */
.chat { display: flex; flex-direction: column; height: 100%; }
.messages { flex: 1 1 auto; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 78%; padding: 9px 12px; border-radius: 14px; word-wrap: break-word; white-space: pre-wrap; }
.msg.them { align-self: flex-start; background: var(--bubble-them); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.msg.me { align-self: flex-end; background: var(--bubble-me); border-bottom-right-radius: 5px; }
.msg.system { align-self: center; background: transparent; border: 1px dashed var(--border-2); color: var(--muted); font-size: 13px; max-width: 92%; text-align: center; }
.msg .meta { font-size: 10px; color: var(--muted-2); margin-top: 4px; }
.msg.me .meta { color: #c3d3f0; }
.msg img.att { max-width: 240px; border-radius: 10px; display: block; margin-top: 4px; cursor: zoom-in; }
.composer { flex: 0 0 auto; display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); background: var(--panel); align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 140px; border-radius: 12px; }
.composer .btn { padding: 11px 14px; }

/* delivery card */
.delivery-card { border: 1px solid var(--border-2); background: var(--panel-2); border-radius: 12px; padding: 12px; max-width: 320px; }
.delivery-card h4 { margin: 0 0 8px; font-size: 14px; }
.cred { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.cred .k { color: var(--muted); font-size: 11px; width: 62px; flex: 0 0 auto; }
.cred .v { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; flex: 1; }
.cred .copy { background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text); border-radius: 7px; padding: 4px 8px; font-size: 12px; }

/* ---- Lists / cards ---- */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px; border-bottom: 1px solid var(--border);
  background: var(--panel); cursor: pointer;
}
.list-item:hover { background: var(--panel-2); }
.list-item .avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: 0 0 auto;
  background: var(--panel-2); border: 1px solid var(--border-2);
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--accent);
}
.list-item .main { flex: 1; min-width: 0; }
.list-item .main .l1 { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.list-item .main .l2 { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .right { text-align: right; color: var(--muted-2); font-size: 11px; }
.pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border-2); color: var(--muted); }
.pill.b-unread { background: var(--accent-2); color: #fff; border: 0; font-weight: 700; }
.pill.s-pending_payment { color: var(--warn); border-color: #4a3a12; }
.pill.s-paid { color: var(--accent); }
.pill.s-delivered, .pill.s-replaced { color: var(--good); border-color: #1f4536; }
.pill.s-refunded, .pill.s-cancelled { color: var(--bad); border-color: #4a2229; }

.prod {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 12px;
}
.prod h3 { margin: 0 0 4px; font-size: 16px; }
.prod .price { color: var(--accent); font-weight: 700; }
.prod .desc { color: var(--muted); font-size: 13px; margin: 6px 0 10px; white-space: pre-wrap; }

.banner {
  background: linear-gradient(180deg, #17233d, #131a2b);
  border: 1px solid var(--border-2); border-radius: 12px; padding: 14px; margin-bottom: 14px;
  display: flex; gap: 12px; align-items: center;
}
.banner .grow { min-width: 0; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted-2); margin: 18px 2px 8px; }

/* admin layout on wide screens */
.admin-split { display: flex; height: 100%; }
.admin-split .col-list { width: 340px; flex: 0 0 auto; border-right: 1px solid var(--border); overflow-y: auto; }
.admin-split .col-main { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
@media (max-width: 760px) {
  .admin-split .col-list { width: 100%; }
  .admin-split.has-detail .col-list { display: none; }
  .admin-split:not(.has-detail) .col-main { display: none; }
}

.toolbar { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--panel); align-items: center; }
.toolbar input { max-width: 260px; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: #0f1420; border: 1px solid var(--border-2); color: var(--text);
  padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50; font-size: 14px;
  max-width: 90vw;
}
.toast.err { border-color: #5a2b34; }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; z-index: 40; }
.modal { margin: auto; background: var(--panel); border: 1px solid var(--border-2); border-radius: var(--radius);
  padding: 20px; width: 92%; max-width: 460px; box-shadow: var(--shadow); max-height: 88vh; overflow-y: auto; }
.modal h3 { margin: 0 0 14px; }
.modal .row-btns { display: flex; gap: 10px; margin-top: 16px; }
.imgview { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; z-index: 60; }
.imgview img { margin: auto; max-width: 96%; max-height: 92%; border-radius: 8px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.kv .k { color: var(--muted); }
