* {
    box-sizing: border-box;
}

:root {
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #172033;
    background: #f4f6f9;
}

body {
    margin: 0;
    min-height: 100vh;
}

button,
input {
    font: inherit;
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 20%, rgba(73, 97, 255, 0.08), transparent 30%),
        radial-gradient(circle at 80% 80%, rgba(0, 169, 157, 0.07), transparent 30%),
        #f4f6f9;
}

.login-card {
    width: 100%;
    max-width: 430px;
    padding: 38px;
    background: #ffffff;
    border: 1px solid #e7eaf0;
    border-radius: 18px;
    box-shadow: 0 18px 50px rgba(26, 39, 68, 0.08);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 32px;
}

.brand-mark {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 13px;
    background: #4657e8;
    color: #ffffff;
    font-size: 22px;
    font-weight: 700;
}

.login-brand h1 {
    margin: 0 0 4px;
    font-size: 24px;
    line-height: 1.2;
}

.login-brand p {
    margin: 0;
    color: #7a8498;
    font-size: 14px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field label {
    font-size: 14px;
    font-weight: 600;
    color: #394258;
}

.field input {
    width: 100%;
    height: 48px;
    padding: 0 14px;
    border: 1px solid #d9deea;
    border-radius: 10px;
    outline: none;
    background: #ffffff;
    color: #172033;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
    border-color: #6674ed;
    box-shadow: 0 0 0 3px rgba(70, 87, 232, 0.10);
}

.login-button {
    height: 50px;
    border: 0;
    border-radius: 10px;
    background: #4657e8;
    color: #ffffff;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, opacity 0.15s;
}

.login-button:hover {
    opacity: 0.94;
}

.login-button:active {
    transform: translateY(1px);
}

.login-button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.login-error {
    padding: 11px 13px;
    border-radius: 9px;
    background: #fff0f0;
    color: #b42318;
    font-size: 14px;
    line-height: 1.4;
}

@media (max-width: 520px) {
    .login-card {
        padding: 28px 22px;
        border-radius: 14px;
    }
}

/* CRM application */

[hidden] {
    display: none !important;
}

.app {
    min-height: 100vh;
    display: flex;
    background: #f5f6f8;
}

.sidebar {
    width: 240px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    background: #ffffff;
    border-right: 1px solid #e7eaf0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 24px;
    font-size: 20px;
}

.sidebar-brand .brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    font-size: 18px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.nav-item {
    width: 100%;
    padding: 11px 13px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: #5b6476;
    text-align: left;
    cursor: pointer;
}

.nav-item:hover {
    background: #f4f5f8;
}

.nav-item.active {
    background: #eef0ff;
    color: #4657e8;
    font-weight: 600;
}

.sidebar-user {
    margin-top: auto;
    padding: 16px 8px 4px;
    border-top: 1px solid #edf0f4;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-user strong {
    font-size: 14px;
}

.sidebar-user span {
    color: #858da0;
    font-size: 12px;
}

#logout-button {
    margin-top: 10px;
    padding: 8px 0;
    border: 0;
    background: transparent;
    color: #687186;
    text-align: left;
    cursor: pointer;
}

.workspace {
    flex: 1;
    min-width: 0;
}

.topbar {
    min-height: 90px;
    padding: 20px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: #ffffff;
    border-bottom: 1px solid #e7eaf0;
}

.topbar h1 {
    margin: 0 0 4px;
    font-size: 24px;
}

.topbar p {
    margin: 0;
    color: #858da0;
    font-size: 14px;
}

.primary-button {
    padding: 11px 17px;
    border: 0;
    border-radius: 9px;
    background: #4657e8;
    color: #ffffff;
    font-weight: 600;
    cursor: pointer;
}

.content {
    padding: 30px;
}

.empty-state {
    padding: 60px 30px;
    background: #ffffff;
    border: 1px solid #e7eaf0;
    border-radius: 14px;
    text-align: center;
}

.empty-state h2 {
    margin: 0 0 8px;
    font-size: 20px;
}

.empty-state p {
    margin: 0;
    color: #858da0;
}

@media (max-width: 800px) {
    .sidebar {
        width: 190px;
    }

    .topbar,
    .content {
        padding-left: 20px;
        padding-right: 20px;
    }
}

/* CRM application */

[hidden] {
    display: none !important;
}

.app {
    min-height: 100vh;
    display: flex;
    background: #f5f6f8;
}

.sidebar {
    width: 240px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 22px 16px;
    background: #ffffff;
    border-right: 1px solid #e7eaf0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 24px;
    font-size: 20px;
}

.sidebar-brand .brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    font-size: 18px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.nav-item {
    width: 100%;
    padding: 11px 13px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: #5b6476;
    text-align: left;
    cursor: pointer;
}

