:root {
  --paper: #f6f7f9;
  --ink: #17191d;
  --muted: #686d77;
  --soft: #a7acb5;
  --line: #e0e4eb;
  --card: #ffffff;
  --hover: #eef0f3;
  --good: #1f8a4c;
  --good-bg: #e6f4ec;
  --warn: #a15c00;
  --warn-bg: #fdf1df;
  --bad: #c0362c;
  --bad-bg: #fbe9e7;
  --ig-bubble: #efefef;
  --ig-blue: #0095f6;
  --radius: 18px;
  --display: 'Manrope', system-ui, sans-serif;
  --body: 'DM Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh;
  padding: 22px 14px; display: flex; flex-direction: column; gap: 22px;
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--ink); color: #fff;
  display: grid; place-items: center; font: 800 15px var(--display); letter-spacing: -0.5px;
}
.brand-name { font: 800 17px var(--display); letter-spacing: -0.6px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
  text-decoration: none; color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--hover); color: var(--ink); }
.nav a.on { background: var(--card); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.nav sup { font-size: 10px; color: var(--soft); margin-left: -6px; transform: translateY(-3px); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; padding: 0 8px; }
.acct { display: flex; align-items: center; gap: 10px; min-width: 0; }
.acct img, .acct .ph { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--line); flex: none; }
.acct-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-sub { font-size: 12px; color: var(--muted); }

