:root {
    --ink: #1f1714;
    --muted: #6b5e57;
    --paper: #f6f1ea;
    --card: #fffdf9;
    --line: #e6d9cc;
    --accent: #c2410c;
    --accent-dark: #9a3412;
    --ok: #166534;
    --bad: #9f1239;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--paper);
    color: var(--ink);
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    padding: 18px 32px;
    background: #7f1d1d;
    color: #fff7ed;
    flex-wrap: wrap;
}

.session {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.session span {
    font-size: 13px;
    opacity: 0.9;
}

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

.brand-mark {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 8px;
    background: #ea580c;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.brand small {
    display: block;
    opacity: 0.8;
    font-size: 12px;
}

nav {
    display: flex;
    gap: 8px;
}

.nav-btn, .btn, .icon-btn {
    border: 0;
    cursor: pointer;
    font: inherit;
}

.nav-btn {
    background: transparent;
    color: #fed7aa;
    padding: 10px 14px;
    border-radius: 999px;
}

.nav-btn.active, .nav-btn:hover {
    background: #ea580c;
    color: white;
}

main {
    max-width: 1080px;
    margin: 0 auto;
    padding: 28px 20px 60px;
}

.view { display: none; }
.view.active { display: block; }

.panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 28px;
    box-shadow: 0 10px 30px rgba(87, 46, 24, 0.06);
}

.panel-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: start;
}

.panel-head .btn + .btn {
    margin-left: 8px;
}

.panel-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin-top: 8px;
    padding: 16px 0 4px;
    background: linear-gradient(to top, var(--card) 70%, rgba(255, 253, 249, 0.85));
}

h1 {
    margin: 0 0 8px;
    font-size: 28px;
}

.lede {
    margin: 0 0 24px;
    color: var(--muted);
}

.field-hint {
    margin: 0 0 8px;
    color: var(--muted);
    font-weight: 400;
    font-size: 13px;
}

form, label {
    display: grid;
    gap: 8px;
}

label {
    margin-bottom: 16px;
    font-weight: 600;
    font-size: 14px;
}

input[type="text"], input[type="url"], input[type="email"], input[type="file"], input[type="password"], input[type="datetime-local"], select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    font: inherit;
    background: white;
}

input[readonly] {
    background: #f6f1ea;
}

.test-email-field {
    max-width: 420px;
}

.type-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0 16px;
}

.filter-btn {
    cursor: pointer;
    font: inherit;
    background: #fff7ed;
    color: var(--accent-dark);
    border: 1px solid #fdba74;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 700;
}

.filter-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.type-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.type-badge.pretplata {
    background: #fff7ed;
    color: #9a3412;
}

.type-badge.obuka {
    background: #eff6ff;
    color: #1d4ed8;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.editor-wrap {
    margin: 8px 0 20px;
}

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

.editor-label {
    display: block;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 0;
}

.editor-tabs {
    display: flex;
    gap: 6px;
}

.editor-tab {
    background: #fff7ed;
    color: var(--accent-dark);
    border: 1px solid #fdba74;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 700;
}

.editor-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.html-source {
    display: none;
    width: 100%;
    min-height: 320px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    background: #1f1714;
    color: #f8f1e9;
}

.editor-wrap.html-mode .html-source {
    display: block;
}

.editor-wrap.html-mode #visual-editor {
    display: none;
}

.ql-toolbar.ql-snow, .ql-container.ql-snow {
    border-color: var(--line);
}

.ql-toolbar.ql-snow {
    border-radius: 10px 10px 0 0;
    background: #fffaf5;
}

.ql-container.ql-snow {
    border-radius: 0 0 10px 10px;
    min-height: 220px;
    font-size: 16px;
    background: white;
}

.btn {
    padding: 11px 16px;
    border-radius: 10px;
    font-weight: 700;
}

.btn.primary {
    background: var(--accent);
    color: white;
}

.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost {
    background: #fff7ed;
    color: var(--accent-dark);
    border: 1px solid #fdba74;
}

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

.btn.danger:hover {
    background: #ffe4e6;
}

.status {
    margin-top: 16px;
    padding: 12px 14px;
    border-radius: 10px;
}

.status.ok { background: #dcfce7; color: var(--ok); }
.status.bad { background: #ffe4e6; color: var(--bad); }

.table-wrap { overflow-x: auto; }

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

th, td {
    text-align: left;
    padding: 12px 8px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

th { color: var(--muted); font-size: 13px; }

td a { color: var(--accent-dark); }

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.schedule-box {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    margin-top: 10px;
}

.schedule-box input[type="datetime-local"] {
    width: auto;
    min-width: 210px;
    padding: 8px 10px;
}

.schedule-note {
    width: 100%;
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-dark);
    text-align: right;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
    margin: 8px 0 20px;
}

.stat-card {
    background: #fff7ed;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px 16px;
}

.stat-card.ok {
    background: #f0fdf4;
}

.stat-card.bad {
    background: #fff1f2;
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.stat-card strong {
    display: block;
    margin-top: 6px;
    font-size: 26px;
    line-height: 1.1;
}

.panel-title {
    margin: 0 0 16px;
    font-size: 20px;
}

.stack {
    display: grid;
    gap: 20px;
}

.optional {
    font-weight: 400;
    color: var(--muted);
}

.user-form {
    margin-bottom: 20px;
}

.user-form-fields {
    display: grid;
    grid-template-columns: 1fr 1.4fr 1fr 1fr;
    gap: 16px;
}

.user-form-actions {
    justify-content: flex-start;
    position: static;
    padding: 0;
    background: none;
}

.import-box {
    display: flex;
    gap: 12px;
    align-items: end;
}

.import-type-field {
    min-width: 180px;
    margin-bottom: 0;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-top: 18px;
}

.result-card {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-radius: 12px;
    padding: 16px;
}

.result-card b {
    display: block;
    font-size: 28px;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(28, 16, 12, 0.55);
    display: none;
    place-items: center;
    padding: 20px;
}

.modal.is-open {
    display: grid;
}

.modal-card {
    width: min(920px, 100%);
    height: min(860px, 92vh);
    background: white;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 51;
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    position: relative;
    z-index: 2;
    flex: 0 0 auto;
    background: white;
}

.icon-btn {
    background: #fff7ed;
    padding: 8px 12px;
    border-radius: 8px;
    position: relative;
    z-index: 3;
}

.modal-card iframe {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    border: 0;
    background: #f3f3f3;
    position: relative;
    z-index: 0;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(440px, 100%);
}

.login-brand {
    color: var(--ink);
    margin-bottom: 18px;
}

.login-brand small {
    color: var(--muted);
}

.remember-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.remember-row input {
    width: auto;
}

@media (max-width: 800px) {
    .topbar, .grid-2, .user-form-fields, .import-box, .result-grid, .panel-head, .stats-grid {
        display: grid;
        grid-template-columns: 1fr;
    }

    nav { flex-wrap: wrap; }
}
