/* Ads Hub — тёмная тема, жёлтый акцент.
   Жёлтый работает только на интерфейсе: кнопки, активные состояния, логотип.
   Цифры красятся по смыслу (зелёный/красный), чтобы не спорить с акцентом. */

:root {
    --bg: #0b0b0c;
    --surface: #151517;
    --surface-2: #1e1e21;
    --border: #2a2a2e;

    --yellow: #ffd100;
    --yellow-dim: #b39200;

    --text: #ededef;
    --text-dim: #8a8a90;
    /* Проверено на контраст: 4.51 к поверхности карточки.
       Прежний #5c5c63 давал 2.75 — мелкие подписи не читались. */
    --text-faint: #7e7e82;

    --good: #4ade80;
    --bad: #f87171;
    --warn: #fbbf24;

    --radius: 14px;
    --tap: 48px; /* минимальная цель для пальца */
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    background: var(--bg);
}

body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
        Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    padding-bottom: env(safe-area-inset-bottom);
}

a {
    color: var(--yellow);
    text-decoration: none;
}

/* ── Шапка ─────────────────────────────────────────────────────────────── */

.top {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    padding-top: calc(14px + env(safe-area-inset-top));
    background: rgba(11, 11, 12, 0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -0.2px;
}

.logo-mark {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--yellow);
    color: #000;
    display: grid;
    place-items: center;
    font-size: 15px;
    font-weight: 800;
}

.top-meta {
    font-size: 12px;
    color: var(--text-faint);
    text-align: right;
    line-height: 1.35;
}

/* ── Каркас ────────────────────────────────────────────────────────────── */

.wrap {
    max-width: 760px;
    margin: 0 auto;
    padding: 18px 16px 40px;
}

.section-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.9px;
    color: var(--text-faint);
    margin: 26px 0 10px;
    font-weight: 600;
}

.section-title:first-child {
    margin-top: 6px;
}

/* ── Карточки ──────────────────────────────────────────────────────────── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 10px;
}

.card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.card-name {
    font-size: 17px;
    font-weight: 650;
    letter-spacing: -0.2px;
}

.card-sub {
    font-size: 13px;
    color: var(--text-faint);
}

/* Ряд метрик: крупные цифры, читаются с расстояния вытянутой руки.
   На телефоне ровно 2×2 — три колонки оставляют четвёртую висеть одна. */
.metrics {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px 12px;
}

@media (min-width: 560px) {
    .metrics {
        grid-template-columns: repeat(4, 1fr);
    }
}

.metric-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-faint);
    margin-bottom: 3px;
}

.metric-value {
    font-size: 22px;
    font-weight: 680;
    letter-spacing: -0.6px;
    font-variant-numeric: tabular-nums;
}

.metric-extra {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
}

.up { color: var(--good); }
.down { color: var(--bad); }
.muted { color: var(--text-dim); }
.accent { color: var(--yellow); }

/* ── Плашки состояния ──────────────────────────────────────────────────── */

.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.pill-ok { background: rgba(74, 222, 128, 0.13); color: var(--good); }
.pill-bad { background: rgba(248, 113, 113, 0.13); color: var(--bad); }
.pill-wait { background: rgba(251, 191, 36, 0.13); color: var(--warn); }
.pill-off { background: var(--surface-2); color: var(--text-faint); }

/* ── Строки списка ─────────────────────────────────────────────────────── */

.row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 0;
    border-bottom: 1px solid var(--border);
    min-height: var(--tap);
}

.row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.row-main {
    min-width: 0;
}

.row-title {
    font-weight: 560;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.row-sub {
    font-size: 13px;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
}

/* ── Кнопки ────────────────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 0 20px;
    border: none;
    border-radius: 12px;
    background: var(--yellow);
    color: #000;
    font-size: 16px;
    font-weight: 680;
    cursor: pointer;
    width: 100%;
    font-family: inherit;
}

.btn:active {
    background: var(--yellow-dim);
}

.btn-ghost {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

/* ── Экран входа ───────────────────────────────────────────────────────── */

.login {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
    gap: 22px;
}

.login-logo {
    width: 58px;
    height: 58px;
    border-radius: 16px;
    background: var(--yellow);
    color: #000;
    display: grid;
    place-items: center;
    font-size: 27px;
    font-weight: 800;
}

.login-title {
    font-size: 19px;
    font-weight: 650;
    text-align: center;
}

.login-hint {
    font-size: 14px;
    color: var(--text-dim);
    text-align: center;
    margin-top: -14px;
    min-height: 20px;
}

.login-hint.error {
    color: var(--bad);
}

/* Точки-индикаторы введённых цифр */
.dots {
    display: flex;
    gap: 14px;
}

.dot {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 2px solid var(--border);
    transition: all 0.12s;
}

.dot.filled {
    background: var(--yellow);
    border-color: var(--yellow);
}

.dots.shake {
    animation: shake 0.35s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

/* Клавиатура: крупная, чтобы попадать пальцем не глядя */
.pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    width: 100%;
    max-width: 290px;
}

.key {
    height: 68px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    font-size: 26px;
    font-weight: 520;
    cursor: pointer;
    font-family: inherit;
    font-variant-numeric: tabular-nums;
}

.key:active {
    background: var(--surface-2);
    border-color: var(--yellow);
}

.key-wide {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-dim);
}

