/* ==========================================================================
   DeepChat - core stylesheet
   ========================================================================== */

:root {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --surface-2: #f7f9fb;
    --surface-3: #eef1f5;
    --border: #e3e8ef;
    --text: #111b21;
    --text-muted: #667781;
    --text-faint: #8696a0;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --accent: #06b6d4;
    --bubble-out: #d9fdd3;
    --bubble-in: #ffffff;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --success: #16a34a;
    --success-soft: #f0fdf4;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --shadow-sm: 0 1px 2px rgba(11, 20, 26, .08);
    --shadow: 0 4px 16px rgba(11, 20, 26, .10);
    --shadow-lg: 0 12px 40px rgba(11, 20, 26, .16);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 18px;
    --sidebar-w: 380px;
}

[data-theme="dark"] {
    --bg: #0b141a;
    --surface: #111b21;
    --surface-2: #1c262d;
    --surface-3: #202c33;
    --border: #2a3942;
    --text: #e9edef;
    --text-muted: #8696a0;
    --text-faint: #667781;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --primary-soft: #1e2450;
    --bubble-out: #005c4b;
    --bubble-in: #202c33;
    --danger-soft: #3b1414;
    --success-soft: #10281a;
    --warning-soft: #2e2410;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }

img { max-width: 100%; display: block; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(134, 150, 160, .4); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(134, 150, 160, .7); }

/* ==========================================================================
   Buttons, forms, alerts
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    color: var(--text);
    font-size: 14.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s, transform .05s, box-shadow .15s, opacity .15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { background: var(--border); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-3); }

.btn-block { width: 100%; margin-top: 10px; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

input[type="text"], input[type="tel"], input[type="password"],
input[type="email"], input[type="search"], input[type="number"],
select, textarea {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .14);
}

input[readonly].locked-field { background: var(--surface-3); color: var(--text-muted); cursor: not-allowed; }

textarea { resize: vertical; min-height: 80px; }

.field-label {
    display: block;
    margin: 16px 0 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.field-hint { margin-top: 5px; font-size: 12.5px; color: var(--text-faint); }
.field-error { margin-top: 7px; font-size: 13px; color: var(--danger); min-height: 18px; }

.alert {
    padding: 12px 15px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}

.alert-error { background: var(--danger-soft); color: var(--danger); border-color: currentColor; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: currentColor; }
.alert-info { background: var(--primary-soft); color: var(--primary); border-color: currentColor; }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: currentColor; }

.spinner {
    width: 15px; height: 15px;
    border: 2px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Auth screen
   ========================================================================== */

.auth-body { background: var(--bg); }

.auth-shell { display: grid; grid-template-columns: 1.05fr 1fr; min-height: 100vh; }

.auth-brand {
    background: linear-gradient(150deg, #4f46e5 0%, #6d28d9 48%, #0891b2 100%);
    color: #fff;
    padding: 56px 52px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    overflow: hidden;
}

.auth-brand::after {
    content: "";
    position: absolute;
    width: 460px; height: 460px;
    right: -160px; bottom: -190px;
    background: rgba(255, 255, 255, .09);
    border-radius: 50%;
}

.auth-brand-inner { position: relative; z-index: 1; }

.brand-logo {
    width: 60px; height: 60px;
    background: rgba(255, 255, 255, .16);
    border-radius: 17px;
    display: grid;
    place-items: center;
    margin-bottom: 26px;
}

.brand-logo svg { width: 31px; height: 31px; }

.auth-brand h1 { font-size: 40px; font-weight: 700; letter-spacing: -.5px; }
.brand-tagline { margin-top: 10px; font-size: 17px; opacity: .9; }

.brand-points { list-style: none; margin-top: 40px; display: grid; gap: 15px; }
.brand-points li { display: flex; align-items: center; gap: 12px; font-size: 15px; opacity: .95; }
.brand-points span {
    width: 24px; height: 24px;
    background: rgba(255, 255, 255, .2);
    border-radius: 50%;
    display: grid; place-items: center;
    font-size: 12px;
    flex-shrink: 0;
}

.brand-foot { position: relative; z-index: 1; font-size: 13px; opacity: .75; }

.auth-panel { display: grid; place-items: center; padding: 40px 28px; }
.auth-card { width: 100%; max-width: 400px; }

.auth-step { display: none; animation: fadeUp .28s ease; }
.auth-step.active { display: block; }

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}

.auth-card h2 { font-size: 26px; font-weight: 700; letter-spacing: -.3px; }
.auth-sub { color: var(--text-muted); margin-top: 7px; font-size: 14.5px; }

.phone-input { display: flex; align-items: stretch; }
.phone-input .country-code {
    display: grid; place-items: center;
    padding: 0 14px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-right: none;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    font-weight: 600;
    color: var(--text-muted);
}
.phone-input input {
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    letter-spacing: 1px;
    font-size: 16px;
}

.password-input { position: relative; }
.password-input input { padding-right: 62px; }
.toggle-password {
    position: absolute;
    right: 6px; top: 50%;
    transform: translateY(-50%);
    background: none; border: none;
    color: var(--primary);
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    padding: 6px 8px;
}

.identity {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 13px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
}

.identity-avatar {
    width: 46px; height: 46px;
    border-radius: 50%;
    display: grid; place-items: center;
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
    object-fit: cover;
}

.identity-meta { display: flex; flex-direction: column; min-width: 0; }
.identity-meta strong { font-size: 15.5px; }
.identity-meta span { font-size: 13.5px; color: var(--text-muted); }
.identity-meta small { font-size: 12px; color: var(--text-faint); }

.recognised-badge {
    display: inline-block;
    padding: 5px 11px;
    background: var(--success-soft);
    color: var(--success);
    border-radius: 20px;
    font-size: 12.5px;
    font-weight: 700;
    margin-bottom: 12px;
}

@media (max-width: 900px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-brand { padding: 32px 28px; }
    .auth-brand h1 { font-size: 30px; }
    .brand-points, .brand-foot { display: none; }
}

/* ==========================================================================
   Chat layout
   ========================================================================== */

.chat-app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: 100vh;
    overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.sidebar-header .me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; cursor: pointer; }
