/* Связистер — minimal dark UI. Inspired by CorpChat but simpler. */

:root {
    --bg: #0b1220;
    --bg-2: #141d30;
    --bg-3: #1c2840;
    --bg-bubble-mine: linear-gradient(135deg, #2f7cf6, #1e67df);
    --bg-bubble-theirs: #1c2d48;
    --text: #f1f5f9;
    --text-soft: #93a7c3;
    --text-faint: rgba(255, 255, 255, 0.35);
    --line: rgba(148, 163, 184, 0.16);
    --line-strong: rgba(148, 163, 184, 0.32);
    --blue: #2f7cf6;
    --blue-soft: rgba(47, 124, 246, 0.18);
    --green: #18c48f;
    --red: #ef5b5b;
    --amber: #f5b742;
    --radius: 12px;
    --radius-lg: 18px;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

input, button, textarea, select {
    font: inherit;
    color: inherit;
}

button { cursor: pointer; }
.hidden { display: none !important; }
.small { font-size: 12px; }
.muted { color: var(--text-soft); }
.mono { font-family: ui-monospace, "Cascadia Code", "Consolas", monospace; }
.error { color: var(--red); margin: 6px 0; min-height: 16px; }
.warn { background: rgba(245, 183, 66, 0.12); border: 1px solid rgba(245, 183, 66, 0.4); color: #ffe5a8; padding: 10px; border-radius: var(--radius); margin: 8px 0; font-size: 13px; }

label {
    display: block;
    margin: 10px 0;
}
label > span { display: block; font-size: 12px; color: var(--text-soft); margin-bottom: 4px; }
label.checkbox { display: flex; align-items: center; gap: 8px; }
label.checkbox > span { margin-bottom: 0; }

input[type="text"], input[type="password"] {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-3);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: var(--radius);
    outline: none;
}
input[type="text"]:focus, input[type="password"]:focus {
    border-color: var(--blue);
    background: var(--bg-2);
}

.btn-primary {
    background: linear-gradient(135deg, #3b8aff, #1e67df);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 10px 18px;
    font-weight: 600;
}
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary.block { width: 100%; }
.btn-secondary {
    background: var(--bg-3);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px 14px;
    text-decoration: none;
    display: inline-block;
}
.btn-text {
    background: transparent;
    border: none;
    color: var(--text-soft);
    padding: 6px 8px;
    border-radius: 6px;
}
.btn-text:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.btn-text.small { padding: 4px 6px; }

/* ─── Modal shell ───────────────────────────────────────────────────────── */

.modal {
    position: fixed; inset: 0;
    background: rgba(8, 12, 24, 0.7);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}
.modal.open { display: flex; }
.modal-card {
    width: min(420px, 100%);
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
}
.modal-card h1 { margin: 0 0 4px; font-size: 24px; }
.modal-card h2 { margin: 14px 0 8px; font-size: 18px; }
.modal-card p { margin: 8px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 8px;
}
.subtitle { font-size: 13px; }

.logo-circle {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    flex-shrink: 0;
    background: linear-gradient(135deg, #5aa9ff, #1e67df);
    box-shadow:
        0 0 0 3px rgba(47, 124, 246, 0.16),
        0 4px 14px rgba(47, 124, 246, 0.30);
    animation: logo-breathe 3.6s ease-in-out infinite;
}
/* 3D shine highlight — gives the circle a subtle "ball" feel */
.logo-circle::after {
    content: '';
    position: absolute;
    top: 6px;
    left: 9px;
    width: 16px;
    height: 10px;
    border-radius: 50%;
    background: radial-gradient(ellipse at center, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 70%);
    pointer-events: none;
}
/* Orbital arc — only visible while .loading is active */
.logo-circle::before {
    content: '';
    position: absolute;
    inset: -7px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: #7ab8ff;
    border-right-color: rgba(122, 184, 255, 0.45);
    opacity: 0;
    transform: rotate(0deg);
    transition: opacity 0.25s ease;
    pointer-events: none;
}
.logo-circle.loading::before {
    opacity: 1;
    animation: logo-spin 1.1s linear infinite;
}
.logo-circle.loading {
    animation: logo-breathe 1.6s ease-in-out infinite;
}

@keyframes logo-breathe {
    0%, 100% {
        box-shadow:
            0 0 0 3px rgba(47, 124, 246, 0.16),
            0 4px 14px rgba(47, 124, 246, 0.30);
        transform: scale(1);
    }
    50% {
        box-shadow:
            0 0 0 6px rgba(47, 124, 246, 0.08),
            0 6px 24px rgba(47, 124, 246, 0.55);
        transform: scale(1.05);
    }
}
@keyframes logo-spin {
    to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
    .logo-circle, .logo-circle.loading { animation: none; }
    .logo-circle.loading::before { animation-duration: 2s; }
}

/* ─── App layout ────────────────────────────────────────────────────────── */

.app {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 100dvh;
}
@media (max-width: 760px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .app.show-sidebar .sidebar { display: flex; }
    .app.show-sidebar .chat-area { display: none; }
}

.sidebar {
    display: flex;
    flex-direction: column;
    background: var(--bg-2);
    border-right: 1px solid var(--line);
    overflow: hidden;
}
.topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px;
    border-bottom: 1px solid var(--line);
}
.me-card {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}
.me-info { min-width: 0; }
.me-name { font-weight: 600; }
.me-key {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-soft);
}
.net-status {
    display: flex;
    align-items: center;
    gap: 6px;
}
.net-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-faint);
}
.net-dot.online { background: var(--green); box-shadow: 0 0 0 4px rgba(24, 196, 143, 0.12); }
.net-dot.offline { background: var(--amber); }