.nav-item:hover {
    background: #f4f5f8;
}

.nav-item.active {
    background: #eef0ff;
    color: #4657e8;
    font-weight: 600;
}

.sidebar-user {
    margin-top: auto;
    padding: 16px 8px 4px;
    border-top: 1px solid #edf0f4;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-user strong {
    font-size: 14px;
}

.sidebar-user span {
    color: #858da0;
    font-size: 12px;
}

#logout-button {
    margin-top: 10px;
    padding: 8px 0;
    border: 0;
    background: transparent;
    color: #687186;
    text-align: left;
    cursor: pointer;
}

.workspace {
    flex: 1;
    min-width: 0;
}

.topbar {
    min-height: 90px;
    padding: 20px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: #ffffff;
    border-bottom: 1px solid #e7eaf0;
}

.topbar h1 {
    margin: 0 0 4px;
    font-size: 24px;
}

.topbar p {
    margin: 0;
    color: #858da0;
    font-size: 14px;
}

.primary-button {
    padding: 11px 17px;
    border: 0;
    border-radius: 9px;
    background: #4657e8;
    color: #ffffff;
    font-weight: 600;
    cursor: pointer;
}

.content {
    padding: 30px;
}

.empty-state {
    padding: 60px 30px;
    background: #ffffff;
    border: 1px solid #e7eaf0;
    border-radius: 14px;
    text-align: center;
}

.empty-state h2 {
    margin: 0 0 8px;
    font-size: 20px;
}

.empty-state p {
    margin: 0;
    color: #858da0;
}

@media (max-width: 800px) {
    .sidebar {
        width: 190px;
    }

    .topbar,
    .content {
        padding-left: 20px;
        padding-right: 20px;
    }
}

/* Leads */

.leads-panel {
    background: #ffffff;
    border: 1px solid #e7eaf0;
    border-radius: 14px;
    overflow: hidden;
}

.leads-summary {
    min-height: 58px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #edf0f4;
}

.leads-summary strong {
    font-size: 16px;
}

.leads-summary span {
    color: #858da0;
    font-size: 13px;
}

.leads-list {
    display: flex;
    flex-direction: column;
}

.lead-row {
    min-height: 78px;
    padding: 14px 20px;
    display: grid;
    grid-template-columns: 60px minmax(250px, 1fr) 300px;
    gap: 18px;
    align-items: center;
    border-bottom: 1px solid #edf0f4;
}

.lead-row:last-child {
    border-bottom: 0;
}

.lead-row:hover {
    background: #fafbfc;
}

.lead-id {
    color: #8a93a6;
    font-size: 13px;
}

.lead-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.lead-main strong {
    font-size: 14px;
}

.lead-main span {
    overflow: hidden;
    color: #7b8497;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lead-meta {
    display: flex;
    justify-content: flex-end;
    gap: 22px;
    color: #687186;
    font-size: 12px;
}

@media (max-width: 1000px) {
    .lead-row {
        grid-template-columns: 45px 1fr;
    }

    .lead-meta {
        grid-column: 2;
        justify-content: flex-start;
    }
}

/* Lead details */

.lead-row-clickable {
    cursor: pointer;
}

.lead-row-clickable:hover {
    background: #f7f9fc;
}

.back-button {
    border: 0;
    background: transparent;
    padding: 0;
    margin: 0 0 20px;
    font: inherit;
    font-weight: 600;
    color: #2563eb;
    cursor: pointer;
}

.back-button:hover {
    text-decoration: underline;
}

.lead-card {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
    gap: 20px;
    align-items: start;
}

.lead-card-main {
    display: grid;
    gap: 20px;
}

.lead-card-side {
    min-width: 0;
}

.detail-section {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 22px;
}