.sidebar-header .me strong { font-size: 15px; display: block; }
.sidebar-header .me span { font-size: 12.5px; color: var(--text-muted); }

.icon-btn {
    width: 38px; height: 38px;
    display: grid; place-items: center;
    border: none;
    background: transparent;
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    transition: background .15s, color .15s;
    flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.active { color: var(--primary); }

.avatar {
    border-radius: 50%;
    display: grid; place-items: center;
    color: #fff;
    font-weight: 600;
    flex-shrink: 0;
    object-fit: cover;
    user-select: none;
}
.avatar-sm { width: 34px; height: 34px; font-size: 13px; }
.avatar-md { width: 42px; height: 42px; font-size: 15px; }
.avatar-lg { width: 50px; height: 50px; font-size: 17px; }
.avatar-xl { width: 110px; height: 110px; font-size: 38px; }

.search-bar { padding: 9px 12px; border-bottom: 1px solid var(--border); }
.search-bar input {
    background: var(--surface-3);
    border-color: transparent;
    padding: 9px 14px;
    font-size: 14px;
    border-radius: 20px;
}

.sidebar-tabs { display: flex; padding: 0 12px; gap: 4px; border-bottom: 1px solid var(--border); }
.sidebar-tab {
    flex: 1;
    padding: 11px 6px;
    background: none;
    border: none;
    border-bottom: 2.5px solid transparent;
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: color .15s, border-color .15s;
}
.sidebar-tab:hover { color: var(--text); }
.sidebar-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.list-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; }

.conv-item {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 11px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background .12s;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--surface-3); }

.conv-avatar-wrap { position: relative; flex-shrink: 0; }
.online-dot {
    position: absolute;
    right: 0; bottom: 0;
    width: 12px; height: 12px;
    background: #22c55e;
    border: 2.5px solid var(--surface);
    border-radius: 50%;
}

