:root {
    --navy: #0a3161;
    --red: #b31942;
    --paper: #f4f6f8;
    --ink: #172033;
    --line: #e4e8ee;
    --sans: "Outfit", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--sans);
    color: var(--ink);
    background: var(--paper);
}

button, input, select, textarea { font: inherit; }

.crm-login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: linear-gradient(160deg, #071525, var(--navy));
}

.crm-login[hidden],
.crm-shell[hidden] {
    display: none !important;
}

.crm-login form {
    width: min(420px, 100%);
    background: #fff;
    border-radius: 24px;
    padding: 1.5rem;
}

.crm-login form[hidden] {
    display: none !important;
}

.crm-login .auth-switch {
    margin: 1rem 0 0;
    text-align: center;
}

.crm-login .auth-switch a {
    color: var(--navy);
    font-weight: 600;
    text-decoration: none;
}

.crm-login .auth-switch a:hover {
    text-decoration: underline;
}

.crm-login .msg.ok {
    color: #0f6b3c;
}

.crm-logo {
    width: 140px;
    height: auto;
    display: block;
    background: #fff;
    border-radius: 18px;
}

.crm-side .crm-logo {
    width: 72px;
    margin-bottom: 0.35rem;
}

.crm-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); width: 100%; }

.crm-side, .crm-main { min-width: 0; }

.crm-side {
    background: #071525;
    color: #fff;
    padding: 1.2rem 0.9rem;
}

.crm-side strong { display: block; margin: 0.2rem 0 1rem; }

.crm-side button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    text-align: left;
    background: transparent;
    color: rgba(255, 255, 255, 0.86);
    border: 0;
    border-radius: 12px;
    padding: 0.7rem 0.8rem;
    cursor: pointer;
}

.side-toggle {
    justify-content: center;
    margin-bottom: 0.8rem;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-weight: 700;
}

.nav-badge {
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: var(--red);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
}

.nav-badge[hidden] { display: none !important; }

.crm-side button.active, .crm-side button:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }

.crm-main { padding: 1.2rem; }

.crm-top {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    margin-bottom: 1rem;
}

.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.8rem; }

.card-metric, .table-wrap, .editor {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 1rem;
}

.card-metric span { color: #66788a; font-size: 0.85rem; }
.card-metric strong { display: block; font-size: 1.5rem; }

.table-wrap { overflow: auto; margin-top: 0.8rem; }

.leads-table { overflow-x: hidden; }

.leads-table table { table-layout: fixed; }

.leads-table th,
.leads-table td {
    white-space: normal;
    overflow-wrap: anywhere;
    vertical-align: top;
}

.leads-table th:nth-child(1),
.leads-table td:nth-child(1) { width: 18%; }
.leads-table th:nth-child(2),
.leads-table td:nth-child(2) { width: 16%; }
.leads-table th:nth-child(3),
.leads-table td:nth-child(3) { width: 22%; }
.leads-table th:nth-child(4),
.leads-table td:nth-child(4) { width: 14%; }
.leads-table th:nth-child(5),
.leads-table td:nth-child(5) { width: 30%; }

.leads-table td { overflow: hidden; }

.lead-message {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    height: 4.2em;
    min-height: 4.2em;
    margin: 0;
    padding: 0;
    border: 0;
    resize: vertical;
    overflow: auto;
    background: transparent;
    color: inherit;
    line-height: 1.4;
}

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.65rem 0.5rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; color: #66788a; }

.panel { display: none; }
.panel.active { display: block; }

.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
    margin-top: 1rem;
}

.chart-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 1rem;
}