.sidebar-actions { padding: 10px 14px; }

.contact-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}
.contact-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px;
    background: transparent;
    border: none;
    border-radius: var(--radius);
    text-align: left;
    color: var(--text);
}
.contact-row:hover { background: var(--bg-3); }
.contact-row.active { background: var(--blue-soft); }
.contact-body { flex: 1; min-width: 0; }
.contact-top, .contact-bottom {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}
.contact-name { font-weight: 600; }
.contact-preview {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.unread-badge {
    background: var(--blue);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 22px;
    text-align: center;
}

.empty {
    padding: 24px;
    text-align: center;
    color: var(--text-soft);
    font-size: 13px;
}
.empty.illu { padding: 80px 24px; }

/* ─── Avatars ───────────────────────────────────────────────────────────── */

.avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    color: #fff;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-transform: uppercase;
    font-size: 13px;
}
.avatar.small { width: 30px; height: 30px; font-size: 11px; }

/* ─── Chat area ─────────────────────────────────────────────────────────── */

.chat-area {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}
.chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(20, 29, 48, 0.5);
}
.chat-title-block { flex: 1; min-width: 0; }
.chat-title { font-weight: 600; }
.chat-actions {
    display: flex;
    gap: 4px;
}

.messages-box {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.messages-box.drop-active {
    background: rgba(47, 124, 246, 0.08);
    outline: 2px dashed var(--blue);
    outline-offset: -10px;
}

.msg {
    display: flex;
    max-width: 70%;
}
.msg.mine { align-self: flex-end; }
.msg.theirs { align-self: flex-start; }

.bubble {
    padding: 9px 13px;
    border-radius: var(--radius-lg);
    background: var(--bg-bubble-theirs);
    color: var(--text);
    word-break: break-word;
    border: 1px solid var(--line);
}
.msg.mine .bubble {
    background: var(--bg-bubble-mine);
    color: #fff;
    border-color: transparent;
    border-bottom-right-radius: 6px;
}
.msg.theirs .bubble {
    border-bottom-left-radius: 6px;
}
.msg-text { white-space: pre-wrap; }
.msg-meta {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    align-items: center;
    margin-top: 4px;
    opacity: 0.7;
    font-size: 11px;
}

/* ─── File attachment block ─────────────────────────────────────────────── */

.file-block {
    background: rgba(0, 0, 0, 0.18);
    border-radius: 10px;
    padding: 8px 10px;
    margin: 4px 0;
}
.msg.mine .file-block { background: rgba(255, 255, 255, 0.12); }

.file-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.file-icon { font-size: 22px; }
.file-meta { flex: 1; min-width: 0; }
.file-name { font-weight: 600; word-break: break-all; }
.file-sub { opacity: 0.85; }

.progress {
    height: 4px;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 6px;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b8aff, #5aa9ff);
    transition: width 0.2s ease;
}

/* ─── Composer ──────────────────────────────────────────────────────────── */

.composer {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    background: rgba(20, 29, 48, 0.6);
}
.composer input[type="text"] { flex: 1; }
.composer .btn-primary {
    width: 44px;
    padding: 0;
    height: 40px;
    font-size: 16px;
}
.composer .btn-text {
    width: 38px;
    height: 38px;
    align-self: center;
}

/* ─── Dialogs (custom prompt/confirm/alert) ─────────────────────────────── */

.dialog-modal {
    position: fixed; inset: 0;
    background: rgba(8, 12, 24, 0.7);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
}
.dialog-card {
    width: min(420px, 100%);
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 22px;
    box-shadow: var(--shadow);
}
.dialog-card h2 { margin: 0 0 10px; font-size: 17px; }
.dialog-body { margin: 6px 0 14px; }
.dialog-body p { margin: 6px 0; }
.dialog-body input[type="text"], .dialog-body .dialog-textarea {
    width: 100%;
    margin-top: 8px;
}
.dialog-textarea {
    padding: 9px 12px;
    background: var(--bg-3);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: var(--radius);
    outline: none;
    resize: vertical;
    font-family: inherit;
}
.dialog-textarea:focus { border-color: var(--blue); background: var(--bg-2); }
.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
.btn-danger {
    background: linear-gradient(135deg, #f56b6b, #d04545);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 10px 18px;
    font-weight: 600;
}
.btn-danger:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Popup menu (per-message, etc) ─────────────────────────────────────── */

.popup-menu {
    position: fixed;
    background: var(--bg-2);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 6px;
    min-width: 200px;
    z-index: 300;
    display: flex;
    flex-direction: column;
}
.popup-menu-item {
    background: transparent;
    color: var(--text);
    border: none;
    text-align: left;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
}
.popup-menu-item:hover { background: var(--bg-3); }
.popup-menu-item.danger { color: var(--red); }
.popup-menu-item.danger:hover { background: rgba(239, 91, 91, 0.12); }
.popup-menu-divider {
    height: 1px;
    background: var(--line);
    margin: 4px 6px;
}

/* ─── Per-message menu trigger + edited tag + deleted state ─────────────── */

.bubble {
    position: relative;
}
.msg-menu-trigger {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border: none;
    background: rgba(0, 0, 0, 0.32);
    color: rgba(255, 255, 255, 0.85);
    border-radius: 50%;
    font-size: 14px;
    line-height: 1;
    padding: 0;
    opacity: 0;
    transition: opacity 0.12s ease;
}
.msg.theirs .msg-menu-trigger {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
}
.msg:hover .msg-menu-trigger,
.msg-menu-trigger:focus { opacity: 1; }
@media (pointer: coarse) {
    .msg-menu-trigger { opacity: 0.6; }
}
.msg-edited { opacity: 0.7; font-style: italic; }
.msg.deleted .bubble {
    background: var(--bg-3);
    border-style: dashed;
    color: var(--text-soft);
}
.msg.deleted.mine .bubble {
    background: rgba(47, 124, 246, 0.18);
}
.msg-deleted-text { font-style: italic; opacity: 0.8; }

mark {
    background: rgba(245, 183, 66, 0.45);
    color: inherit;
    border-radius: 3px;
    padding: 0 2px;
}

/* ─── Chat-area search ──────────────────────────────────────────────────── */

.chat-search {
    display: none;
    align-items: center;
    gap: 4px;
    flex: 1;
    max-width: 320px;
    margin-left: 8px;
}
.chat-search.open { display: flex; }
.chat-search input[type="text"] {
    flex: 1;
    padding: 6px 10px;
    background: var(--bg-3);
    border: 1px solid var(--line);
    color: var(--text);
    border-radius: var(--radius);
    outline: none;
    font-size: 13px;
}
.chat-search input[type="text"]:focus { border-color: var(--blue); background: var(--bg-2); }
.chat-search.open ~ .chat-actions #btn-toggle-search { color: var(--blue); }

/* ─── Edit-mode banner above composer ───────────────────────────────────── */

.edit-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: var(--blue-soft);
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    border-left: 3px solid var(--blue);
}
.edit-banner-icon {
    color: var(--blue);
    font-size: 16px;
}
.edit-banner-body {
    flex: 1;
    min-width: 0;
}
.edit-banner-preview {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}
.composer.editing .btn-primary {
    background: linear-gradient(135deg, #18c48f, #11a378);
}

/* ─── QR modals ────────────────────────────────────────────────────────── */

.qr-card { width: min(360px, 100%); text-align: center; }
.qr-wrap {
    display: flex;
    justify-content: center;
    margin: 6px 0 12px;
}
.qr-wrap svg {
    width: 240px;
    height: 240px;
    border-radius: 8px;
    background: #fff;
    padding: 8px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
}
.qr-info { margin-bottom: 10px; }
.qr-pubkey, .qr-link {
    word-break: break-all;
    background: var(--bg-3);
    border-radius: 8px;
    padding: 6px 10px;
    margin-top: 6px;
    text-align: left;
}

.scan-card { width: min(420px, 100%); }
.scan-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    margin: 6px 0 4px;
}
.scan-frame video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.scan-overlay {
    position: absolute; inset: 0;
    pointer-events: none;
    border: 2px solid var(--blue);
    border-radius: var(--radius);
    box-shadow: 0 0 0 2000px rgba(8, 12, 24, 0.4) inset;
    margin: 16%;
}

.btn-secondary.block-row {
    display: block;
    width: 100%;
    text-align: center;
    margin: -2px 0 4px;
}

/* ─── Calls: incoming-call modal ────────────────────────────────────────── */

.incoming-call-modal {
    position: fixed; inset: 0;
    background: rgba(8, 12, 24, 0.85);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 400;
    animation: fadeIn 0.18s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.97); }
    to   { opacity: 1; transform: scale(1); }
}
.incoming-call-card {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 36px 28px 24px;
    width: min(360px, 100%);
    text-align: center;
    box-shadow: var(--shadow);
}
.incoming-avatar {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    margin: 0 auto 16px;
    font-size: 32px;
    box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.06), 0 0 0 12px rgba(47, 124, 246, 0.18);
    animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.06), 0 0 0 12px rgba(47, 124, 246, 0.18); }
    50%      { box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.10), 0 0 0 22px rgba(47, 124, 246, 0.06); }
}
.incoming-name { font-size: 22px; font-weight: 600; }
.incoming-kind { margin-top: 4px; font-size: 13px; }
.incoming-actions {
    display: flex;
    justify-content: center;
    gap: 28px;
    margin-top: 26px;
}
.btn-call-decline, .btn-call-accept {
    background: transparent;
    border: none;
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 12px;
}
.btn-call-emoji {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 22px;
    font-weight: 700;
}
.btn-call-decline .btn-call-emoji { background: var(--red); }
.btn-call-accept  .btn-call-emoji { background: var(--green); }
.btn-call-text { font-size: 13px; }

