:root {
    --bg-base: #212121;
    --bg-panel: #171717;
    --bg-modal: #202020;
    --bg-surface: #2f2f2f;
    --bg-surface-hover: #3a3a3a;
    --text-primary: #ececec;
    --text-secondary: #b4b4b4;
    --border-subtle: rgba(255, 255, 255, 0.08);
    --danger-soft: #ff8a80;
    --success-soft: #8fd694;
    --radius-md: 8px;
    --radius-lg: 12px;
}

* { box-sizing: border-box; }

body {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    height: 100vh;
    overflow: hidden;
}

body.auth-active {
    overflow: hidden;
}

.app-shell {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-base);
    transition: filter 0.85s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.85s cubic-bezier(0.2, 0.8, 0.2, 1);
}

body.auth-active .app-shell {
    filter: blur(18px) brightness(0.34);
    transform: translateZ(0);
    pointer-events: none;
    user-select: none;
}

.top-brand-header {
    height: 105px;
    min-height: 105px;
    padding: 0 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-base);
    border-bottom: 1px solid var(--border-subtle);
}

.brand-header-inner {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
}

.brand-icon { color: var(--text-primary); flex-shrink: 0; }
.brand-info { display: flex; align-items: center; gap: 12px; }
.brand-title { font-size: 1.3rem; font-weight: 800; letter-spacing: 0.5px; color: var(--text-primary); text-transform: uppercase; line-height: 1; margin: 0; }
.brand-divider { width: 1px; height: 22px; background-color: var(--border-subtle); }
.brand-subtitle { display: flex; flex-direction: column; font-size: 0.65rem; font-weight: 500; text-transform: uppercase; color: var(--text-secondary); line-height: 1.1; letter-spacing: 0.5px; }

.top-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sync-indicator {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.app-layout {
    flex-grow: 1;
    min-height: 0;
    display: flex;
}

.projects-panel {
    width: 400px;
    min-width: 400px;
    background-color: var(--bg-panel);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-subtle);
}

.panel-section-title {
    padding: 18px 20px 10px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-secondary);
}

.history-header {
    margin: 0 16px 14px;
    padding: 13px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: 0.2s;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.92rem;
    background: var(--bg-surface);
    border: none;
    border-radius: var(--radius-md);
    text-align: left;
}

.history-header:hover { background: var(--bg-surface-hover); }
.history-divider { height: 1px; background: var(--border-subtle); margin: 0 20px; }
.history-list { flex-grow: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }

.history-item {
    position: relative;
    padding: 12px 14px 12px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 3px;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: 0.2s;
    min-height: 58px;
    border: 1px solid transparent;
}

.history-item:hover { background: var(--bg-surface-hover); }
.history-item.active { background: var(--bg-surface-hover); box-shadow: inset 0 0 0 1px var(--text-secondary); }
.history-item-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; }
.history-item-meta { font-size: 0.72rem; color: var(--text-secondary); }
.history-item-running { color: var(--success-soft); font-size: 0.72rem; }

.workspace-panel {
    flex-grow: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-base);
}

.dashboard-zone {
    flex-grow: 1;
    min-height: 0;
    padding: 32px 40px;
    overflow-y: auto;
}

