/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
    /* Colors */
    --primary: #468de5;       /* Основной (Индиго) */
    --primary-hover: #3a75bd;
    --bg-body: #f3f4f6;       /* Фон страницы */
    --bg-card: #ffffff;       /* Фон карточек */
    --text-main: #111827;     /* Основной текст */
    --text-muted: #6b7280;    /* Вторичный текст */
    --border: #e5e7eb;        /* Границы */
    --danger: #ef4444;        /* Ошибка/Удаление */
    --success: #10b981;       /* Успех */
    --warning: #f59e0b;       /* Внимание */

    /* Spacing & Layout */
    --header-height: 64px;
    --radius: 12px;
    --container-width: 1380px;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);

    /* Font */
    --font-stack: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
    font-family: var(--font-stack);
    background-color: var(--bg-body);
    color: var(--text-main);
    font-size: 14px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

[v-cloak] { display: none !important; }

/* =========================================
   2. LAYOUT & TYPOGRAPHY
   ========================================= */
main {
    flex: 1;
    width: 100%;
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 2rem;
}

h1, h2, h3, h4 {
    color: var(--text-main);
    font-weight: 700;
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

h1 { font-size: 1.875rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.125rem; font-weight: 600; margin-bottom: 1rem; }

p { margin-bottom: 1rem; color: var(--text-muted); }
small { font-size: 0.8rem; color: var(--text-muted); }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }
a { color: var(--primary); text-decoration: none; transition: 0.2s; }
a:hover { text-decoration: underline; }

/* =========================================
   3. COMPONENTS: CARDS & CONTAINERS
   ========================================= */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    margin-bottom: 24px;
}

.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-start { display: flex; align-items: center; gap: 12px; }
.flex-col { display: flex; flex-direction: column; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-2 { margin-top: 0.5rem; }

/* =========================================
   4. HEADER (FIXED & ROBUST)
   ========================================= */
.app-header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--primary);
    text-decoration: none !important;
}
.logo span { color: var(--text-main); }

.user-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 6px;
    color: var(--text-muted);
    font-weight: 500;
    text-decoration: none !important;
    transition: all 0.2s;
}

.nav-link:hover, .nav-link.active {
    background: #eef2ff;
    color: var(--primary);
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
    margin-left: 12px;
    white-space: nowrap;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: var(--text-muted);
    transition: 0.2s;
    cursor: pointer;
}
.btn-icon:hover { background: #fee2e2; color: var(--danger); }

/* =========================================
   5. FORMS & BUTTONS
   ========================================= */
label { display: block; font-weight: 500; margin-bottom: 6px; font-size: 0.9rem; }

input[type="text"], input[type="password"], input[type="number"], select {
    width: 20%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.login-wrap input{
    width: 100%;
}
input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    outline: none;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-decoration: none !important;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { background: #a5b4fc; cursor: wait; }

/* =========================================
   6. UI ELEMENTS: ALERTS, TABS, BADGES
   ========================================= */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    font-weight: 500;
    margin-bottom: 20px;
    display: flex; align-items: center; gap: 10px;
}
.alert-danger { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }

.tabs-nav {
    display: flex;
    gap: 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}

.tab-btn {
    padding: 12px 0;
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 500;
    position: relative;
    transition: 0.2s;
}

.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); font-weight: 600; }
.tab-btn.active::after {
    content: ''; position: absolute; bottom: -1px; left: 0; right: 0;
    height: 2px; background: var(--primary);
}

.badge {
    display: inline-flex; align-items: center;
    padding: 2px 8px; border-radius: 4px;
    font-size: 0.75rem; font-weight: 600; font-family: monospace;
    background: #f3f4f6; color: var(--text-muted);
}
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-green { background: #dcfce7; color: #166534; }

/* =========================================
   7. TABLES (RESPONSIVE)
   ========================================= */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}

table { width: 100%; border-collapse: collapse; min-width: 600px; }
th {
    background: #f9fafb;
    text-align: left;
    padding: 12px 16px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}
td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-main);
    font-size: 0.9rem;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f9fafb; }

/* =========================================
   8. SETTINGS PAGE GRID
   ========================================= */
.fields-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    max-height: 400px;
    overflow-y: auto;
    padding: 4px;
}

.field-card { cursor: pointer; position: relative; display: block; }
.field-card input { position: absolute; opacity: 0; width: 0; height: 0; }
.field-inner {
    display: flex; align-items: center; gap: 12px;
    padding: 12px; background: #fff;
    border: 1px solid var(--border); border-radius: 8px;
    transition: 0.2s;
}
.field-card:hover .field-inner { border-color: #d1d5db; background: #f9fafb; }
.field-card input:checked ~ .field-inner {
    border-color: var(--primary); background: #eef2ff;
    box-shadow: 0 0 0 1px var(--primary);
}

.check-circle {
    width: 20px; height: 20px; border-radius: 50%;
    border: 2px solid #d1d5db; background: #fff;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; transition: 0.2s;
}
.field-card input:checked ~ .field-inner .check-circle {
    border-color: var(--primary); background: var(--primary);
}
.check-circle::after {
    content: ''; width: 8px; height: 4px;
    border-left: 2px solid #fff; border-bottom: 2px solid #fff;
    transform: rotate(-45deg) translate(1px, -1px); opacity: 0;
}
.field-card input:checked ~ .field-inner .check-circle::after { opacity: 1; }

.pipeline-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 0; border-bottom: 1px solid #f3f4f6;
}
.pipeline-row:last-child { border-bottom: none; }