.conv-body { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.conv-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11.5px; color: var(--text-faint); flex-shrink: 0; }
.conv-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 2px; }
.conv-preview { font-size: 13.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge {
    min-width: 20px; height: 20px;
    padding: 0 6px;
    background: var(--primary);
    color: #fff;
    border-radius: 10px;
    font-size: 11.5px;
    font-weight: 700;
    display: grid; place-items: center;
    flex-shrink: 0;
}
.badge-muted { background: var(--text-faint); }

.empty-state {
    padding: 46px 26px;
    text-align: center;
    color: var(--text-muted);
}
.empty-state svg { width: 46px; height: 46px; margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: 14px; }

/* --- Chat panel --- */
.chat-panel { display: flex; flex-direction: column; min-width: 0; background: var(--bg); position: relative; }

.chat-panel::before {
    content: "";
    position: absolute;
    inset: 0;
    opacity: .045;
    pointer-events: none;
    background-image: radial-gradient(circle at 1px 1px, var(--text) 1px, transparent 0);
    background-size: 22px 22px;
}

.chat-placeholder {
    flex: 1;
    display: grid;
    place-items: center;
    text-align: center;
    color: var(--text-muted);
    padding: 30px;
}
.chat-placeholder svg { width: 78px; height: 78px; opacity: .3; margin: 0 auto 18px; }
.chat-placeholder h3 { font-size: 22px; color: var(--text); font-weight: 600; }
.chat-placeholder p { margin-top: 8px; font-size: 14.5px; max-width: 380px; }

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    z-index: 2;
}
.chat-header .peer { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; cursor: pointer; }
.chat-header .peer h3 { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header .peer p { font-size: 12.5px; color: var(--text-muted); }
.chat-header .peer p.is-online { color: var(--success); font-weight: 600; }

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 7% 10px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    z-index: 1;
}