.auth-zone {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: rgba(10, 10, 10, 0.28);
    opacity: 1;
    visibility: visible;
    transition: opacity 0.85s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0.85s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.auth-zone.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.auth-card {
    width: 100%;
    max-width: 460px;
    padding: 32px;
    transform: translateY(0) scale(1);
    opacity: 1;
    transition: transform 0.85s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.85s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.auth-zone.is-hidden .auth-card {
    transform: translateY(-18px) scale(0.98);
    opacity: 0;
}

.auth-card.auth-success {
    border-color: rgba(143, 214, 148, 0.38);
    box-shadow: 0 0 45px rgba(0, 0, 0, 0.72), 0 0 0 1px rgba(143, 214, 148, 0.08);
}

.btn-auth-success,
.btn-auth-success:hover,
.btn-auth-success:disabled {
    background: var(--success-soft) !important;
    color: #102214 !important;
    opacity: 1 !important;
}

.auth-title-block h1 {
    font-size: 1.55rem;
    font-weight: 650;
    margin: 0 0 8px;
}

.auth-title-block p {
    color: var(--text-secondary);
    margin: 0 0 28px;
    font-size: 0.95rem;
    line-height: 1.45;
}

.empty-state {
    height: 100%;
    min-height: 420px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.project-workspace {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
}

.workspace-heading {
    min-height: 98px;
    padding: 18px 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 24px;
}

.eyebrow {
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 700;
    margin-bottom: 6px;
}

.workspace-title {
    color: var(--text-primary);
    font-size: 1.55rem;
    font-weight: 650;
    margin: 0;
}

.workspace-meta {
    color: var(--text-secondary);
    margin-top: 6px;
    font-size: 0.9rem;
}

.workspace-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.robots-grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-bottom: 32px;
}

.robot-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 18px;
    transition: 0.2s;
}

.robot-card.running {
    border-color: rgba(143, 214, 148, 0.45);
    box-shadow: 0 0 0 1px rgba(143, 214, 148, 0.08), 0 0 30px rgba(143, 214, 148, 0.06);
}

.robot-topline {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
}

.robot-name {
    margin: 0;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 650;
    line-height: 1.35;
}

.robot-id {
    color: var(--text-secondary);
    font-size: 0.78rem;
    margin-top: 3px;
}

.robot-status-area {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.status-pill {
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    background: var(--bg-surface);
    color: var(--text-secondary);
}

.status-pill.running { background: rgba(143, 214, 148, 0.14); color: var(--success-soft); }
.status-pill.completed { background: rgba(168, 199, 250, 0.14); color: #a8c7fa; }

.btn-delete-robot {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    transition: 0.2s;
    line-height: 1;
}

.btn-delete-robot:hover { background: var(--bg-surface); color: var(--danger-soft); }

.robot-controls {
    display: grid;
    grid-template-columns: minmax(150px, 1.2fr) minmax(150px, 1.2fr) 96px 96px 54px;
    gap: 12px;
    align-items: end;
}

.counter-box {
    width: 100%;
    min-height: 42px;
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Consolas', monospace;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.counter-box.running { color: var(--success-soft); }
.compact-number-input { width: 100%; padding-left: 8px; padding-right: 8px; }


.form-label { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 6px; }
.custom-input,
.form-select.custom-input {
    background-color: var(--bg-surface);
    border: 1px solid transparent;
    color: var(--text-primary);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 0.9rem;
    transition: 0.2s;
}

.custom-input:focus,
.form-select.custom-input:focus {
    background-color: var(--bg-surface-hover);
    border-color: var(--border-subtle);
    color: var(--text-primary);
    box-shadow: none;
}

.custom-input:disabled,
.form-select.custom-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-flat,
.btn-save,
.btn-run {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 500;
    transition: 0.2s;
}

.btn-save,
.btn-run { padding: 10px 24px; }
.btn-flat:hover:not(:disabled),
.btn-save:hover:not(:disabled),
.btn-run:hover:not(:disabled) { background: var(--bg-surface-hover); color: var(--text-primary); }
.btn-flat:disabled,
.btn-save:disabled,
.btn-run:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-danger-soft { color: var(--danger-soft); }
.btn-danger-soft:hover:not(:disabled) { color: #ffb4ac; }
.btn-confirm-danger { background: #d32f2f; color: white; }
.btn-confirm-danger:hover:not(:disabled) { background: #b92828; color: white; }

.modal-custom { background-color: var(--bg-modal); border: 1px solid #484f58; border-radius: var(--radius-lg); box-shadow: 0 0 40px rgba(0,0,0,0.8); overflow: hidden; }
.modal-header-custom { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px 0 16px; background-color: var(--bg-modal); }
.btn-close-custom { background: none; border: none; color: var(--text-secondary); font-size: 1.2rem; padding: 8px 12px; border-radius: var(--radius-md); cursor: pointer; line-height: 1; }
.btn-close-custom:hover { background: var(--bg-surface); color: var(--text-primary); }
.danger-modal { border-color: rgba(255, 138, 128, 0.45); }

.list-group-custom {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pick-item {
    background: var(--bg-surface);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    padding: 13px 14px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: 0.2s;
}

.pick-item:hover { background: var(--bg-surface-hover); }
.pick-item small { color: var(--text-secondary); }
.form-check-input { background-color: var(--bg-panel); border-color: var(--border-subtle); }
.form-check-input:checked { background-color: var(--text-primary); border-color: var(--text-primary); }

.info-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 24px;
    color: var(--text-secondary);
    text-align: center;
}

@media (max-width: 980px) {
    .top-brand-header { padding: 0 18px; }
    .projects-panel { width: 320px; min-width: 320px; }
    .auth-zone, .dashboard-zone { padding: 24px; }
    .workspace-heading { flex-direction: column; align-items: flex-start; }
    .workspace-actions { width: 100%; flex-wrap: wrap; }
    .robot-controls { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
    body { overflow: auto; height: auto; }
    .app-shell { min-height: 100vh; height: auto; }
    .top-brand-header { height: auto; min-height: 92px; gap: 16px; flex-wrap: wrap; padding: 18px; }
    .app-layout { flex-direction: column; }
    .projects-panel { width: 100%; min-width: 0; max-height: 320px; border-right: none; border-bottom: 1px solid var(--border-subtle); }
    .workspace-panel { min-height: 560px; }
    .robot-controls { grid-template-columns: 1fr; }
}


/* =========================================================
   НАСТРОЙКИ / УВЕДОМЛЕНИЯ
========================================================= */
.settings-dialog {
    max-width: 820px;
}

.settings-modal-content {
    min-height: 520px;
}

.settings-modal-header {
    padding: 18px 20px 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.settings-modal-subtitle {
    color: var(--text-secondary);
    font-size: 0.82rem;
    margin-top: 4px;
}

.settings-modal-body {
    display: flex;
    height: 500px;
    min-height: 500px;
}

.settings-nav {
    width: 220px;
    background-color: var(--bg-panel);
    padding: 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-right: 1px solid var(--border-subtle);
}

.compact-settings-nav {
    width: 210px;
    min-width: 210px;
}

.nav-item {
    background: transparent;
    border: none;
    padding: 10px 16px;
    text-align: left;
    color: var(--text-secondary);
    font-size: 0.95rem;
    border-radius: var(--radius-md);
    transition: 0.2s;
}

.nav-item:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    font-weight: 500;
}

.compact-settings-form {
    flex-grow: 1;
    min-width: 0;
    padding: 26px;
    overflow-y: auto;
    background-color: var(--bg-modal);
}

.settings-pane-heading {
    margin-bottom: 22px;
}

.notification-settings-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.notification-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 18px;
}

.notification-card-head {
    display: flex;
    justify-content: space-between;
    gap: 22px;
    align-items: flex-start;
    margin-bottom: 16px;
}

.notification-title {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 650;
    margin: 0 0 6px 0;
}

.notification-desc {
    color: var(--text-secondary);
    font-size: 0.86rem;
    line-height: 1.45;
    margin: 0;
}

.standard-sound-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.84rem;
    white-space: nowrap;
    user-select: none;
    cursor: pointer;
}

.standard-sound-toggle input {
    width: 16px;
    height: 16px;
    accent-color: var(--text-primary);
}

.sound-file-row {
    margin-bottom: 14px;
}

.sound-file-picker {
    width: 100%;
    min-height: 62px;
    border: 1px dashed rgba(255, 255, 255, 0.18);
    border-radius: var(--radius-md);
    background: rgba(0, 0, 0, 0.12);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    transition: 0.2s;
}

.sound-file-picker:hover {
    background: var(--bg-surface-hover);
    border-color: rgba(255, 255, 255, 0.28);
}

.sound-file-picker.is-disabled {
    opacity: 0.42;
    cursor: not-allowed;
    pointer-events: none;
}

.sound-file-picker-title {
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 550;
}

.sound-file-picker-subtitle {
    color: var(--text-secondary);
    font-size: 0.78rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sound-controls-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-sound-control {
    padding: 8px 14px;
    border-radius: 18px;
    font-size: 0.84rem;
}

.sound-status {
    color: var(--text-secondary);
    font-size: 0.78rem;
    line-height: 1.35;
    margin-left: 4px;
}

.sound-status.is-error {
    color: var(--danger-soft);
}

.sound-status.is-ok {
    color: var(--success-soft);
}

@media (max-width: 900px) {
    .settings-modal-body {
        height: auto;
        min-height: 0;
        flex-direction: column;
    }

    .compact-settings-nav {
        width: 100%;
        min-width: 0;
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
    }

    .notification-card-head,
    .sound-controls-row {
        flex-direction: column;
        align-items: stretch;
    }
}


/* Финальные правки уведомлений */
.notification-card-head {
    display: block;
}
.notification-card-head > div {
    width: 100%;
    min-width: 0;
}
.notification-desc {
    width: 100%;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: anywhere;
}
.standard-sound-toggle {
    margin-top: 10px;
    width: fit-content;
}
.btn-sound-control {
    width: 42px;
    height: 38px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.settings-actions-row {
    display: flex;
    justify-content: flex-end;
    padding-top: 18px;
}
.btn-settings-save.is-saved,
.btn-settings-save.is-saved:hover,
.btn-settings-save.is-saved:disabled {
    background: var(--success-soft) !important;
    color: #102214 !important;
    opacity: 1 !important;
}

/* =========================================================
   ТОЧЕЧНОЕ ДОБАВЛЕНИЕ РОБОТОВ / УДАЛЕНИЕ ПРОЕКТА ИЗ БОКОВОЙ ПАНЕЛИ
========================================================= */
.history-item {
    padding-right: 44px;
}

.btn-delete-project {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: 0.2s;
}

.history-item:hover .btn-delete-project {
    display: flex;
}

.btn-delete-project:hover {
    background: var(--bg-surface);
    color: var(--danger-soft);
}

.add-robots-dialog {
    max-width: 620px;
}

.modal-step-label {
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 4px;
}

.robot-pick-item > span {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.pick-item-subline {
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 400;
}

.workspace-actions,
#btnSyncRobots,
#btnDeleteProject,
#syncModal,
#addProjectModal {
    display: none !important;
}

/* =========================================================
   МАССОВЫЙ ЗАПУСК / ЗВУКИ / ПРОКРУТКА ПРОЕКТОВ
========================================================= */
.projects-panel {
    min-height: 0;
}

.history-list {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.history-item {
    flex: 0 0 auto;
}

.btn-icon {
    background: var(--bg-surface);
    border: none;
    color: var(--text-primary);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

.btn-icon:hover:not(:disabled) {
    background: var(--bg-surface-hover);
}

.btn-sound-toggle.is-on {
    color: var(--success-soft);
    box-shadow: inset 0 0 0 1px rgba(143, 214, 148, 0.26);
}

.btn-sound-toggle.is-off {
    color: var(--text-secondary);
    opacity: 0.72;
}

.btn-bulk-robots {
    min-width: 188px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border-radius: 22px;
    padding: 10px 18px;
}

.btn-bulk-start,
.btn-bulk-start:hover:not(:disabled) {
    background: var(--success-soft);
    color: #102214;
}

.btn-bulk-stop,
.btn-bulk-stop:hover:not(:disabled) {
    background: #d32f2f;
    color: #ffffff;
}

.btn-bulk-robots:disabled {
    background: var(--bg-surface);
    color: var(--text-secondary);
    opacity: 0.45;
}

.bulk-icon {
    font-size: 0.92rem;
    line-height: 1;
}

.btn-robot-action {
    width: 46px;
    height: 42px;
    min-width: 46px;
    border-radius: 50%;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.92rem;
    line-height: 1;
    border: none;
    transition: 0.2s;
}

.btn-robot-action.is-start-ready,
.btn-robot-action.is-start-ready:hover:not(:disabled) {
    background: var(--success-soft);
    color: #102214;
}

.btn-robot-action.is-start-disabled,
.btn-robot-action.is-start-disabled:hover:not(:disabled) {
    background: var(--bg-surface);
    color: var(--text-secondary);
    opacity: 0.58;
}

.btn-robot-action.is-stop,
.btn-robot-action.is-stop:hover:not(:disabled) {
    background: #d32f2f;
    color: #ffffff;
}

.robot-card {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.robot-card-body {
    flex: 1;
    min-width: 0;
}

.robot-select-wrap {
    flex: 0 0 auto;
    width: 34px;
    min-height: 42px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 1px;
    cursor: pointer;
    user-select: none;
}

.robot-select-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.robot-select-box {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: rgba(143, 214, 148, 0.14);
    border: 2px solid var(--success-soft);
    box-shadow: 0 0 0 1px rgba(143, 214, 148, 0.14), 0 0 18px rgba(143, 214, 148, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.18s;
}

.robot-select-box::after {
    content: '✓';
    color: #ffffff;
    font-size: 1.12rem;
    font-weight: 800;
    line-height: 1;
    transform: scale(0.35);
    opacity: 0;
    transition: 0.18s;
}

.robot-select-wrap:hover .robot-select-box {
    background: rgba(143, 214, 148, 0.22);
    transform: translateY(-1px);
}

.robot-select-input:checked + .robot-select-box {
    background: var(--success-soft);
    border-color: var(--success-soft);
}

.robot-select-input:checked + .robot-select-box::after {
    opacity: 1;
    transform: scale(1);
}

@media (max-width: 980px) {
    .btn-bulk-robots {
        min-width: 52px;
        width: 52px;
        padding-left: 0;
        padding-right: 0;
        border-radius: 50%;
    }

    .btn-bulk-robots .bulk-text {
        display: none;
    }
}

@media (max-width: 720px) {
    .top-actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .robot-card {
        gap: 12px;
    }

    .robot-select-wrap {
        width: 30px;
    }

    .robot-select-box {
        width: 28px;
        height: 28px;
    }
}

/* =========================================================
   КАСТОМНОЕ ИНФОРМАЦИОННОЕ ОКНО
========================================================= */
.info-modal {
    border-color: rgba(143, 214, 148, 0.32);
}

.info-modal-text {
    font-size: 0.92rem;
    line-height: 1.5;
}

.info-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 260px;
    overflow-y: auto;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    background: rgba(0, 0, 0, 0.14);
    border: 1px solid var(--border-subtle);
}

.info-list-item {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    color: var(--text-primary);
    font-size: 0.88rem;
}

.info-list-bullet {
    color: var(--success-soft);
    line-height: 1.5;
}

.info-list-muted {
    color: var(--text-secondary);
}

/* =========================================================
   ФИКСЫ: СЕССИЯ/ЧЕКБОКСЫ БЕЗ СКАЧКА ПРОКРУТКИ
========================================================= */
.robot-select-wrap {
    position: relative;
}

.robot-select-input {
    position: absolute;
    inset: 0 auto auto 2px;
    width: 30px;
    height: 30px;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    pointer-events: auto;
    z-index: 2;
}

.robot-select-input:focus + .robot-select-box {
    box-shadow: 0 0 0 3px rgba(143, 214, 148, 0.18), 0 0 0 1px rgba(143, 214, 148, 0.14), 0 0 18px rgba(143, 214, 148, 0.08);
}

/* Если сессия уже есть, не показываем auth-overlay и не размываем интерфейс даже на мгновение после F5. */
html.auth-session-restored body.auth-active .app-shell {
    filter: none !important;
    pointer-events: auto !important;
    user-select: auto !important;
}

html.auth-session-restored .auth-zone {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* =========================================================
   DRAG-AND-DROP СОРТИРОВКА ПРОЕКТОВ И РОБОТОВ
========================================================= */
.history-item[data-drag-type],
.robot-card[data-drag-type] {
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.history-item[data-drag-type]:active,
.robot-card[data-drag-type]:active {
    cursor: grabbing;
}

.history-item.real-dragging,
.robot-card.real-dragging {
    opacity: 1 !important;
    filter: none !important;
    cursor: grabbing;
    box-shadow: 0 26px 70px rgba(0, 0, 0, 0.52), 0 0 0 1px rgba(143, 214, 148, 0.28);
    outline: 1px solid rgba(143, 214, 148, 0.44);
    outline-offset: 2px;
    will-change: left, top, transform;
}

.history-item.drag-placeholder,
.robot-card.drag-placeholder {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    box-shadow: none !important;
    outline: none !important;
}

body.is-dragging-cards,
body.is-dragging-cards * {
    cursor: grabbing !important;
}

body.is-dragging-cards .history-list,
body.is-dragging-cards .dashboard-zone {
    scroll-behavior: auto !important;
}

body.is-dragging-cards .history-item:not(.real-dragging):not(.drag-placeholder),
body.is-dragging-cards .robot-card:not(.real-dragging):not(.drag-placeholder) {
    transition: transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.2s, border-color 0.2s;
}

.robot-card button,
.robot-card input,
.robot-card select,
.robot-card label,
.history-item button {
    cursor: pointer;
}

/* =========================================================
   СЧЁТЧИК ЖДУТ ЗВОНКА И КОМПАКТНАЯ КНОПКА РОБОТА
========================================================= */
@media (max-width: 980px) {
    .robot-controls {
        grid-template-columns: 1fr 1fr;
    }

    .btn-robot-action {
        width: 46px;
        justify-self: start;
    }
}

@media (max-width: 720px) {
    .robot-controls {
        grid-template-columns: 1fr;
    }
}

/* =========================================================
   МАССОВЫЙ ЗАПУСК / ОСТАНОВКА РОБОТОВ — ПРОГРЕСС
========================================================= */
.bulk-progress-modal {
    border-color: rgba(143, 214, 148, 0.22);
}

.bulk-progress-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 420px;
    overflow-y: auto;
    padding-right: 4px;
}

.bulk-progress-item {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    grid-template-areas:
        "state name"
        "state project";
    align-items: center;
    column-gap: 12px;
    min-height: 54px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
}

.bulk-progress-state {
    grid-area: state;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 1rem;
    font-weight: 800;
    line-height: 1;
}

.bulk-progress-state.is-success {
    color: var(--success-soft);
    background: rgba(143, 214, 148, 0.12);
}

.bulk-progress-state.is-error {
    color: var(--danger-soft);
    background: rgba(255, 138, 128, 0.12);
}

.bulk-progress-name {
    grid-area: name;
    color: var(--text-primary);
    font-size: 0.92rem;
    font-weight: 550;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.bulk-progress-project {
    grid-area: project;
    color: var(--text-secondary);
    font-size: 0.76rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.bulk-progress-spinner {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.16);
    border-top-color: var(--success-soft);
    animation: bulk-progress-spin 0.75s linear infinite;
}

@keyframes bulk-progress-spin {
    to { transform: rotate(360deg); }
}

/* =========================================================
   ОДИНОЧНЫЙ ЗАПУСК / ОСТАНОВКА РОБОТА: BUSY-СОСТОЯНИЕ
========================================================= */
.robot-card {
    position: relative;
}

.robot-card.is-busy {
    pointer-events: none;
}

.robot-card.is-busy .robot-card-body,
.robot-card.is-busy .robot-select-wrap {
    opacity: 0.34;
    filter: blur(1px);
}

.robot-busy-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 10px;
    border-radius: var(--radius-lg);
    background: rgba(18, 18, 18, 0.46);
    z-index: 5;
}

.robot-card.is-busy .robot-busy-overlay {
    display: flex;
}

.robot-busy-spinner {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.18);
    border-top-color: var(--success-soft);
    animation: robot-busy-spin 0.75s linear infinite;
}

.robot-busy-text {
    color: var(--text-primary);
    font-size: 0.88rem;
    font-weight: 600;
}

@keyframes robot-busy-spin {
    to { transform: rotate(360deg); }
}


/* =========================================================
   BITRIX24 / ПЕРЕДАЧА ЛИДОВ
========================================================= */
.top-nav-menu {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-left: 56px;
    margin-right: auto;
    height: 100%;
}

.top-nav-link {
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    min-height: 42px;
    padding: 0 20px;
    border-radius: 999px;
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.1px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: color 0.18s ease, background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.top-nav-link:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
}

.top-nav-link.active {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.035);
    border-color: rgba(255, 255, 255, 0.65);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.history-item { padding-right: 78px; }
.history-item-actions {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-project-settings,
.btn-delete-project {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: 0.2s;
}

.history-item:hover .btn-project-settings,
.history-item:hover .btn-delete-project {
    display: flex;
}

.btn-project-settings:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.history-item-bitrix {
    color: #f0c674;
    font-size: 0.72rem;
}

.history-item-bitrix.ready {
    color: var(--success-soft);
}

.bitrix-settings-dialog {
    max-width: 680px;
}

.bitrix-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.bitrix-enable-toggle {
    margin: 0;
}

.transfer-heading {
    align-items: flex-end;
}

.transfer-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.bitrix-notice {
    margin-bottom: 18px;
}

.bitrix-notice-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.bitrix-notice-card.ready {
    color: var(--success-soft);
    border-color: rgba(143, 214, 148, 0.22);
}

.transfer-leads-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.transfer-empty-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 28px;
    color: var(--text-secondary);
}

.transfer-empty-card h3 {
    color: var(--text-primary);
    margin: 0 0 8px;
    font-size: 1.05rem;
}

.transfer-empty-card p {
    margin: 0;
    line-height: 1.5;
}

.transfer-table-head,
.transfer-lead-row {
    display: grid;
    grid-template-columns: minmax(260px, 1.5fr) 160px minmax(180px, 1fr) 170px;
    gap: 12px;
    align-items: center;
}

.transfer-table-head {
    padding: 0 14px 6px;
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.45px;
}

.transfer-lead-row {
    min-height: 66px;
    padding: 12px 14px;
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
}

.transfer-lead-main,
.transfer-check-all {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    margin: 0;
}

.transfer-lead-main strong {
    display: block;
    color: var(--text-primary);
    font-size: 0.92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.transfer-lead-main small {
    display: block;
    color: var(--text-secondary);
    font-size: 0.78rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.transfer-lead-phone,
.transfer-lead-robot {
    color: var(--text-secondary);
    font-size: 0.86rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.transfer-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 0.84rem;
    font-weight: 650;
}

.transfer-status.new { color: var(--text-secondary); }
.transfer-status.sending { color: #a8c7fa; }
.transfer-status.success { color: var(--success-soft); }
.transfer-status.error { color: var(--danger-soft); }

.mini-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.16);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@media (max-width: 1180px) {
    .transfer-table-head,
    .transfer-lead-row {
        grid-template-columns: minmax(220px, 1.5fr) 150px 140px;
    }
    .transfer-table-head span:nth-child(3),
    .transfer-lead-robot { display: none; }
}

@media (max-width: 720px) {
    .top-nav-menu { width: 100%; order: 3; margin-left: 0; gap: 12px; height: auto; }
    .top-nav-link { flex: 0 0 auto; min-height: 38px; padding: 0 16px; }
    .bitrix-form-grid { grid-template-columns: 1fr; }
    .transfer-heading { align-items: stretch; }
    .transfer-actions { width: 100%; }
    .transfer-actions .btn { flex: 1; }
    .transfer-table-head { display: none; }
    .transfer-lead-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }
}

.history-item-actions .btn-delete-project,
.history-item-actions .btn-project-settings {
    position: static;
    transform: none;
}