.chart-card h3 { margin: 0 0 0.75rem; font-size: 1rem; }
.chart-card p { margin: 0; color: #66788a; }
.chart-frame { position: relative; height: 280px; }

.btn {
    border: 0;
    border-radius: 999px;
    padding: 0.65rem 1rem;
    background: var(--navy);
    color: #fff;
    cursor: pointer;
}

.btn.red { background: var(--red); }
.btn.ghost { background: #eef2f6; color: var(--ink); }

.inline { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: end; }
.field { display: grid; gap: 0.25rem; }
.field input, .field textarea, .search {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.65rem 0.75rem;
}

.msg { min-height: 1.2rem; color: var(--red); }
.msg.ok { color: #0f6b3c; }

.table-actions {
    display: inline-flex;
    gap: 0.35rem;
}

.table-actions .btn {
    padding: 0.35rem 0.7rem;
    font-size: 0.82rem;
}

.crm-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(7, 21, 37, 0.55);
}

.crm-modal-backdrop[hidden] {
    display: none !important;
}

.crm-modal {
    width: min(560px, 100%);
    max-height: min(90vh, 900px);
    overflow: auto;
    background: #fff;
    border-radius: 22px;
    padding: 1.25rem;
    display: grid;
    gap: 0.75rem;
}

.crm-modal h2 {
    margin: 0;
    font-size: 1.2rem;
}

.crm-modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.crm-modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
}

.crm-modal-meta {
    margin: 0;
    color: #66788a;
    font-size: 0.9rem;
}

.crm-readonly {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 0.35rem 0.75rem;
    margin: 0;
}

.crm-readonly dt {
    color: #66788a;
    font-size: 0.85rem;
}

.crm-readonly dd {
    margin: 0;
    overflow-wrap: anywhere;
}

@media (max-width: 640px) {
    .crm-modal-grid { grid-template-columns: 1fr; }
    .crm-readonly { grid-template-columns: 1fr; }
}

.menu-btn { display: none; }

@media (min-width: 981px) {
    .crm-shell.side-collapsed { grid-template-columns: 88px 1fr; }
    .crm-shell.side-collapsed .crm-side .crm-logo,
    .crm-shell.side-collapsed .crm-side > strong,
    .crm-shell.side-collapsed .crm-side button[data-panel] { display: none; }
}

@media (max-width: 980px) {
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .chart-grid { grid-template-columns: 1fr; }
    .crm-shell { grid-template-columns: minmax(0, 1fr); }
    .crm-side {
        display: none;
        position: sticky;
        top: 0;
        z-index: 5;
        width: 100%;
        max-width: 100%;
    }
    .crm-side.open { display: block; }
    .menu-btn { display: inline-flex; }
}

.password-field { position: relative; }
.password-field input { width: 100%; box-sizing: border-box; padding-right: 6.5rem; }
.password-toggle {
    position: absolute;
    top: 50%;
    right: .45rem;
    transform: translateY(-50%);
    border: 0;
    background: transparent;
    color: var(--navy);
    font-weight: 700;
}

.inbox {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 68vh;
    border: 1px solid var(--line);
    border-radius: 18px;
    overflow: hidden;
    background: #fff;
}
.inbox-users { overflow: auto; background: #f4f7fb; border-right: 1px solid var(--line); }
.inbox-users button {
    display: grid;
    gap: 0.15rem;
    width: 100%;
    padding: 0.8rem 0.9rem;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    text-align: left;
    cursor: pointer;
}
.inbox-users button.active { background: #fff; }
.inbox-users span { color: #66788a; font-size: 0.85rem; }
.inbox-users em {
    justify-self: start;
    min-width: 1.35rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: var(--red);
    color: #fff;
    font-style: normal;
    font-size: 0.72rem;
    text-align: center;
}
.inbox-chat { display: flex; flex-direction: column; min-width: 0; min-height: 68vh; }
.inbox-log { flex: 1; overflow: auto; padding: 1rem; background: #efeae2; display: flex; flex-direction: column; gap: 0.5rem; }
.inbox-log .bubble { max-width: 75%; padding: 0.55rem 0.7rem; border-radius: 14px; background: #fff; }
.inbox-log .bubble.mine { align-self: flex-end; background: #d9fdd3; }
.inbox-log p { margin: 0; white-space: pre-wrap; }
.inbox-log time { display: block; margin-top: 0.2rem; color: #66788a; font-size: 0.72rem; }
.inbox-log img, .inbox-log video { max-width: 100%; border-radius: 10px; }
.inbox-log audio { width: 220px; }
.inbox-form { display: grid; gap: 0.45rem; padding: 0.75rem; border-top: 1px solid var(--line); }
.inbox-form .chat-composer-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.45rem;
    align-items: end;
}
.inbox-form .chat-icon-btn {
    width: 2.55rem;
    height: 2.55rem;
    border: 0;
    border-radius: 999px;
    display: inline-grid;
    place-items: center;
    background: #eef2f6;
    color: var(--navy);
    cursor: pointer;
    position: relative;
    padding: 0;
}
.inbox-form .chat-icon-btn svg { width: 1.2rem; height: 1.2rem; display: block; }
.inbox-form .chat-send-btn { background: var(--navy); color: #fff; }
.inbox-form .chat-file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    font-size: 0;
}
.inbox-form .chat-composer-input {
    min-height: 2.55rem;
    max-height: 8rem;
    resize: none;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.55rem 0.7rem;
}
.inbox-form .chat-file-name {
    margin: 0;
    color: #66788a;
    font-size: 0.82rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
@media (max-width: 800px) {
    .inbox { grid-template-columns: 1fr; }
    .inbox-users { max-height: 220px; }
}

.traffic-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: end;
    margin-bottom: 0.85rem;
}

.traffic-head h2 { margin: 0; font-size: 1.35rem; }
.traffic-head p { margin: 0.25rem 0 0; color: #66788a; }

.traffic-kpis { margin-bottom: 0.4rem; }
.traffic-kpis .card-metric em {
    display: block;
    margin-top: 0.25rem;
    font-style: normal;
    color: #66788a;
    font-size: 0.78rem;
}

.traffic-charts { margin-top: 0.85rem; }
.traffic-table-title { margin: 1.4rem 0 0.4rem; font-size: 1.05rem; }

.traffic-empty {
    margin: 0.4rem 0 0;
    color: #66788a;
    font-size: 0.92rem;
}

.traffic-hbars {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.55rem;
}

.traffic-hbars li {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.6fr) auto;
    gap: 0.55rem;
    align-items: center;
}

.traffic-hbar-label {
    font-size: 0.88rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.traffic-hbar-track {
    height: 0.55rem;
    border-radius: 999px;
    background: #eef2f6;
    overflow: hidden;
}

.traffic-hbar-fill {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--navy);
}

.traffic-hbar-value {
    font-size: 0.82rem;
    color: #66788a;
    font-variant-numeric: tabular-nums;
}

@media (max-width: 900px) {
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .chart-grid { grid-template-columns: 1fr; }
    .traffic-hbars li { grid-template-columns: minmax(0, 1fr) auto; }
    .traffic-hbar-track { grid-column: 1 / -1; order: 3; }
}
