@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --secondary: #6366f1;
    --primary-soft: #eef2ff;
    --gradient: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    --gradient-dark: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
    --dark: #0f172a;
    --light: #f1f5f9;
    --white: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --danger: #ef4444;
    --danger-soft: #fef2f2;
    --success: #10b981;
    --success-soft: #ecfdf5;
    --warning: #f59e0b;
    --warning-soft: #fffbeb;
    --border: #e8edf3;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 6px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 18px 40px -12px rgba(15, 23, 42, 0.18), 0 8px 16px -8px rgba(15, 23, 42, 0.1);
    --shadow-primary: 0 8px 20px -6px rgba(79, 70, 229, 0.45);
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===================== Тёмная тема ===================== */
[data-theme="dark"] {
    --primary-soft: #1e1b4b;
    --dark: #f1f5f9;
    --light: #0b1120;
    --white: #1e293b;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --danger-soft: #3f1d1d;
    --success-soft: #0f2e23;
    --warning-soft: #3a2c10;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3), 0 1px 3px rgba(0,0,0,0.35);
    --shadow: 0 4px 12px -2px rgba(0,0,0,0.45), 0 2px 6px -2px rgba(0,0,0,0.4);
    --shadow-lg: 0 18px 40px -12px rgba(0,0,0,0.6), 0 8px 16px -8px rgba(0,0,0,0.5);
}
[data-theme="dark"] body {
    background-image: radial-gradient(at 0% 0%, rgba(99,102,241,0.10) 0px, transparent 50%),
                      radial-gradient(at 100% 0%, rgba(16,185,129,0.07) 0px, transparent 50%);
}
[data-theme="dark"] .sidebar { background-color: rgba(15,23,42,0.88); }
[data-theme="dark"] input, [data-theme="dark"] textarea, [data-theme="dark"] select { background: #0f172a; color: var(--text-main); }
[data-theme="dark"] input:focus, [data-theme="dark"] textarea:focus, [data-theme="dark"] select:focus { background: #0b1120; }
[data-theme="dark"] .btn-danger, [data-theme="dark"] .edit-task-btn { background: var(--white); }
[data-theme="dark"] .task-item, [data-theme="dark"] .upload-box { background: #0f172a; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #475569; border-color: var(--light); }
/* Ретрофит инлайновых светлых цветов в шаблонах */
[data-theme="dark"] [style*="background: white"],
[data-theme="dark"] [style*="background:white"],
[data-theme="dark"] [style*="background: #fff"],
[data-theme="dark"] [style*="background:#fff"],
[data-theme="dark"] [style*="background-color: white"],
[data-theme="dark"] [style*="background: #f9fafb"],
[data-theme="dark"] [style*="background:#f9fafb"] { background: var(--white) !important; }
[data-theme="dark"] thead[style*="background"] { background: #0f172a !important; }
[data-theme="dark"] tr[style*="border-bottom"] { border-color: var(--border) !important; }
[data-theme="dark"] [style*="color: #666"],
[data-theme="dark"] [style*="color:#666"],
[data-theme="dark"] [style*="color: #888"],
[data-theme="dark"] [style*="color:#888"],
[data-theme="dark"] [style*="color: #9ca3af"] { color: var(--text-muted) !important; }

/* ===================== Переключатель темы ===================== */
.theme-toggle {
    position: fixed; bottom: 24px; right: 24px; z-index: 1500;
    width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--border);
    background: var(--white); color: var(--primary); cursor: pointer;
    box-shadow: var(--shadow-lg); font-size: 1.15rem; display: grid; place-items: center;
    transition: var(--transition);
}
.theme-toggle:hover { transform: scale(1.08) rotate(8deg); }
@media (max-width: 768px) { .theme-toggle { bottom: 20px; right: 16px; width: 44px; height: 44px; } }

/* ===================== Бургер + шторка (моб.) ===================== */
.hamburger {
    display: none;
    position: fixed; top: 14px; right: 14px; z-index: 2100;
    width: 46px; height: 46px; border-radius: 13px; cursor: pointer;
    border: 1px solid var(--border); background: var(--white); color: var(--text-main);
    box-shadow: var(--shadow); font-size: 1.2rem; place-items: center;
    transition: var(--transition);
}
.hamburger:active { transform: scale(0.93); }
.drawer-backdrop {
    position: fixed; inset: 0; z-index: 1900;
    background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(3px);
    opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease;
}
.drawer-backdrop.show { opacity: 1; visibility: visible; }

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

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--light);
    background-image: radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.06) 0px, transparent 50%),
                      radial-gradient(at 100% 0%, rgba(16, 185, 129, 0.05) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: -0.01em;
}

