:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #dce3ea;
  --text: #17212f;
  --muted: #68778a;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #147a55;
  --success-bg: #e8f7f0;
  --danger: #b4232c;
  --danger-bg: #fff0f1;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: 24px; line-height: 1.25; }
h2 { margin-bottom: 0; font-size: 17px; }
.topbar { position: sticky; top: 0; z-index: 10; border-bottom: 1px solid var(--line); background: var(--surface); }
.nav-shell { max-width: 1320px; min-height: 64px; margin: 0 auto; padding: 0 24px; display: flex; align-items: center; gap: 24px; }
.brand { flex: 0 0 auto; color: var(--text); font-size: 18px; font-weight: 760; }
.brand span, .login-brand span { color: var(--primary); }
.nav-links { display: flex; align-self: stretch; gap: 3px; overflow-x: auto; }
.nav-link { display: flex; align-items: center; padding: 0 12px; border-bottom: 2px solid transparent; color: #516174; font-weight: 650; white-space: nowrap; }
.nav-link.active { border-bottom-color: var(--primary); color: var(--primary); }
.logout { margin-left: auto; }
.page-shell { max-width: 1320px; margin: 0 auto; padding: 28px 24px 48px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 20px; }
.page-head p { margin-bottom: 0; color: var(--muted); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.compact-stats { margin-bottom: 24px; }
.compact-stats .stat { min-height: 92px; }
.compact-stats .stat strong { margin-top: 8px; font-size: 24px; }
.stat { min-height: 108px; padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.stat span { color: var(--muted); font-weight: 650; }
.stat strong { display: block; margin-top: 12px; font-size: 28px; line-height: 1; }
.stat small { display: block; margin-top: 6px; color: var(--muted); }
.section { margin-top: 24px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 20px; }
.table-wrap { overflow-x: auto; padding: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--surface-soft); color: #58687b; font-size: 12px; font-weight: 750; white-space: nowrap; }
tbody tr:hover { background: #fbfdff; }
tbody tr:last-child td { border-bottom: 0; }
.type-strip { display: flex; flex-wrap: wrap; gap: 10px; }
.type-strip > div { min-width: 130px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); display: flex; justify-content: space-between; gap: 16px; }
.badge { display: inline-flex; min-height: 24px; align-items: center; padding: 2px 8px; border-radius: 999px; background: #eef2f6; color: #4f6074; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge.success { background: var(--success-bg); color: var(--success); }
.badge.disabled { background: var(--danger-bg); color: var(--danger); }
.badge.warning { background: #fff6df; color: #8a5a00; }
.button { display: inline-flex; min-height: 36px; align-items: center; justify-content: center; border: 1px solid var(--primary); border-radius: 6px; padding: 7px 12px; background: var(--primary); color: #fff; font: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
.button:hover { border-color: var(--primary-hover); background: var(--primary-hover); color: #fff; }
.button.secondary { border-color: #bac5d1; background: var(--surface); color: #344256; }
.button.secondary:hover { background: #f1f5f9; color: var(--text); }
.button.danger { border-color: #e1a4a8; background: var(--surface); color: var(--danger); }
.button.danger:hover { background: var(--danger-bg); }
.button.success-solid { border-color: var(--success); background: var(--success); color: #fff; }
.button.success-solid:hover { border-color: #0f6848; background: #0f6848; color: #fff; }
.button.danger-solid { border-color: var(--danger); background: var(--danger); color: #fff; }
.button.danger-solid:hover { border-color: #8f1c24; background: #8f1c24; color: #fff; }
.button.compact { min-height: 32px; padding: 5px 9px; }
.button.full { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: .55; }
.action-row { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.action-row form { margin: 0; }
.filter-bar { display: grid; grid-template-columns: minmax(240px, 1fr) 220px 170px auto auto; gap: 9px; margin-bottom: 14px; }
.filter-bar.users-filter { grid-template-columns: minmax(260px, 1fr) auto auto; max-width: 700px; }
.status-tabs { margin-bottom: 14px; display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.status-tabs a { padding: 9px 12px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 700; white-space: nowrap; }
.status-tabs a:hover { color: var(--text); }
.status-tabs a.active { border-bottom-color: var(--primary); color: var(--primary); }
.status-tabs a span { margin-left: 4px; color: inherit; font-variant-numeric: tabular-nums; }
input, select, textarea { width: 100%; min-height: 40px; border: 1px solid #bcc7d3; border-radius: 6px; padding: 9px 10px; background: var(--surface); color: var(--text); font: inherit; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
input[type="checkbox"] { width: 17px; min-height: 17px; accent-color: var(--primary); }
label { display: block; margin-bottom: 6px; color: #344256; font-weight: 700; }
.field { margin-bottom: 17px; }
.hint, .muted { color: var(--muted); }
.hint { margin-top: 5px; font-size: 12px; }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.message-cell { min-width: 280px; max-width: 560px; overflow-wrap: anywhere; white-space: pre-wrap; }
.check { width: 42px; text-align: center; }
.bulk-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 18px; }
.empty { padding: 32px 16px; color: var(--muted); text-align: center; }
.input-compact { min-width: 140px; margin-bottom: 8px; }
.check-label { display: flex; align-items: center; gap: 7px; margin-bottom: 10px; white-space: nowrap; }
.danger-text { color: var(--danger); }
.success-text { color: var(--success); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.finance-settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; align-items: end; }
.finance-settings .field { margin: 0; }
.withdrawal-filter { grid-template-columns: 220px auto; max-width: 360px; }
.review-form { display: grid; grid-template-columns: minmax(120px, .7fr) minmax(150px, 1fr) auto auto; gap: 7px; min-width: 560px; }
.bot-add-form { display: grid; grid-template-columns: minmax(280px, 1fr) auto; gap: 12px; max-width: 760px; align-items: end; }
.bot-add-form .field { margin: 0; }
.category-form { display: grid; grid-template-columns: 180px 130px minmax(260px, 1fr) auto; gap: 12px; align-items: end; }
.channel-results { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.channel-result { display: grid; grid-template-columns: 64px 1fr; gap: 14px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.channel-result img, .avatar-placeholder { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }
.avatar-placeholder { display: grid; place-items: center; background: #e8eef5; color: #516174; font-weight: 800; }
.channel-result p { margin: 5px 0 9px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.channel-result-body { min-width: 0; }
.channel-result-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.channel-result-title a { min-width: 0; overflow-wrap: anywhere; }
.channel-actions { margin-top: 12px; }
.confirm-import-form { display: grid; grid-template-columns: minmax(130px, 1fr) auto; gap: 7px; min-width: 260px; }
.confirm-import-form select { min-height: 34px; }
.task-actions { margin-top: 8px; }
.delete-user-form { margin-top: 8px; }
.flash { margin-bottom: 14px; padding: 11px 14px; border: 1px solid #b8d7fb; border-radius: 6px; background: #edf5ff; color: #194f8c; }
.flash.success { border-color: #a9dfc9; background: var(--success-bg); color: #126548; }
.flash.error { border-color: #efb5b5; background: var(--danger-bg); color: #941c24; }
.settings-form { max-width: 760px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 22px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.setting-row label { margin: 0; font-size: 15px; }
.setting-row p { margin: 4px 0 0; color: var(--muted); }
.setting-row input { flex: 0 0 auto; }
.login-page { display: grid; min-height: 100vh; place-items: center; padding: 20px; }
.login-panel { width: min(400px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: 0 16px 40px rgba(35, 50, 70, .1); }
.login-brand { margin-bottom: 28px; font-size: 18px; font-weight: 760; }
.login-panel h1 { margin-bottom: 20px; }
.error-state { padding: 80px 20px; text-align: center; }
.error-state > strong { display: block; color: var(--primary); font-size: 64px; }
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .filter-bar { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 680px) {
  .nav-shell { min-height: auto; padding: 12px 14px 0; display: block; }
  .nav-links { margin-top: 8px; }
  .nav-link { min-height: 44px; padding: 0 10px; }
  .logout { position: absolute; top: 9px; right: 14px; }
  .page-shell { padding: 20px 12px 36px; }
  .filter-bar, .filter-bar.users-filter { grid-template-columns: 1fr; max-width: none; }
  .bot-add-form { grid-template-columns: 1fr; }
  .category-form { grid-template-columns: 1fr; }
  .message-cell { min-width: 240px; }
}

/* Sidebar application shell */
.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; width: 240px; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: #fff; }
.sidebar-brand { min-height: 68px; padding: 14px 18px; display: flex; align-items: center; gap: 11px; border-bottom: 1px solid var(--line); color: var(--text); }
.sidebar-brand > span { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 7px; background: var(--primary); color: #fff; font-weight: 800; }
.sidebar-brand strong { font-size: 15px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 10px; }
.nav-group { margin-bottom: 18px; }
.nav-label { display: block; padding: 0 10px 6px; color: #8a97a7; font-size: 11px; font-weight: 800; text-transform: uppercase; }
.side-link { min-height: 39px; margin: 2px 0; padding: 8px 10px; display: flex; align-items: center; gap: 10px; border-radius: 6px; color: #46566a; font-weight: 650; }
.side-link > span { width: 20px; text-align: center; }
.side-link:hover { background: #f1f5f9; color: var(--text); }
.side-link.active { background: #eaf2ff; color: var(--primary); }
.nav-tree { margin: 2px 0 8px; }
.nav-tree-summary { min-height: 40px; padding: 0 12px; display: flex; align-items: center; justify-content: space-between; border-radius: 6px; color: #2f4054; font-weight: 750; cursor: pointer; list-style: none; }
.nav-tree-summary::-webkit-details-marker { display: none; }
.nav-tree-summary:hover { background: #f2f6fa; }
.nav-tree-summary > span:first-child { display: flex; align-items: center; gap: 10px; }
.nav-tree-summary > span:first-child > span { width: 20px; text-align: center; }
.nav-tree-chevron { color: var(--muted); font-size: 20px; line-height: 1; transform: rotate(0); transition: transform .15s ease; }
.nav-tree[open] .nav-tree-chevron { transform: rotate(90deg); }
.nav-tree-links { margin: 2px 0 0 21px; padding-left: 10px; border-left: 1px solid var(--line); }
.nav-tree-links .side-link { min-height: 38px; padding-left: 10px; font-size: 13px; }
.sidebar-logout { padding: 14px; border-top: 1px solid var(--line); }
.workspace { min-height: 100vh; margin-left: 240px; }
.mobile-header { display: none; }
.page-shell { max-width: 1440px; }
.live-indicator { display: inline-flex; align-items: center; gap: 7px; color: var(--success); font-weight: 700; }
.live-indicator i { width: 8px; height: 8px; border-radius: 50%; background: #19a56f; box-shadow: 0 0 0 4px #dff5eb; }
.dashboard-stats { grid-template-columns: repeat(5, minmax(150px, 1fr)); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, .8fr); gap: 18px; }
.dashboard-grid .section { min-width: 0; }
.activity-list { padding: 4px 18px; }
.activity-item { display: grid; grid-template-columns: 64px 1fr; gap: 10px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.activity-item:last-child { border-bottom: 0; }
.activity-type { color: var(--primary); font-size: 12px; font-weight: 800; }
.activity-item strong { display: block; font-size: 13px; }
.activity-item small { display: block; margin-top: 3px; color: var(--muted); }
.inline-details, .row-editor { position: relative; }
.inline-details summary, .row-editor summary { color: var(--primary); font-weight: 700; cursor: pointer; white-space: nowrap; }
.inline-details > form, .row-editor > form { position: absolute; z-index: 12; top: calc(100% + 7px); right: 0; width: 300px; padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: #fff; box-shadow: 0 12px 28px rgba(31, 45, 61, .16); }
.inline-details > form { display: grid; grid-template-columns: 1fr auto; gap: 7px; width: 390px; }
.row-editor > form { display: grid; gap: 8px; }
.channel-form-grid { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 12px; align-items: end; }
.channel-form-grid .wide { grid-column: span 2; }
.channel-form-grid label { margin-bottom: 5px; }
.channel-filter { grid-template-columns: minmax(240px, 1fr) 180px 160px auto auto; }
.top-search { margin: 18px 0 0; }
.chat-bulk-bar { justify-content: flex-start; gap: 14px; min-height: 38px; }
.chat-bulk-bar .bulk-select-all { margin: 0; }
.selection-count { min-width: 76px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bulk-actions { margin-left: auto; }
.chat-table .check input { display: block; margin: 2px auto 0; }
.record-title { min-width: 190px; }
.record-title > strong, .record-title > .hint { display: block; }
.record-title > .badge { margin-top: 6px; }
.record-link { min-width: 190px; max-width: 320px; overflow-wrap: anywhere; }
.ad-filter { grid-template-columns: minmax(240px, 1fr) 170px 150px auto auto; }
.ad-form-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.ad-form-grid .field { margin: 0; }
.ad-form-grid .wide { grid-column: span 2; }
.system-fields { display: grid; grid-template-columns: repeat(3, minmax(200px, 1fr)); gap: 14px; }
.system-fields .field { margin: 0; }
.switch-grid { display: grid; grid-template-columns: repeat(2, minmax(240px, 1fr)); gap: 1px 24px; }
.switch-row { min-height: 70px; margin: 0; padding: 12px 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.switch-row span { min-width: 0; }
.switch-row strong, .switch-row small { display: block; }
.switch-row small { margin-top: 3px; color: var(--muted); font-weight: 400; }
.switch-row input { flex: 0 0 auto; }
.sticky-actions { position: sticky; z-index: 8; bottom: 12px; margin-top: 16px; padding: 10px; display: flex; justify-content: flex-end; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.95); box-shadow: 0 8px 24px rgba(31,45,61,.12); }

@media (max-width: 1180px) {
  .dashboard-stats { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .channel-form-grid { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
  .ad-form-grid { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
  .system-fields { grid-template-columns: repeat(2, minmax(200px, 1fr)); }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: transform .18s ease; box-shadow: 12px 0 32px rgba(31, 45, 61, .16); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .workspace { margin-left: 0; }
  .mobile-header { min-height: 54px; padding: 0 14px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); background: #fff; }
  .menu-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text); font-size: 20px; cursor: pointer; }
  .dashboard-stats { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .channel-filter { grid-template-columns: 1fr 1fr; }
  .ad-filter { grid-template-columns: 1fr 1fr; }
  .switch-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .dashboard-stats, .channel-form-grid, .channel-filter, .ad-filter, .ad-form-grid, .system-fields { grid-template-columns: 1fr; }
  .channel-form-grid .wide, .ad-form-grid .wide { grid-column: auto; }
  .page-head { gap: 12px; }
  .page-head { align-items: stretch; flex-direction: column; }
  .review-form { min-width: 300px; grid-template-columns: 1fr 1fr; }
  .inline-details > form, .row-editor > form { position: fixed; inset: auto 12px 12px; width: auto; max-height: 70vh; overflow-y: auto; }
  .chat-bulk-bar { align-items: flex-start; flex-wrap: wrap; }
  .bulk-actions { width: 100%; margin-left: 0; }
  .bulk-actions .button { flex: 1 1 140px; }
}
