/* ReferOn Mini App: light style of the ReferOn admin (see mockup.html) */
:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --line: #e7eaf0;
  --text: #1d2433;
  --muted: #6b7486;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --up: #12a150;
  --up-soft: #dcf7e7;
  --down: #e5484d;
  --down-soft: #fde4e4;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .04);
  --radius: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); }
body {
  font-family: Inter, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text);
  font-size: 14px; padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button { font: inherit; cursor: pointer; }
.content { padding: 14px 14px 18px; display: flex; flex-direction: column; gap: 14px; max-width: 640px; margin: 0 auto; }

/* top: logo + partner picker */
.top { display: flex; align-items: center; gap: 10px; }
.logo { font-weight: 800; font-size: 22px; letter-spacing: -1px; color: var(--accent); }
.partner {
  flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 9px 12px; display: flex; align-items: center; gap: 8px;
  font-weight: 500; text-align: left; color: var(--text);
}
.partner .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.partner .dot { width: 8px; height: 8px; border-radius: 50%; background: #ff5a36; flex: none; }
.partner .chev { margin-left: auto; color: var(--muted); font-size: 11px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: #2b3345; color: #fff; flex: none;
  display: grid; place-items: center; font-weight: 600; font-size: 14px;
}

.title-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 24px; font-weight: 600; margin: 0; }

/* period chips */
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.range { font-size: 12px; color: var(--muted); margin-top: -6px; }

/* cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid #eef0f4; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { padding: 12px; min-width: 0; }
.kpi-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.badge { font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 6px; white-space: nowrap; }
.badge.up { color: var(--up); background: var(--up-soft); }
.badge.down { color: var(--down); background: var(--down-soft); }
.badge.flat { color: var(--muted); background: #eef0f4; }
.kpi-value { font-size: 22px; font-weight: 700; margin: 6px 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi svg { display: block; width: 100%; height: 28px; margin-top: 6px; }
.kpi.wide { grid-column: span 2; display: flex; align-items: center; gap: 12px; }
.kpi.wide .kpi-main { flex: 1; min-width: 0; }
.kpi.wide .kpi-sub { white-space: normal; }
.kpi.wide svg { width: 42%; height: 40px; margin: 0; flex: none; }

/* underline tabs */
.tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--line); padding: 0 14px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; padding: 12px 0 10px; font-size: 14px; color: var(--muted); border: 0; background: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.on { color: var(--accent); border-color: var(--accent); font-weight: 500; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 14px 0; }
.chart-head b { font-size: 16px; font-weight: 600; }
.chart-head span { font-size: 12px; color: var(--muted); }
.chart { padding: 8px 14px 14px; }
.chart svg { width: 100%; height: 160px; display: block; }