::selection { background: rgba(99, 102, 241, 0.2); }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; border: 2px solid var(--light); }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ===================== Sidebar ===================== */
.sidebar {
    width: 264px;
    background-color: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border);
    position: fixed;
    height: 100%;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.logo {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 36px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    letter-spacing: -0.03em;
}
.logo i {
    background: var(--gradient);
    color: white;
    width: 38px; height: 38px;
    display: grid; place-items: center;
    border-radius: 11px;
    font-size: 1.1rem;
    box-shadow: var(--shadow-primary);
}

.nav-links { display: flex; flex-direction: column; }

.nav-links a {
    position: relative;
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 12px 15px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 11px;
    margin-bottom: 4px;
    transition: var(--transition);
    font-weight: 500;
    font-size: 0.93rem;
}
.nav-links a i { width: 20px; text-align: center; font-size: 1rem; transition: var(--transition); }

.nav-links a:hover {
    background-color: var(--primary-soft);
    color: var(--primary);
    transform: translateX(3px);
}
.nav-links a.active {
    background: var(--gradient);
    color: #fff;
    box-shadow: var(--shadow-primary);
}
.nav-links a.active i { transform: scale(1.05); }

/* ===================== Main ===================== */
.main-content {
    margin-left: 264px;
    flex: 1;
    padding: 40px 44px;
    animation: pageIn 0.4s ease;
}
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

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

h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.03em; color: var(--dark); }
h2 { margin-bottom: 16px; font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; }
h3 { font-weight: 700; letter-spacing: -0.01em; }

.user-profile {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: var(--text-main);
    background: var(--white);
    padding: 9px 16px;
    border-radius: 30px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}
.user-profile i { color: var(--primary); font-size: 1.3rem; }

/* ===================== Cards & Stats ===================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--white);
    padding: 22px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    animation: cardIn 0.45s ease both;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }

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

.stat-title { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 8px; font-weight: 500; }
.stat-value { font-size: 1.9rem; font-weight: 800; color: var(--dark); letter-spacing: -0.03em; }

/* ===================== Buttons ===================== */
.btn {
    background: var(--gradient);
    color: white;
    padding: 11px 20px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    font-family: inherit;
    transition: var(--transition);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: var(--shadow-primary);
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 12px 24px -8px rgba(79, 70, 229, 0.55); filter: brightness(1.05); }
.btn:active { transform: translateY(0); box-shadow: var(--shadow-sm); }

.btn-danger {
    background: var(--white); color: var(--danger); border: 1px solid #fecaca;
    padding: 8px 14px; font-size: 0.8rem; cursor: pointer; box-shadow: none;
}
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ===================== Inputs ===================== */
input, textarea, select {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-family: inherit;
    font-size: 0.92rem;
    color: var(--text-main);
    background: #fbfcfe;
    transition: var(--transition);
    outline: none;
}
input::placeholder, textarea::placeholder { color: #94a3b8; }
input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}
select { cursor: pointer; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px;
}

/* ===================== Projects Grid ===================== */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 22px;
}

.project-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    animation: cardIn 0.45s ease both;
}
.project-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: var(--gradient); opacity: 0; transition: var(--transition);
}
.project-card:hover { transform: translateY(-6px); box-shadow: var(--shadow-lg); border-color: #dfe5ee; }
.project-card:hover::before { opacity: 1; }

.project-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; gap: 10px; }
.project-title { font-weight: 700; font-size: 1.12rem; color: var(--dark); letter-spacing: -0.02em; }

