:root {
  color-scheme: dark;
  --bg: #171717;
  --surface: #1f1f1f;
  --surface-soft: #252525;
  --surface-raised: #292929;
  --line: #303030;
  --line-strong: #3a3a3a;
  --text: #f5f5f5;
  --muted: #a3a3a3;
  --subtle: #737373;
  --brand: #19e68c;
  --brand-hover: #32eda0;
  --brand-soft: rgb(25 230 140 / 12%);
  --red: #ef626c;
  --red-soft: rgb(239 98 108 / 12%);
  --green: #19e68c;
  --green-soft: rgb(25 230 140 / 12%);
  --amber: #e6b35c;
  --shadow: none;
  --shadow-lg: 0 24px 64px rgb(0 0 0 / 42%);
  --radius: 12px;
  --control-height: 40px;
  --panel-padding: 24px;
  font: 14px/1.43 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-soft: #f2f2f2;
  --surface-raised: #ebebeb;
  --line: #dedede;
  --line-strong: #c8c8c8;
  --text: #171717;
  --muted: #626262;
  --subtle: #8a8a8a;
  --brand: #0f9f61;
  --brand-hover: #0b8952;
  --brand-soft: rgb(15 159 97 / 10%);
  --red: #d94854;
  --red-soft: rgb(217 72 84 / 9%);
  --green: #0f9f61;
  --green-soft: rgb(15 159 97 / 10%);
  --amber: #946c23;
  --shadow-lg: 0 24px 64px rgb(0 0 0 / 18%);
}

