* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #0f172a;
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(168, 85, 247, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(59, 130, 246, 0.15) 0px, transparent 50%);
    min-height: 100vh;
    padding: 30px;
    color: #e2e8f0;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 20px 30px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    margin-bottom: 30px;
}

header h1 {
    color: #667eea;
    font-size: 28px;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #e0e7ff;
    color: #667eea;
}

.btn-secondary:hover {
    background: #c7d2fe;
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

/* Сетка кабинетов */
.cabinets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.cabinet-card {
    background: white;
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.3s;
}

.cabinet-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}

.cabinet-card h3 {
    color: #1f2937;
    margin-bottom: 10px;
    font-size: 18px;
}

.cabinet-card .meta {
    color: #6b7280;
    font-size: 13px;
    margin-bottom: 15px;
}

.cabinet-card .actions {
    display: flex;
    gap: 10px;
}

.cabinet-card .btn {
    flex: 1;
    padding: 8px 16px;
    font-size: 13px;
}

/* Дашборд */
.dashboard {
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    padding: 20px 30px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    margin-bottom: 30px;
}

.dashboard-header h2 {
    color: #1f2937;
    font-size: 24px;
}

.dashboard-actions {
    display: flex;
    gap: 10px;
}

/* Метрики */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.metric-card {
    background: white;
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    text-align: center;
}

.metric-label {
    color: #6b7280;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 10px;
}

.metric-value {
    color: #1f2937;
    font-size: 32px;
    font-weight: 700;
}

/* Графики */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.chart-container {
    background: white;
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
}

.chart-container canvas {
    max-height: 300px;
}

/* Таблица */
.table-container {
    background: white;
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    overflow-x: auto;
}

.table-container h3 {
    color: #1f2937;
    margin-bottom: 20px;
    font-size: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    background: #f9fafb;
    color: #6b7280;
    font-weight: 600;
    text-align: left;
    padding: 12px;
    border-bottom: 2px solid #e5e7eb;
}

tbody td {
    padding: 12px;
    border-bottom: 1px solid #e5e7eb;
    color: #1f2937;
}

tbody tr:hover {
    background: #f9fafb;
}

/* Счётчик в заголовке таблицы и кнопка «показать все» */
.table-count {
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    margin-left: 8px;
}

.table-toggle {
    text-align: center;
    margin-top: 15px;
}

.table-note td {
    text-align: center;
    color: #94a3b8;
}

/* Модальное окно */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}

.modal-content h2 {
    color: #1f2937;
    margin-bottom: 15px;
}

.help-text {
    color: #6b7280;
    font-size: 14px;
    margin-bottom: 20px;
    line-height: 1.6;
}

.help-text a {
    color: #667eea;
    text-decoration: none;
}

.help-text code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
}

textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    margin-bottom: 20px;
    resize: vertical;
}

textarea:focus {
    outline: none;
    border-color: #667eea;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions .btn {
    flex: 1;
}

.error-message {
    background: #fee2e2;
    color: #dc2626;
    padding: 12px;
    border-radius: 8px;
    margin-top: 15px;
    font-size: 14px;
}

/* Адаптив */
@media (max-width: 768px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    header {
        flex-direction: column;
        gap: 15px;
    }
    
    .dashboard-header {
        flex-direction: column;
        gap: 15px;
    }
}


/* ===== Выбор периода ===== */
.period-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 15px 25px;
    background: white;
    padding: 18px 30px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    margin-bottom: 30px;
}

.period-presets {
    display: flex;
    gap: 8px;
}

.period-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    background: #e0e7ff;
    color: #667eea;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.period-btn:hover {
    background: #c7d2fe;
}

.period-btn.active {
    background: #667eea;
    color: white;
}

.period-dates {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #6b7280;
    font-size: 14px;
}

.period-dates input[type="date"] {
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    color: #1f2937;
    font-family: inherit;
}

.period-dates .btn {
    padding: 8px 18px;
}

.period-label {
    margin-left: auto;
    color: #6b7280;
    font-size: 14px;
}

.period-bar .error-message {
    flex-basis: 100%;
    margin-top: 0;
}

/* ===== Баланс ===== */
.metric-sub {
    color: #9ca3af;
    font-size: 12px;
    margin-top: 6px;
}

