/* Базовые переменные и сброс */
:root {
    --primary: #0096d3;
    --primary-hover: #0077a8;
    --bg-main: #f8fafc;
    --bg-panel: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --radius: 8px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Скроллбары */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Header */
.app-header {
    height: 60px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.logo {
    font-weight: 800;
    font-size: 18px;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Переключатель шаблонов */
.template-selector {
    display: flex;
    background: var(--bg-main);
    padding: 4px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.tab {
    padding: 6px 16px;
    border: none;
    background: transparent;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.tab.active {
    background: var(--bg-panel);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

/* Основной контейнер (Сплит скрин) */
.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Левая панель (Форма) */
.panel-left {
    width: 450px;
    min-width: 400px;
    background: var(--bg-main);
    border-right: 1px solid var(--border);
    padding: 24px;
    overflow-y: auto;
}

.form-container {
    display: none;
}
.form-container.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Карточки аккордеона */
.card {
    background: var(--bg-panel);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    background: var(--bg-panel);
    transition: background 0.2s;
}

.card-header:hover {
    background: #f8fafc;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
}

.chevron {
    font-size: 12px;
    color: var(--text-muted);
    transition: transform 0.3s ease;
}

.card-body {
    padding: 0 16px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.card.expanded .chevron {
    transform: rotate(180deg);
}

.card.expanded .card-body {
    padding: 0 16px 16px 16px;
    max-height: 800px; /* Достаточно большое число для раскрытия */
}

/* Формы ввода */
.form-group {
    margin-bottom: 16px;
}
.form-group:last-child {
    margin-bottom: 0;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}

input[type="text"],
input[type="url"],
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-main);
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 150, 211, 0.1);
}

/* Кнопки */
.primary-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.primary-btn:hover {
    background: var(--primary-hover);
}

.primary-btn.success {
    background: #10b981;
}

.outline-btn {
    background: transparent;
    color: var(--primary);
    border: 1px dashed var(--primary);
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    transition: all 0.2s;
}

.outline-btn:hover {
    background: rgba(0, 150, 211, 0.05);
    border-style: solid;
}

/* Динамические списки */
.list-item {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
    position: relative;
}

.remove-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 4px;
    border-radius: 4px;
}
.remove-btn:hover {
    background: #fee2e2;
}

/* Правая панель (Предпросмотр) */
.panel-right {
    flex: 1;
    background: #e2e8f0;
    display: flex;
    flex-direction: column;
    padding: 24px;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
}

.preview-badge {
    background: var(--primary);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
}

.preview-container {
    flex: 1;
    background: transparent;
    display: flex;
    justify-content: center;
}

iframe {
    width: 600px; /* Ширина письма из шаблона */
    height: 100%;
    background: white;
    border: none;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
}

@media (max-width: 1000px) {
    .app-container {
        flex-direction: column;
    }
    .panel-left {
        width: 100%;
        height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
}