.key-blank {
    border: none;
    background: none;
    cursor: default;
}

/* ── Пустые состояния и подсказки ──────────────────────────────────────── */

.empty {
    text-align: center;
    padding: 34px 20px;
    color: var(--text-dim);
}

.empty-icon {
    font-size: 32px;
    margin-bottom: 10px;
}

.todo {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--yellow);
    border-radius: var(--radius);
    padding: 15px 16px;
    margin-bottom: 10px;
}

.todo-title {
    font-weight: 650;
    margin-bottom: 5px;
}

.todo-text {
    font-size: 14px;
    color: var(--text-dim);
}

code {
    background: var(--surface-2);
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 13px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

/* ── Переключатель периода ─────────────────────────────────────────────── */

.periods {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 2px 2px 14px;
    scrollbar-width: none;
}

.periods::-webkit-scrollbar {
    display: none;
}

.period {
    flex: 0 0 auto;
    padding: 9px 15px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 14px;
    font-weight: 560;
    white-space: nowrap;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
}

.period.active {
    background: var(--yellow);
    border-color: var(--yellow);
    color: #000;
}

button.period {
    font-family: inherit;
    cursor: pointer;
}

.custom-range {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px 16px;
    margin-bottom: 12px;
}

/* Нативный календарь на тёмном фоне: иконку осветляем, иначе не видно */
.custom-range input[type="date"] {
    color-scheme: dark;
}

.period-note {
    font-size: 13px;
    color: var(--text-faint);
    margin: -4px 0 14px 2px;
}

/* ── Таблица клиентов: десяток строк должен помещаться на экран ─────────── */

.table {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.thead,
.trow {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) repeat(4, minmax(0, 1fr));
    gap: 8px;
    align-items: center;
    padding: 11px 14px;
}

.thead {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-faint);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.thead div:not(:first-child),
.tnum {
    text-align: right;
}

.trow {
    border-bottom: 1px solid var(--border);
    color: inherit;
    text-decoration: none;
    min-height: 56px;
}

.trow:last-child {
    border-bottom: none;
}

.trow:active {
    background: var(--surface-2);
}

.tname {
    font-weight: 600;
    font-size: 15px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tsub {
    font-size: 11px;
    color: var(--text-faint);
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
}

.tnum {
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    line-height: 1.25;
}

.tnum b {
    font-weight: 650;
}

.tnum .metric-extra {
    margin-top: 1px;
    font-size: 11px;
}

/* Не только цветом: рядом с точкой стоит число сломанных кабинетов,
   иначе при дальтонизме метка не читается */
.badge-bad {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 5px;
    background: rgba(248, 113, 113, 0.16);
    color: var(--bad);
    font-size: 10px;
    font-weight: 700;
    margin-left: 5px;
    vertical-align: middle;
}

/* Мини-график прямо в строке */
.spark-inline {
    display: inline-flex;
    align-items: flex-end;
    gap: 1px;
    height: 12px;
    width: 46px;
}

.spark-inline i {
    flex: 1;
    background: var(--text-faint);
    border-radius: 1px;
    min-height: 1px;
}

.spark-inline i:last-child {
    background: var(--yellow);
}

/* Сортировка */
.sorters {
    float: right;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
}

.sorters a {
    color: var(--text-faint);
    margin-left: 10px;
    font-size: 12px;
}

.sorters a.on {
    color: var(--yellow);
}

/* Длинный список сигналов сворачиваем */
.signals .extra {
    display: none;
}

.signals.open .extra {
    display: flex;
}

.more-btn {
    width: 100%;
    min-height: 40px;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: 12px;
    color: var(--text-dim);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    margin-top: 4px;
}

@media (max-width: 560px) {
    /* На телефоне пятая колонка не влезает — прячем контакты,
       они всё равно есть на карточке клиента */
    .thead div:nth-child(4),
    .trow > div:nth-child(4) {
        display: none;
    }

    .thead,
    .trow {
        grid-template-columns: minmax(0, 1.5fr) repeat(3, minmax(0, 1fr));
        padding: 11px 12px;
        gap: 6px;
    }

    .tnum { font-size: 14px; }
    .tname { font-size: 14px; }
}

/* ── Сигналы: что сломалось, крупно и сверху ───────────────────────────── */

.signals {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-bottom: 6px;
}

.signal {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 14px;
    line-height: 1.4;
    min-height: var(--tap);
}

.signal-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.signal-bad { border-left: 3px solid var(--bad); }
.signal-bad .signal-dot { background: var(--bad); }

.signal-warn { border-left: 3px solid var(--warn); }
.signal-warn .signal-dot { background: var(--warn); }

.signal-good { border-left: 3px solid var(--good); }
.signal-good .signal-dot { background: var(--good); }

/* ── Мини-график расхода по дням ───────────────────────────────────────── */

.spark {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 34px;
    margin: 2px 0 14px;
}

.spark-bar {
    flex: 1;
    background: var(--surface-2);
    border-radius: 2px 2px 0 0;
    min-height: 2px;
}

.spark-bar:last-child {
    background: var(--yellow);
}

.card-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.compare {
    margin-top: 13px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-dim);
}

/* ── Формы ─────────────────────────────────────────────────────────────── */

.field {
    margin-bottom: 14px;
}

.field label {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-faint);
    margin-bottom: 6px;
    font-weight: 600;
}

