*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f7f6f3;
    color: #1a1a2e;
    font-size: 15px;
}

a { color: #3b7dd8; text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
    max-width: 860px;
    margin: 0 auto;
    padding: 32px 20px 60px;
}

.container--edit {
    max-width: 1400px;
}

/* Edit page: two-column layout */
.edit-layout {
    display: flex;
    gap: 28px;
    align-items: flex-start;
}

.edit-form-col {
    width: 820px;
    flex-shrink: 0;
}

.edit-preview-col {
    flex: 1;
    min-width: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
    padding: 20px 0;
    box-sizing: border-box;
}

.preview-pane {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.preview-pane__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    flex-shrink: 0;
}

.preview-pane__label {
    font-size: 13px;
    font-weight: 600;
    color: #6b7280;
    letter-spacing: .01em;
}

.preview-pane iframe {
    /* Растягиваем по высоте (главная ось колонки), но НЕ по ширине. */
    flex: 1 1 auto;
    /* align-self отменяет stretch родителя (align-items:stretch по умолчанию),
       иначе iframe растянулся бы на всю ширину колонки (~510px) и width не держал бы. */
    align-self: center;
    /* Жёстко фиксируем «телефонную» ширину 390px: внутренний viewport визитки
       = 390px, поэтому vw/clamp в public.css считаются как у реального телефона. */
    width: 390px;
    min-width: 390px;
    max-width: 390px;
    flex-shrink: 0;            /* flex не сжимает по ширине на узких окнах */
    min-height: 0;
    border: 1px solid #e5e7eb;
    border-radius: 16px;       /* «экран телефона» */
    background: #fff;
    display: block;
}

