/* ============================================================
   Дизайн-система
   ============================================================ */
:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --primary-soft: #e0e7ff;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-soft: #94a3b8;
    --success: #10b981;
    --success-light: #d1fae5;
    --success-text: #065f46;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --danger-text: #991b1b;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --warning-text: #92400e;
    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 8px;
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 20px 48px rgba(15, 23, 42, 0.14);
    --sidebar-width: 288px;
    --header-height: 84px;
}

/* ============================================================
   База
   ============================================================ */
* {
    box-sizing: border-box;
}

html {
    font-size: 15px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

a {
    color: var(--primary);
    text-decoration: none;
}

    a:hover {
        color: var(--primary-hover);
    }

/* ============================================================
   Общие поля формы
   ============================================================ */
.form-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    margin-bottom: 0.35rem;
}

.form-control,
.form-select {
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 0.55rem 0.85rem;
    font-size: 0.9rem;
    color: var(--text);
    background-color: var(--surface);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
    box-shadow: var(--shadow-xs);
}

    .form-control::placeholder {
        color: var(--text-soft);
    }

    .form-control:hover,
    .form-select:hover {
        border-color: var(--border-strong);
    }

    .form-control:focus,
    .form-select:focus {
        border-color: var(--primary);
        background-color: var(--surface);
        box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12);
        outline: none;
    }

    .form-control:disabled,
    .form-select:disabled {
        background-color: var(--surface-2);
        color: var(--text-soft);
    }

.form-check-input {
    width: 1.1em;
    height: 1.1em;
    margin-top: 0.15em;
    border: 1.5px solid var(--border-strong);
    transition: all 0.15s ease;
}

    .form-check-input:checked {
        background-color: var(--primary);
        border-color: var(--primary);
    }

    .form-check-input:focus {
        border-color: var(--primary);
        box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12);
    }

.form-check-label {
    font-size: 0.9rem;
    color: var(--text);
    cursor: pointer;
}

/* ============================================================
   Кнопки
   ============================================================ */
.btn {
    border-radius: var(--radius-xs);
    font-weight: 500;
    font-size: 0.875rem;
    padding: 0.55rem 1.1rem;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: 1px solid transparent;
    box-shadow: var(--shadow-xs);
}

    .btn i {
        font-size: 1rem;
        line-height: 1;
    }

.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

    .btn-primary:hover, .btn-primary:focus {
        background-color: var(--primary-hover);
        border-color: var(--primary-hover);
        color: #fff;
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    }

.btn-success {
    background-color: var(--success);
    border-color: var(--success);
    color: #fff;
}

    .btn-success:hover, .btn-success:focus {
        background-color: #059669;
        border-color: #059669;
        color: #fff;
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    }

.btn-danger {
    background-color: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

    .btn-danger:hover, .btn-danger:focus {
        background-color: #dc2626;
        border-color: #dc2626;
        color: #fff;
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
    }

.btn-outline-secondary {
    background-color: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}

    .btn-outline-secondary:hover {
        background-color: var(--surface-2);
        color: var(--text);
        border-color: var(--border-strong);
    }

.btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
    border-radius: var(--radius-xs);
}

/* ============================================================
   Каркас приложения
   ============================================================ */
.app-shell {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* ---------- Сайдбар ---------- */
.app-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    padding: 1.25rem 0.85rem;
    scrollbar-width: thin;
}

    .app-sidebar::-webkit-scrollbar {
        width: 6px;
    }

    .app-sidebar::-webkit-scrollbar-thumb {
        background: var(--border-strong);
        border-radius: 3px;
    }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.brand-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    min-width: 0;
}

.brand-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    letter-spacing: -0.01em;
}

.brand-subtitle {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.nav-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-soft);
    padding: 0.75rem 0.75rem 0.4rem;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem;
    border-radius: var(--radius-xs);
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    transition: all 0.15s ease;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    position: relative;
}

    .sidebar-nav-item i {
        font-size: 1.1rem;
        flex-shrink: 0;
        color: var(--text-soft);
        transition: color 0.15s ease;
    }

    .sidebar-nav-item:hover {
        background: var(--surface-2);
        color: var(--text);
    }

        .sidebar-nav-item:hover i {
            color: var(--text-muted);
        }

    .sidebar-nav-item.active {
        background: var(--primary-light);
        color: var(--primary);
        font-weight: 600;
    }

        .sidebar-nav-item.active i {
            color: var(--primary);
        }

        .sidebar-nav-item.active::before {
            content: '';
            position: absolute;
            left: -0.85rem;
            top: 20%;
            bottom: 20%;
            width: 3px;
            background: var(--primary);
            border-radius: 0 3px 3px 0;
        }

.sidebar-footer {
    padding: 0.85rem 0.75rem 0.25rem;
    border-top: 1px solid var(--border);
    margin-top: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-soft);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

    .sidebar-footer code {
        background: var(--surface-2);
        color: var(--text-muted);
        padding: 0.15rem 0.4rem;
        border-radius: 4px;
        font-size: 0.7rem;
    }

