:root {
    --bg: #f3f5f9;
    --card: #ffffff;
    --text: #1a2233;
    --muted: #8490a5;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef0fe;
    --danger: #e11d48;
    --danger-soft: #fef2f2;
    --warn-bg: #fef9c3;
    --warn-text: #a16207;
    --ok-bg: #dcfce7;
    --ok-text: #15803d;
    --border: #e7eaf1;
    --surface-2: #f8fafc;
    --surface-hover: #f8f9fd;
    --surface-board: #e9edf4;
    --surface-track: #eef1f6;
    --input-bg: #ffffff;
    --label-text: #3c4457;
    --sidebar-bg: #171c2b;
    --sidebar-text: #9aa3b8;
    --sidebar-active: #232a3f;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(23, 28, 43, .04), 0 4px 16px rgba(23, 28, 43, .06);
    --shadow-hover: 0 2px 4px rgba(23, 28, 43, .06), 0 10px 28px rgba(23, 28, 43, .12);
}

/* ============ Тёмная тема ============ */
[data-theme="dark"] {
    --bg: #0f1218;
    --card: #1a1f2b;
    --text: #e4e8f0;
    --muted: #8a93a8;
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --primary-soft: #2b2f4a;
    --danger: #fb7185;
    --danger-soft: #3a1f28;
    --warn-bg: #3a3220;
    --warn-text: #fbbf24;
    --ok-bg: #1d3a2a;
    --ok-text: #4ade80;
    --border: #2a3140;
    --surface-2: #222838;
    --surface-hover: #222839;
    --surface-board: #141924;
    --surface-track: #2a3140;
    --input-bg: #141924;
    --label-text: #b9c0d0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .3);
    --shadow-hover: 0 2px 4px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .45);
}
[data-theme="dark"] .btn-secondary { background: var(--surface-2); }
[data-theme="dark"] .tab { background: var(--surface-2); }
[data-theme="dark"] .stage-new { background: #2b2f4a; color: #a5b4fc; }
[data-theme="dark"] .stage-in_progress { background: #1e2a4a; color: #60a5fa; }
[data-theme="dark"] .badge { background: var(--primary-soft); }

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Inter", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    display: flex;
    min-height: 100vh;
    transition: background .2s, color .2s;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ Боковая панель ============ */
.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 20px 14px;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
    margin-bottom: 14px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-weight: 800;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.brand-name { color: #fff; font-weight: 700; font-size: 17px; letter-spacing: .2px; }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav a {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-weight: 500;
    transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 2px 0 0 var(--primary); }
.nav .ico { width: 20px; text-align: center; font-size: 14px; }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, .07);
}
.user-link {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    color: var(--sidebar-text);
    padding: 6px;
    border-radius: var(--radius-sm);
}
.user-link:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.user-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.logout { color: var(--sidebar-text); font-size: 17px; padding: 6px; border-radius: 8px; }
.logout:hover { color: var(--danger); text-decoration: none; }
.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 15px;
    padding: 6px;
    border-radius: 8px;
    color: var(--sidebar-text);
    line-height: 1;
}
.theme-toggle:hover { background: rgba(255, 255, 255, .06); }

/* ============ Контент ============ */
.content { flex: 1; min-width: 0; padding: 28px 32px; max-width: 1200px; }

h1 { font-size: 24px; font-weight: 700; margin: 0 0 20px; letter-spacing: -.3px; }
h2 { font-size: 16px; font-weight: 650; margin: 0 0 14px; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.page-head h1 { margin: 0; }
.page-head > div { display: flex; gap: 8px; align-items: center; }

/* ============ Карточки ============ */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 18px;
    box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.form-card { max-width: 540px; }

.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .columns { grid-template-columns: 1fr; } }

/* ============ Статистика ============ */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
@media (max-width: 900px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: linear-gradient(180deg, #6366f1, #8b5cf6);
    border-radius: 4px 0 0 4px;
}
.stat-num { font-size: 28px; font-weight: 750; letter-spacing: -.5px; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 5px; }

/* ============ Кнопки ============ */
.btn {
    display: inline-block;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(79, 70, 229, .3); }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #be123c; }
.btn-block { width: 100%; }
.link-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--primary);
    font-size: 15px;
    padding: 2px 4px;
    font-family: inherit;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.inline-form { display: inline; }

/* ============ Формы ============ */
label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 13.5px; color: var(--label-text); }
input, select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    margin-top: 5px;
    background: var(--input-bg);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input[type="date"]::-webkit-calendar-picker-indicator { cursor: pointer; }
[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(.7); }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .14);
}
.row { display: flex; gap: 10px; margin-bottom: 10px; }
.row > * { margin-top: 0; }
.small-input { width: 150px; display: inline-block; margin: 0 4px 0 0; }
.note-form { margin-bottom: 14px; }
.note-form textarea, .note-form input[type="text"] { margin-bottom: 8px; }

/* ============ Таблицы ============ */
.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
.table th {
    background: var(--surface-2);
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    font-weight: 650;
}
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-hover); }
.table tr:last-child td { border-bottom: none; }
.table td a { font-weight: 600; }
.table .actions { white-space: nowrap; text-align: right; }

