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

:root {
    --bg-color: #ffffff;
    --bg-soft: #f4f6fb;
    --surface-color: rgba(255, 255, 255, 0.72);
    --primary-color: #0071e3;
    --primary-hover: #0077ed;
    --text-main: #1d1d1f;
    --text-muted: #6e6e73;
    --border-color: rgba(0, 0, 0, 0.08);
    --danger-color: #ff3b30;
    --success-color: #34c759;
    --warning-color: #ff9500;
    --glass-bg: rgba(255, 255, 255, 0.55);
    --glass-border: rgba(255, 255, 255, 0.85);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.06);
    --glass-blur: blur(20px) saturate(180%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    background: var(--bg-color);
    background-image:
        radial-gradient(ellipse 80% 50% at 20% -10%, rgba(0, 113, 227, 0.08), transparent),
        radial-gradient(ellipse 60% 40% at 90% 10%, rgba(52, 199, 89, 0.06), transparent);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: 16px;
}

.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.auth-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    padding: 2.5rem;
    border-radius: 20px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--glass-shadow);
}

.auth-card h2 {
    text-align: center;
    margin-bottom: 2rem;
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-main);
}

.form-group { margin-bottom: 1.5rem; }

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: 12px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: background 0.2s, transform 0.15s;
    width: 100%;
    text-decoration: none;
}

.btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.dashboard-layout {
    display: flex;
    flex: 1;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--glass-border);
    padding: 1.25rem 0;
    display: flex;
    flex-direction: column;
}

