:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1c2026;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #2f6fde;
  --accent-soft: #e8f0fd;
  --ok: #1a7f4b;
  --ok-soft: #e3f4ea;
  --warn: #a15c00;
  --warn-soft: #fdf1dd;
  --bad: #b42318;
  --bad-soft: #fde9e7;
  --bubble: #ffffff;
  --chat-bg: #d9e6d3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --panel: #1a1e24; --text: #e6e8eb; --muted: #98a2b3; --line: #2b313a;
    --accent: #6ea0ff; --accent-soft: #1f2d45; --ok: #5cd191; --ok-soft: #173326; --warn: #f5b454;
    --warn-soft: #3a2c14; --bad: #ff8a80; --bad-soft: #3d1c1a; --bubble: #212d3b; --chat-bg: #0e1621;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
header.top {
  display: flex; align-items: center; gap: 12px; padding: 14px 28px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
header.top h1 { font-size: 18px; margin: 0; font-weight: 650; }
header.top button { white-space: nowrap; }
header.top .spacer { flex: 1; }
main { max-width: 1240px; margin: 0 auto; padding: 24px 28px 60px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; letter-spacing: .02em; white-space: nowrap;
}
.badge.dry { background: var(--warn-soft); color: var(--warn); border: 1px solid currentColor; }
.badge.live { background: var(--bad-soft); color: var(--bad); border: 1px solid currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.neutral { background: var(--accent-soft); color: var(--accent); }
.badge.muted { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

.grid { display: grid; gap: 20px; }
.cols-2 { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
.cols-2b { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 960px) { .cols-2, .cols-2b { grid-template-columns: 1fr; } }
section.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 22px;
}
section.panel > h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  margin: 0 0 14px; font-weight: 650; display: flex; align-items: center; gap: 10px;
}
section.panel > h2 .right { margin-left: auto; text-transform: none; letter-spacing: 0; }
.stack > * + * { margin-top: 20px; }

.status-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.card .label { font-size: 12px; color: var(--muted); }
/* Long names never spill into the next card (usernames wrap after underscores via <wbr>). */
.card .value { font-size: 15px; font-weight: 600; margin-top: 2px; overflow-wrap: break-word; }

label.field { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; }
.hint { font-size: 12.5px; color: var(--muted); }
textarea, input[type=number], input[type=text], input[type=password], select {
  width: 100%; font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
}
textarea { min-height: 220px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13.5px; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.toolbar button { padding: 4px 10px; font-size: 13px; }
.counter { font-size: 12.5px; color: var(--muted); text-align: right; margin-top: 4px; }
.counter.over { color: var(--bad); font-weight: 600; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1 1 auto; min-width: 0; }
/* Number + unit pairs: the number keeps a readable width, the unit select only takes what it needs. */
.row > input[type=number] { flex: 1 1 120px; min-width: 90px; }
.row > .fit { flex: 0 0 auto; width: auto; min-width: 110px; }
.actions { display: flex; gap: 10px; margin-top: 18px; align-items: center; flex-wrap: wrap; }

button, .button {
  font: inherit; font-size: 14px; font-weight: 600; border-radius: 8px; padding: 8px 16px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--bad); }
button:hover { filter: brightness(.97); }
button.link { border: none; background: none; color: var(--accent); padding: 0; font-weight: 500; }

.dropzone {
  border: 1.5px dashed var(--line); border-radius: 10px; padding: 14px; display: flex; gap: 12px;
  align-items: center; justify-content: space-between; flex-wrap: wrap;
}
.dropzone .current { font-size: 13.5px; }

/* Telegram-like preview */
.phone { background: var(--chat-bg); border-radius: 12px; padding: 18px; min-height: 280px; }
.bubble {
  background: var(--bubble); border-radius: 12px 12px 12px 4px; max-width: 420px; overflow: hidden;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .12);
}
.bubble .media img, .bubble .media video { display: block; width: 100%; max-height: 420px; object-fit: cover; background: #000; }
.bubble .text { padding: 8px 12px 10px; white-space: pre-wrap; word-wrap: break-word; font-size: 15px; }
.bubble .text:empty::before { content: "(no text)"; color: var(--muted); font-style: italic; }
.bubble .meta { text-align: right; font-size: 11px; color: var(--muted); padding: 0 10px 6px; }
.bubble blockquote { border-left: 3px solid var(--accent); margin: 4px 0; padding: 2px 8px; background: var(--accent-soft); border-radius: 4px; }
.bubble code, .bubble pre { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--bg); border-radius: 4px; padding: 0 3px; }
.bubble pre { padding: 6px 8px; overflow-x: auto; }
.bubble tg-spoiler { background: var(--muted); color: transparent; border-radius: 3px; }
.bubble tg-spoiler:hover { color: inherit; background: transparent; }
.preview-legend { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; font-size: 12.5px; color: var(--muted); }
.problem { margin-top: 10px; font-size: 13px; color: var(--bad); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
td .sub { font-size: 12.5px; color: var(--muted); }
.counter-pill { font-variant-numeric: tabular-nums; font-weight: 650; }
.switch { position: relative; width: 42px; height: 24px; border-radius: 999px; border: none; padding: 0; background: var(--line); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch.on { background: var(--ok); }
.switch.on::after { left: 21px; }
.toggle-line { display: flex; align-items: center; gap: 10px; font-weight: 600; margin-top: 4px; }
.toggle-line input { width: 18px; height: 18px; }

ul.activity { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; }
ul.activity li { display: grid; grid-template-columns: 118px 1fr; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
ul.activity li:last-child { border-bottom: none; }
ul.activity time { color: var(--muted); font-size: 12px; }
.kind { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin-right: 6px; }
.kind.publication { color: var(--ok); }
.kind.simulated_publication { color: var(--warn); }
.kind.repost_trigger { color: var(--accent); }
.kind.error, .kind.permission { color: var(--bad); }
.kind.interaction { color: #8b5cf6; }
.kind.settings, .kind.targets { color: var(--muted); }

.flash { border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--bad-soft); color: var(--bad); }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

.actions-inline { display: flex; gap: 8px; align-items: center; }
.card-dry { border-color: var(--warn); background: var(--warn-soft); }
.card-dry .value { color: var(--warn); }
.card-live { border-color: var(--bad); background: var(--bad-soft); }
.card-on { border-color: var(--ok); }
.card-on .value { color: var(--ok); }
.updated { margin: 8px 0 0; font-size: 12px; }
details summary { cursor: pointer; font-size: 12.5px; color: var(--accent); margin-top: 4px; }
dl.details { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 6px 0 0; font-size: 12.5px; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; font-variant-numeric: tabular-nums; }
.big-switch { display: flex; align-items: center; gap: 12px; cursor: pointer; margin: 4px 0 6px; user-select: none; }
.big-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.big-switch .track { position: relative; width: 52px; height: 30px; border-radius: 999px; background: var(--line); flex: 0 0 auto; transition: background .15s; }
.big-switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: left .15s; }
.big-switch input:checked + .track { background: var(--ok); }
.big-switch input:checked + .track::after { left: 25px; }
.big-switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.big-switch .state-label { font-weight: 700; font-size: 16px; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 380px; }
.login h1 { font-size: 20px; margin: 0 0 4px; }

/* ---- Narrow screens and the Telegram Mini App ------------------------------------------------ */
body { overflow-x: hidden; }
html.tg body { min-height: var(--tg-viewport-stable-height, 100vh); }
header.top { padding-left: max(28px, env(safe-area-inset-left)); padding-right: max(28px, env(safe-area-inset-right)); }
main { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
img, video { max-width: 100%; }
button.wide { width: 100%; }
.login-wrap { min-height: var(--tg-viewport-stable-height, 100vh); }

@media (max-width: 720px) {
  header.top { padding: 10px max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left)); gap: 8px; }
  header.top h1 { font-size: 16px; }
  #live-indicator { display: none; }
  main { padding: 14px max(12px, env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .stack > * + * { margin-top: 14px; }
  section.panel { padding: 16px 14px; border-radius: 10px; }
  section.panel > h2 { flex-wrap: wrap; row-gap: 10px; }
  section.panel > h2 .right { margin-left: 0; width: 100%; }
  .actions-inline { flex-wrap: wrap; }
  .actions-inline form { flex: 1 1 140px; }
  .actions-inline button, section.panel > h2 .right button { width: 100%; }
  .status-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card { padding: 10px 12px; }
  button, .button { min-height: 44px; }
  .toolbar button { min-height: 38px; padding: 6px 12px; }
  input, select, textarea { font-size: 16px; }            /* no iOS zoom on focus */
  textarea { min-height: 170px; }
  .dropzone { flex-direction: column; align-items: stretch; }
  .dropzone .row, .dropzone input[type=file] { width: 100%; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions > button { width: 100%; }
  .phone { padding: 12px; min-height: 0; }
  .bubble { max-width: 100%; }
  ul.activity { max-height: 320px; }
  ul.activity li { grid-template-columns: 1fr; gap: 2px; }
  .flash { overflow-wrap: anywhere; }

  /* Targets become cards: one field per line, labelled. */
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards thead { display: none; }
  table.cards tr { border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; margin-bottom: 10px; }
  table.cards td { border: none; padding: 7px 0; display: flex; gap: 12px; justify-content: space-between;
                     align-items: center; text-align: right; overflow-wrap: anywhere; }
  table.cards td { flex-wrap: wrap; justify-content: flex-end; column-gap: 8px; }
  table.cards td::before { content: attr(data-label); font-size: 12px; color: var(--muted); text-align: left;
                             flex: 0 0 auto; margin-right: auto; }
  table.cards td.lead { display: block; text-align: left; }
  table.cards td.lead::before { display: block; margin-bottom: 2px; }
  .switch { width: 52px; height: 30px; min-height: 0; flex: 0 0 auto; }   /* not stretched by the 44px button rule */
  .switch::after { width: 24px; height: 24px; }
  .switch.on::after { left: 25px; }
  dl.details { grid-template-columns: 1fr; text-align: left; }
}

/* ---- Team layout: sticky header + tab navigation --------------------------------------------- */
.sticky { position: sticky; top: 0; z-index: 5; }
.sticky header.top { position: static; }
nav.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 6px 28px; background: var(--panel);
           border-bottom: 1px solid var(--line); scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a { padding: 7px 13px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600;
             font-size: 14px; white-space: nowrap; }
nav.tabs a.active { background: var(--accent-soft); color: var(--accent); }
.ws-switch select { width: auto; padding: 5px 8px; font-size: 13px; }
.who { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.who .ws { font-weight: 650; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.who .me { font-size: 12px; color: var(--muted); }
.role { font-size: 11px; font-weight: 700; letter-spacing: .04em; padding: 1px 7px; border-radius: 6px;
        background: var(--accent-soft); color: var(--accent); }
.inline { display: inline; }
.inline-flex { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.secret-box { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--bg);
              border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow-wrap: anywhere; }
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps li { padding: 4px 0 4px 28px; position: relative; font-size: 14px; }
.steps li::before { counter-increment: step; content: counter(step); position: absolute; left: 0; top: 5px;
                    width: 20px; height: 20px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
                    font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.steps li.done { color: var(--muted); }
.kind.accounts { color: var(--accent); }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; overflow-wrap: anywhere; }
.readonly-note { font-size: 13px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 8px 12px; }
fieldset { border: none; padding: 0; margin: 0; }
fieldset[disabled] { opacity: .75; }
.checks label { display: flex; gap: 10px; align-items: center; padding: 6px 0; font-size: 14px; }
.checks input { width: 18px; height: 18px; flex: 0 0 auto; }
@media (max-width: 720px) {
  nav.tabs { padding: 6px max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left)); }
  nav.tabs a { padding: 8px 11px; }
  .who .ws { max-width: 150px; }
  .ws-switch { display: none; }
  table.cards td form, table.cards td select { max-width: 100%; }
}
