:root {
    --accent: #2f6bff;
    --accent-dark: #1f4fd6;
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1c1f26;
    --muted: #6b7280;
    --border: #e3e7ef;
    --danger: #d64545;
    --success: #1f9d55;
    --radius: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 14px 28px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 20px;
    font-weight: 700;
    text-decoration: none;
    color: var(--text);
}

.logo span { color: var(--accent); }

.topbar nav a {
    color: var(--muted);
    text-decoration: none;
    margin-right: 16px;
    font-weight: 500;
}

.topbar nav a:hover { color: var(--accent); }

.container {
    max-width: 1080px;
    margin: 28px auto;
    padding: 0 20px;
}

h1 { font-size: 24px; margin: 0 0 20px; }
h2 { font-size: 18px; margin: 24px 0 12px; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 12px;
    flex-wrap: wrap;
}

.page-head h1 { margin: 0; }

.flash {
    background: #e8f6ee;
    border: 1px solid #bfe5cf;
    color: #14532d;
    border-radius: var(--radius);
    padding: 10px 16px;
    margin-bottom: 18px;
}

.flash-error {
    background: #fdecec;
    border-color: #f5c2c2;
    color: #7f1d1d;
}

.login-box {
    max-width: 380px;
    margin: 48px auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
}

.login-box h1 {
    font-size: 22px;
    margin: 0 0 18px;
}

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

/* Таблицы */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.table th, .table td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table th {
    background: #fafbfe;
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.table tr:last-child td { border-bottom: none; }

/* Бейджи статусов */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 600;
}

.badge-active   { background: #e8f6ee; color: var(--success); }
.badge-disabled { background: #f3f4f6; color: var(--muted); }
.badge-draft    { background: #fef4e2; color: #b45309; }
.badge-stopped  { background: #fdecec; color: var(--danger); }

/* Кнопки */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.btn:hover { background: var(--accent-dark); }

.btn-outline {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
}

.btn-outline:hover { background: #eef3ff; }

.btn-sm { padding: 4px 10px; font-size: 13px; }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b93a3a; }

/* Формы */
.form-grid { display: grid; gap: 16px; }

label.field { display: block; }

label.field .label,
fieldset .label {
    display: block;
    font-weight: 600;
    font-size: 13.5px;
    margin-bottom: 5px;
}

input[type="text"], input[type="url"], input[type="number"], input[type="password"], textarea, select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14.5px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(47, 107, 255, 0.12);
}

textarea { min-height: 110px; resize: vertical; }

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

.inline { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* Блок установочного кода */
.install-code {
    background: #0f172a;
    color: #d7e3ff;
    font-family: Consolas, Menlo, monospace;
    font-size: 12.5px;
    padding: 14px;
    border-radius: 8px;
    overflow-x: auto;
    white-space: pre;
}

.muted { color: var(--muted); }

/* Карточки статистики */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 8px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.stat-value { font-size: 28px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

.period-filter {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding: 14px 20px;
}

.period-filter input[type="date"] { width: auto; padding: 6px 10px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Карточки выбора типа попапа */
.type-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    max-width: 900px;
}

.type-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    text-decoration: none;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}

.type-card:hover {
    border-color: var(--accent);
    box-shadow: 0 8px 24px rgba(47, 107, 255, .12);
}

.type-ico {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: #eef3ff;
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}

.type-ico svg { width: 24px; height: 24px; }
.type-name { font-size: 16.5px; font-weight: 700; }
.type-desc { font-size: 13.5px; color: var(--muted); }

/* Форма попапа с предпросмотром */
.form-columns {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    gap: 20px;
    align-items: start;
}

.form-preview { position: sticky; top: 20px; }

.preview-toggle { display: flex; gap: 8px; margin-bottom: 12px; }

.preview-toggle button {
    flex: 1;
    padding: 7px 10px;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13.5px;
    color: var(--muted);
}

.preview-toggle button.active {
    border-color: var(--accent);
    color: var(--accent);
    background: #eef3ff;
}

.preview-stage {
    background: repeating-conic-gradient(#eceff5 0% 25%, #f7f8fc 0% 50%) 0 0/24px 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    display: flex;
    justify-content: center;
}

.preview-frame { width: 100%; transition: width .2s; }
.preview-frame.mobile { width: 300px; }

.pv-popup {
    position: relative;
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(15, 23, 42, .25);
    padding: 24px 20px 20px;
    line-height: 1.5;
    font-size: 14px;
}

.pv-close {
    position: absolute;
    top: 8px; right: 8px;
    width: 28px; height: 28px;
    border-radius: 50%;
    background: rgba(128,128,128,.14);
    text-align: center;
    line-height: 28px;
    font-size: 13px;
}

.pv-title { font-size: 17px; font-weight: 700; margin: 0 22px 8px 0; }
.pv-body p { margin: 0 0 8px; }
.pv-image { width: 100%; border-radius: 8px; margin-bottom: 10px; display: block; }

.pv-video {
    position: relative; width: 100%; padding-top: 56.25%;
    border-radius: 8px; overflow: hidden; background: #000; margin-bottom: 10px;
}
.pv-video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.pv-buttons { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.pv-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 12px; border-radius: 8px; font-weight: 600;
    border: 1px solid rgba(128,128,128,.25);
}

.pv-btn .pv-ico { width: 19px; height: 19px; display: inline-flex; }
.pv-btn .pv-ico svg { width: 100%; height: 100%; }

.pv-mini {
    display: inline-flex; align-items: center; gap: 7px;
    margin-top: 14px; padding: 9px 14px; border-radius: 999px;
    color: #fff; font-weight: 600; font-size: 13px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .25);
}

@media (max-width: 1000px) {
    .form-columns { grid-template-columns: 1fr; }
    .form-preview { position: static; }
}

@media (max-width: 720px) {
    .table { display: block; overflow-x: auto; }
    .container { margin-top: 16px; }
}