.sidebar-logo {
    padding: 0 1.25rem 1.25rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

.nav-links { list-style: none; }

.nav-links li a {
    display: flex;
    align-items: center;
    padding: 0.65rem 1.25rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.nav-links li a:hover,
.nav-links li a.active {
    background: rgba(0, 113, 227, 0.08);
    color: var(--primary-color);
}

.main-content {
    flex: 1;
    padding: 1.75rem 2rem;
    overflow-y: auto;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.header h1 {
    font-size: 1.625rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    padding: 1.25rem;
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

.stat-title {
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    margin-bottom: 0.35rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
}

.data-table-container {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    overflow: hidden;
    margin-top: 1rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 0.875rem 1.25rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

.data-table th {
    background: rgba(255, 255, 255, 0.5);
    font-weight: 500;
    color: var(--text-muted);
}

.data-table tr:hover {
    background: rgba(0, 113, 227, 0.03);
}

.action-btn {
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    font-size: 0.8125rem;
    cursor: pointer;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.7);
    color: var(--text-main);
}

.action-btn:hover {
    background: white;
}

.btn-danger {
    background: rgba(255, 59, 48, 0.08);
    color: var(--danger-color);
    border-color: rgba(255, 59, 48, 0.2);
}

.btn-primary-sm {
    background: var(--primary-color);
    color: white;
    border: none;
}

/* CRM Kanban */
.crm-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.crm-toolbar-hint {
    flex: 1 1 220px;
    margin: 0;
}

.crm-clear-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
    min-height: 40px;
    padding: 0.5rem 0.9rem;
    font-size: 0.8125rem;
}

.crm-board-wrap {
    width: 100%;
}

.crm-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    align-items: start;
}

.crm-column {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 0.875rem;
    min-height: 200px;
    box-shadow: var(--glass-shadow);
}

.crm-column-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.crm-column-head h3 {
    font-size: 0.8125rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.crm-count {
    font-size: 0.75rem;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    color: var(--text-muted);
}

.crm-card {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: box-shadow 0.15s, transform 0.15s;
}

.crm-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    transform: translateY(-1px);
}

.crm-card-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.crm-card-title {
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.35;
    margin-bottom: 0.35rem;
}

.crm-card-actions {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.crm-card-actions .action-btn {
    min-height: 32px;
}

.modal-confirm {
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-confirm-dialog {
    max-width: 420px;
    margin: auto;
    text-align: center;
    animation: fadeIn 0.2s ease;
}

.modal-confirm-dialog h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.modal-confirm-text {
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.modal-confirm-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.modal-confirm-actions .action-btn {
    min-width: 110px;
    min-height: 44px;
    padding: 0.6rem 1rem;
}

.btn-confirm-yes {
    font-weight: 500;
}

.status-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.15rem 0.45rem;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.status-yangi { background: rgba(0, 113, 227, 0.1); color: var(--primary-color); }
.status-boglandi { background: rgba(52, 199, 89, 0.12); color: #248a3d; }
.status-adminga_yuborildi { background: rgba(255, 149, 0, 0.12); color: #c93400; }
.status-muammolar { background: rgba(255, 59, 48, 0.1); color: var(--danger-color); }

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-content {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: var(--glass-blur);
    margin: 4% auto;
    padding: 1.75rem;
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    width: 92%;
    max-width: 680px;
    max-height: 88vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.12);
}

.close-modal {
    position: absolute;
    right: 1.25rem;
    top: 1.25rem;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-content.modal-lead-dialog { max-width: 720px; }

.lead-profile-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.badge-channel {
    font-size: 0.75rem;
    padding: 0.2rem 0.55rem;
    border-radius: 6px;
    background: rgba(0, 113, 227, 0.1);
    color: var(--primary-color);
    border: 1px solid rgba(0, 113, 227, 0.2);
}

.lead-chat-stream {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    max-height: min(42vh, 400px);
    overflow-y: auto;
    padding: 0.5rem 0;
}

.lead-msg-wrap {
    display: flex;
    flex-direction: column;
    max-width: 88%;
}

.lead-msg-wrap.from-user { align-self: flex-end; align-items: flex-end; }
.lead-msg-wrap.from-ai { align-self: flex-start; align-items: flex-start; }

.lead-msg-meta {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
}

.lead-msg-bubble {
    padding: 0.6rem 0.85rem;
    border-radius: 14px;
    font-size: 0.875rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.lead-msg-bubble.user {
    background: rgba(0, 113, 227, 0.12);
    border: 1px solid rgba(0, 113, 227, 0.18);
}

.lead-msg-bubble.ai {
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid var(--border-color);
}

.switch { position: relative; display: inline-block; width: 46px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; inset: 0;
    background: #e5e5ea; transition: 0.3s; border-radius: 34px;
}
.slider:before {
    position: absolute; content: ""; height: 18px; width: 18px;
    left: 3px; bottom: 3px; background: white; transition: 0.3s; border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
input:checked + .slider { background: var(--success-color); }
input:checked + .slider:before { transform: translateX(22px); }

.hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

.sheet-wrap { padding: 0; }
.sheet-scroll { max-height: min(70vh, 720px); overflow: auto; }
.sheet-table { font-size: 0.8125rem; }
.sheet-table thead th {
    position: sticky; top: 0; z-index: 2;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 1px 0 var(--border-color);
}

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

@media (max-width: 1100px) {
    .crm-board { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .dashboard-layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 0.75rem 0;
    }
    .sidebar-logo { padding: 0 1rem 0.75rem; margin-bottom: 0.5rem; }
    .nav-links {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 0.15rem;
        padding: 0 0.5rem;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .nav-links::-webkit-scrollbar { display: none; }
    .nav-links li a {
        white-space: nowrap;
        padding: 0.55rem 0.85rem;
        font-size: 0.8125rem;
        border-radius: 10px;
    }
    .main-content { padding: 1rem; }
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
        margin-bottom: 1rem;
    }
    .header h1 { font-size: 1.375rem; }

    .crm-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .crm-clear-btn {
        width: 100%;
        justify-content: center;
    }

    .crm-board-wrap {
        margin: 0 -1rem;
        padding: 0 1rem 0.25rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        scrollbar-width: none;
    }
    .crm-board-wrap::-webkit-scrollbar { display: none; }

    .crm-board {
        display: flex;
        flex-direction: row;
        gap: 0.75rem;
        grid-template-columns: unset;
        width: max-content;
        min-width: 100%;
        padding-bottom: 0.5rem;
    }

    .crm-column {
        flex: 0 0 min(300px, 84vw);
        scroll-snap-align: start;
        max-height: min(68vh, 520px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .crm-card {
        padding: 0.875rem;
        margin-bottom: 0.6rem;
    }

    .crm-card:active {
        transform: scale(0.99);
    }

    .crm-card-actions .action-btn {
        min-height: 38px;
        padding: 0.45rem 0.65rem;
        font-size: 0.75rem;
    }

    .modal-content {
        margin: auto 0 0;
        width: 100%;
        max-width: 100%;
        border-radius: 20px 20px 0 0;
        max-height: 92vh;
        padding: 1.25rem 1rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
    }

    .modal:not(.modal-confirm) {
        align-items: flex-end;
    }

    .modal-confirm {
        align-items: center;
        padding: 1.25rem;
    }

    .modal-confirm-dialog {
        border-radius: 20px;
        margin: auto;
    }

    .modal-confirm-actions {
        flex-direction: column-reverse;
    }

    .modal-confirm-actions .action-btn {
        width: 100%;
    }

    .lead-chat-stream {
        max-height: min(50vh, 360px);
    }

    .lead-msg-wrap { max-width: 92%; }
}

.crm-alert-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(10, 132, 255, 0.08);
    color: var(--primary-color);
    border-color: rgba(10, 132, 255, 0.22);
}
.crm-alert-btn.active {
    background: rgba(52, 199, 89, 0.14);
    color: #248a3d;
    border-color: rgba(52, 199, 89, 0.28);
}