/* ============ Поиск ============ */
.search-bar { display: flex; gap: 8px; margin-bottom: 18px; }
.search-bar input { margin-top: 0; }

/* ============ Списки ============ */
.simple-list { list-style: none; padding: 0; margin: 0 0 12px; }
.simple-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
}
.simple-list li:last-child { border-bottom: none; }
.simple-list .amount { margin-left: auto; font-weight: 650; }

/* ============ Доска сделок ============ */
.board { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; align-items: start; }
@media (max-width: 1100px) { .board { grid-template-columns: repeat(2, 1fr); } }
.board-col {
    background: var(--surface-board);
    border-radius: var(--radius);
    padding: 12px;
    min-height: 140px;
}
.board-col-head {
    font-weight: 650;
    font-size: 13px;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2px;
}
.board-col-head .count {
    background: var(--card);
    color: var(--muted);
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 12px;
}
.board-empty { font-size: 13px; text-align: center; padding: 14px 0; color: var(--muted); }
.deal-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 12px 13px;
    margin-bottom: 9px;
    box-shadow: var(--shadow);
    transition: box-shadow .15s, transform .15s;
}
.deal-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-1px); }
.deal-title { font-weight: 650; font-size: 14px; }
.deal-client { font-size: 13px; margin: 4px 0; }
.deal-amount { font-weight: 750; color: var(--primary); margin-bottom: 8px; }
.deal-actions { display: flex; gap: 4px; border-top: 1px solid var(--border); padding-top: 7px; }

/* ============ Задачи ============ */
.tabs { display: flex; gap: 6px; margin: 18px 0 14px; flex-wrap: wrap; }
.tab {
    padding: 7px 16px;
    border-radius: 20px;
    border: 1px solid var(--border);
    color: var(--text);
    background: #fff;
    font-size: 13px;
    font-weight: 600;
    transition: all .15s;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); box-shadow: 0 2px 8px rgba(79, 70, 229, .3); }
.tab:hover { text-decoration: none; border-color: var(--primary); }
.task-list { list-style: none; padding: 0; margin: 0; }
.task-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 9px;
    box-shadow: var(--shadow);
    transition: box-shadow .15s;
}
.task-item:hover { box-shadow: var(--shadow-hover); }
.task-item .check { font-size: 19px; line-height: 1.2; }
.task-body { flex: 1; }
.task-title { font-weight: 600; }
.task-item.done { opacity: .6; }
.task-item.done .task-title { text-decoration: line-through; }
.overdue { color: var(--danger); font-weight: 650; }

/* ============ Заметки ============ */
.note { border-top: 1px solid var(--border); padding: 11px 0; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.note-meta { font-size: 12px; color: var(--muted); margin-bottom: 3px; width: 100%; }
.note.done span { text-decoration: line-through; color: var(--muted); }

/* ============ Бейджи и детали ============ */
.badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 650;
    background: var(--primary-soft);
    color: var(--primary);
}
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }
.stage-new { background: #e0e7ff; color: #3730a3; }
.stage-in_progress { background: #dbeafe; color: #1d4ed8; }
.stage-waiting { background: var(--warn-bg); color: var(--warn-text); }
.stage-won { background: var(--ok-bg); color: var(--ok-text); }
.stage-lost { background: var(--danger-soft); color: var(--danger); }

.details { display: grid; grid-template-columns: 120px 1fr; gap: 8px 14px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }

.muted { color: var(--muted); }
.amount { font-weight: 650; }

/* ============ Столбчатый график ============ */
.bar-chart { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: flex; align-items: center; gap: 12px; }
.bar-label { width: 74px; color: var(--muted); font-size: 13px; font-weight: 600; }
.bar-track { flex: 1; background: var(--surface-track); border-radius: 7px; height: 22px; overflow: hidden; }
.bar-fill {
    background: linear-gradient(90deg, #6366f1, #8b5cf6);
    height: 100%;
    border-radius: 7px;
    min-width: 3px;
}
.bar-value { width: 100px; text-align: right; font-weight: 650; font-size: 13px; }

/* ============ Логин ============ */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #171c2b 0%, #2b2350 55%, #4338ca 100%);
}
.login-card {
    background: var(--card);
    border-radius: 18px;
    padding: 40px 36px;
    width: 360px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .35);
}
.login-card h1 {
    text-align: center;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 24px;
}
.login-card p { text-align: center; color: var(--muted); }

/* ============ Уведомления ============ */
.alert { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; font-weight: 500; }
.alert-error { background: var(--danger-soft); color: #9f1239; }
.alert-ok { background: var(--ok-bg); color: var(--ok-text); }

/* ============ Мобильная адаптация ============ */
@media (max-width: 760px) {
    body { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        flex-direction: row;
        align-items: center;
        padding: 10px 14px;
        gap: 10px;
    }
    .brand { padding: 0; border-bottom: none; margin-bottom: 0; }
    .brand-name { display: none; }
    .nav { flex-direction: row; flex-wrap: wrap; }
    .nav a { padding: 7px 9px; font-size: 13px; }
    .nav a.active { box-shadow: none; }
    .sidebar-user { border-top: none; padding-top: 0; }
    .user-name { display: none; }
    .content { padding: 18px 16px; }
}