.cabinet-balance {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 12px;
    padding: 10px 12px;
    background: #f3f4f6;
    border-radius: 10px;
}

.cabinet-balance .label {
    color: #6b7280;
    font-size: 13px;
}

.cabinet-balance .value {
    color: #1f2937;
    font-size: 18px;
    font-weight: 700;
}

@media (max-width: 768px) {
    .period-label {
        margin-left: 0;
    }
}

/* ===== Переименование кабинета ===== */
.dashboard-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.icon-btn {
    background: #f3f4f6;
    border: none;
    border-radius: 8px;
    padding: 6px 9px;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: #e0e7ff;
}

.cabinet-card h3 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.cabinet-card h3 .name {
    overflow-wrap: anywhere;
}

.text-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 15px;
    margin-bottom: 20px;
}

.text-input:focus {
    outline: none;
    border-color: #667eea;
}

/* ===== Красные флаги ===== */
.cabinet-balance.low {
    background: #fee2e2;
}

.cabinet-balance.low .value,
.metric-value.low {
    color: #dc2626;
}

.metric-card.low {
    background: #fef2f2;
    box-shadow: 0 0 0 2px #fca5a5, 0 5px 20px rgba(0,0,0,0.1);
}

.low-note {
    color: #dc2626;
    font-size: 12px;
    font-weight: 600;
    margin-top: 4px;
}

td.ctr-low {
    color: #dc2626;
    font-weight: 700;
    background: #fef2f2;
}

/* ===== Раскрытие кампании ===== */
.table-hint {
    color: #9ca3af;
    font-size: 13px;
    margin: -8px 0 12px;
}

tr.clickable {
    cursor: pointer;
}

tr.clickable.open td {
    background: #eef2ff;
}

.chevron {
    display: inline-block;
    width: 16px;
    color: #667eea;
    font-size: 12px;
}

tr.detail-row td {
    padding: 0;
    background: #f8fafc;
    border-bottom: 2px solid #c7d2fe;
}

.detail-panel {
    padding: 18px 20px;
}

.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 24px;
}

.detail-title {
    color: #374151;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

.detail-canvas {
    position: relative;
    height: 240px;
}

.detail-note,
.detail-error {
    color: #9ca3af;
    font-size: 14px;
    padding: 20px 0;
    text-align: center;
}

.detail-error {
    color: #dc2626;
}

.mini-table {
    width: 100%;
    font-size: 13px;
}

.mini-table th {
    background: transparent;
    padding: 8px 10px;
    font-size: 12px;
}

.mini-table td {
    padding: 8px 10px;
}

.detail-toggle {
    margin-top: 10px;
    padding: 6px 14px;
    font-size: 13px;
}

@media (max-width: 900px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }
}


/* Статус показа: «идёт показ» — спокойный зелёный, причина остановки — красный */
.state-on {
    color: #059669;
    white-space: nowrap;
}

.state-off {
    color: #dc2626;
    font-weight: 600;
    white-space: nowrap;
}


/* ========== Алерты ========== */
.header-actions { display: flex; gap: 10px; }