.main { padding: 32px 40px 80px; max-width: 1120px; width: 100%; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
h1 { font: 800 34px/1.05 var(--display); letter-spacing: -1.4px; margin: 0; }
h2 { font: 800 19px/1.2 var(--display); letter-spacing: -0.5px; margin: 0; }
h3 { font: 700 15px/1.3 var(--body); margin: 0; }
.lede { color: var(--muted); margin: 6px 0 0; }
.muted { color: var(--muted); }
.soft { color: var(--soft); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 13px; }

/* ---------- primitives ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px; border-radius: 999px; border: 1px solid var(--ink);
  background: var(--ink); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #2a2d33; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { background: var(--card); color: var(--bad); border-color: var(--line); }
.btn.sm { height: 32px; padding: 0 13px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { width: 32px; height: 32px; border-radius: 999px; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }

.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--hover); color: var(--ink); white-space: nowrap; }
.pill.key { background: var(--ink); color: #fff; letter-spacing: .3px; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.field > label, .label { font-size: 13px; font-weight: 600; }
.hint { font-size: 12.5px; color: var(--muted); }
.input, textarea.input, select.input {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { resize: vertical; min-height: 84px; line-height: 1.45; }
.input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(23, 25, 29, .08); }
.counter { font-size: 12px; color: var(--soft); text-align: right; margin-top: -2px; }
.counter.over { color: var(--bad); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }

.seg { display: inline-flex; align-self: flex-start; max-width: 100%; overflow-x: auto; scrollbar-width: none; background: var(--hover); border-radius: 999px; padding: 3px; gap: 2px; }
.seg::-webkit-scrollbar { display: none; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; flex: none; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

.switch { position: relative; width: 40px; height: 24px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .15s; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: transform .15s; }
.switch input:checked + span { background: var(--ink); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px rgba(23, 25, 29, .15); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 6px; background: var(--card); }
.chips:focus-within { border-color: var(--ink); box-shadow: 0 0 0 3px rgba(23, 25, 29, .08); }
.chips input { border: 0; outline: none; flex: 1; min-width: 120px; padding: 4px 6px; background: transparent; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--ink); color: #fff; border-radius: 999px; padding: 3px 4px 3px 11px; font-size: 13px; font-weight: 600; }
.chip button { border: 0; background: rgba(255, 255, 255, .15); color: #fff; width: 18px; height: 18px; border-radius: 50%; cursor: pointer; font-size: 12px; line-height: 1; }

/* ---------- stats ---------- */
.stat .k { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat .v { font: 800 36px/1.1 var(--display); letter-spacing: -1.5px; margin-top: 6px; }
.stat .s { font-size: 12.5px; color: var(--soft); margin-top: 2px; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 180px; overflow: visible; }
.chart .bar { fill: var(--ink); }
.chart .bar-hit { fill: transparent; cursor: default; }
.chart .bar-hit:hover + .bar, .chart .bar.hl { fill: #3d414a; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--soft); font-size: 11px; }
.tip {
  position: absolute; pointer-events: none; background: var(--ink); color: #fff; border-radius: 10px;
  padding: 8px 10px; font-size: 12px; line-height: 1.5; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
}
.tip b { font-weight: 600; }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; padding-top: 0; }
.ev-ico { width: 30px; height: 30px; border-radius: 50%; background: var(--hover); display: grid; place-items: center; flex: none; color: var(--muted); }
.ev-ico svg { width: 15px; height: 15px; }
.ev-ico.bad { background: var(--bad-bg); color: var(--bad); }
.ev-ico.good { background: var(--good-bg); color: var(--good); }
.ev-body { min-width: 0; flex: 1; }
.ev-title { font-size: 14px; }
.ev-detail { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.ev-time { font-size: 12px; color: var(--soft); white-space: nowrap; }

.auto-card { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; }
.auto-card + .auto-card { margin-top: 12px; }
.auto-card .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.funnel { display: flex; gap: 22px; margin-top: 14px; flex-wrap: wrap; }
.funnel div { font-size: 12.5px; color: var(--muted); }
.funnel b { display: block; font: 800 20px/1.2 var(--display); color: var(--ink); letter-spacing: -.5px; }
.funnel sup { font-size: 11px; color: var(--soft); font-weight: 600; margin-left: 2px; }
.clickable { cursor: pointer; transition: box-shadow .15s; }
.clickable:hover { box-shadow: 0 0 0 1px var(--ink); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 12px 10px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }

.alert { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 14px; margin-bottom: 16px; font-size: 14px; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.good { background: var(--good-bg); color: var(--good); }
.alert a { font-weight: 600; }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 4px; }

/* ---------- media picker ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; max-height: 340px; overflow-y: auto; padding: 2px; }
.media { position: relative; aspect-ratio: 4 / 5; border-radius: 10px; overflow: hidden; background: var(--hover); border: 0; padding: 0; cursor: pointer; }
.media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media.on { box-shadow: 0 0 0 3px var(--ink); }
.media .check { position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%; background: rgba(255, 255, 255, .9); border: 1.5px solid var(--soft); display: grid; place-items: center; }
.media.on .check { background: var(--ink); border-color: var(--ink); color: #fff; }
.media .check svg { width: 13px; height: 13px; }
.media .kind { position: absolute; bottom: 6px; left: 6px; font-size: 10.5px; font-weight: 700; background: rgba(0, 0, 0, .55); color: #fff; padding: 1px 6px; border-radius: 6px; }

/* ---------- IG preview ---------- */
.preview { position: sticky; top: 24px; }
.phone { background: #fff; border: 1px solid var(--line); border-radius: 28px; overflow: hidden; }
.phone-top { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid #efefef; }
.phone-top img, .phone-top .ph { width: 28px; height: 28px; border-radius: 50%; background: var(--line); object-fit: cover; }
.phone-top b { font-size: 14px; }
.thread { padding: 16px 14px 20px; display: flex; flex-direction: column; gap: 8px; min-height: 260px; font-family: -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; font-size: 14px; }
.thread .ctx { align-self: center; font-size: 11.5px; color: #737373; text-align: center; margin-bottom: 4px; max-width: 90%; }
.bubble { max-width: 82%; padding: 9px 13px; border-radius: 20px; line-height: 1.35; overflow-wrap: anywhere; white-space: pre-wrap; }
.bubble.them { background: var(--ig-bubble); align-self: flex-start; }
.bubble.me { background: #3797f0; color: #fff; align-self: flex-end; }
.tpl { align-self: flex-start; max-width: 82%; border: 1px solid #dbdbdb; border-radius: 18px; overflow: hidden; }
.tpl .t { padding: 10px 13px; line-height: 1.35; white-space: pre-wrap; overflow-wrap: anywhere; }
.tpl .b { border-top: 1px solid #dbdbdb; text-align: center; padding: 9px 13px; font-weight: 600; color: var(--ig-blue); }
.comment-mock { border-top: 1px solid var(--line); padding: 14px 16px; font-family: -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; font-size: 13.5px; }
.comment-mock .c { display: flex; gap: 8px; }
.comment-mock .c + .c { margin: 10px 0 0 36px; }
.comment-mock .av { width: 28px; height: 28px; border-radius: 50%; background: var(--line); flex: none; object-fit: cover; }
.comment-mock .c.reply .av { width: 22px; height: 22px; }

.test-result { margin-top: 8px; font-size: 13px; }

/* ---------- settings steps ---------- */
.steps { counter-reset: step; }
.step { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 14px; padding: 18px 0; border-top: 1px solid var(--line); }
.step:first-child { border-top: 0; padding-top: 0; }
.step-n { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center; font: 800 13px var(--display); color: var(--muted); }
.step-n.ok { background: var(--ink); border-color: var(--ink); color: #fff; }
.step-n svg { width: 15px; height: 15px; }
.copy { display: flex; gap: 6px; align-items: center; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 6px 6px 6px 12px; }
.copy code { flex: 1; overflow-x: auto; white-space: nowrap; font-size: 13px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 32px; }
.login h1 { font-size: 28px; margin: 18px 0 6px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 500; z-index: 50; box-shadow: 0 8px 24px rgba(0, 0, 0, .15); }
.toast.bad { background: var(--bad); }

.loading { padding: 60px 0; text-align: center; color: var(--soft); }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(to top, var(--paper) 70%, transparent); padding: 18px 0 4px; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- mobile ---------- */
.tabbar { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
  .main { padding: 20px 16px 110px; }
  h1 { font-size: 28px; letter-spacing: -1px; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g2, .split { grid-template-columns: minmax(0, 1fr); }
  .preview { position: static; }
  .stat .v { font-size: 30px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: rgba(246, 247, 249, .94); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--soft); text-decoration: none; padding: 4px 0; font-weight: 600; }
  .tabbar a.on { color: var(--ink); }
  .tabbar svg { width: 21px; height: 21px; }
  .auto-card { grid-template-columns: 1fr; }
  .tbl .hide-sm { display: none; }
  .seg button { padding: 6px 11px; }
  .sticky-actions { bottom: calc(58px + env(safe-area-inset-bottom)); }
}
