:root {
  --red: #e31c13;
  --red-soft: #fff1f0;
  --green: #2e9e4b;
  --green-soft: #e8f6ec;
  --green-tab: #eaf7ee;
  --text: #1f1f1f;
  --muted: #8a8a8a;
  --line: #ececec;
  --bg: #f7f7f7;
  --warn: #fdece6;
  --warn-text: #c24a2a;
  --sidebar: 56px;
  --sidebar-open: 232px;
  --topbar: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: #fff;
  display: flex;
  min-height: 100vh;
  overflow: hidden;
}

button, input, select { font-family: inherit; }
button { cursor: pointer; }
a { color: var(--green); }

/* ---------- SIDEBAR ---------- */
#sidebar {
  width: var(--sidebar);
  min-width: var(--sidebar);
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100vh;
  z-index: 40;
  transition: width .2s ease, min-width .2s ease;
  overflow: hidden;
}
#sidebar.open { width: var(--sidebar-open); min-width: var(--sidebar-open); }

.sidebar-logo {
  height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-bottom: 1px solid #f2f2f2;
  flex-shrink: 0;
  overflow: hidden;
}
.logo-a {
  width: 28px; height: 28px; min-width: 28px;
  display: block; object-fit: contain;
}
.logo-publisher {
  height: 32px; width: 0; max-width: 0; opacity: 0;
  object-fit: contain; object-position: left center;
  overflow: hidden; pointer-events: none;
  transition: opacity .2s ease, width .2s ease, max-width .2s ease;
}
#sidebar.open .logo-publisher {
  opacity: 1; width: 148px; max-width: 148px;
}