/* ─── Calls: active-call panel ──────────────────────────────────────────── */

.active-call-panel {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 250;
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.active-call-panel.audio { width: 280px; }
.active-call-panel.video { width: min(420px, calc(100vw - 32px)); }

.call-audio-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 120px;
    background: linear-gradient(180deg, #0f1a30 0%, #0b1220 100%);
}
.call-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    font-size: 28px;
    box-shadow: 0 0 0 4px rgba(47, 124, 246, 0.25);
    animation: callBreath 2s ease-in-out infinite;
}
@keyframes callBreath {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

.call-video-grid {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #000;
}
.call-remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.call-local-video {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 30%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: #111;
}

.call-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-top: 1px solid var(--line);
}
.call-bar-info { flex: 1; min-width: 0; }
.call-bar-name { font-weight: 600; }
.call-bar-actions {
    display: flex;
    gap: 6px;
}
.btn-call-control {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--bg-3);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    cursor: pointer;
}
.btn-call-control:hover { background: var(--line); }
.btn-call-control.danger {
    background: var(--red);
    border-color: var(--red);
    color: #fff;
}
.btn-call-control.danger:hover { background: #d04545; }

/* ─── Call entries inside the chat history ──────────────────────────────── */

.call-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}
.call-entry-icon { font-size: 18px; }
.call-entry-arrow { opacity: 0.7; }
.call-entry-label { font-weight: 500; }
.call-entry.missed .call-entry-icon { color: var(--red); filter: hue-rotate(330deg); }
.call-entry.missed .call-entry-label { color: var(--red); }

@media (max-width: 760px) {
    .active-call-panel.video { width: calc(100vw - 32px); }
    .active-call-panel.audio { width: calc(100vw - 32px); }
}

/* ─── Scrollbar ─────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.18);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.35); }
