/* ============================================================
   SCBot — стили кабинета (Фаза 2, T-13)
   Точка входа: шаблон «Кабинет scbot», чанки scbot.*
   Без иконочных шрифтов; акцент — оранжевый SoundCloud.
   ============================================================ */

:root {
    --c-bg: #f4f5f7;
    --c-card: #ffffff;
    --c-border: #e3e7ec;
    --c-text: #26303c;
    --c-muted: #7a8694;
    --c-dark: #1e2530;
    --c-dark-2: #2a3342;
    --c-accent: #ff5500;
    --c-accent-dark: #d94800;
    --c-danger: #d94242;
    --c-danger-bg: #fdeeee;
    --c-success: #2f9e63;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(20, 28, 38, .08);
    --topbar-h: 56px;
    --sidebar-w: 220px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--c-text);
    background: var(--c-bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--c-accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
    background: #eef1f4;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 13px;
}

/* ---------- Topbar ---------- */

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--c-dark);
    color: #fff;
}

.topbar__logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    letter-spacing: .2px;
}
.topbar__logo:hover { text-decoration: none; }

.topbar__logo-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 7px;
    background: var(--c-accent);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
}

/* ---------- User menu ---------- */

.user-menu { position: relative; }

.user-menu__toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: var(--radius);
    color: #fff;
    font: inherit;
    font-size: 14px;
    cursor: pointer;
}
.user-menu__toggle:hover { background: rgba(255, 255, 255, .08); }

.user-menu__avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--c-accent);
    font-size: 11px;
    font-weight: 700;
}

.user-menu__dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 160px;
    background: var(--c-card);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: 0 6px 18px rgba(20, 28, 38, .14);
    overflow: hidden;
}
.user-menu.is-open .user-menu__dropdown { display: block; }

.user-menu__item {
    display: block;
    padding: 9px 14px;
    color: var(--c-text);
    font-size: 14px;
}
.user-menu__item:hover { background: #f2f4f6; text-decoration: none; }
.user-menu__item--danger { color: var(--c-danger); }

/* ---------- Layout ---------- */

.cabinet__body {
    display: flex;
    min-height: 100vh;
    padding-top: var(--topbar-h);
}

.cabinet__content {
    flex: 1;
    min-width: 0;
    padding: 26px 30px 40px;
    max-width: 1280px;
}

/* ---------- Sidebar ---------- */

.sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--c-dark);
    padding: 14px 10px;
    overflow-y: auto;
}

.sidebar__nav {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar__link {
    display: block;
    padding: 10px 14px;
    border-left: 3px solid transparent;
    border-radius: 0 6px 6px 0;
    color: #aab4c0;
    font-size: 14px;
}
.sidebar__link:hover { color: #fff; background: rgba(255, 255, 255, .06); text-decoration: none; }
.sidebar__link.active {
    color: #fff;
    background: rgba(255, 85, 0, .16);
    border-left-color: var(--c-accent);
}

.cabinet__body { margin-left: var(--sidebar-w); }

/* ---------- Page title ---------- */

.page-title {
    margin: 0 0 20px;
    font-size: 22px;
    font-weight: 700;
    line-height: 1.3;
}

/* ---------- Tables ---------- */

.table-wrapper {
    background: var(--c-card);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table th,
.table td {
    padding: 10px 14px;
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}
.table td.wrap { white-space: normal; }

.table th {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--c-muted);
    border-bottom: 1px solid var(--c-border);
    background: #fafbfc;
}

.table tbody tr { border-bottom: 1px solid var(--c-border); }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: #f7f9fa; }

/* Д-4: миниатюра постера трека (таблица «Треки», колонка «Обложка») */
.track-thumb {
    display: block;
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--c-border);
    background: #fafbfc;
}

/* ---------- Forms ---------- */

.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--c-text);
}

.form-control {
    width: 100%;
    max-width: 640px;
    padding: 9px 12px;
    border: 1px solid var(--c-border);
    border-radius: 6px;
    font: inherit;
    font-size: 14px;
    color: var(--c-text);
    background: #fff;
}
.form-control:focus {
    outline: none;
    border-color: var(--c-accent);
    box-shadow: 0 0 0 3px rgba(255, 85, 0, .14);
}

textarea.form-control { min-height: 84px; resize: vertical; }

.hint {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--c-muted);
}

.password-wrap { position: relative; }

.password-wrap .form-control { padding-right: 46px; }

.password-toggle {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 40px;
    border: 0;
    background: transparent;
    color: var(--c-muted);
    font-size: 15px;
    cursor: pointer;
}
.password-toggle:hover { color: var(--c-text); }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: 6px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease;
    text-decoration: none;
}