.status-badge {
    background: var(--success-soft); color: #047857;
    padding: 5px 12px; border-radius: 30px; font-size: 0.72rem; font-weight: 700;
    text-transform: capitalize; letter-spacing: 0.01em; white-space: nowrap;
    border: 1px solid rgba(16, 185, 129, 0.2);
}
.status-badge.active { background: var(--success-soft); color: #047857; border-color: rgba(16,185,129,0.2); }
.status-badge.done, .status-badge.completed { background: var(--primary-soft); color: var(--primary); border-color: rgba(79,70,229,0.2); }
.status-badge.paused, .status-badge.onhold { background: var(--warning-soft); color: #b45309; border-color: rgba(245,158,11,0.2); }
.status-badge.planning, .status-badge.draft { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.over-budget { background: var(--danger-soft); color: #b91c1c; border-color: rgba(239,68,68,0.2); }

/* ===================== Progress ===================== */
.progress-container { margin: 16px 0 4px; }
.progress-info { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 7px; font-weight: 600; }
.progress-track, .progress-bar-bg {
    background: #eef2f7; height: 8px; border-radius: 20px; overflow: hidden;
}
.progress-fill, .progress-bar-fill {
    height: 100%; background: var(--gradient); border-radius: 20px;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 4px rgba(79, 70, 229, 0.4);
}
.progress-fill.completed { background: linear-gradient(135deg, #34d399, #10b981); box-shadow: 0 1px 4px rgba(16,185,129,0.4); }

.project-footer { display: flex; justify-content: space-between; margin-top: 18px; align-items: center; }

/* ===================== Info boxes / labels ===================== */
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 26px; }
.info-box {
    background: var(--white); padding: 20px; border-radius: var(--radius);
    box-shadow: var(--shadow-sm); border: 1px solid var(--border); transition: var(--transition);
}
.info-box:hover { box-shadow: var(--shadow); }
.info-box p { color: var(--text-main); line-height: 1.55; }
.info-label {
    display: block; font-size: 0.74rem; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; margin-bottom: 7px;
}

/* ===================== Tasks ===================== */
.task-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 13px 15px; border-radius: var(--radius-sm); margin-bottom: 9px;
    background: #fbfcfe; border: 1px solid var(--border); transition: var(--transition);
}
.active-task { cursor: pointer; }
.active-task:hover { background: var(--primary-soft); border-color: #c7d2fe; transform: translateX(3px); }
.task-done { background: var(--success-soft); border-color: rgba(16,185,129,0.18); }
.task-done .task-text { text-decoration: line-through; color: var(--text-muted); }

.check-btn {
    width: 22px; height: 22px; border-radius: 7px; border: 2px solid #cbd5e1;
    display: grid; place-items: center; color: #fff; flex-shrink: 0; transition: var(--transition);
}
.active-task:hover .check-btn { border-color: var(--primary); }
.check-btn.checked { background: var(--success); border-color: var(--success); }

.task-date { font-size: 0.8rem; color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.date-overdue { color: var(--danger); font-weight: 700; }
.edit-task-btn {
    border: none; background: #fff; color: var(--text-muted); cursor: pointer;
    width: 30px; height: 30px; border-radius: 8px; transition: var(--transition); border: 1px solid var(--border);
}
.edit-task-btn:hover { color: var(--primary); background: var(--primary-soft); border-color: #c7d2fe; }

/* ===================== Finance link card ===================== */
.financial-link-card {
    display: block; background: var(--white); padding: 22px; border-radius: var(--radius);
    box-shadow: var(--shadow-sm); border: 1px solid var(--border); text-decoration: none;
    color: var(--text-main); transition: var(--transition);
}
.financial-link-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.fin-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 0.92rem; }
.fin-val { font-weight: 700; }

/* ===================== Timeline ===================== */
.timeline { border-left: 2px solid var(--border); padding-left: 28px; margin-top: 20px; }
.timeline-item { position: relative; margin-bottom: 28px; }
.timeline-item::before {
    content: ''; position: absolute; left: -35px; top: 4px;
    width: 13px; height: 13px; background: var(--gradient); border-radius: 50%;
    border: 2px solid white; box-shadow: 0 0 0 3px var(--primary-soft);
}
.timeline-date { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.timeline-card {
    background: var(--white); padding: 17px; border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm); border: 1px solid var(--border); transition: var(--transition);
}
.timeline-card:hover { box-shadow: var(--shadow); transform: translateX(2px); }

.timeline-image {
    height: 150px; width: auto; max-width: 100%; object-fit: cover;
    border-radius: var(--radius-sm); margin-top: 10px; border: 1px solid var(--border);
    cursor: pointer; transition: var(--transition);
}
.timeline-image:hover { transform: scale(1.03); box-shadow: var(--shadow); }

/* ===================== Upload box ===================== */
.upload-box {
    border: 2px dashed #cbd5e1; border-radius: var(--radius-sm); padding: 20px;
    text-align: center; background: #f8fafc; cursor: pointer; transition: var(--transition);
    color: var(--text-muted); margin-top: 10px; display: block;
}
.upload-box:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

.project-analytics-card {
    background: white; padding: 22px; border-radius: var(--radius);
    box-shadow: var(--shadow-sm); border: 1px solid var(--border); margin-bottom: 20px; text-align: center;
}

/* ===================== Tables ===================== */
table { border-collapse: collapse; }
.cf-table, table.cf-table {
    width: 100%; background: var(--white); border-radius: var(--radius);
    overflow: hidden; box-shadow: var(--shadow-sm); border: 1px solid var(--border);
}
.cf-table th, .cf-table td { padding: 14px 16px; }
.cf-table tbody tr { transition: var(--transition); }
.cf-table tbody tr:hover { background: var(--primary-soft); }
.cf-table a { color: var(--primary); text-decoration: none; font-weight: 600; }
.cf-table a:hover { text-decoration: underline; }

/* ===================== Modals ===================== */
.modal-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(5px);
    align-items: center; justify-content: center;
    padding: 20px;
    animation: overlayIn 0.2s ease;
}
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.modal-content {
    background: var(--white);
    border-radius: var(--radius);
    padding: 30px;
    width: 100%; max-width: 460px;
    max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow-lg);
    position: relative;
    border: 1px solid var(--border);
    animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(24px) scale(0.97); } to { opacity: 1; transform: translateY(0) scale(1); } }

.close-modal {
    position: absolute; top: 16px; right: 20px;
    font-size: 1.6rem; color: #94a3b8; cursor: pointer; line-height: 1;
    width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
    transition: var(--transition);
}
.close-modal:hover { background: #f1f5f9; color: var(--danger); }

a { color: var(--primary); }

/* =========================================
   МОБИЛЬНАЯ АДАПТАЦИЯ (Responsive)
   ========================================= */
@media (max-width: 768px) {
    /* Бургер-кнопка и затемнение видны только на мобильных */
    .hamburger { display: grid; }

    /* Сайдбар превращается в выезжающую справа шторку */
    .sidebar {
        width: 82%; max-width: 320px; height: 100%; top: 0; right: 0; left: auto; bottom: auto;
        flex-direction: column; padding: 24px 18px; z-index: 2000;
        border-right: none; border-left: 1px solid var(--border);
        background-color: var(--white); backdrop-filter: blur(14px);
        box-shadow: -10px 0 40px rgba(15, 23, 42, 0.18);
        transform: translateX(105%);
        transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar .logo { display: flex; margin-bottom: 26px; }

    /* Возвращаем вертикальный список ссылок */
    .nav-links { flex-direction: column; width: 100%; }
    .nav-links a {
        flex-direction: row; font-size: 0.98rem; padding: 13px 15px; margin-bottom: 4px;
        border-radius: 11px; gap: 13px;
    }
    .nav-links a i { font-size: 1.05rem; }

    .main-content { margin-left: 0; padding: 16px; padding-top: 72px; width: 100%; }

    .info-grid, .stats-grid, .projects-grid,
    div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important; gap: 14px !important;
    }
    .stats-grid { margin-bottom: 20px; }

    .header-bar { flex-direction: column; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
    .header-bar div[style*="text-align: right"] {
        text-align: left !important; width: 100%; display: flex;
        justify-content: space-between; align-items: center;
    }
    /* Профиль пользователя не должен прижиматься к бургеру */
    .user-profile { max-width: calc(100% - 60px); }

    h1 { font-size: 1.45rem; }
    h2 { font-size: 1.18rem; }

    /* Крупные числа (бюджеты) не должны переполнять карточку */
    .stat-value { font-size: 1.5rem; overflow-wrap: anywhere; line-height: 1.15; }
    .stat-card { padding: 18px; }

    .modal-content { width: 95% !important; padding: 20px; max-height: 88vh; overflow-y: auto; }

    input, textarea, select, button { font-size: 16px !important; }

    /* Кнопки занимают всю ширину, но не «иконочные» и не в инлайн-формах */
    .btn { width: 100%; }
    .btn[style*="width:auto"], .btn[style*="width: auto"] { width: auto !important; }
    form[style*="display:flex"] .btn, form[style*="display: flex"] .btn { width: auto; }

    table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }

    /* Графики Chart.js: не вылезают за карточку, разумная высота */
    canvas { max-width: 100% !important; }

    /* Фильтры на дашборде — каждый элемент на всю ширину */
    .filter-bar { gap: 8px !important; }
    .filter-bar > div, .filter-bar select, .filter-bar .btn, .filter-bar a.btn {
        width: 100% !important; min-width: 0 !important;
    }

    .timeline { padding-left: 16px; }
    .timeline-item::before { left: -23px; }

    .progress-info span { font-size: 0.74rem; }
}