/* ---------- Основная область ---------- */
.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
    padding: 1.1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    min-height: var(--header-height);
    flex-wrap: wrap;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
}

.header-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.header-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.header-description {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin: 2px 0 0;
    line-height: 1.3;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.sidebar-toggle {
    display: none;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text);
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

/* ---------- Бейдж статуса ---------- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.85rem;
    border-radius: 100px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid transparent;
    white-space: nowrap;
}

    .status-badge i {
        font-size: 0.9rem;
    }

.status-pending {
    background: var(--warning-light);
    color: var(--warning-text);
    border-color: rgba(245, 158, 11, 0.25);
}

.status-approved {
    background: var(--success-light);
    color: var(--success-text);
    border-color: rgba(16, 185, 129, 0.25);
}

.status-rejected {
    background: var(--danger-light);
    color: var(--danger-text);
    border-color: rgba(239, 68, 68, 0.25);
}

/* ---------- Контент ---------- */
.app-content {
    padding: 1.75rem 2rem 5rem;
    flex: 1;
    max-width: 1400px;
    width: 100%;
}

.content-section {
    display: none;
    animation: fadeIn 0.25s ease;
}

    .content-section.active {
        display: block;
    }

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
}

.section-card-title {
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 0.25rem;
    letter-spacing: -0.01em;
}

.section-card-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin: 0 0 1rem;
}

/* ---------- Двухуровневые подтабы ---------- */
.subtabs-group {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.subtabs {
    display: flex;
    gap: 0.25rem;
    background: var(--surface-2);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    overflow-x: auto;
}

.subtab {
    background: transparent;
    border: none;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-xs);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
}

    .subtab:hover {
        color: var(--text);
    }

    .subtab.active {
        background: var(--surface);
        color: var(--primary);
        font-weight: 600;
        box-shadow: var(--shadow-xs);
    }

.subtab-panel {
    display: none;
}

    .subtab-panel.active {
        display: block;
        animation: fadeIn 0.2s ease;
    }

/* ---------- Коллекции (динамические списки) ---------- */
.collection-container {
    border-top: 1px dashed var(--border-strong);
    padding-top: 1rem;
    margin-top: 1rem;
}

.collection-item {
    background: var(--surface-2);
    padding: 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    position: relative;
    transition: border-color 0.15s ease;
}

    .collection-item:hover {
        border-color: var(--border-strong);
    }

    .collection-item > .remove-item,
    .collection-item > .btn.remove-item {
        margin-top: 0.75rem;
    }

/* ---------- Вложенные карточки из EditorTemplates ---------- */
.content-section .card.card-body,
.content-section .card.card-body.bg-light {
    background: var(--surface) !important;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: none;
}

.content-section .collection-item .card.card-body,
.content-section .collection-item .card.card-body.bg-light {
    background: var(--surface) !important;
    border-color: var(--border);
}

/* ---------- Аккордеон в шаблонах ---------- */
.accordion-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-xs) !important;
    margin-bottom: 0.5rem;
    overflow: hidden;
}

.accordion-button {
    background: var(--surface-2);
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 0.65rem 1rem;
    box-shadow: none !important;
}

    .accordion-button:not(.collapsed) {
        background: var(--primary-light);
        color: var(--primary);
    }

.accordion-body {
    background: var(--surface);
    padding: 1rem;
}

/* ---------- Заголовки внутри секций ---------- */
.content-section h5,
.content-section h6 {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-soft);
    margin: 0.25rem 0 0.75rem;
}

/* ---------- Модалка ---------- */
.modal-content {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-header {
    border-bottom: 1px solid var(--border);
    padding: 1.1rem 1.4rem;
}

.modal-title {
    font-weight: 700;
    font-size: 1rem;
}

.modal-body {
    padding: 1.25rem 1.4rem;
}

.modal-footer {
    border-top: 1px solid var(--border);
    padding: 0.9rem 1.4rem;
    gap: 0.5rem;
}

/* ============================================================
   Адаптивность
   ============================================================ */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1030;
    backdrop-filter: blur(2px);
}

@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1040;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: var(--shadow-lg);
        height: 100vh;
    }

        .app-sidebar.open {
            transform: translateX(0);
        }

    .sidebar-backdrop.show {
        display: block;
    }

    .sidebar-toggle {
        display: inline-flex;
    }

    .app-header {
        padding: 1rem 1.25rem;
    }

    .header-title {
        font-size: 1.1rem;
    }

    .app-content {
        padding: 1.25rem 1rem 4rem;
    }

    .header-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

@media (max-width: 575.98px) {
    .header-actions .btn span {
        display: none;
    }

    .header-actions .btn {
        padding: 0.55rem 0.8rem;
    }

        .header-actions .btn i {
            font-size: 1.05rem;
        }
}