/* =========================================
   9. LOGIN PAGE
   ========================================= */
.login-wrap {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: #eef2f6; padding: 20px;
}
.login-box { width: 100%; max-width: 380px; }

.pipeline-block{
    display: flex;
    gap: 25px;
}

/* =========================================
   10. PIPELINE & SLA SETTINGS (Missing Styles)
   ========================================= */

/* Контейнер для колонок воронок */
.pipeline-block {
    display: flex;
    gap: 24px;
    flex-wrap: wrap; /* Чтобы переносилось на моб. устройствах */
    align-items: flex-start; /* Выравнивание по верху */
}

/* Карточка одной воронки */
.pipeline-card {
    flex: 1;
    min-width: 320px; /* Минимальная ширина колонки */
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden; /* Чтобы шапка не вылезала за скругления */
}

/* Шапка воронки */
.pipeline-header {
    background: #f9fafb; /* Светло-серый фон */
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.pipeline-header span {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* Тело карточки со стадиями */
.pipeline-body {
    background: #fff;
    max-height: 500px; /* Ограничение высоты, если стадий очень много */
    overflow-y: auto;
}

/* Строка одной стадии */
.stage-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.stage-row:last-child {
    border-bottom: none;
}

.stage-row:hover {
    background: #f9fafb;
}

/* Левая часть стадии (бейдж + название) */
.stage-info {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden; /* Защита от длинных названий */
}

/* Переопределение стилей бейджа внутри стадии для аккуратности */
.stage-info .badge {
    min-width: 40px;
    justify-content: center;
    font-size: 0.7rem;
    background: #e0e7ff;
    color: var(--primary);
}

.stage-name {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px; /* Обрезка очень длинных названий */
}

/* Правая часть (инпут + подпись "дн.") */
.stage-input-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.stage-input-group input {
    width: 70px;
    padding: 6px 8px;
    text-align: center;
    font-size: 0.9rem;
}

.stage-input-group span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* =========================================
   11. FIELDS GRID TYPOGRAPHY (Refinement)
   ========================================= */

/* Стили для кода поля (например, TITLE, ID) */
.field-code {
    font-family: monospace; /* Моноширинный шрифт для кодов */
    font-size: 0.75rem;
    color: var(--primary);
    margin-bottom: 2px;
    font-weight: 600;
    opacity: 0.9;
}

/* Стили для названия поля */
.field-label {
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.2;
    color: var(--text-main);

    /* Обрезка текста в 2 строки, если название длинное */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Доработка скроллбара для длинных списков (Chrome/Safari) */
.pipeline-body::-webkit-scrollbar,
.fields-grid::-webkit-scrollbar {
    width: 6px;
}
.pipeline-body::-webkit-scrollbar-track,
.fields-grid::-webkit-scrollbar-track {
    background: transparent;
}
.pipeline-body::-webkit-scrollbar-thumb,
.fields-grid::-webkit-scrollbar-thumb {
    background-color: #d1d5db;
    border-radius: 3px;
}

/* =========================================
   12. LOADING OVERLAY
   ========================================= */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.3s ease;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 40px;
    background: white;
    border-radius: var(--radius);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.loading-text {
    text-align: center;
    max-width: 400px;
}

/* =========================================
   13. MODAL WINDOWS
   ========================================= */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

.modal-large {
    max-width: 1200px;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

/* =========================================
   13. STATISTICS CARDS
   ========================================= */
.stat-card {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.2s;
}

.stat-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 6px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-sublabel {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* =========================================
   14. TAB CONTENT & EMPTY STATES
   ========================================= */
.tab-content {
    margin-top: 20px;
    animation: fadeIn 0.3s ease;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 1rem;
    background: #f9fafb;
    border-radius: var(--radius);
    border: 2px dashed var(--border);
}



/* =========================================
   15. RESPONSIVE DESIGN
   ========================================= */
@media (max-width: 768px) {
    main {
        padding: 1rem;
    }

    .app-header {
        padding: 0 16px;
    }

    .user-nav {
        gap: 4px;
    }

    .nav-link {
        padding: 6px 8px;
        font-size: 0.85rem;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .modal-content {
        margin: 10px;
        max-height: 95vh;
    }

    .modal-header,
    .modal-body {
        padding: 16px;
    }

    .table-responsive {
        font-size: 0.85rem;
    }

    th, td {
        padding: 10px 12px;
    }
}

/* =========================================
   TOAST NOTIFICATIONS
   ========================================= */
.toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 10001;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: white;
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 320px;
    max-width: 450px;
    pointer-events: all;
    animation: slideInRight 0.3s ease;
    border-left: 4px solid;
}

.toast.toast-success {
    border-left-color: #10b981;
}

.toast.toast-error {
    border-left-color: #ef4444;
}

.toast.toast-info {
    border-left-color: #3b82f6;
}

.toast-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.toast-success .toast-icon {
    background: #dcfce7;
    color: #166534;
}

.toast-error .toast-icon {
    background: #fee2e2;
    color: #991b1b;
}

.toast-info .toast-icon {
    background: #dbeafe;
    color: #1e40af;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 4px;
    color: var(--text-main);
}

.toast-message {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.toast-close {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.toast-close:hover {
    background: #f3f4f6;
    color: var(--text-main);
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100px);
    }
}

.toast.toast-hiding {
    animation: slideOutRight 0.3s ease forwards;
}