.date-divider { display: grid; place-items: center; margin: 14px 0 10px; }
.date-divider span {
    background: var(--surface-3);
    color: var(--text-muted);
    padding: 5px 13px;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

.system-message { display: grid; place-items: center; margin: 8px 0; }
.system-message span {
    background: var(--warning-soft);
    color: var(--warning);
    padding: 5px 14px;
    border-radius: 14px;
    font-size: 12.5px;
    text-align: center;
}

.msg-row { display: flex; gap: 8px; align-items: flex-end; margin-top: 2px; }
.msg-row.out { flex-direction: row-reverse; }
.msg-row.first-of-group { margin-top: 12px; }

.msg-avatar { width: 28px; flex-shrink: 0; }

.bubble {
    max-width: min(65%, 560px);
    padding: 7px 11px 6px;
    background: var(--bubble-in);
    border-radius: 9px;
    box-shadow: var(--shadow-sm);
    position: relative;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    animation: pop .16s ease;
}
.msg-row.out .bubble { background: var(--bubble-out); }
[data-theme="dark"] .msg-row.out .bubble { color: #e9edef; }

/* Outgoing message status — the bubble itself carries the state. */
.msg-row.out .bubble.status-sending { opacity: var(--bubble-sending-opacity, 0.55); }
.msg-row.out .bubble.status-delivered { background: var(--bubble-delivered, #e7f0ff); }
.msg-row.out .bubble.status-seen {
    background: var(--bubble-seen, #2563eb);
    color: #fff;
    transition: background 0.42s ease, color 0.42s ease;
}
.msg-row.out .bubble.status-failed {
    border-left: 3.5px solid var(--bubble-failed, #dc2626);
    opacity: 1;
}
.bubble-meta .status-icon { margin-left: 4px; font-size: 12px; opacity: 0.75; }
.bubble-meta .failed-hint {
    color: var(--bubble-failed, #dc2626);
    font-size: 10.5px;
    font-weight: 600;
    margin-right: 6px;
}
.msg-row.out .bubble.status-seen .bubble-meta,
.msg-row.out .bubble.status-seen .bubble-text a { color: rgba(255,255,255,0.92); }
.msg-row.out .bubble.status-seen .bubble-meta .status-icon { opacity: 0.9; }

@keyframes pop {
    from { opacity: 0; transform: translateY(6px) scale(.98); }
    to { opacity: 1; transform: none; }
}

.msg-row.first-of-group .bubble { border-radius: 9px 9px 9px 3px; }
.msg-row.out.first-of-group .bubble { border-radius: 9px 9px 3px 9px; }

.bubble-sender { font-size: 12.5px; font-weight: 700; margin-bottom: 3px; }
.bubble-text { font-size: 14.6px; white-space: pre-wrap; }
.bubble-text a { color: var(--primary); word-break: break-all; }

.bubble-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 2px;
    font-size: 11px;
    color: var(--text-faint);
    float: right;
    margin-left: 10px;
    position: relative;
    top: 4px;
}
.bubble-meta .ticks { display: inline-flex; }
.bubble-meta .ticks.read { color: #53bdeb; }
.bubble-meta .edited { font-style: italic; }

.bubble.deleted .bubble-text { color: var(--text-faint); font-style: italic; }

.reply-quote {
    border-left: 3.5px solid var(--primary);
    background: rgba(127, 127, 127, .11);
    border-radius: 5px;
    padding: 5px 9px;
    margin-bottom: 5px;
    cursor: pointer;
}
.reply-quote strong { font-size: 12.5px; color: var(--primary); display: block; }
.reply-quote span { font-size: 13px; color: var(--text-muted); }

.bubble-image { border-radius: 7px; overflow: hidden; margin-bottom: 3px; max-width: 320px; }
.bubble-image img { cursor: zoom-in; width: 100%; }

.file-attach {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px;
    background: rgba(127, 127, 127, .11);
    border-radius: 7px;
    text-decoration: none;
    color: inherit;
    min-width: 210px;
}
.file-attach .file-icon {
    width: 38px; height: 38px;
    background: var(--primary);
    color: #fff;
    border-radius: 7px;
    display: grid; place-items: center;
    flex-shrink: 0;
}
.file-attach .file-icon svg { width: 19px; height: 19px; }
.file-attach .file-meta { min-width: 0; }
.file-attach .file-meta strong { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-attach .file-meta span { font-size: 11.5px; color: var(--text-muted); }

.reactions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 7px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    border-radius: 11px;
    font-size: 12px;
    cursor: pointer;
}
.reaction-chip.mine { background: var(--primary-soft); border-color: var(--primary); }

.msg-actions {
    display: flex;
    gap: 2px;
    align-self: center;
    opacity: 0;
    transition: opacity .15s;
}
.msg-row:hover .msg-actions { opacity: 1; }
.msg-actions button {
    width: 27px; height: 27px;
    border: none;
    background: transparent;
    border-radius: 50%;
    color: var(--text-faint);
    cursor: pointer;
    display: grid;
    place-items: center;
    font-size: 13px;
}
.msg-actions button:hover { background: var(--surface-3); color: var(--text); }

.typing-row { display: flex; align-items: center; gap: 8px; padding: 4px 0 8px; }
.typing-bubble {
    background: var(--bubble-in);
    padding: 11px 14px;
    border-radius: 9px;
    display: flex;
    gap: 4px;
    box-shadow: var(--shadow-sm);
}
.typing-bubble i {
    width: 7px; height: 7px;
    background: var(--text-faint);
    border-radius: 50%;
    animation: bounce 1.3s infinite;
}
.typing-bubble i:nth-child(2) { animation-delay: .18s; }
.typing-bubble i:nth-child(3) { animation-delay: .36s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* --- Composer --- */
.composer-wrap { background: var(--surface-2); border-top: 1px solid var(--border); z-index: 2; }

.reply-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    background: var(--surface-3);
    border-left: 4px solid var(--primary);
}
.reply-preview .rp-body { flex: 1; min-width: 0; }
.reply-preview strong { display: block; font-size: 12.5px; color: var(--primary); }
.reply-preview span { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

.composer { display: flex; align-items: flex-end; gap: 7px; padding: 9px 14px; }

.composer textarea {
    flex: 1;
    min-height: 42px;
    max-height: 130px;
    padding: 10px 15px;
    border-radius: 21px;
    border-color: transparent;
    background: var(--surface);
    resize: none;
    font-size: 14.6px;
    line-height: 1.4;
}

.send-btn {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    display: grid;
    place-items: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, transform .1s;
}
.send-btn:hover { background: var(--primary-hover); }
.send-btn:active { transform: scale(.93); }
.send-btn svg { width: 20px; height: 20px; }

.blocked-note {
    padding: 15px;
    text-align: center;
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: 14px;
}

.emoji-panel {
    position: absolute;
    bottom: 66px; left: 14px;
    width: 306px;
    max-height: 230px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 10px;
    display: none;
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
    z-index: 30;
}
.emoji-panel.open { display: grid; }
.emoji-panel button {
    border: none;
    background: none;
    font-size: 21px;
    padding: 5px;
    border-radius: 6px;
    cursor: pointer;
    line-height: 1;
}
.emoji-panel button:hover { background: var(--surface-3); }

/* ==========================================================================
   Modals, drawers, toasts
   ========================================================================== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(11, 20, 26, .55);
    display: none;
    place-items: center;
    z-index: 100;
    padding: 20px;
    backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: grid; }

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 460px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalIn .2s ease;
}
.modal.modal-wide { max-width: 620px; }

@keyframes modalIn {
    from { opacity: 0; transform: translateY(18px) scale(.97); }
    to { opacity: 1; transform: none; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 17px 21px;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-body { padding: 21px; overflow-y: auto; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 9px;
    padding: 15px 21px;
    border-top: 1px solid var(--border);
}

.close-btn {
    background: none; border: none;
    font-size: 25px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 4px;
}
.close-btn:hover { color: var(--text); }

.pick-list { max-height: 340px; overflow-y: auto; margin-top: 12px; }
.pick-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.pick-item:hover { background: var(--surface-2); }
.pick-item .pick-meta { flex: 1; min-width: 0; }
.pick-item strong { font-size: 14.5px; display: block; }
.pick-item span { font-size: 12.5px; color: var(--text-muted); }
.pick-item input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }

.profile-view { text-align: center; }
.profile-view .avatar { margin: 0 auto 14px; }
.profile-view h3 { font-size: 21px; }
.profile-view .phone { color: var(--text-muted); margin-top: 3px; }
.profile-view .about {
    margin-top: 16px;
    padding: 13px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    font-size: 14px;
    text-align: left;
}

.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .9);
    display: none;
    place-items: center;
    z-index: 200;
    padding: 30px;
}
.lightbox.open { display: grid; }
.lightbox img { max-width: 92vw; max-height: 88vh; object-fit: contain; border-radius: 6px; }
.lightbox .close-btn { position: absolute; top: 16px; right: 24px; color: #fff; font-size: 38px; }

.toast-stack {
    position: fixed;
    bottom: 22px; right: 22px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    z-index: 300;
}
.toast {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    padding: 12px 17px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    max-width: 330px;
    animation: toastIn .25s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: none; }
}

.dropdown { position: relative; }
.dropdown-menu {
    position: absolute;
    right: 0; top: calc(100% + 6px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    min-width: 190px;
    padding: 5px;
    display: none;
    z-index: 40;
}
.dropdown-menu.open { display: block; }
.dropdown-menu button, .dropdown-menu a {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 9px 11px;
    border: none;
    background: none;
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}
.dropdown-menu button:hover, .dropdown-menu a:hover { background: var(--surface-2); }
.dropdown-menu .danger { color: var(--danger); }
.dropdown-divider { height: 1px; background: var(--border); margin: 5px 0; }

.mobile-back { display: none; }

@media (max-width: 860px) {
    .chat-app { grid-template-columns: 1fr; }
    .sidebar { display: flex; }
    .chat-panel { display: none; }
    .chat-app.viewing-chat .sidebar { display: none; }
    .chat-app.viewing-chat .chat-panel { display: flex; }
    .mobile-back { display: grid; }
    .messages { padding: 14px 12px 8px; }
    .bubble { max-width: 82%; }
}
