/* ═══════════════════ Qaiyn City CRM ═══════════════════ */
:root {
    --brand: #6366f1;
    --brand2: #8b5cf6;
    --ink: #1e293b;
    --text: #374151;
    --muted: #64748b;
    --faint: #94a3b8;
    --line: #e2e8f0;
    --line-soft: #f1f5f9;
    --bg: #f1f5f9;
    --card: #ffffff;
    --danger: #ef4444;
    --sidebar-w: 232px;
    --stage-color: #64748b;
}

* { font-family: 'Inter', sans-serif; box-sizing: border-box; margin: 0; padding: 0; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--line-soft); }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

html, body { height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; }
button { cursor: pointer; font: inherit; background: none; border: none; color: inherit; }
a { color: var(--brand); text-decoration: none; }
svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ─── Кнопки, поля ─── */
.btn-primary {
    padding: 9px 18px; border-radius: 10px; color: #fff; font-weight: 600; font-size: 13px;
    background: linear-gradient(135deg, var(--brand), var(--brand2));
    box-shadow: 0 4px 14px rgba(99, 102, 241, .35); transition: transform .12s, box-shadow .12s;
    white-space: nowrap;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(99, 102, 241, .45); }
.btn-ghost { padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); font-size: 13px; font-weight: 500; background: #fff; }
.btn-ghost:hover { background: var(--line-soft); }
.btn-danger { padding: 9px 16px; border-radius: 10px; color: var(--danger); border: 1px solid #fecaca; background: #fff; font-size: 13px; font-weight: 500; }
.btn-danger:hover { background: #fef2f2; }
.w-full { width: 100%; }

.icon-btn {
    width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center;
    justify-content: center; color: var(--faint); transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--line-soft); color: var(--muted); }
.icon-btn.danger:hover { background: #fef2f2; color: var(--danger); }
.icon-btn svg { width: 16px; height: 16px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field span { font-size: 12px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea {
    border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-size: 14px;
    color: var(--ink); background: #fff; width: 100%;
}
.field textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.req { color: var(--danger); }

/* ─── Логотип ─── */
.logo-badge {
    width: 34px; height: 34px; border-radius: 10px; color: #fff; font-weight: 800; font-size: 16px;
    background: linear-gradient(135deg, var(--brand), var(--brand2));
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.logo-badge.lg { width: 52px; height: 52px; font-size: 24px; border-radius: 14px; margin: 0 auto 12px; }

/* ─── Сайдбар ─── */
aside#sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); background: #fff;
    border-right: 1px solid var(--line); display: flex; flex-direction: column; z-index: 50;
}
.side-logo { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid var(--line-soft); }
.side-logo b { display: block; font-size: 15px; color: var(--ink); }
.side-logo small { font-size: 11px; color: var(--faint); }
.side-nav { padding: 12px 10px; flex: 1; }
.nav-item {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
    font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 2px; transition: all .15s;
}
.nav-item:hover { background: rgba(99, 102, 241, .08); color: var(--brand); }
.nav-item.active { background: rgba(99, 102, 241, .12); color: var(--brand); font-weight: 600; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 14px 14px; border-top: 1px solid var(--line-soft); }
.avatar {
    width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), var(--brand2));
    color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.avatar.xl { width: 64px; height: 64px; font-size: 26px; border-radius: 18px; }
.side-user-info { flex: 1; min-width: 0; }
.side-user-info b { display: block; font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-info small { font-size: 11px; color: var(--faint); }
.logout-btn { color: var(--faint); width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.logout-btn:hover { background: #fef2f2; color: var(--danger); }

main { margin-left: var(--sidebar-w); min-height: 100vh; }

/* ─── Страница ─── */
.page { padding: 24px; }
.page-narrow { max-width: 620px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-head h1 { font-size: 22px; font-weight: 700; color: var(--ink); }
.page-head p { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ─── Статистика (Клиенты) ─── */
.stat-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; transition: all .15s; }
.stat:hover { box-shadow: 0 4px 20px rgba(0, 0, 0, .07); transform: translateY(-2px); }
.stat small { display: block; font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat b { font-size: 22px; color: var(--ink); }

/* ─── Фильтры ─── */
.filter-row { display: flex; gap: 10px; margin-bottom: 14px; }
.filter-row input[type="search"] { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; font-size: 13px; background: #fff; }
.filter-row select { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-size: 13px; background: #fff; color: var(--muted); min-width: 170px; }

/* ─── Таблица клиентов ─── */
.table-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; min-width: 1080px; }
.tbl th {
    background: #f8fafc; font-size: 11px; color: var(--faint); text-transform: uppercase;
    letter-spacing: .05em; padding: 10px 12px; text-align: left; font-weight: 600; white-space: nowrap;
}
.tbl td { padding: 10px 12px; font-size: 13px; color: var(--text); border-top: 1px solid var(--line-soft); vertical-align: top; }
.tbl tbody tr:hover td { background: #f8fafc; }
.td-name { font-weight: 600; color: var(--ink); }
.td-wrap { max-width: 260px; }
.td-note { display: block; color: var(--faint); font-size: 11px; margin-top: 2px; }
.td-actions { white-space: nowrap; text-align: right; }
.tbl-empty { padding: 40px; text-align: center; color: var(--faint); font-size: 13px; }

.badge {
    display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 600; white-space: nowrap;
    background: color-mix(in srgb, var(--stage-color) 14%, #fff);
    color: color-mix(in srgb, var(--stage-color) 85%, #000);
}

/* ─── Kanban (Сделки) ─── */
.board-wrap { overflow-x: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
.board { display: flex; gap: 14px; min-width: max-content; align-items: flex-start; }
.kanban-col { width: 290px; flex-shrink: 0; }
.kanban-head {
    display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line);
    border-top: 3px solid var(--stage-color); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px;
}
.kanban-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--stage-color); }
.kanban-title { font-size: 13px; font-weight: 600; color: var(--ink); flex: 1; }
.kanban-count { font-size: 11px; font-weight: 700; color: var(--muted); background: var(--line-soft); border-radius: 12px; padding: 2px 8px; }
.kanban-cards { display: flex; flex-direction: column; gap: 8px; min-height: 60px; border-radius: 12px; transition: background .15s; padding: 2px; }
.kanban-cards.drop-hover { background: rgba(99, 102, 241, .1); outline: 2px dashed var(--brand); outline-offset: -2px; }

.deal-card {
    background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
    cursor: grab; transition: transform .12s, box-shadow .12s; user-select: none; -webkit-user-select: none;
}
.deal-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 0, 0, .08); }
.deal-card.dragging { opacity: .35; }
.deal-card.drag-clone {
    position: fixed; z-index: 999; pointer-events: none; width: 270px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .25); transform: rotate(2deg); opacity: .95;
}
.dc-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; }
.dc-name { font-size: 13px; font-weight: 600; color: var(--ink); line-height: 1.3; }
.dc-menu { width: 26px; height: 26px; border-radius: 7px; color: var(--faint); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.dc-menu:hover { background: var(--line-soft); color: var(--muted); }
.dc-menu svg { width: 16px; height: 16px; }
.dc-phone { display: inline-block; font-size: 12px; color: var(--brand); margin-top: 2px; }
.dc-body { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.dc-line { font-size: 12px; color: var(--text); line-height: 1.35; }
.dc-line small { display: block; font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.dc-next { color: #0e7490; font-weight: 600; }
.dc-foot { display: flex; justify-content: space-between; margin-top: 8px; font-size: 11px; color: var(--faint); }

/* ─── Меню «три точки» ─── */
.card-menu {
    position: fixed; z-index: 500; background: #fff; border: 1px solid var(--line); border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .16); padding: 6px; width: 210px; animation: fadeIn .15s ease;
}
.card-menu button {
    display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; padding: 9px 10px;
    border-radius: 8px; font-size: 13px; color: var(--text);
}
.card-menu button:hover { background: var(--line-soft); }
.card-menu button.danger { color: var(--danger); }
.card-menu button.danger:hover { background: #fef2f2; }
.card-menu button svg { width: 15px; height: 15px; color: var(--faint); }
.card-menu button.danger svg { color: var(--danger); }
.cm-sep { height: 1px; background: var(--line-soft); margin: 5px 4px; }
.cm-label { font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; padding: 4px 10px; }
.cm-stage-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ─── Drawer (панель лида) ─── */
.drawer-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 300; }
.drawer {
    position: fixed; right: 0; top: 0; height: 100%; width: 480px; max-width: 100%; background: #fff;
    z-index: 301; transform: translateX(105%); transition: transform .25s ease;
    box-shadow: -8px 0 40px rgba(0, 0, 0, .15);
}
.drawer.open { transform: translateX(0); }
.drawer-inner { display: flex; flex-direction: column; height: 100%; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 12px; border-bottom: 1px solid var(--line-soft); }
.drawer-title { font-size: 17px; font-weight: 700; color: var(--ink); }
.drawer-sub { font-size: 12px; color: var(--faint); margin-top: 2px; }
.drawer-move-note {
    margin: 12px 20px 0; padding: 10px 14px; border-radius: 10px; font-size: 13px; font-weight: 500;
    background: rgba(99, 102, 241, .1); color: var(--brand); border: 1px solid rgba(99, 102, 241, .25);
}
.drawer-tabs { display: flex; gap: 22px; padding: 0 20px; border-bottom: 1px solid var(--line-soft); }
.tab-btn { padding: 11px 0; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; }
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.drawer-foot { display: flex; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line-soft); }
.drawer-foot .spacer { flex: 1; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .span-2 { grid-column: span 2; }

.stage-sec { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; overflow: hidden; }
.stage-sec summary {
    list-style: none; cursor: pointer; padding: 11px 14px; font-size: 13px; font-weight: 600;
    color: var(--ink); background: #f8fafc; display: flex; align-items: center; user-select: none;
}
.stage-sec summary::-webkit-details-marker { display: none; }
.stage-sec summary::after { content: '▸'; margin-left: auto; color: var(--faint); transition: transform .15s; }
.stage-sec[open] summary::after { transform: rotate(90deg); }
.stage-sec > *:not(summary) { padding: 12px 14px 2px; }
.stage-sec.highlight { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(99, 102, 241, .15); }

/* ─── История ─── */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item { border: 1px solid var(--line-soft); border-radius: 12px; padding: 10px 14px; background: #fbfcfe; }
.hi-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; margin-bottom: 3px; }
.hi-action { font-weight: 700; color: var(--ink); }
.hi-at { color: var(--faint); white-space: nowrap; }
.hi-user { font-size: 11px; color: var(--brand); font-weight: 600; margin-bottom: 3px; }
.hi-details { font-size: 12px; color: var(--muted); line-height: 1.45; word-break: break-word; }
.hi-stages { font-size: 12px; color: var(--text); margin-bottom: 2px; }
.history-empty { color: var(--faint); font-size: 13px; text-align: center; padding: 30px 0; }

/* ─── Профиль ─── */
.profile-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 22px; display: flex; gap: 18px; align-items: center; }
.profile-info h2 { font-size: 18px; color: var(--ink); margin-bottom: 10px; }
.profile-rows { display: flex; gap: 26px; flex-wrap: wrap; }
.profile-rows small { display: block; font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; }
.profile-rows b { font-size: 14px; color: var(--ink); }
.profile-note {
    margin-top: 14px; background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
    border-radius: 12px; padding: 12px 16px; font-size: 13px; line-height: 1.5;
}

/* ─── Вход ─── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 30px 28px; width: 380px; max-width: 100%; box-shadow: 0 20px 60px rgba(15, 23, 42, .08); }
.login-logo { text-align: center; margin-bottom: 20px; }
.login-logo h1 { font-size: 20px; color: var(--ink); }
.login-logo p { font-size: 12px; color: var(--faint); margin-top: 3px; }
.login-error { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; border-radius: 10px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; }
.remember { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin: 4px 0 16px; cursor: pointer; }
.remember input { width: 15px; height: 15px; accent-color: var(--brand); }

/* ─── Toast ─── */
.toast {
    position: fixed; bottom: 22px; right: 22px; background: var(--ink); color: #fff; padding: 12px 20px;
    border-radius: 12px; z-index: 700; font-size: 13px; font-weight: 500;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .3); animation: fadeIn .2s ease; max-width: 90vw;
}
.toast.error { background: #b91c1c; }

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

/* ─── Мобильная шапка ─── */
.mobile-topbar {
    display: none; position: fixed; top: 0; left: 0; right: 0; height: 56px; background: #fff;
    border-bottom: 1px solid var(--line); z-index: 60; align-items: center;
    justify-content: space-between; padding: 0 14px; box-shadow: 0 2px 8px rgba(0, 0, 0, .05);
}
.topbar-logo { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.burger-btn { width: 40px; height: 40px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px; border-radius: 8px; }
.burger-btn span { display: block; width: 20px; height: 2px; background: #475569; border-radius: 2px; transition: all .25s; }
.burger-btn.open span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.burger-btn.open span:nth-child(2) { opacity: 0; }
.burger-btn.open span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 48; }
.sidebar-overlay.show { display: block; }

/* ═══════════════ МОБИЛЬНАЯ АДАПТАЦИЯ ═══════════════ */
@media (max-width: 768px) {
    .mobile-topbar { display: flex; }

    aside#sidebar { transform: translateX(-100%); transition: transform .25s ease; width: 262px; z-index: 49; }
    aside#sidebar.mobile-open { transform: translateX(0); }

    main { margin-left: 0; padding-top: 56px; }
    .page { padding: 14px; }
    .page-head { flex-wrap: wrap; }
    .page-head h1 { font-size: 19px; }

    /* Статистика 2 в ряд */
    .stat-row { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat b { font-size: 18px; }

    .filter-row { flex-direction: column; }
    .filter-row select { min-width: 0; }

    /* Kanban: колонки уже, горизонтальный скролл */
    .kanban-col { width: 265px; }

    /* Таблица клиентов → карточки, все данные сохраняются */
    .table-card { overflow: visible; background: none; border: none; }
    .tbl { min-width: 0; display: block; }
    .tbl thead { display: none; }
    .tbl tbody { display: flex; flex-direction: column; gap: 10px; }
    .tbl tbody tr { display: block; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 6px 0; }
    .tbl td { display: flex; gap: 10px; border: none; padding: 6px 14px; font-size: 13px; }
    .tbl td::before { content: attr(data-l); width: 96px; flex-shrink: 0; font-size: 11px; color: var(--faint); font-weight: 600; padding-top: 1px; }
    .tbl td[data-l=""]::before { display: none; }
    .td-wrap { max-width: none; }
    .td-actions { justify-content: flex-end; border-top: 1px solid var(--line-soft) !important; margin-top: 4px; padding-top: 10px; }

    /* Drawer на весь экран */
    .drawer { width: 100%; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: span 1; }

    /* Меню карточки — снизу, как action sheet */
    .card-menu { left: 10px !important; right: 10px; bottom: 10px; top: auto !important; width: auto; }
    .card-menu button { padding: 13px 12px; font-size: 14px; }

    .toast { left: 16px; right: 16px; bottom: 16px; text-align: center; }

    .profile-card { flex-direction: column; text-align: center; }
    .profile-rows { justify-content: center; }
}