.alerts-panel {
    background: white;
    border-radius: 15px;
    padding: 18px 22px;
    margin-bottom: 25px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    border-left: 6px solid #ef4444;
}
.alerts-panel.ok { border-left-color: #10b981; }
.alerts-panel h3 { margin: 0 0 10px 0; font-size: 1.05rem; color: #111827; }
.alerts-panel .alerts-ok { color: #047857; font-weight: 600; }
.alert-item {
    display: flex;
    gap: 10px;
    padding: 9px 0;
    border-top: 1px solid #f3f4f6;
}
.alert-item:first-of-type { border-top: none; }
.alert-dot {
    flex: 0 0 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 6px;
    background: #f59e0b;
}
.alert-item.critical .alert-dot { background: #ef4444; }
.alert-title { font-weight: 600; color: #111827; }
.alert-cabinet { font-size: 0.8rem; color: #6b7280; font-weight: 500; margin-left: 6px; }
.alert-detail { font-size: 0.88rem; color: #4b5563; margin-top: 2px; }
.alert-item.clickable { cursor: pointer; }
.alert-item.clickable:hover .alert-title { text-decoration: underline; }

.card-badges { margin: 8px 0 4px 0; display: flex; gap: 6px; flex-wrap: wrap; min-height: 22px; }
.badge { font-size: 0.78rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.badge.critical { background: #fee2e2; color: #b91c1c; }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.ok { background: #d1fae5; color: #047857; }

.forecast-note { font-size: 0.8rem; color: #4b5563; margin-top: 4px; }
.forecast-note.bad { color: #b91c1c; font-weight: 600; }

.settings-content { max-width: 520px; }
.settings-form { display: grid; gap: 10px; margin: 12px 0 16px 0; }
.settings-row { display: grid; grid-template-columns: 1fr 120px; gap: 12px; align-items: center; }
.settings-row label { font-size: 0.92rem; color: #374151; }
.settings-row input { padding: 7px 10px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 0.95rem; }
.settings-row input.invalid { border-color: #ef4444; background: #fef2f2; }


/* ========== PDF-отчёт ========== */
.report-balance { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: #4b5563; margin-right: 6px; cursor: pointer; }
#reportBtn[disabled] { opacity: 0.7; cursor: wait; }


/* ========== Уведомления ========== */
.notify-check { display: flex; align-items: center; gap: 8px; font-size: 0.95rem;
    color: #111827; margin: 14px 0 6px 0; cursor: pointer; }
.settings-row select { padding: 7px 10px; border: 1px solid #d1d5db; border-radius: 8px;
    font-size: 0.95rem; background: white; }
.notify-bot-info { font-size: 0.85rem; color: #4b5563; margin: 4px 0 0 0; }
.notify-bot-info a { color: #4f46e5; }
.notify-status { font-size: 0.88rem; margin-top: 8px; white-space: pre-wrap; }
.notify-status.ok { color: #047857; }
.notify-status.bad { color: #b91c1c; }
.notify-status.wait { color: #92400e; }
.notify-actions { flex-wrap: wrap; }
#testNotifyBtn[disabled], #findTargetBtn[disabled] { opacity: 0.7; cursor: wait; }

/* ===== Уведомления: список получателей ===== */
.notify-recipients { margin: 16px 0; }
.notify-recipients h3 { font-size: 1rem; margin: 0 0 6px; }
.notify-recipients-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.recipient-row { display: flex; align-items: center; justify-content: space-between;
    padding: 7px 0; border-bottom: 1px solid #f1f3f5; gap: 10px; }
.recipient-row:last-child { border-bottom: none; }
.recipient-name { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.94rem; }
.recipient-name input { width: 16px; height: 16px; cursor: pointer; }
.recipient-id { color: #98a1ab; font-size: 0.82rem; }
.btn-small { padding: 4px 10px; font-size: 0.84rem; }
.pending-row { background: #fffaf0; }
.pending-actions { display: flex; align-items: center; gap: 6px; }
.notify-check { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 0.94rem; cursor: pointer; }
.notify-check input { width: 16px; height: 16px; cursor: pointer; }

/* ===== Вход в дашборд ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 20px; background: #f5f7fa; }
.login-card { background: #fff; border-radius: 14px; padding: 32px 28px; width: 100%;
    max-width: 400px; box-shadow: 0 10px 30px rgba(0,0,0,0.08); }
.login-card h1 { font-size: 1.25rem; margin: 0 0 6px; }
.login-hint { color: #6b7280; font-size: 0.92rem; margin: 0 0 18px; }
.login-card input[type="password"] { width: 100%; box-sizing: border-box; padding: 11px 12px;
    border: 1px solid #d7dbe0; border-radius: 8px; font-size: 1rem; margin-bottom: 12px; }
.login-card input[type="password"]:focus { outline: none; border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.login-remember { display: flex; align-items: center; gap: 8px; font-size: 0.88rem;
    color: #4b5563; margin-bottom: 16px; cursor: pointer; }
.login-btn { width: 100%; }
.login-foot { color: #9ca3af; font-size: 0.8rem; margin: 18px 0 0; line-height: 1.45; }
.login-foot code { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; }

/* Поле пароля с кнопкой «показать» */
.password-field { position: relative; }
.password-field input { padding-right: 44px; }
.reveal-btn { position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer; font-size: 1.05rem; opacity: .65;
    padding: 4px 6px; line-height: 1; }
.reveal-btn:hover { opacity: 1; }