.detail-section h2 {
    margin: 0 0 18px;
    font-size: 16px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.detail-item,
.side-detail {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.detail-item span,
.side-detail span {
    color: #6b7280;
    font-size: 13px;
}

.detail-item strong,
.side-detail strong {
    font-size: 14px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.side-detail + .side-detail {
    margin-top: 18px;
}

.lead-message {
    margin: 0;
    white-space: pre-wrap;
    line-height: 1.6;
}

@media (max-width: 900px) {
    .lead-card {
        grid-template-columns: 1fr;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }
}

/* Lead activity history */

.activity-list {
    display: flex;
    flex-direction: column;
}

.activity-item {
    position: relative;
    padding: 0 0 20px 22px;
    border-left: 2px solid #e5e7eb;
}

.activity-item:last-child {
    padding-bottom: 0;
    border-left-color: transparent;
}

.activity-item::before {
    content: "";
    position: absolute;
    left: -6px;
    top: 3px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4f46e5;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #c7d2fe;
}

.activity-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
}

.activity-meta {
    margin-top: 5px;
    font-size: 12px;
    color: #6b7280;
}

.empty-activity {
    font-size: 14px;
    color: #6b7280;
}

/* Lead edit mode */

.lead-edit-title {
    width: min(620px, 100%);
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #111827;
    font: inherit;
    font-size: 22px;
    font-weight: 700;
    outline: none;
}

.lead-edit-title:focus,
.lead-edit-message:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.lead-edit-message {
    width: 100%;
    min-height: 130px;
    box-sizing: border-box;
    resize: vertical;
    padding: 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #111827;
    font: inherit;
    line-height: 1.5;
    outline: none;
}

.primary-button:disabled {
    opacity: 0.65;
    cursor: wait;
}

.lead-edit-select {
    width: 100%;
    max-width: 360px;
    box-sizing: border-box;
    padding: 9px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
    color: #111827;
    font: inherit;
    font-size: 14px;
    outline: none;
}

.lead-edit-select:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

/* Lead creation form */

.lead-create-form {
    width: 100%;
    max-width: 760px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}

.lead-create-form h2 {
    margin: 0 0 12px;
}

.lead-create-form label {
    margin-top: 10px;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
}

.lead-create-form .lead-edit-select {
    width: 100%;
    max-width: none;
    min-height: 42px;
}

.lead-create-form .lead-edit-message {
    min-height: 120px;
}

.lead-create-form .primary-button {
    align-self: flex-start;
    margin-top: 18px;
}

.lead-create-form select:disabled {
    background: #f3f4f6;
    color: #6b7280;
    cursor: not-allowed;
}


/* Компактное отображение телефонов и email в карточке контакта */
.contact-channel-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.contact-channel-group h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.contact-channel-group p {
    margin: 0;
}

/* Редактирование телефонов и email */
.contact-edit-channels {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.contact-channel-edit-card {
    border: 1px solid #dce3ee;
    border-radius: 10px;
    padding: 14px;
    background: #fafbfe;
}

.contact-channel-edit-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 600;
}

.contact-channel-edit-status {
    font-size: 12px;
    font-weight: 500;
    color: #64748b;
}

.contact-channel-edit-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.contact-channel-edit-actions label {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 0;
    cursor: pointer;
}

.contact-channel-edit-actions input[type="radio"] {
    margin: 0;
    width: auto;
}

.contact-channel-edit-actions button {
    margin: 0;
}


/* CRM Deals Kanban */

.deals-view-switch {
    display: flex;
    gap: 5px;
    margin-left: auto;
}

.deals-view-switch button {
    padding: 8px 14px;
    border: 1px solid #e1e5ee;
    border-radius: 7px;
    background: #fff;
    color: #64748b;
    cursor: pointer;
}

.deals-view-switch button.active {
    background: #4f46e5;
    border-color: #4f46e5;
    color: #fff;
}

.kanban-board {
    display: flex;
    gap: 16px;
    padding: 18px;
    overflow-x: auto;
    align-items: flex-start;
}

.kanban-board[hidden],
.leads-list[hidden] {
    display: none !important;
}

.kanban-column {
    flex: 0 0 270px;
    min-width: 270px;
    background: #f5f7fb;
    border: 1px solid #e7eaf0;
    border-radius: 10px;
    overflow: hidden;
}

.kanban-column-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 15px;
    border-bottom: 1px solid #e7eaf0;
}

.kanban-column-header strong {
    font-size: 14px;
}

.kanban-column-header span,
.kanban-column-header small {
    color: #64748b;
    font-size: 12px;
}

.kanban-column-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    min-height: 100px;
}

.kanban-card {
    display: flex;
    flex-direction: column;
    gap: 9px;
    padding: 14px;
    border: 1px solid #e7eaf0;
    border-radius: 9px;
    background: #fff;
    cursor: pointer;
}

.kanban-card:hover {
    border-color: #a5b4fc;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.05);
}

.kanban-card strong {
    font-size: 13px;
    overflow-wrap: anywhere;
}

.kanban-card span {
    font-size: 13px;
    font-weight: 600;
}

.kanban-card small,
.kanban-empty {
    color: #64748b;
    font-size: 12px;
}

/* Kanban drag and drop */

.kanban-card[draggable="true"] {
    cursor: grab;
}

.kanban-card[draggable="true"]:active {
    cursor: grabbing;
}

.kanban-dragging {
    opacity: 0.4;
}

.kanban-drop-target {
    background: #eef2ff;
    border-color: #818cf8;
}

.kanban-drop-target .kanban-column-body {
    background: #eef2ff;
}

/* Deal stage changes in activity history */