/* table card */
.card-title { display: flex; justify-content: space-between; align-items: center; padding: 14px 14px 8px; gap: 8px; }
.card-title b { font-size: 16px; font-weight: 600; }
.seg { display: flex; background: var(--bg); border-radius: 8px; padding: 2px; }
.seg button { font-size: 12px; padding: 4px 8px; border-radius: 6px; color: var(--muted); border: 0; background: none; }
.seg button.on { background: var(--card); color: var(--accent); box-shadow: var(--shadow); font-weight: 500; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
  font-weight: 600; background: #f8f9fb; padding: 8px 14px;
}
th.num, td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td { padding: 10px 14px; border-top: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.brand i { width: 22px; height: 22px; border-radius: 6px; display: inline-grid; place-items: center; color: #fff; font-style: normal; font-size: 11px; flex: none; }
.bar { height: 4px; background: var(--accent-soft); border-radius: 2px; margin-top: 5px; }
.bar div { height: 100%; background: var(--accent); border-radius: 2px; }
.neg { color: var(--down); }
.empty { text-align: center; color: var(--muted); padding: 22px 14px; font-size: 13px; }

/* shortcuts */
.list .row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-top: 1px solid var(--line); font-weight: 500; width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; color: var(--text); }
.list .row:first-child { border-top: 0; }
.list .ico { width: 32px; height: 32px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.list .ico svg { width: 17px; height: 17px; }
.list .row small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; margin-top: 1px; }
.list .row .go { margin-left: auto; color: #b3bac7; }

/* bottom navigation */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.nav button { height: 60px; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--muted); }
.nav button.on { color: var(--accent); font-weight: 500; }
.nav svg { width: 20px; height: 20px; }

/* lists and cards (campaigns, affiliates) */
.search {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit;
  background: var(--card); box-shadow: var(--shadow); outline: none; color: var(--text);
}
.search:focus { border-color: var(--accent); }
.clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .row small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 11.5px; font-weight: 600; padding: 3px 8px; border-radius: 6px; white-space: nowrap; flex: none; }
.status.ok { color: var(--up); background: var(--up-soft); }
.status.no { color: var(--muted); background: #eef0f4; }
.status.wait { color: #8a6100; background: #fff3cf; }
.status.bad { color: var(--down); background: var(--down-soft); }
.back { color: var(--accent); font-size: 15px; font-weight: 500; border: 0; background: none; padding: 2px 0; text-align: left; align-self: flex-start; }
.camp-head { display: flex; gap: 12px; align-items: center; padding: 14px; }
.camp-logo { width: 48px; height: 48px; border-radius: 12px; background: #ffb020; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 18px; flex: none; }
.camp-head h2 { margin: 0; font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.counters { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); text-align: center; }
.counters div { padding: 12px 6px; }
.counters div + div { border-left: 1px solid var(--line); }
.counters b { display: block; font-size: 18px; }
.kv .row { display: flex; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 13.5px; }
.kv .row:first-child { border-top: 0; }
.kv .k { color: var(--muted); width: 96px; flex: none; }
.kv .v { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.kv .v.link { color: var(--accent); }

/* partner sheet */
.sheet-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 10; display: none; }
.sheet-back.open { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-height: 80vh; background: var(--card); z-index: 11;
  border-radius: 16px 16px 0 0; display: flex; flex-direction: column; transform: translateY(100%);
  visibility: hidden; transition: transform .2s, visibility 0s .2s; padding-bottom: env(safe-area-inset-bottom);
}
.sheet.open { transform: none; visibility: visible; transition: transform .2s; }
.sheet-head { padding: 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.sheet-head b { font-size: 16px; }
.sheet-x { border: 0; background: var(--bg); color: var(--muted); width: 30px; height: 30px; border-radius: 50%; }
.sheet-body { overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }
.sheet-tools { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); }
.sheet input[type=search], .sheet input[type=text], .sheet input[type=date] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; background: var(--bg); outline: none; color: var(--text);
}
.sheet input:focus { border-color: var(--accent); }
.sheet-list { overflow-y: auto; }
.sheet-list button { width: 100%; text-align: left; padding: 12px 14px; border: 0; border-top: 1px solid var(--line); background: none; color: var(--text); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sheet-list button:first-child { border-top: 0; }
.sheet-list button.on { color: var(--accent); font-weight: 600; }
.sheet-list small { color: var(--muted); font-weight: 400; }
.sheet-list .check { width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid #c5ccd8; flex: none; display: grid; place-items: center; font-size: 13px; color: #fff; }
.sheet-list .on .check { background: var(--accent); border-color: var(--accent); }
.sheet-list .item { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sheet-foot { padding: 12px 14px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.sheet-foot button { flex: 1; }
.btn-light { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; font-weight: 500; }
.danger-link { color: var(--down); }

/* report builder */
.title-row .btn { border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow); border-radius: 10px; padding: 8px 11px; font-size: 13px; font-weight: 500; color: var(--accent); }
.section { padding: 12px 14px; }
.section + .section { border-top: 1px solid var(--line); }
.label { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; display: flex; justify-content: space-between; }
.label span { text-transform: none; letter-spacing: 0; font-weight: 500; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  font-size: 12.5px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); display: inline-flex; align-items: center; gap: 5px;
}
.pill.on { background: var(--accent-soft); border-color: #c9dcfd; color: var(--accent); font-weight: 500; }
.pill.add { color: var(--accent); border-style: dashed; }
.pill .x { color: #93a0b4; padding-left: 2px; }
.sub { font-size: 12px; color: var(--muted); }
.run-bar {
  position: fixed; left: 0; right: 0; bottom: calc(60px + env(safe-area-inset-bottom)); padding: 10px 14px;
  background: linear-gradient(rgba(244, 246, 250, 0), var(--bg) 35%); z-index: 4;
}
.run-bar button { width: 100%; max-width: 612px; display: block; margin: 0 auto; height: 46px; border-radius: 12px; border: 0; background: var(--accent); color: #fff; font-weight: 600; font-size: 15px; box-shadow: 0 4px 12px rgba(31, 111, 235, .25); }
.run-bar button:disabled { opacity: .6; }
body.has-run { padding-bottom: calc(136px + env(safe-area-inset-bottom)); }
.totals { display: grid; grid-template-columns: repeat(3, 1fr); }
.totals div { padding: 12px 8px; text-align: center; min-width: 0; }
.totals div + div { border-left: 1px solid var(--line); }
.totals b { display: block; font-size: 16px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-head { padding: 14px 14px 10px; }
.result-head b { font-size: 16px; }
.stale { opacity: .55; }
.hint { background: #fff7e0; color: #8a6100; border: 1px solid #f5e1a4; border-radius: 10px; padding: 9px 12px; font-size: 13px; }
.rank { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 22px; display: inline-block; }
.who { font-weight: 500; word-break: break-word; }
.who small { display: block; color: var(--muted); font-weight: 400; font-size: 11.5px; }
tr.tap { cursor: pointer; }
tr.tap:active td { background: #f8f9fb; }
.more { display: block; width: 100%; text-align: center; color: var(--accent); font-size: 13px; font-weight: 500; padding: 12px; border: 0; border-top: 1px solid var(--line); background: none; }
.sort-btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 5px 9px; font-size: 12.5px; color: var(--accent); font-weight: 500; }
.kv-list .row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 14px; border-top: 1px solid var(--line); font-size: 13.5px; }
.kv-list .row span:last-child { font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.kv-list .group { padding: 12px 14px 4px; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.kv-list .group + .row { border-top: 0; }
.kv-list .total { font-weight: 700; }
.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dates label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }

/* states */
.skeleton { background: linear-gradient(90deg, #eceff4 0%, #f6f7fa 50%, #eceff4 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.notice { padding: 28px 18px; text-align: center; }
.notice b { display: block; font-size: 17px; margin-bottom: 6px; }
.notice p { color: var(--muted); margin: 0 0 14px; }
.btn-primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600; }
.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #1d2433; color: #fff; padding: 9px 14px; border-radius: 10px; font-size: 13px; z-index: 20;
  opacity: 0; transition: opacity .2s; pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; }