.field input,
.field textarea,
.field select {
    width: 100%;
    min-height: var(--tap);
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font: inherit;
    font-size: 16px; /* меньше 16px — iOS зумит страницу при фокусе */
}

.field textarea {
    min-height: 96px;
    resize: vertical;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 14px;
    line-height: 1.5;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    outline: none;
    border-color: var(--yellow);
}

.field input::placeholder,
.field textarea::placeholder {
    color: var(--text-faint);
}

.field-hint {
    font-size: 12px;
    color: var(--text-faint);
    margin-top: 6px;
    line-height: 1.45;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.btn-row {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}

.btn-sm {
    min-height: 38px;
    padding: 0 14px;
    font-size: 14px;
    width: auto;
    border-radius: 10px;
}

.btn-danger {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--bad);
}

/* ── Строка кабинета: поле + крестик ───────────────────────────────────── */

.acc-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    margin-bottom: 8px;
    align-items: center;
}

.acc-row input {
    width: 100%;
    min-height: var(--tap);
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font: inherit;
    font-size: 16px;
    font-variant-numeric: tabular-nums;
}

.acc-row input:focus {
    outline: none;
    border-color: var(--yellow);
}

.acc-row input::placeholder {
    color: var(--text-faint);
}

.acc-del {
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: transparent;
    color: var(--text-faint);
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0;
}

.acc-del:active {
    color: var(--bad);
    border-color: var(--bad);
}

.acc-note {
    grid-column: 1 / -1;
    font-size: 12px;
    color: var(--text-faint);
    margin: -4px 0 4px 4px;
}

/* ── Всплывающее уведомление после действия ────────────────────────────── */

.flash {
    padding: 13px 15px;
    border-radius: 12px;
    margin-bottom: 14px;
    font-size: 14px;
    line-height: 1.45;
}

.flash-ok {
    background: rgba(74, 222, 128, 0.11);
    color: var(--good);
    border: 1px solid rgba(74, 222, 128, 0.25);
}

.flash-bad {
    background: rgba(248, 113, 113, 0.11);
    color: var(--bad);
    border: 1px solid rgba(248, 113, 113, 0.25);
}

/* ── Ссылка-строка с шевроном ──────────────────────────────────────────── */

.row-link {
    text-decoration: none;
    color: inherit;
    display: flex;
}

.chev {
    color: var(--text-faint);
    font-size: 20px;
    flex-shrink: 0;
    align-self: center;
}

.back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-dim);
    font-size: 14px;
    margin-bottom: 12px;
    min-height: 38px;
}

/* ── Нижняя навигация: большим пальцем, не тянясь вверх ────────────────── */

.tabs {
    position: sticky;
    bottom: 0;
    display: flex;
    background: rgba(11, 11, 12, 0.94);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 9px 0 7px;
    font-size: 11px;
    color: var(--text-faint);
    min-height: var(--tap);
}

.tab.active {
    color: var(--yellow);
}

.tab-icon {
    font-size: 19px;
    line-height: 1;
}

/* ── Готовые UTM-ссылки ────────────────────────────────────────────────── */

.link-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.link-item:last-of-type {
    border-bottom: none;
    padding-bottom: 0;
}

.link-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--yellow);
    margin-bottom: 6px;
}

.link-url {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-dim);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    /* Ссылки длинные: переносим по любому символу, чтобы не было горизонтальной прокрутки */
    word-break: break-all;
    margin-bottom: 8px;
}

.btn-copy {
    min-height: 38px;
    padding: 0 16px;
    font-size: 14px;
    width: auto;
    border-radius: 10px;
}

.btn-copy.copied,
.btn.copied {
    color: var(--good);
    border-color: var(--good);
}

.btn-copy.copy-failed,
.btn.copy-failed {
    color: var(--bad);
    border-color: var(--bad);
}

.btn-add {
    min-height: 40px;
    font-size: 14px;
    margin-top: 2px;
}

/* Держит все ссылки одним куском для кнопки «Копировать все» */
.hidden-copy {
    position: absolute;
    left: -9999px;
    opacity: 0;
    height: 1px;
}

.check {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 4px 0 16px;
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.5;
}

.check input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-top: 1px;
    accent-color: var(--yellow);
    flex-shrink: 0;
}

@media (min-width: 700px) {
    .metric-value { font-size: 25px; }
}
