:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #e0e7ff;
  --good: #047857;
  --good-soft: #d1fae5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --fb: #1877f2;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 5%), 0 8px 24px rgb(0 0 0 / 5%);
  color-scheme: light;
  font-family: "Segoe UI", Tahoma, system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --card: #141a2e;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --line: #273047;
    --primary: #4f7cff;
    --primary-hover: #6b91ff;
    --primary-soft: #1e2a55;
    --good: #34d399;
    --good-soft: #0f3a2e;
    --warn: #fbbf24;
    --warn-soft: #3d2f0c;
    --bad: #f87171;
    --bad-soft: #3f1515;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--primary); }
h1 { font-size: clamp(22px, 4vw, 30px); margin: 0; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 0 0 8px; }
ul, ol { padding-inline-start: 20px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
main { width: min(1100px, 100%); margin: 0 auto; padding: 20px 16px 60px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card.narrow { max-width: 460px; margin: 40px auto; }
.warn-card { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.error-card { background: var(--bad-soft); color: var(--bad); }
details.card > summary { cursor: pointer; font-weight: 600; }
details > summary { cursor: pointer; margin-top: 12px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: end; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar p { margin: 0; flex: 1 1 300px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
.error-text { color: var(--bad); font-size: 14px; }
.good-text { color: var(--good); font-weight: 600; }
.pre { white-space: pre-wrap; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.field { display: grid; gap: 4px; }
.field > span { font-weight: 600; font-size: 14px; }
.field small { color: var(--muted); font-size: 12.5px; }
input, textarea, select {
  width: 100%; padding: 10px 12px; font: inherit; color: inherit;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input:disabled, select:disabled { opacity: .7; }
textarea { resize: vertical; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 3px; flex: none; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 12px; margin: 0; }
legend { font-weight: 700; padding: 0 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; min-height: 40px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px;
}
.btn:hover { border-color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.fb { background: var(--fb); border-color: var(--fb); color: #fff; font-size: 17px; min-height: 48px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 13.5px; }
.btn.block { width: 100%; }
.icon-btn { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--muted); padding: 6px; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; background: var(--line); color: var(--muted); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12.5px; padding: 2px 8px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); }

.switch { display: inline-flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; }
.switch i { width: 38px; height: 22px; border-radius: 999px; background: var(--line); position: relative; transition: background .2s; }
.switch i::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: inset-inline-start .2s; box-shadow: 0 1px 2px rgb(0 0 0 / 30%); }
.switch.on { border-color: var(--good); color: var(--good); }
.switch.on i { background: var(--good); }
.switch.on i::after { inset-inline-start: 19px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; }
.stat b { font-size: 28px; }
.stat span { color: var(--muted); font-size: 13.5px; }
.stat.bad b { color: var(--bad); }

.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.list li:first-child { border-top: 0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: start; padding: 10px 8px; border-bottom: 1px solid var(--line); }
th { font-size: 13px; color: var(--muted); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--bg); }

.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.product { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.product.inactive { opacity: .65; }
.product img, .product .img-ph { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--bg); }
.img-ph { display: grid; place-items: center; font-size: 32px; }
.product-body { padding: 12px 14px; display: grid; gap: 8px; }
.product-body p { margin: 0; font-size: 14px; }
.price { font-weight: 800; color: var(--good); white-space: nowrap; }

.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.post-card { display: grid; gap: 6px; text-align: start; padding: 8px; font: inherit; color: inherit; background: var(--bg); border: 2px solid transparent; border-radius: 12px; cursor: pointer; }
.post-card:hover:not(:disabled) { border-color: var(--primary); }
.post-card:disabled { opacity: .5; cursor: not-allowed; }
.post-card img, .post-card .img-ph { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--card); }
.post-preview:not(:empty) { font-size: 14px; color: var(--muted); padding: 8px 10px; border-inline-start: 3px solid var(--primary); background: var(--bg); border-radius: 6px; white-space: pre-wrap; max-height: 90px; overflow: auto; }
.message-preview { white-space: pre-wrap; padding: 12px 14px; border-radius: 18px 18px 18px 4px; background: var(--primary); color: #fff; max-width: 90%; justify-self: start; }
.message-preview:empty { display: none; }

.activity { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.activity li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; }
.activity p { margin: 0; }
.comment { font-style: italic; }

.copy { display: flex; gap: 8px; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px 6px 6px 12px; margin-top: 8px; }
.copy code { flex: 1; overflow-x: auto; white-space: nowrap; font-size: 13.5px; direction: ltr; text-align: left; }

dialog { border: 0; border-radius: 18px; padding: 20px; width: min(480px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--card); color: var(--text); }
dialog.wide { width: min(760px, calc(100vw - 24px)); }
dialog::backdrop { background: rgb(0 0 0 / 45%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { margin: 0; }

.page-choice { padding: 12px; border: 1px solid var(--line); border-radius: 10px; }
.big-icon { font-size: 48px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; padding: 12px 18px; border-radius: 12px; background: #111827; color: #fff; box-shadow: 0 10px 30px rgb(0 0 0 / 25%); max-width: calc(100vw - 32px); }
.toast.error { background: var(--bad); }

@media (max-width: 600px) {
  .two { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .card.narrow { margin: 16px auto; }
  .topbar .btn.small { padding: 5px 6px; }
}