.sidebar-toggle {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid #f2f2f2;
  color: #777;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .4px;
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: #fafafa; }
.sidebar-toggle span { opacity: 0; width: 0; overflow: hidden; white-space: nowrap; }
#sidebar.open .sidebar-toggle span { opacity: 1; width: auto; }
.sidebar-toggle svg { transform: rotate(180deg); }
#sidebar.open .sidebar-toggle svg { transform: none; }

.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 8px 0 12px; }
.nav-section {
  font-size: 10px; color: #b0b0b0; letter-spacing: .8px; font-weight: 600;
  padding: 14px 16px 6px; white-space: nowrap; opacity: 0; height: 0; overflow: hidden;
}
#sidebar.open .nav-section { opacity: 1; height: auto; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  height: 40px; margin: 2px 8px; padding: 0 10px;
  border-radius: 8px; color: #6b6b6b; cursor: pointer; white-space: nowrap;
}
.nav-item:hover { background: #f6f6f6; color: #333; }
.nav-item.active { background: #fff4f3; color: var(--red); }
.nav-item svg { min-width: 20px; width: 20px; height: 20px; fill: currentColor; }
.nav-item span { font-size: 13px; opacity: 0; width: 0; overflow: hidden; }
#sidebar.open .nav-item span { opacity: 1; width: auto; }

.sidebar-footer {
  padding: 12px 16px 16px; font-size: 10px; color: #b8b8b8; line-height: 1.5;
  border-top: 1px solid #f2f2f2; white-space: nowrap; opacity: 0; height: 0; overflow: hidden;
}
#sidebar.open .sidebar-footer { opacity: 1; height: auto; }
.sidebar-footer a { color: #b8b8b8; text-decoration: none; }
.demo-label { color: #c24a2a; font-weight: 600; margin-bottom: 6px; white-space: normal; }

/* ---------- MAIN ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100vh; background: #fff; }

#topbar {
  height: var(--topbar);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; flex-shrink: 0; background: #fff;
}
.page-title { font-size: 20px; font-weight: 600; flex: 1; color: #222; }

.btn-outline {
  height: 36px; padding: 0 16px; border: 1.5px solid #222; background: #fff;
  border-radius: 6px; font-size: 12px; font-weight: 700; letter-spacing: .3px;
}
.btn-outline:hover { background: #f7f7f7; }

.balance-wrap { position: relative; display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 6px; cursor: default; }
.balance-wrap .lbl { font-size: 13px; color: #555; }
.balance-wrap .val { font-size: 13px; font-weight: 700; }
.balance-arrow {
  font-size: 10px; color: #777; line-height: 1; cursor: pointer;
  background: none; border: none; padding: 4px 6px; border-radius: 4px;
  transition: transform .2s, background .15s;
}
.balance-arrow:hover { background: #f0f0f0; }
.balance-wrap.open .balance-arrow { transform: rotate(180deg); }
.balance-popup {
  display: none; position: absolute; top: calc(100% + 6px); right: 0;
  background: #fff; border: 1px solid #e6e6e6; border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,.12); padding: 14px 18px; z-index: 50; min-width: 360px;
  white-space: nowrap;
}
.balance-wrap.open .balance-popup { display: block; }
.bp-row { display: flex; align-items: flex-end; gap: 8px; }
.bp-item { display: flex; flex-direction: column; align-items: center; min-width: 70px; }
.bp-val { font-size: 13px; font-weight: 600; }
.bp-val.green { color: #3d9a4c; }
.bp-val.dark { color: #333; }
.bp-lbl { font-size: 9px; color: #9a9a9a; letter-spacing: .5px; text-transform: uppercase; margin-top: 3px; }
.bp-op { padding-bottom: 14px; color: #444; }

.user-badge { display: flex; align-items: center; gap: 8px; cursor: pointer; position: relative; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--red);
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.user-meta { line-height: 1.2; }
.user-meta .name { font-size: 13px; font-weight: 600; }
.user-meta .role { font-size: 10px; color: #aaa; letter-spacing: .5px; text-transform: uppercase; }
.user-menu {
  display: none; position: absolute; top: calc(100% + 8px); right: 0;
  background: #fff; border: 1px solid #eee; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.1); min-width: 160px; z-index: 50; overflow: hidden;
}
.user-badge.open .user-menu { display: block; }
.user-menu button {
  width: 100%; text-align: left; background: none; border: none;
  padding: 10px 14px; font-size: 13px; color: #333;
}
.user-menu button:hover { background: #f7f7f7; }

#content { flex: 1; overflow: auto; padding: 20px 28px 48px; background: #fff; }
.page { display: none; }
.page.active { display: block; }

.warn { display: none !important; }

/* ---------- FILTERS ---------- */
.filters-title { font-size: 18px; font-weight: 600; margin-bottom: 14px; }
.filters-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1fr;
  gap: 16px;
  max-width: 1100px;
}
.filter-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.filter-label { font-size: 12px; color: #8d8d8d; }
.filter-control {
  height: 40px; border: 1px solid #ddd; border-radius: 4px;
  padding: 0 12px; font-size: 13px; background: #fff; color: #222;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  cursor: pointer; position: relative; width: 100%;
}
.filter-control:hover { border-color: #bbb; }
.filter-control.disabled { background: #fafafa; color: #bbb; cursor: not-allowed; }
.filter-control .value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-actions { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.btn-apply {
  background: #1a1a1a; color: #fff; border: none; height: 38px; padding: 0 22px;
  border-radius: 4px; font-size: 12px; font-weight: 700; letter-spacing: .4px;
}
.btn-apply:hover { background: #000; }
.btn-reset { background: none; border: none; height: 38px; padding: 0 10px; font-size: 12px; font-weight: 700; color: #444; letter-spacing: .4px; }
.btn-reset:hover { color: #000; }

.dropdown {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: #fff; border: 1px solid #e4e4e4; border-radius: 6px;
  box-shadow: 0 10px 28px rgba(0,0,0,.12); z-index: 30; max-height: 280px; overflow: auto;
}
.dropdown.show { display: block; }
.dropdown-item {
  padding: 8px 12px; font-size: 13px; display: flex; align-items: center; gap: 8px; cursor: pointer;
}
.dropdown-item:hover, .dropdown-item.active { background: #eef8f1; }
.dropdown-item input { accent-color: var(--green); }

/* Date picker */
.datepicker {
  display: none; position: absolute; top: calc(100% + 4px); left: 0;
  background: #fff; border: 1px solid #e4e4e4; border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0,0,0,.14); z-index: 40; width: 640px; padding: 12px;
}
.datepicker.show { display: block; }
.dp-body { display: grid; grid-template-columns: 120px 1fr 1fr; gap: 8px; }
.dp-presets { display: flex; flex-direction: column; gap: 6px; padding-right: 8px; }
.dp-presets button {
  background: #f3f3f3; border: none; border-radius: 14px; height: 28px;
  font-size: 12px; color: #444; padding: 0 10px; text-align: left;
}
.dp-presets button:hover, .dp-presets button.on { background: #e8e8e8; }
.dp-cal h4 { text-align: center; font-size: 14px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; padding: 0 4px; }
.dp-cal h4 button { background: none; border: none; font-size: 16px; color: #666; width: 24px; }
.dp-week, .dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.dp-week span { text-align: center; font-size: 11px; color: #999; padding: 4px 0; }
.dp-grid button {
  height: 32px; border: none; background: none; font-size: 12px; border-radius: 16px; color: #333;
}
.dp-grid button:hover { background: #f3f3f3; }
.dp-grid button.out { color: #ccc; }
.dp-grid button.inrange { background: #e8f6ec; }
.dp-grid button.start, .dp-grid button.end { background: var(--green); color: #fff; }
.dp-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; padding-top: 10px; border-top: 1px solid #f0f0f0; }
.dp-foot select { height: 32px; border: 1px solid #ddd; border-radius: 4px; padding: 0 8px; font-size: 12px; }
.dp-foot .acts { display: flex; gap: 16px; }
.dp-foot .acts button { background: none; border: none; font-size: 12px; font-weight: 700; letter-spacing: .4px; }
.dp-ok { color: var(--green) !important; }

/* Group by */
.group-by { margin: 28px 0 14px; }
.group-label { font-size: 16px; font-weight: 500; margin-bottom: 10px; }
.tabs { display: flex; width: fit-content; border: 1px solid #e3e3e3; border-radius: 6px; overflow: hidden; }
.tab {
  padding: 8px 14px; font-size: 12px; font-weight: 600; letter-spacing: .3px;
  background: #fff; color: #666; border-right: 1px solid #e3e3e3; cursor: pointer; white-space: nowrap;
}
.tab:last-child { border-right: none; }
.tab.active { background: var(--green-tab); color: var(--green); }
.tab:hover:not(.active) { background: #fafafa; }

/* Table */
.table-card { border: 1px solid #ececec; border-radius: 8px; overflow: hidden; background: #fff; }
.table-card .data { min-width: 640px; }
.table-scroll { overflow-x: auto; }
.table-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; }
.btn-export, .btn-link {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; color: var(--green); font-size: 12px; font-weight: 600;
}
.btn-export:hover { color: #237a3a; }
.col-btn { background: none; border: none; color: #888; padding: 4px; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; padding: 12px 16px; font-size: 12px; font-weight: 600; color: #666;
  border-bottom: 1px solid #f0f0f0; background: #fff; white-space: nowrap;
}
table.data th.num, table.data td.num { text-align: right; }
table.data th.sortable { text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
table.data td { padding: 14px 16px; font-size: 13px; border-bottom: 1px solid #f6f6f6; color: #333; }
table.data tr:last-child td { border-bottom: none; }
table.data tr.total td { font-weight: 700; border-top: 1px solid #eee; background: #fafafa; }
.empty {
  text-align: center; color: #9a9a9a; padding: 48px 16px; font-size: 13px; line-height: 1.6;
}
.table-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  padding: 10px 16px; font-size: 12px; color: #888;
}
.rows-select { border: 1px solid #e0e0e0; border-radius: 4px; padding: 4px 6px; font-size: 12px; background: #fff; }
.pager { background: none; border: none; color: #888; font-size: 18px; padding: 0 4px; }
.pager:disabled { color: #ddd; cursor: default; }
.help-line { text-align: center; color: #b0b0b0; font-size: 12px; margin-top: 18px; }
.help-line a { color: #b0b0b0; }

/* Smartlinks / websites */
.tip-card, .panel {
  border: 1px solid #ececec; border-radius: 8px; padding: 18px 22px; margin-bottom: 16px; background: #fff;
}
.tip-head { display: flex; justify-content: space-between; align-items: center; }
.tip-head h3 { font-size: 16px; font-weight: 600; }
.tip-toggle { background: none; border: none; color: #888; font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.tip-body { margin-top: 10px; }
.tip-sub { font-size: 13px; color: #666; margin-bottom: 18px; line-height: 1.5; max-width: 980px; }
.tip-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.tip-ill {
  height: 92px; background: #f4f6f8; border-radius: 8px; display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px; position: relative; overflow: hidden;
}
.mock-ui { width: 150px; height: 70px; background: #fff; border: 1px solid #e6e6e6; border-radius: 4px; display: flex; }
.mock-side { width: 18px; background: #2b2b2b; }
.mock-lens {
  position: absolute; width: 72px; height: 72px; border-radius: 50%;
  background: rgba(255,255,255,.85); border: 1px solid #e8e8e8;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
}
.mock-chip { background: var(--green); color: #fff; font-size: 8px; font-weight: 700; padding: 5px 8px; border-radius: 3px; }
.mock-chip.ghost { background: #fff; color: #444; border: 1px solid #ccc; }
.tip-num { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.tip-num span { font-weight: 400; }
.tip-desc { font-size: 12px; color: #666; line-height: 1.5; }
.guide { font-size: 12px; color: #888; margin-top: 12px; }

.toolbar-right { display: flex; justify-content: flex-end; align-items: center; gap: 14px; margin: 8px 0 12px; }
.btn-green {
  background: var(--green); color: #fff; border: none; height: 38px; padding: 0 18px;
  border-radius: 6px; font-size: 12px; font-weight: 700; letter-spacing: .3px;
}
.btn-green:hover { background: #278a40; }
.btn-green.soft { background: #d8efdd; color: #2a7a3d; }
.status-inactive { color: #d32f2f; font-size: 12px; font-weight: 600; }
.status-active { color: #2e7d32; font-size: 12px; font-weight: 600; }
.actions { display: flex; align-items: center; gap: 16px; color: #555; font-size: 12px; font-weight: 600; }
.actions span { cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.actions span:hover { color: var(--red); }
.copy { cursor: pointer; color: #aaa; margin-left: 4px; }
.site-row {
  border: 1px solid #ececec; border-radius: 8px; padding: 14px 16px; margin-bottom: 10px;
  display: flex; align-items: center; gap: 16px; font-size: 13px;
}
.site-row .id { color: #777; }
.site-row .domain { font-weight: 600; flex: 1; }
.filters-mini { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 8px 0 14px; }
.search {
  height: 38px; border: 1px solid #ddd; border-radius: 6px; padding: 0 12px 0 34px;
  font-size: 13px; width: 240px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3-3'/%3E%3C/svg%3E") no-repeat 10px 50%;
}
.filter-select { height: 38px; border: 1px solid #ddd; border-radius: 6px; padding: 0 10px; font-size: 13px; min-width: 180px; background: #fff; }

/* Payouts / settings */
.payout-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 22px; }
.card { border: 1px solid #ececec; border-radius: 8px; padding: 20px; }
.card h3 { font-size: 16px; margin-bottom: 14px; }
.steps li { list-style: none; display: flex; gap: 10px; font-size: 13px; color: #555; margin-bottom: 10px; line-height: 1.4; }
.step-n {
  width: 22px; height: 22px; min-width: 22px; border-radius: 50%; background: #f1f1f1;
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
}
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 12px; font-size: 13px; }
.kv .k { color: #888; }
.section-title { font-size: 16px; font-weight: 600; margin: 18px 0 6px; }
.section-sub { font-size: 12px; color: #aaa; margin-bottom: 10px; }

.settings-tabs { display: flex; border-bottom: 1px solid #eee; margin: -4px 0 18px; }
.settings-tabs button {
  flex: 1; background: none; border: none; padding: 14px 8px; font-size: 12px; font-weight: 700;
  letter-spacing: .6px; color: #777;
}
.settings-tabs button.active { color: var(--green); box-shadow: inset 0 -2px 0 var(--green); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; max-width: 360px; }
.field label { font-size: 12px; color: #888; }
.field input, .field select {
  height: 40px; border: 1px solid #ddd; border-radius: 4px; padding: 0 10px; font-size: 13px;
}
.readonly-box { background: #f4f4f4; border-radius: 6px; padding: 12px 14px; max-width: 420px; font-size: 13px; color: #666; line-height: 1.6; margin-bottom: 16px; }

.dash-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.dash-card { border: 1px solid #ececec; border-radius: 8px; padding: 16px; }
.dash-card .lbl { font-size: 11px; color: #999; letter-spacing: .4px; text-transform: uppercase; margin-bottom: 6px; }
.dash-card .val { font-size: 22px; font-weight: 700; }
.dash-card .sub { font-size: 11px; color: #aaa; margin-top: 4px; }

.modal-back {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 80;
  align-items: center; justify-content: center;
}
.modal-back.show { display: flex; }
.modal {
  background: #fff; border-radius: 10px; width: 460px; max-width: calc(100% - 32px);
  padding: 22px; box-shadow: 0 16px 48px rgba(0,0,0,.2);
}
.modal h3 { margin-bottom: 14px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 6px; font-size: 13px;
  display: none; z-index: 90;
}
.toast.show { display: block; }

.chat {
  position: fixed; right: 22px; bottom: 22px; width: 52px; height: 52px; border-radius: 50%;
  background: var(--red); color: #fff; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 20px rgba(227,28,19,.35); cursor: pointer; z-index: 60; border: none;
}
.chat .badge {
  position: absolute; top: -4px; right: -4px; background: #222; color: #fff;
  width: 18px; height: 18px; border-radius: 50%; font-size: 10px; display: flex; align-items: center; justify-content: center;
}

.method-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.unit-list { margin: 8px 0 0 48px; display: none; }
.unit-list.show { display: block; }
.unit-list div { font-size: 12px; color: #666; padding: 6px 0; border-top: 1px dashed #eee; }

@media (max-width: 1100px) {
  .filters-grid { grid-template-columns: 1fr 1fr; }
  .payout-grid, .tip-grid, .dash-cards { grid-template-columns: 1fr 1fr; }
  .datepicker { width: 320px; }
  .dp-body { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  #content { padding: 14px; }
  .filters-grid, .payout-grid, .tip-grid, .dash-cards { grid-template-columns: 1fr; }
  .page-title { font-size: 16px; }
  .user-meta { display: none; }
  .btn-outline { display: none; }
  #topbar { padding: 0 12px; gap: 8px; }
  .balance-popup { right: -40px; min-width: 300px; transform: scale(.92); transform-origin: top right; }
  .table-card { overflow-x: auto; }
  #sidebar {
    position: relative;
  }
  #sidebar.open {
    width: min(var(--sidebar-open), 80vw);
    min-width: min(var(--sidebar-open), 80vw);
  }
}