.btn-primary { background: var(--c-accent); color: #fff; }
.btn-primary:hover { background: var(--c-accent-dark); text-decoration: none; }

.btn-secondary { background: #fff; color: var(--c-text); border-color: var(--c-border); }
.btn-secondary:hover { background: #f2f4f6; }

.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger:hover { background: #b83232; }

.btn-sm { padding: 5px 11px; font-size: 13px; font-weight: 500; }

.btn[disabled], .btn.is-disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Badges ---------- */

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.5;
    letter-spacing: .3px;
}

.badge-sc { background: #ffeee4; color: #c24100; }

.badge-tg { background: #e7f0fb; color: #2b6cb0; }

/* ---------- Filter bar (страницы списков) ---------- */

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 18px;
}
.filter-bar .form-group { margin-bottom: 0; }
.filter-bar .form-control { width: auto; min-width: 200px; }

/* select в фильтр-баре (T-18 «Лог»: источник SC/TG) — высота строки как у input,
   нативная стрелка остаётся; ширина auto уже даёт .filter-bar .form-control */
.filter-bar select.form-control {
    padding-top: 8px;
    padding-bottom: 8px;
    cursor: pointer;
}

/* ---------- Settings sections ---------- */

.settings-section {
    background: var(--c-card);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    overflow: hidden;
}

.settings-section__title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0;
    padding: 14px 18px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
}

.settings-section__chevron {
    color: var(--c-muted);
    font-size: 12px;
    transition: transform .15s ease;
}
.settings-section.is-collapsed .settings-section__chevron { transform: rotate(-90deg); }
.settings-section.is-collapsed .settings-section__fields { display: none; }

.settings-section__fields {
    display: grid;
    gap: 14px;
    padding: 6px 18px 18px;
    border-top: 1px solid var(--c-border);
}

/* ---------- Login page ---------- */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: linear-gradient(160deg, var(--c-dark) 0%, #2c3648 100%);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--c-card);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
    padding: 30px 28px 26px;
}

.login-card__header { text-align: center; margin-bottom: 22px; }

.login-card__logo {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: .3px;
}
.login-card__logo::after {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-left: 3px;
    border-radius: 50%;
    background: var(--c-accent);
}

.login-card__subtitle {
    margin-top: 4px;
    font-size: 13px;
    color: var(--c-muted);
}

.login-card .btn-primary { width: 100%; justify-content: center; }

.login-error {
    margin-bottom: 16px;
    padding: 10px 12px;
    border: 1px solid #f2c4c4;
    border-radius: 6px;
    background: var(--c-danger-bg);
    color: #a93232;
    font-size: 13px;
}
.login-error:empty { display: none; }

/* ---------- Toasts ---------- */

.toast-container {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 360px;
}

.toast {
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--c-dark-2);
    color: #fff;
    font-size: 14px;
    box-shadow: 0 8px 22px rgba(20, 28, 38, .3);
    animation: toast-in .2s ease;
}

.toast-error { background: var(--c-danger); }
.toast-success { background: var(--c-success); }

.toast.is-out { opacity: 0; transition: opacity .25s ease; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Pagination (pdoPage) ---------- */

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 18px 0 0;
    padding: 0;
    list-style: none;
    font-size: 14px;
}

.pagination li a,
.pagination li span {
    display: block;
    padding: 6px 11px;
    border: 1px solid var(--c-border);
    border-radius: 6px;
    background: #fff;
    color: var(--c-text);
}
.pagination li a:hover { background: #f2f4f6; text-decoration: none; }
.pagination li.active span,
.pagination li.active a {
    background: var(--c-accent);
    border-color: var(--c-accent);
    color: #fff;
}
.pagination li.disabled span { color: var(--c-muted); background: #fafbfc; }

/* ---------- Адаптив ---------- */

@media (max-width: 860px) {
    .sidebar {
        position: static;
        width: auto;
        bottom: auto;
    }
    .cabinet__body {
        flex-direction: column;
        margin-left: 0;
    }
    .cabinet__content { padding: 18px 14px 30px; }
    .table th, .table td { padding: 8px 10px; }
}

/* ---------- Настройки: действия и результат вебхука (T-15) ---------- */

.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 20px 0 0;
}

.js-webhook-result {
    margin: 16px 0 0;
    padding: 12px 14px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-card);
    font-size: 14px;
    overflow-wrap: anywhere;
}

.js-webhook-result:empty { display: none; }

.js-webhook-result.is-loading { color: var(--c-muted); }

.js-webhook-result.is-success {
    border-color: var(--c-success);
    background: #eef8f2;
}

.js-webhook-result.is-error {
    border-color: var(--c-danger);
    background: var(--c-danger-bg);
}

.webhook-info {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 16px;
    margin: 0;
}

.webhook-info dt { color: var(--c-muted); }
.webhook-info dd { margin: 0; }

/* toast типа ok (scbotToast(msg, 'ok')) — в цвет success */
.toast-ok { background: var(--c-success); }

/* ---------- Списки: пустой результат и загрузка (T-16) ---------- */

.empty-state {
    margin: 18px 0 0;
    padding: 28px 18px;
    text-align: center;
    border: 1px dashed var(--c-border);
    border-radius: var(--radius);
    background: var(--c-card);
    color: var(--c-muted);
    font-size: 14px;
}

#pdopage { transition: opacity .15s ease; }
#pdopage.loading { opacity: .3; }

/* ---------- Рассылка (T-20) ---------- */

.broadcast__recipients {
    margin: 0 0 16px;
    padding: 10px 14px;
    background: var(--c-card);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    font-size: 14px;
}
.broadcast__recipients strong { font-size: 16px; }

.broadcast__editor { margin-bottom: 10px; }

/* fallback-поле (пока редактор не инициализирован / не запустился) */
.broadcast__source {
    display: block;
    width: 100%;
    min-height: 170px;
    padding: 10px 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-card);
    font: inherit;
    font-size: 14px;
    resize: vertical;
}
/* редактор готов — исходный textarea спрятан самим Suneditor'ом */
.broadcast--ready .broadcast__source { display: none; }

/* рамка редактора — в стиле кабинета */
.broadcast__editor .sun-editor {
    border-color: var(--c-border);
    border-radius: var(--radius);
}
.broadcast__editor .sun-editor-editable { min-height: 170px; }

.broadcast__counter {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 18px;
    font-size: 13px;
    color: var(--c-muted);
}
.js-broadcast-count.is-over { color: var(--c-danger); font-weight: 700; }
.broadcast__counter-note { color: var(--c-danger); }

.broadcast__dropzone {
    padding: 16px;
    margin-bottom: 18px;
    border: 2px dashed var(--c-border);
    border-radius: var(--radius);
    background: var(--c-card);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.broadcast__dropzone.is-drag {
    border-color: var(--c-accent);
    background: #fff6f1;
}
.broadcast__drop-hint {
    margin-bottom: 10px;
    color: var(--c-muted);
    font-size: 13px;
    text-align: center;
}

.broadcast__chips { display: flex; flex-wrap: wrap; gap: 10px; }
.broadcast__chips:empty { display: none; }

.broadcast__chip {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 200px;
    padding: 6px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: #fff;
}
.broadcast__chip img {
    display: block;
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
}
.broadcast__chip span {
    max-width: 110px;
    overflow: hidden;
    color: var(--c-text);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.broadcast__chip.is-loading { opacity: .65; }
.broadcast__chip.is-loading::after {
    content: '';
    width: 14px;
    height: 14px;
    border: 2px solid var(--c-border);
    border-top-color: var(--c-accent);
    border-radius: 50%;
    animation: bcast-spin .8s linear infinite;
}
.broadcast__chip.is-failed { border-color: var(--c-danger); }
@keyframes bcast-spin { to { transform: rotate(360deg); } }

.broadcast__chip-x {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    padding: 0;
    border: 1px solid var(--c-border);
    border-radius: 50%;
    background: #fff;
    color: var(--c-muted);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
}
.broadcast__chip-x:hover { color: var(--c-danger); border-color: var(--c-danger); }

.broadcast-result {
    margin-top: 14px;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
}
.broadcast-result.is-error {
    border: 1px solid var(--c-danger);
    background: var(--c-danger-bg);
    color: var(--c-danger);
}

/* статусы рассылки в истории */
.badge-bc-new     { background: #eef1f4; color: #5a6774; }
.badge-bc-sending { background: #fff3df; color: #b97a00; }
.badge-bc-done    { background: #e6f5ed; color: var(--c-success); }
.badge-bc-failed  { background: var(--c-danger-bg); color: var(--c-danger); }

.page-subtitle {
    margin: 28px 0 12px;
    font-size: 17px;
    font-weight: 700;
}
.empty-cell { color: var(--c-muted); text-align: center; }

/* ---------- Topbar: статистика хранилища (scbotStorageStat) ---------- */
/* Пользователи · Скачиваний · Треки · Кеш · Свободно — scbot_users (пожизненный
   счётчик юзера), scbot_tracks (SUM(filesize)) и df(). */

.topbar__stats {
    display: flex;
    align-items: center;
    margin-left: auto; /* правая зона topbar, перед user-menu */
    margin-right: 14px;
    font-size: 13px;
    line-height: 1.4;
    color: rgba(255, 255, 255, .62);
    white-space: nowrap;
}

.topbar__stat { padding: 0 2px; }

.topbar__stat + .topbar__stat {
    margin-left: 12px;
    padding-left: 13px;
    border-left: 1px solid rgba(255, 255, 255, .16);
}

.topbar__stat-value {
    color: #fff;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 860px) {
    /* остаются «Треки · Кеш» — пять сегментов (nowrap) вместе с логотипом и
       user-menu уже не влезают в 860 px */
    .topbar__stat--users,
    .topbar__stat--downloads,
    .topbar__stat--free { display: none; }
}

@media (max-width: 560px) {
    .topbar__stats { display: none; }
}