.activity-stage-change {
    margin: 5px 0;
    font-size: 13px;
    font-weight: 500;
    color: #4f46e5;
}

/* Deals manager filter */

.deals-manager-filter {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: 20px;
    font-size: 13px;
    color: #64748b;
}

.deals-manager-filter select {
    max-width: 220px;
    padding: 8px 10px;
    border: 1px solid #e1e5ee;
    border-radius: 7px;
    background: #fff;
    color: #334155;
    font: inherit;
}

@media (max-width: 750px) {
    .deals-summary {
        flex-wrap: wrap;
        gap: 10px;
        padding-top: 12px;
        padding-bottom: 12px;
    }

    .deals-manager-filter {
        margin-left: 0;
    }
}

/* Deals search */

.deals-search {
    display: flex;
    align-items: center;
    min-width: 180px;
    margin-left: 12px;
}

.deals-search input {
    width: 220px;
    max-width: 100%;
    padding: 8px 12px;
    border: 1px solid #e1e5ee;
    border-radius: 7px;
    background: #fff;
    color: #334155;
    font: inherit;
    font-size: 13px;
    outline: none;
}

.deals-search input:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

@media (max-width: 750px) {
    .deals-search {
        margin-left: 0;
        flex: 1 1 180px;
    }

    .deals-search input {
        width: 100%;
    }
}

/* Deals sorting */

.deals-sort {
    display: flex;
    align-items: center;
}

.deals-sort select {
    max-width: 210px;
    padding: 8px 10px;
    border: 1px solid #e1e5ee;
    border-radius: 7px;
    background: #fff;
    color: #334155;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.deals-sort select:focus {
    outline: 2px solid #a5b4fc;
    outline-offset: 1px;
}
/* Local CRM stage 1 controls. */
.record-actions, .dialog-actions { display:flex; gap:10px; flex-wrap:wrap; margin-bottom:18px; }
.record-actions button, .dialog-actions button { padding:10px 16px; cursor:pointer; border-radius:8px; border:1px solid #d6dce6; }
.record-actions button[aria-pressed="true"] { background:#e5edff; border-color:#4564ad; }
.crm-dialog { width:min(540px, 90vw); border:1px solid #d6dce6; border-radius:14px; padding:24px; }
.crm-dialog::backdrop { background:rgba(20,30,50,.4); }
.crm-dialog .field { display:flex; flex-direction:column; gap:8px; margin:12px 0; }
.crm-dialog input, .crm-dialog textarea { padding:10px; border:1px solid #cdd5df; border-radius:6px; font:inherit; }
.interaction-card { border:1px solid #dbe1ec; border-left:5px solid #64748b; border-radius:10px; padding:18px; margin:16px 0; background:#fff; }
.interaction-phone { border-left-color:#0d9488; } .interaction-email { border-left-color:#4f46e5; }
.interaction-form { border-left-color:#d97706; } .interaction-chat { border-left-color:#9333ea; }
.interaction-card header { display:flex; justify-content:space-between; gap:12px; flex-wrap:wrap; }
.interaction-card pre, .detail-section details pre { white-space:pre-wrap; overflow-wrap:anywhere; font:inherit; background:#f8fafc; padding:10px; }
.interaction-card summary, .detail-section details summary { cursor:pointer; padding:10px 0; }
.interaction-data { display:grid; grid-template-columns:minmax(130px,1fr) 2fr; gap:8px; }
.interaction-data dd { margin:0; overflow-wrap:anywhere; } .interaction-data dt { color:#64748b; }
.interaction-materials a { display:inline-block; margin-left:12px; } .first-interaction { padding:14px; background:#f1f5ff; margin-bottom:18px; }
.crm-dialog { max-height:90vh; overflow:auto; } .crm-dialog select { padding:10px; font:inherit; }
.merge-comparison { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px; }
.merge-table-wrap { overflow-x:auto; margin:16px 0; }
.merge-table { width:100%; border-collapse:collapse; background:white; }
.merge-table th, .merge-table td { padding:12px; border:1px solid #e2e5ed; text-align:left; vertical-align:top; }
#merge-confirm-form, #undo-confirm-form { margin:24px 0; padding:18px; border:1px solid #d9ddea; border-radius:12px; background:white; }
#undo-review-form select { min-width:240px; }
[role="tab"][aria-selected="true"] { border-color:#5655df; color:#4544cd; background:#efefff; }
@media(max-width:800px) { .merge-comparison { grid-template-columns:1fr; } }
/* Compact task indicators reuse the existing cards and dialogs. */
.work-badge{display:block;margin-top:6px;padding:4px 7px;border-radius:6px;background:#eef1ff;color:#394b83}
.work-0{background:#fff0ef;color:#a22}.work-1{background:#fff6da;color:#785500}
