:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --line: #e3e5e9;
  --accent: #2f6fed;
  --accent-soft: #e8f0fe;
  --ok: #1f9d55;
  --ok-soft: #e3f6ea;
  --warn: #b7791f;
  --warn-soft: #fdf3dc;
  --danger: #d64545;
  --danger-soft: #fde8e8;
  --note: #fff8db;
  --ig: #c13584;
  --fb: #1877f2;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 72px;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 17px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Навігація */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 4px; padding: 0 16px; height: 54px;
}
.brand { font-weight: 700; margin-right: 16px; color: var(--text); }
.nav a {
  color: var(--muted); padding: 8px 12px; border-radius: 8px; position: relative; display: inline-flex;
  align-items: center; gap: 6px;
}
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.badge {
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; border-radius: 10px;
  padding: 1px 6px; min-width: 18px; text-align: center;
}
.badge:empty, .badge[data-n="0"] { display: none; }
.who { color: var(--muted); font-size: 13px; }
.bottomnav { display: none; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }

@media (max-width: 760px) {
  .topbar .nav, .topbar .who { display: none; }
  .topbar #enable-notify .lbl { display: none; }
  .bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
    background: var(--card); border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav a {
    flex: 1; text-align: center; padding: 8px 2px 10px; color: var(--muted); font-size: 11px;
    display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative;
  }
  .bottomnav a .ico { font-size: 20px; line-height: 1; }
  .bottomnav a.active { color: var(--accent); }
  .bottomnav .badge { position: absolute; top: 4px; left: 54%; }
  main { padding: 12px; }
}

/* Картки, форми, кнопки */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  margin-bottom: 12px;
}
label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 3px; }
input, select, textarea {
  width: 100%; font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--text);
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 600px) { .grid2 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 9px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f2c4c4; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
form.inline { display: inline; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--ok-soft); }
.flash.error { background: var(--danger-soft); color: #8a1f1f; }

/* Вкладки-фільтри */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.tabs a {
  white-space: nowrap; padding: 6px 12px; border-radius: 20px; background: var(--card);
  border: 1px solid var(--line); color: var(--text); font-size: 14px; display: inline-flex; gap: 6px;
  align-items: center;
}
.tabs a.active { background: var(--text); color: #fff; border-color: var(--text); }

/* Списки */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list a.item {
  display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); color: var(--text);
  align-items: flex-start;
}
.list a.item:last-child { border-bottom: 0; }
.list a.item:hover { background: #fafbfc; }
.list a.item.unread { background: #f5f9ff; }
.list a.item.unread .title { font-weight: 700; }
.item .body { flex: 1; min-width: 0; }
.item .title { display: flex; gap: 8px; align-items: center; }
.item .preview { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { text-align: right; font-size: 12px; color: var(--muted); white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.pf { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; color: #fff; }
.pf.instagram { background: var(--ig); }
.pf.facebook { background: var(--fb); }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: #eef0f3; color: var(--muted); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }

/* Статуси замовлень */
.status { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 12px; white-space: nowrap; }
.st-reserved { background: #eef0f3; color: #4b5563; }
.st-awaiting_payment { background: var(--warn-soft); color: var(--warn); }
.st-client_paid { background: #fff0d6; color: #b45309; }
.st-payment_confirmed, .st-ttn_ready { background: var(--accent-soft); color: var(--accent); }
.st-shipped { background: #ede9fe; color: #6d28d9; }
.st-received, .st-refunded { background: var(--ok-soft); color: var(--ok); }
.st-cancelled { background: #eef0f3; color: #9ca3af; text-decoration: line-through; }
.st-return_requested, .st-return_processed, .st-return_arrived { background: var(--danger-soft); color: var(--danger); }
.overdue { background: var(--danger-soft) !important; }

table.tbl { width: 100%; border-collapse: collapse; background: var(--card); }
.tbl th, .tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
.tbl tr.link { cursor: pointer; }
.tbl tr.link:hover td { background: #fafbfc; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }

/* Діалог */
.chat-layout { display: grid; grid-template-columns: 1fr 300px; gap: 12px; align-items: start; }
@media (max-width: 900px) { .chat-layout { grid-template-columns: 1fr; } }
.chat { display: flex; flex-direction: column; gap: 6px; padding: 12px; min-height: 200px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 14px; word-wrap: break-word; }
.msg .text { white-space: pre-wrap; }
.msg.in { align-self: flex-start; background: #eef0f3; border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.note { align-self: center; background: var(--note); border: 1px dashed #e6cf6b; font-size: 13px; max-width: 90%; }
.msg.failed { background: var(--danger-soft); color: #8a1f1f; border: 1px solid #f2c4c4; }
.msg .time { font-size: 11px; opacity: .7; margin-top: 3px; }
.msg img { max-width: 220px; border-radius: 8px; display: block; margin-top: 4px; }
.composer textarea { min-height: 80px; }
.composer .modes { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.composer .modes label {
  margin: 0; display: inline-flex; gap: 5px; align-items: center; color: var(--text); font-size: 13px;
  border: 1px solid var(--line); border-radius: 16px; padding: 4px 10px; cursor: pointer;
}
.composer .modes input { width: auto; margin: 0; }
.notice { padding: 8px 12px; border-radius: 8px; background: var(--warn-soft); color: #7c5410; font-size: 13px; margin-bottom: 8px; }
.notice.danger { background: var(--danger-soft); color: #8a1f1f; }

/* Картка замовлення */
.progress { display: flex; gap: 4px; margin: 6px 0 14px; flex-wrap: wrap; }
.progress span {
  flex: 1; min-width: 90px; font-size: 11px; text-align: center; padding: 6px 4px; border-radius: 6px;
  background: #eef0f3; color: var(--muted);
}
.progress span.done { background: var(--ok-soft); color: var(--ok); }
.progress span.now { background: var(--accent); color: #fff; font-weight: 700; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; white-space: pre-wrap; }
@media (max-width: 600px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: 6px; } }
.steps { display: flex; flex-direction: column; gap: 8px; }
.step-form { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.history li:last-child { border-bottom: 0; }
.copybox { white-space: pre-wrap; background: #fafbfc; border: 1px dashed var(--line); border-radius: 8px; padding: 10px; font-size: 14px; }
details summary { cursor: pointer; font-weight: 600; }

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile .n { font-size: 26px; font-weight: 700; }
.tile .l { font-size: 13px; color: var(--muted); }
.tile.alert .n { color: var(--danger); }

.login-wrap { max-width: 360px; margin: 10vh auto; }