:root[data-density="compact"] { --control-height: 38px; --panel-padding: 18px; font-size: 14px; }
:root[data-motion="reduced"] *, :root[data-motion="reduced"] *::before, :root[data-motion="reduced"] *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ui-icon { flex: none; width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ui-icon .filled, .service-logo .filled { fill: currentColor; stroke: none; }
.service-logo { display: block; width: 20px; height: 20px; fill: currentColor; }
.service-logo.telegram { color: #229ed9; }
.service-logo.max { padding: 3px; border-radius: 5px; background: linear-gradient(135deg, #367df4, #8155e8); color: #fff; }
button, input, textarea, select { font: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
.shell { min-height: 100vh; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

#app { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.app-sidebar { position: sticky; top: 0; height: 100vh; z-index: 40; display: flex; flex-direction: column; padding: 28px 16px 16px; border-right: 1px solid var(--line); background: #171717; }
:root[data-theme="light"] .app-sidebar { background: #ffffff; }
.app-main { min-width: 0; padding: 32px; }
.brand, .header-actions, .panel-heading, .section-title, .card-head, .modal-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { justify-content: flex-start; padding: 0 8px 36px; }
.brand-logo { flex: none; display: flex; align-items: center; width: max-content; color: var(--text); }
.brand-ink-fill { fill: currentColor; }
.brand-accent { fill: #19e68c; }
.brand-wide-logo { display: block; width: 150px; height: auto; aspect-ratio: 710 / 220; overflow: visible; }
.brand-logo.large { margin-bottom: 26px; }
.brand-logo.large .brand-wide-logo { width: 224px; }
.sidebar-project-row { display: flex; align-items: end; gap: 6px; margin: -18px 4px 22px; }
.sidebar-project { min-width: 0; flex: 1; display: grid; gap: 5px; }
.sidebar-project > span { padding-left: 8px; color: var(--subtle); font-size: 10px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; }
.sidebar-project select { min-width: 0; min-height: 38px; padding: 7px 28px 7px 10px; border-color: var(--line); background-color: var(--surface-soft); font-size: 12px; font-weight: 500; text-overflow: ellipsis; }
.sidebar-project-row > button { width: 38px; min-height: 38px; }
.status-badge, .context-pill { display: inline-flex; align-items: center; gap: 7px; width: max-content; border-radius: 999px; white-space: nowrap; font-size: 12px; font-weight: 700; }
.status-badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.header-actions { display: grid; justify-content: stretch; gap: 8px; margin-top: auto; }
.user-chip { min-width: 0; display: flex; align-items: center; gap: 8px; max-width: 240px; padding: 5px 9px 5px 5px; border-radius: 10px; color: var(--muted); font-size: 12px; }
.user-chip #current-user { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-avatar { flex: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; background: var(--brand-soft); color: var(--brand); font-size: 11px; font-weight: 600; text-transform: uppercase; }

.tabs { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tabs button { position: relative; display: flex; align-items: center; justify-content: flex-start; gap: 12px; min-height: 40px; padding: 8px 12px 8px 28px; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 500; }
.tabs button:hover { background: var(--surface-soft); color: var(--text); }
.tabs button.active { background: #292929; color: #f5f5f5; box-shadow: none; }
:root[data-theme="light"] .tabs button.active { background: #ededed; color: #171717; }
.tabs button.active::before { content: ""; position: absolute; left: 12px; width: 6px; height: 6px; border-radius: 999px; background: var(--brand); }
.tab-icon { display: grid; place-items: center; width: 18px; height: 18px; font-size: 14px; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(28px, 3vw, 32px); font-weight: 500; line-height: 1.19; letter-spacing: -.03em; }
h2 { margin-bottom: 4px; font-size: 24px; font-weight: 500; line-height: 1.25; letter-spacing: -.02em; }
h3 { font-size: 18px; font-weight: 500; }
.muted { color: var(--muted); }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin: 0 0 24px; }
.page-heading h1 { margin: 0; }
.page-heading p, .section-title p, .panel-heading p { margin: 0; color: var(--muted); }
.status-badge { padding: 8px 12px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); }
.status-badge.success, .status-badge.ok { border-color: color-mix(in srgb, var(--green) 22%, var(--line)); background: var(--green-soft); color: var(--green); }
.status-badge.bad { border-color: color-mix(in srgb, var(--red) 22%, var(--line)); background: var(--red-soft); color: var(--red); }

.panel, .card { padding: var(--panel-padding); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: none; }
.panel:hover, .card:hover { border-color: var(--line-strong); }
.panel-heading { align-items: flex-start; margin-bottom: 22px; }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric-card { display: flex; align-items: center; gap: 16px; min-height: 104px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.metric-icon { flex: none; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 14px; background: #229ed9; color: #fff; font-weight: 850; }
.metric-icon .service-logo { width: 24px; height: 24px; color: #fff; }
.metric-icon .service-logo.max { padding: 0; background: none; }
.metric-card.max .metric-icon { background: linear-gradient(135deg, #367df4, #8155e8); color: #fff; }
.metric-card.total .metric-icon { background: var(--brand-soft); color: var(--brand); }
.metric-card span, .metric-card small { display: block; color: var(--muted); }
.metric-card strong { display: inline-block; margin: 4px 0; font-size: 24px; font-weight: 500; line-height: 1; letter-spacing: -.02em; }
.metric-card small { font-size: 12px; }

.broadcast-workspace { display: grid; grid-template-columns: 310px minmax(0, 1fr); gap: 18px; align-items: start; }
.campaign-library { position: sticky; top: 16px; max-height: calc(100vh - 32px); padding: 16px; overflow: hidden; }
.library-heading { padding: 3px 3px 14px; }
.library-heading h2 { margin-bottom: 3px; font-size: 18px; }
.library-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.campaign-search { display: flex; align-items: center; gap: 5px; margin-bottom: 10px; padding-left: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); color: var(--muted); }
.campaign-search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 12%, transparent); }
.campaign-search input { min-height: 38px; padding-left: 4px; border: 0; background: transparent; box-shadow: none; }
.campaign-filters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 10px; padding: 4px; border-radius: 10px; background: var(--surface-soft); }
.campaign-filters button { min-height: 32px; padding: 5px 7px; border: 0; background: transparent; color: var(--muted); font-size: 11px; }
.campaign-filters button:hover:not(:disabled) { background: var(--surface); color: var(--text); }
.campaign-filters button.active { background: var(--surface); color: var(--brand); box-shadow: 0 1px 4px rgb(20 32 54 / 10%); }
.campaign-list { max-height: calc(100vh - 272px); margin: 0 -5px; padding: 0 5px 6px; overflow: auto; }
.campaign-item { width: 100%; min-height: 0; display: block; margin-bottom: 6px; padding: 12px; border: 1px solid transparent; border-radius: 11px; background: transparent; color: var(--text); text-align: left; }
.campaign-item:hover:not(:disabled) { border-color: var(--line); background: var(--surface-soft); }
.campaign-item.active { border-color: color-mix(in srgb, var(--brand) 30%, var(--line)); background: var(--brand-soft); }
.campaign-item-top, .campaign-item-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.campaign-item strong { min-width: 0; overflow: hidden; font-size: 14px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.campaign-item-bottom { margin-top: 8px; color: var(--muted); font-size: 12px; font-weight: 400; }
.campaign-channels { display: flex; gap: 3px; }
.channel-chip { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: #e9f5ff; color: #1689de; font-style: normal; }
.channel-chip.max { background: transparent; color: #7048d6; }
.channel-chip .service-logo { width: 14px; height: 14px; }
.channel-chip .service-logo.max { padding: 2px; border-radius: 4px; }
.campaign-status { display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: 12px; font-weight: 500; white-space: nowrap; }
.campaign-status.draft { background: rgb(230 179 92 / 12%); color: var(--amber); }
.campaign-status.scheduled { background: var(--brand-soft); color: var(--brand); }
.campaign-status.running, .campaign-status.queued { background: var(--brand-soft); color: var(--brand); }
.campaign-status.completed { background: var(--green-soft); color: var(--green); }
.campaign-status.completed_with_errors { background: rgb(230 179 92 / 12%); color: var(--amber); }
.campaign-status.published { background: var(--green-soft); color: var(--green); }
.campaign-status.failed, .campaign-status.interrupted, .campaign-status.cancelled { background: var(--red-soft); color: var(--red); }
.campaign-progress { height: 4px; margin-top: 9px; overflow: hidden; border-radius: 999px; background: var(--line); }
.campaign-progress i { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.library-empty { min-height: 190px; display: grid; place-items: center; align-content: center; padding: 20px; color: var(--muted); text-align: center; }
.library-empty > span { margin-bottom: 7px; color: var(--brand); font-size: 22px; }
.library-empty strong { color: var(--text); font-size: 13px; }
.library-empty p { margin: 2px 0 0; font-size: 11px; }
.broadcast-editor { min-width: 0; }
.editor-heading { min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 2px; padding: 0 2px; }
.editor-heading-actions { display: flex; gap: 8px; }
.editor-state { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 11px; }
.editor-state #editor-meta:empty { display: none; }
.campaign-basics { margin-bottom: 26px; padding: 0 2px 20px; border-bottom: 1px solid var(--line); }
.campaign-title-input { min-height: 52px; padding: 4px 0 8px; border: 0; border-bottom: 1px solid transparent; border-radius: 0; background: transparent; color: var(--text); font-size: clamp(26px, 3vw, 32px); font-weight: 500; letter-spacing: -.03em; box-shadow: none; }
.campaign-title-input:focus { border-bottom-color: var(--brand); box-shadow: none; }
.campaign-title-input::placeholder { color: var(--subtle); }
.channel-picker { margin-top: 13px; }
.channel-picker legend { margin-bottom: 6px; }
.channel-picker .segments { margin-top: 0; }
.channel-picker .segments label > span { display: flex; align-items: center; gap: 9px; min-height: 48px; padding: 8px 13px 8px 9px; background: var(--surface); }
.channel-picker .service-logo { flex: none; width: 30px; height: 30px; padding: 6px; border-radius: 9px; color: #fff; box-shadow: 0 2px 7px rgb(0 0 0 / 14%); }
.channel-picker .service-logo.telegram { background: #229ed9; }
.channel-picker .service-logo.max { padding: 6px; background: linear-gradient(135deg, #367df4, #8155e8); }
.dual-logo { display: flex; align-items: center; justify-content: center; flex: none; gap: 14px; width: 76px; height: 42px; }
.dual-logo .service-logo.telegram { transform: rotate(-30deg); }
.dual-logo .service-logo.max { transform: rotate(30deg); }
.broadcast-editor.readonly .campaign-basics input, .broadcast-editor.readonly .campaign-basics .segments, .broadcast-editor.readonly .card input, .broadcast-editor.readonly .card textarea, .broadcast-editor.readonly .card button { pointer-events: none; opacity: .78; }
.broadcast-editor.readonly .add-section, .broadcast-editor.readonly .action-bar { display: none; }
.broadcast-editor.monitor-mode > .campaign-basics, .broadcast-editor.monitor-mode > .composer, .broadcast-editor.monitor-mode > .add-section, .broadcast-editor.monitor-mode > .action-bar { display: none; }
.campaign-monitor { margin-top: 16px; padding: clamp(18px, 3vw, 28px); border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.monitor-hero { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.monitor-heading { display: flex; align-items: flex-start; gap: 14px; }
.monitor-heading > span { flex: none; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: var(--brand-soft); color: var(--brand); }
.monitor-heading h2 { margin: 0 0 5px; font-size: 22px; font-weight: 500; }
.monitor-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.monitor-overall { min-width: 150px; text-align: right; }
.monitor-overall strong { display: block; font-size: 30px; font-weight: 500; letter-spacing: -.04em; }
.monitor-overall span { color: var(--muted); font-size: 12px; }
.monitor-channel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 20px; }
.monitor-channel { padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.monitor-channel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.monitor-channel-name { display: flex; align-items: center; gap: 9px; font-weight: 500; }
.monitor-channel-name .service-logo { width: 24px; height: 24px; padding: 5px; border-radius: 7px; color: #fff; }
.monitor-channel-name .telegram { background: #229ed9; }
.monitor-channel-name .max { background: linear-gradient(135deg, #367df4, #8155e8); }
.monitor-channel-head > span:last-child { color: var(--muted); font-size: 12px; }
.monitor-bar { height: 7px; overflow: hidden; border-radius: 999px; background: var(--line); }
.monitor-bar i { display: block; height: 100%; border-radius: inherit; background: var(--brand); transition: width .25s ease; }
.monitor-channel-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 13px; }
.monitor-channel-stats span { color: var(--muted); font-size: 11px; }
.monitor-channel-stats strong { display: block; margin-bottom: 2px; color: var(--text); font-size: 16px; font-weight: 500; }
.monitor-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 20px; }
.monitor-stat { padding: 14px; border: 1px solid var(--line); border-radius: 11px; }
.monitor-stat strong { display: block; margin-bottom: 4px; font-size: 22px; font-weight: 500; }
.monitor-stat span { color: var(--muted); font-size: 11px; }
.monitor-cleanup { margin-top: 16px; padding: 12px 14px; border-radius: 10px; background: var(--surface-soft); color: var(--muted); font-size: 12px; }
.monitor-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 20px; }

.setup-panel { margin-bottom: 38px; }
.setup-grid { display: grid; grid-template-columns: minmax(280px, 1fr) auto; align-items: end; gap: 28px; }
.field { display: grid; gap: 7px; }
.field > span, legend { color: var(--muted); font-size: 12px; font-weight: 500; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
input, textarea, select { width: 100%; min-height: var(--control-height); padding: 10px 13px; border: 1px solid var(--line-strong); border-radius: 10px; outline: none; background: var(--surface); color: var(--text); transition: border-color .16s ease, box-shadow .16s ease, background .16s ease; }
input::placeholder, textarea::placeholder { color: var(--subtle); }
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 15%, transparent); }
button { min-height: var(--control-height); display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 16px; border: 0; border-radius: 8px; background: var(--brand); color: #101010; font-weight: 500; cursor: pointer; transition: transform .15s ease, background .15s ease, border-color .15s ease, color .15s ease; }
button:hover:not(:disabled) { background: var(--brand-hover); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .42; cursor: not-allowed; }
button.small { min-height: 36px; padding: 7px 13px; font-size: 13px; }
.secondary { border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.secondary:hover:not(:disabled) { border-color: var(--line-strong); background: var(--surface-soft); }
.danger { background: var(--red); color: #fff; }
.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--red) 86%, #000); }
.danger-outline { border-color: color-mix(in srgb, var(--red) 28%, var(--line)); color: var(--red); }
.danger-outline:hover:not(:disabled) { border-color: color-mix(in srgb, var(--red) 48%, var(--line)); background: var(--red-soft); color: var(--red); }
.square { width: var(--control-height); padding: 0; }
.segments { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 7px; }
.segments input, .choice-grid input { position: absolute; width: 1px; height: 1px; min-height: 0; margin: 0; padding: 0; overflow: hidden; opacity: 0; clip-path: inset(50%); pointer-events: none; }
.segments label > span { display: block; min-height: var(--control-height); padding: 10px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); color: var(--muted); cursor: pointer; }
.segments input:checked + span { border-color: color-mix(in srgb, var(--brand) 42%, var(--line)); background: var(--brand-soft); color: var(--brand); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 8%, transparent); }
.segments input:disabled + span { opacity: .42; cursor: not-allowed; }
.audience { margin-top: 16px; color: var(--muted); font-size: 13px; }
.audience strong { color: var(--text); }

.composer { margin-top: 36px; }
.section-title { align-items: flex-end; margin: 0 0 16px; }
.section-title h2 { margin-top: 0; }
.context-pill { padding: 7px 11px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
#cards { display: grid; gap: 14px; }
.card { padding: var(--panel-padding); }
.card h3 { margin: 0; font-size: 18px; font-weight: 500; }
.card-controls { display: flex; gap: 6px; }
.icon { min-height: 34px; padding: 5px 9px; border: 1px solid var(--line); background: var(--surface-soft); color: var(--muted); }
.icon:hover:not(:disabled) { background: var(--brand-soft); color: var(--brand); }
.delete, .delete-button { color: var(--red); }
.editor { margin-top: 18px; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); }
.editor:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 12%, transparent); }
.toolbar { display: flex; gap: 3px; flex-wrap: wrap; padding: 7px; border-bottom: 1px solid var(--line); background: var(--surface-soft); }
.toolbar button { min-height: 32px; padding: 5px 9px; border: 0; background: transparent; color: var(--muted); }
.toolbar button:hover { background: var(--brand-soft); color: var(--brand); }
.editor textarea { min-height: 145px; resize: vertical; border: 0; border-radius: 0; box-shadow: none; }
.options { display: flex; gap: 22px; flex-wrap: wrap; margin-top: 15px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.check input { width: auto; min-height: auto; accent-color: var(--brand); }
.tg-only { color: var(--brand); }
.media-row { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.file-list { color: var(--muted); font-size: 12px; }
.button-list { display: grid; gap: 8px; margin-top: 14px; }
.inline-button { display: grid; grid-template-columns: minmax(150px, 1fr) 180px minmax(210px, 1.45fr) auto; gap: 8px; align-items: center; }
.button-destination { min-width: 0; }
.button-destination > * { width: 100%; }
.add-inline { margin-top: 12px; padding-left: 2px; background: transparent; color: var(--brand); }
.add-inline:hover:not(:disabled) { background: transparent; color: var(--brand-hover); }
.add-section { margin-top: 28px; }
.type-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.type-grid button { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(20 32 54 / 4%); }
.type-grid button .ui-icon { color: var(--brand); }
.type-grid button:hover { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); background: var(--brand-soft); color: var(--brand); }
.action-bar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 32px; padding: 16px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.action-bar > div:first-child { display: grid; gap: 2px; }
.action-bar > div:first-child span { color: var(--muted); font-size: 12px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.history { margin-top: 48px; }
.job { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.job:last-child { border: 0; }
.status { color: var(--green); font-size: 13px; font-weight: 700; }

.subscriber-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.subscriber-metric { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--muted); text-align: left; }
.subscriber-metric > span { display: flex; align-items: center; gap: 8px; }
.subscriber-metric strong { color: var(--text); font-size: 24px; font-weight: 500; }
.subscriber-metric.active { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); background: var(--brand-soft); color: var(--brand); }
.subscriber-panel { padding: 0; overflow: hidden; }
.subscriber-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px; border-bottom: 1px solid var(--line); }
.subscriber-toolbar .campaign-search { width: min(420px, 100%); margin: 0; }
.subscriber-table-head, .subscriber-row { display: grid; grid-template-columns: minmax(230px, 1.4fr) 120px minmax(170px, 1fr) 150px 40px; gap: 14px; align-items: center; }
.subscriber-table-head { padding: 10px 16px; background: var(--surface-soft); color: var(--muted); font-size: 11px; }
.subscriber-row { min-height: 70px; padding: 10px 16px; border-top: 1px solid var(--line); }
.subscriber-person { min-width: 0; display: flex; align-items: center; gap: 11px; }
.subscriber-avatar { position: relative; flex: none; width: 42px; height: 42px; display: grid; place-items: center; overflow: hidden; border-radius: 12px; background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.subscriber-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--surface-soft); }
.subscriber-identity { min-width: 0; display: grid; gap: 2px; }
.subscriber-identity strong, .subscriber-identity small, .subscriber-contact { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subscriber-identity strong { font-weight: 500; }
.subscriber-identity small, .subscriber-contact, .subscriber-date { color: var(--muted); font-size: 12px; }
.subscriber-channel { display: inline-flex; align-items: center; gap: 7px; width: max-content; }
.subscriber-channel .service-logo { width: 18px; height: 18px; }
.subscriber-delete { width: 34px; min-height: 34px; padding: 0; color: var(--red); }
.subscriber-pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line); }
.subscriber-pagination button { min-height: 34px; }

.notice { position: fixed; right: 24px; bottom: 24px; z-index: 200; width: min(380px, calc(100vw - 48px)); margin: 0; padding: 12px 14px 12px 38px; border: 1px solid color-mix(in srgb, var(--brand) 28%, var(--line)); border-radius: 12px; background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: 0 14px 40px rgb(0 0 0 / 18%); color: var(--text); font-size: 13px; line-height: 1.45; opacity: 0; transform: translateY(10px) scale(.98); visibility: hidden; cursor: pointer; backdrop-filter: blur(16px); transition: opacity .18s ease, transform .18s ease, visibility .18s ease; }
.notice::before { position: absolute; top: 17px; left: 16px; width: 8px; height: 8px; border-radius: 999px; background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); content: ''; }
.notice.show { opacity: 1; transform: translateY(0) scale(1); visibility: visible; }
.notice.error { margin: 0; border-color: color-mix(in srgb, var(--red) 28%, var(--line)); background: color-mix(in srgb, var(--surface) 94%, var(--red-soft)); color: var(--text); }
.notice.error::before { background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }
.error { margin-top: 10px; color: var(--red); }
.ok { color: var(--green); }
.bad { color: var(--red); }
code { padding: 2px 5px; border-radius: 5px; background: var(--surface-soft); color: var(--text); font-size: .88em; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: stretch; }
.settings-card { position: relative; padding-left: calc(var(--panel-padding) + 54px); }
.settings-card.appearance-settings, .settings-card.project-settings, .settings-card.project-integrations-settings, .settings-card.project-members-settings, .settings-card.project-variables-settings { grid-column: 1 / -1; }
.settings-icon { position: absolute; left: var(--panel-padding); top: var(--panel-padding); width: 40px; height: 40px; display: grid; place-items: center; border: 1px solid color-mix(in srgb, currentColor 10%, transparent); border-radius: 12px; background: var(--brand-soft); color: var(--brand); }
.settings-icon .ui-icon { width: 20px; height: 20px; }
.settings-icon.sheets { background: color-mix(in srgb, #0f9d58 10%, var(--surface)); color: #0f9d58; }
.settings-service-logo { width: 25px; height: 25px; }
.settings-icon.appearance { background: rgb(230 179 92 / 12%); color: var(--amber); }
.settings-icon.project { background: var(--brand-soft); color: var(--brand); }
.settings-icon.variables { background: var(--brand-soft); color: var(--brand); }
.settings-card .field { max-width: 360px; }
.settings-card .hint { margin: 12px 0 18px; color: var(--muted); font-size: 12px; }
.project-fields { display: grid; grid-template-columns: minmax(220px, 1.2fr) minmax(160px, .7fr) minmax(240px, 1fr); gap: 12px; margin-bottom: 22px; }
.project-fields .field { max-width: none; }
.project-fields .field small { color: var(--muted); font-size: 11px; }
.project-fields input[readonly] { background: var(--surface-soft); color: var(--muted); cursor: default; }
.project-channels { margin: 0 0 20px; }
.project-channels legend { margin-bottom: 8px; }
.project-channel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 760px; }
.project-channel { position: relative; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); cursor: pointer; transition: border-color .16s ease, background .16s ease; }
.project-channel:hover { border-color: var(--line-strong); }
.project-channel:has(input:checked) { border-color: color-mix(in srgb, var(--brand) 48%, var(--line)); background: var(--brand-soft); }
.project-channel input { position: absolute; width: 1px; height: 1px; min-height: 0; margin: 0; padding: 0; overflow: hidden; opacity: 0; clip-path: inset(50%); pointer-events: none; }
.project-channel-logo { flex: none; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; }
.project-channel-logo.telegram { background: #229ed9; }
.project-channel-logo.telegram .service-logo { color: #fff; }
.project-channel-logo.max { background: linear-gradient(135deg, #367df4, #8155e8); }
.project-channel-logo.max .service-logo.max { width: 25px; height: 25px; padding: 0; background: none; }
.project-channel-copy { min-width: 0; display: grid; gap: 2px; margin-right: auto; }
.project-channel-copy strong { font-weight: 500; }
.project-channel-copy small { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.project-channel-copy small.is-ready { color: var(--green); }
.project-channel-copy small.is-missing { color: var(--amber); }
.project-channel-switch { position: relative; flex: none; width: 38px; height: 22px; border-radius: 999px; background: var(--line-strong); transition: background .16s ease; }
.project-channel-switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgb(0 0 0 / 20%); transition: transform .16s ease; }
.project-channel input:checked ~ .project-channel-switch { background: var(--brand); }
.project-channel input:checked ~ .project-channel-switch::after { transform: translateX(16px); }
.integration-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.integration-form > button { grid-column: 1 / -1; justify-self: start; }
.integration-group { min-width: 0; display: grid; gap: 12px; align-content: start; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.integration-group.google { grid-column: 1 / -1; }
.integration-title { display: flex; align-items: center; gap: 10px; }
.integration-title > div { display: grid; gap: 2px; }
.integration-title strong { font-weight: 500; }
.integration-title small { color: var(--muted); }
.integration-title small.is-ready { color: var(--green); }
.project-channel-logo.sheets { background: #fff; }
.integration-form .field { max-width: none; }
.integration-google-fields { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(160px, .6fr); gap: 10px; }
.integration-group textarea { min-height: 96px; resize: vertical; }
.member-list { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; }
.member-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; min-height: 58px; padding: 10px 14px; border-top: 1px solid var(--line); }
.member-row:first-child { border-top: 0; }
.member-row > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-role { padding: 3px 7px; border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: 11px; }
.member-row button { width: 34px; min-height: 34px; padding: 0; }
.variables-heading { align-items: center; }
.variables-table { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; }
.variables-table-head, .variable-row { display: grid; grid-template-columns: minmax(210px, 1.2fr) minmax(180px, 1fr) auto; gap: 18px; align-items: center; }
.variables-table-head { padding: 10px 14px; background: var(--surface-soft); color: var(--muted); font-size: 11px; font-weight: 500; }
.variable-row { min-height: 72px; padding: 12px 14px; border-top: 1px solid var(--line); }
.variable-row:first-child { border-top: 0; }
.variable-identity, .variable-value { min-width: 0; display: grid; gap: 4px; }
.variable-identity strong { overflow: hidden; font-size: 14px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.variable-identity small { display: flex; align-items: center; gap: 7px; color: var(--muted); }
.variable-type { padding: 2px 6px; border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: 10px; }
.variable-value span { overflow: hidden; color: var(--text); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.variable-value small { color: var(--muted); }
.variable-actions { display: flex; gap: 5px; }
.variable-actions button { width: 34px; min-height: 34px; padding: 0; border: 1px solid var(--line); background: transparent; color: var(--muted); }
.variable-actions button:hover:not(:disabled) { border-color: var(--line-strong); background: var(--surface-soft); color: var(--text); }
.variable-actions .delete-variable { color: var(--red); }
.variables-empty { padding: 30px 16px; color: var(--muted); text-align: center; }
.field > small { color: var(--muted); font-size: 11px; }
.field > small code { color: var(--brand); }
.integration-status { margin: 18px 0; padding: 12px 14px; border-radius: 10px; background: var(--surface-soft); }
.text-link { color: var(--brand); font-weight: 700; text-decoration: none; }
.choice-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin: 8px 0 20px; }
.choice-grid span { display: grid; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); cursor: pointer; }
.choice-grid input:checked + span { border-color: var(--brand); color: var(--brand); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 10%, transparent); }
.theme-preview { display: block; height: 46px; border: 1px solid #d7dee8; border-radius: 7px; background: linear-gradient(90deg, #f2f5f9 0 25%, #fff 25%); box-shadow: inset 0 7px #fff; }
.theme-preview.dark { border-color: #303030; background: linear-gradient(90deg, #171717 0 25%, #1f1f1f 25%); box-shadow: inset 0 7px #252525; }
.theme-preview.system { background: linear-gradient(90deg, #f5f5f5 0 12.5%, #fff 12.5% 50%, #171717 50% 62.5%, #1f1f1f 62.5%); box-shadow: inset 0 7px #fff; }
.setting-toggles { display: grid; margin: 22px 0; border-top: 1px solid var(--line); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch-row > span { display: grid; gap: 2px; }
.switch-row small { color: var(--muted); }
.switch-row input { position: absolute; width: 1px; height: 1px; min-height: 0; margin: 0; padding: 0; overflow: hidden; opacity: 0; clip-path: inset(50%); pointer-events: none; }
.switch-row > i { position: relative; flex: none; width: 42px; height: 24px; border-radius: 999px; background: var(--line-strong); transition: background .16s ease; }
.switch-row > i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: white; box-shadow: 0 1px 4px rgb(0 0 0 / 20%); transition: transform .16s ease; }
.switch-row input:checked + i { background: var(--brand); }
.switch-row input:checked + i::after { transform: translateX(18px); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 30px 0; }
.login-card { width: min(440px, 100%); padding: 40px; box-shadow: none; }
.login-card h1 { margin-bottom: 9px; font-size: 32px; }
.login-card form { display: grid; gap: 14px; margin-top: 24px; }
.login-fields { display: grid; gap: 14px; }
.link-button { min-height: 30px; padding: 3px; background: transparent; color: var(--brand); font-size: 12px; }
.link-button:hover:not(:disabled) { background: transparent; color: var(--brand-hover); }
dialog { width: min(520px, calc(100% - 28px)); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgb(12 20 32 / 58%); backdrop-filter: blur(2px); }
.modal { padding: 28px; }
.modal h2 { margin: 0 0 8px; }
.modal .field { margin: 14px 0; }
.modal-actions { justify-content: flex-end; margin-top: 22px; }
.tabs button:hover:not(:disabled) { background: var(--surface-soft); color: var(--text); }
.tabs button.active, .tabs button.active:hover:not(:disabled) { background: #292929; color: #f5f5f5; }
:root[data-theme="light"] .tabs button.active, :root[data-theme="light"] .tabs button.active:hover:not(:disabled) { background: #ededed; color: #171717; }

@media (max-width: 850px) {
  #app { grid-template-columns: 1fr; }
  .app-sidebar { position: sticky; height: auto; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 16px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .app-sidebar .brand { padding: 0; }
  .app-sidebar .brand-wide-logo { width: 132px; }
  .sidebar-project-row { min-width: 150px; margin: 0; }
  .sidebar-project > span { display: none; }
  .tabs { justify-self: center; flex-direction: row; }
  .tabs button { padding-left: 12px; }
  .tabs button.active::before { display: none; }
  .header-actions { display: flex; margin: 0; }
  .user-chip { display: none; }
  .app-main { padding: 24px 20px 48px; }
  .broadcast-workspace { grid-template-columns: 1fr; }
  .campaign-library { position: static; max-height: none; }
  .campaign-list { max-height: 340px; }
  .metric-grid, .settings-grid { grid-template-columns: 1fr; }
  .subscriber-table-head { display: none; }
  .subscriber-row { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; }
  .subscriber-channel, .subscriber-contact, .subscriber-date { grid-column: 1; margin-left: 53px; }
  .subscriber-delete { grid-column: 2; grid-row: 1; }
  .settings-card.appearance-settings, .settings-card.project-settings, .settings-card.project-integrations-settings, .settings-card.project-members-settings, .settings-card.project-variables-settings { grid-column: auto; }
  .project-fields, .project-channel-grid, .integration-form { grid-template-columns: 1fr; }
  .setup-grid { grid-template-columns: 1fr; align-items: stretch; }
  .action-bar { align-items: flex-start; flex-direction: column; }
  .actions { width: 100%; }
  .monitor-channel-grid { grid-template-columns: 1fr; }
  .monitor-summary { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  .app-sidebar { grid-template-columns: 1fr auto; gap: 8px; padding: 12px; }
  .sidebar-project-row { grid-column: 1 / -1; grid-row: 2; width: 100%; }
  .tabs { grid-column: 1 / -1; grid-row: 3; justify-self: stretch; overflow-x: auto; }
  .tabs button { flex: 1 0 auto; justify-content: center; }
  .header-actions { grid-column: 2; grid-row: 1; }
  .header-actions #logout span { display: none; }
  .app-main { padding: 24px 14px 40px; }
  .notice { right: 12px; bottom: 12px; width: calc(100vw - 24px); }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .metric-card { min-height: 98px; }
  .monitor-hero { flex-direction: column; }
  .monitor-overall { text-align: left; }
  .subscriber-metrics { grid-template-columns: 1fr; }
  .subscriber-toolbar { align-items: stretch; flex-direction: column; }
  .section-title { align-items: flex-start; flex-direction: column; }
  .inline-button { grid-template-columns: 1fr; }
  .choice-grid { grid-template-columns: 1fr; }
  .actions button { flex: 1 0 100%; }
  .settings-card { padding-left: var(--panel-padding); padding-top: calc(var(--panel-padding) + 52px); }
  .project-channel-copy small { white-space: normal; }
  .integration-google-fields { grid-template-columns: 1fr; }
  .variables-heading { align-items: flex-start; }
  .variables-table-head { display: none; }
  .variable-row { grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
  .variable-value { grid-column: 1 / -1; grid-row: 2; }
  .variable-actions { grid-column: 2; grid-row: 1; }
  .login-card { padding: 28px 22px; }
}