h1 { font-size: 22px; margin: 0 0 24px; }
h2 { font-size: 18px; margin: 32px 0 12px; }
h3 { font-size: 15px; margin: 0 0 10px; }

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 9px 18px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s;
    text-decoration: none;
}
.btn:hover { opacity: .85; text-decoration: none; }
.btn-primary { background: #3b7dd8; color: #fff; }
.btn-success { background: #22c55e; color: #fff; }
.btn-outline { background: transparent; color: #3b7dd8; border: 1.5px solid #3b7dd8; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-copy { background: #6b7280; color: #fff; }
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 8px;
    border: 0.5px solid #e5e7eb;
    background: transparent;
    cursor: pointer;
    transition: background .15s;
    text-decoration: none;
    flex-shrink: 0;
}
.btn-icon:hover { background: #f1f0ed; text-decoration: none; opacity: 1; }

/* Table */
.card {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,.07);
}

table { width: 100%; border-collapse: collapse; }
th { background: #f1f0ed; text-align: left; padding: 10px 16px; font-size: 13px; color: #6b7280; }
td { padding: 12px 16px; border-top: 1px solid #f1f0ed; }
tr:first-child td { border-top: none; }

.slug-badge {
    font-family: monospace;
    background: #f1f0ed;
    padding: 2px 7px;
    border-radius: 5px;
    font-size: 13px;
}

/* Form */
.form-card {
    background: #fff;
    border-radius: 12px;
    padding: 28px;
    box-shadow: 0 1px 4px rgba(0,0,0,.07);
    margin-bottom: 20px;
}

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

label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 5px;
}

input[type="text"],
input[type="url"],
textarea,
select {
    width: 100%;
    padding: 9px 12px;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: #1a1a2e;
    background: #fafafa;
    transition: border-color .15s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: #3b7dd8;
    background: #fff;
}

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

.hint {
    font-size: 12px;
    color: #9ca3af;
    margin-top: 4px;
}

/* Header type toggle */
.radio-group {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}
.radio-option {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 14px;
}

/* Contact toggles */
.contact-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    min-width: 110px;
    cursor: pointer;
}
.contact-row input[type="text"],
.contact-row input[type="url"] {
    flex: 1;
    margin: 0;
}

/* Block builder */
.block-section {
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 14px;
}

.block-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.block-header label { margin: 0; font-weight: 700; min-width: 60px; }
.block-header select { flex: 1; margin: 0; }

/* Reorder ↑/↓ */
.block-move {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.btn-move {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1.5px solid #e5e7eb;
    border-radius: 7px;
    background: #fafafa;
    color: #6b7280;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
}
.btn-move:hover:not(:disabled) {
    background: #f0f4ff;
    border-color: #93b4f5;
    color: #3b7dd8;
}
.btn-move:disabled {
    opacity: .4;
    cursor: not-allowed;
}

/* Show/hide (eye) toggle */
.btn-eye {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1.5px solid #e5e7eb;
    border-radius: 7px;
    background: #fafafa;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, border-color .15s;
}
.btn-eye:hover { background: #f0f4ff; border-color: #93b4f5; }
.btn-eye.is-hidden { background: #fff4f4; border-color: #f0b4b4; }

/* Скрытый блок: приглушаем карточку, но поля остаются редактируемыми */
.block-section.block-hidden { opacity: .55; }
.block-section.block-hidden:focus-within { opacity: 1; }

.block-hidden-badge {
    display: none;
    flex-shrink: 0;
    padding: 2px 8px;
    border-radius: 999px;
    background: #fde2e2;
    color: #b42318;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.block-section.block-hidden .block-hidden-badge { display: inline-block; }

.block-fields { display: none; }
.block-fields.active { display: block; }

.item-row {
    background: #f7f6f3;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    position: relative;
}

.item-row input[type="text"],
.item-row textarea {
    background: #fff;
    margin-bottom: 6px;
}
.item-row input[type="text"]:last-of-type,
.item-row textarea:last-of-type { margin-bottom: 0; }

.btn-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #fee2e2;
    color: #dc2626;
    border: none;
    border-radius: 5px;
    width: 26px;
    height: 26px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.add-item-btn {
    width: 100%;
    padding: 8px;
    background: #f0f4ff;
    color: #3b7dd8;
    border: 1.5px dashed #93b4f5;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
}
.add-item-btn:hover { background: #e0eaff; }

/* Upload inline */
.upload-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.upload-row input[type="text"] { flex: 1; margin: 0; }
.btn-upload {
    padding: 8px 12px;
    background: #6b7280;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}

.img-preview {
    max-height: 60px;
    border-radius: 6px;
    margin-top: 6px;
    display: block;
}

/* Error banner */
.error-banner {
    background: #fee2e2;
    color: #b91c1c;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: 14px;
}

/* ── AI Intake ── */
.btn-ai {
    background: #7c3aed;
    color: #fff;
    width: 100%;
    padding: 11px;
    font-size: 14px;
    margin-top: 4px;
}
.btn-ai:disabled { opacity: .5; cursor: not-allowed; }

/* ── Provenance badges ── */
.prov-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: 20px;
    vertical-align: middle;
}
.prov-site     { background: #dcfce7; color: #15803d; }
.prov-reworded { background: #fef3c7; color: #92400e; }
.prov-invented { background: #fee2e2; color: #b91c1c; }
.prov-toggle-btn {
    background: none;
    border: none;
    font-size: 11px;
    color: #6b7280;
    cursor: pointer;
    margin-left: 6px;
    padding: 0;
}
.prov-toggle-btn:hover { color: #374151; }

.sticky-bottom {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    padding: 16px 28px;
    display: flex;
    gap: 12px;
    margin: 0 -28px -28px;
    border-radius: 0 0 12px 12px;
}

/* ── Greeting template button ── */
.btn-tpl {
    display: inline-block;
    margin-bottom: 8px;
    padding: 6px 14px;
    background: transparent;
    color: #3b7dd8;
    border: 1.5px solid #3b7dd8;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s;
}
.btn-tpl:hover { background: #eff6ff; }
