/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:          #0f1117;
    --bg2:         #1a1d27;
    --bg3:         #22263a;
    --border:      #2e3348;
    --accent:      #4f8ef7;
    --accent2:     #36d399;
    --accent3:     #f7b731;
    --text:        #e2e8f0;
    --text-muted:  #6b7280;
    --danger:      #ef4444;
    --radius:      10px;
    --shadow:      0 4px 24px rgba(0,0,0,0.4);
    --header-h:    56px;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────────────── */
.chat-header {
    height: var(--header-h);
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    flex-shrink: 0;
    gap: 1rem;
}

.header-left, .header-right { display: flex; align-items: center; gap: 0.75rem; }

.logo { font-size: 1.1rem; font-weight: 700; color: var(--accent); white-space: nowrap; }

.room-select, .lang-select {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.85rem;
    cursor: pointer;
}

.user-info { font-size: 0.85rem; color: var(--text-muted); }

.conn-status {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.conn-status.connected    { background: var(--accent2); box-shadow: 0 0 6px var(--accent2); }
.conn-status.disconnected { background: var(--danger); }
.conn-status.connecting   { background: var(--accent3); animation: pulse 1s infinite; }

@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:0.4 } }

/* ── Main Layout ──────────────────────────────────────────────────── */
.chat-layout {
    flex: 1;
    display: grid;
    grid-template-columns: 42% 1fr;
    gap: 0;
    overflow: hidden;
    min-height: 0;
}

/* ── Panels ───────────────────────────────────────────────────────── */
.panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.panel-left  { background: var(--bg2); border-right: 1px solid var(--border); }
.panel-right { background: var(--bg); }

.panel-header {
    padding: 0.9rem 1rem 0.6rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.panel-header h2 { font-size: 0.95rem; font-weight: 600; display: flex; align-items: center; gap: 0.5rem; margin: 0; }

.badge {
    font-size: 0.7rem;
    background: var(--accent);
    color: #fff;
    border-radius: 4px;
    padding: 1px 6px;
    font-weight: 500;
}

/* ── Messages ─────────────────────────────────────────────────────── */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 0;
}

.message {
    background: var(--bg3);
    border-radius: var(--radius);
    padding: 0.6rem 0.85rem;
    border-left: 3px solid var(--accent);
    animation: fadeIn 0.2s ease;
}
.message.mine { border-left-color: var(--accent2); }

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

.msg-meta {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}
.msg-author { font-size: 0.78rem; font-weight: 600; color: var(--accent); }
.message.mine .msg-author { color: var(--accent2); }
.msg-lang   { font-size: 0.7rem;  color: var(--text-muted); }
.msg-time   { font-size: 0.68rem; color: var(--text-muted); margin-left: auto; }
.msg-text   { font-size: 0.88rem; line-height: 1.5; }

.msg-translate {
    background: none; border: none; cursor: pointer;
    font-size: 0.72rem; padding: 0 0.25rem;
    opacity: 0.35; transition: opacity 0.15s;
    vertical-align: middle; line-height: 1;
}
.msg-translate:hover { opacity: 1; }
.msg-translate:disabled { opacity: 0.2; cursor: default; }
.msg-translation {
    margin-top: 0.35rem;
    padding: 0.35rem 0.6rem;
    background: var(--bg2);
    border-left: 2px solid var(--accent2);
    border-radius: 4px;
    font-size: 0.82rem;
    color: var(--accent2);
    line-height: 1.45;
}

/* ── Typing Indicator ─────────────────────────────────────────────── */
.typing-indicator {
    padding: 0.3rem 1rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
    flex-shrink: 0;
}

/* ── Participants ─────────────────────────────────────────────────── */
.participants-section {
    border-top: 1px solid var(--border);
    padding: 0.6rem 1rem;
    flex-shrink: 0;
    max-height: 160px;
    overflow-y: auto;
}
.participants-section h4 { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.4rem; display: flex; gap: 0.4rem; align-items: center; }
.count { background: var(--bg3); border-radius: 10px; padding: 0 6px; font-size: 0.72rem; }

.participant-list { list-style: none; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.participant-list li {
    background: var(--bg3);
    border-radius: 20px;
    padding: 2px 10px;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.online-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent2); }

/* ── Right Panel Tabs ─────────────────────────────────────────────── */
.panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.tab-btn {
    flex: 1;
    padding: 0.7rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}
.tab-btn:hover  { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; flex: 1; overflow: hidden; min-height: 0; flex-direction: column; }
.tab-content.active { display: flex; }

/* ── Workspace ────────────────────────────────────────────────────── */
.workspace {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    overflow-y: auto;
    flex: 1;
}

.step label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

textarea {
    width: 100%;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0.65rem 0.85rem;
    font-size: 0.9rem;
    resize: vertical;
    min-height: 90px;
    font-family: inherit;
    line-height: 1.5;
    transition: border-color 0.15s;
}
textarea:focus { outline: none; border-color: var(--accent); }

.text-preview {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem 0.85rem;
    font-size: 0.9rem;
    line-height: 1.5;
    min-height: 60px;
    white-space: pre-wrap;
}
.text-preview.editable:focus { outline: 1px solid var(--accent); }

.step-improved .text-preview { border-color: var(--accent3); }
.step-translated .text-preview { border-color: var(--accent2); }

.step-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
    padding: 0.45rem 1rem;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: opacity 0.15s, transform 0.1s;
    white-space: nowrap;
}
.btn:hover   { opacity: 0.85; }
.btn:active  { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent);  color: #fff; }
.btn-success { background: var(--accent2); color: #0f1117; }
.btn-ghost   { background: var(--bg3); color: var(--text-muted); border: 1px solid var(--border); }
.btn-sm      { padding: 0.3rem 0.7rem; font-size: 0.78rem; }

/* ── Mic Button ───────────────────────────────────────────────────── */
.btn-mic-active {
    background: var(--danger) !important;
    color: #fff !important;
    animation: pulse 1s infinite;
}

/* ── AI Spinner ───────────────────────────────────────────────────── */
.ai-spinner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg3);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--text-muted);
}
.spinner {
    width: 18px; height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ── Private Chat ─────────────────────────────────────────────────── */
.private-layout {
    display: grid;
    grid-template-columns: 180px 1fr;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.contact-list {
    border-right: 1px solid var(--border);
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    overflow-y: auto;
    background: var(--bg2);
}

.contact-item {
    padding: 0.5rem 0.65rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: background 0.1s;
}
.contact-item:hover  { background: var(--bg3); }
.contact-item.active { background: var(--accent); color: #fff; }

.private-chat {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.private-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-height: 0;
}

.pm { font-size: 0.85rem; padding: 0.4rem 0.65rem; border-radius: 6px; max-width: 80%; }
.pm.mine    { background: var(--accent); color: #fff; align-self: flex-end; }
.pm.theirs  { background: var(--bg3); align-self: flex-start; }

.private-input {
    display: flex;
    gap: 0.4rem;
    padding: 0.6rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.private-input input {
    flex: 1;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 0.45rem 0.75rem;
    font-size: 0.85rem;
    font-family: inherit;
}
.private-input input:focus { outline: none; border-color: var(--accent); }

/* ── Unread Badge ─────────────────────────────────────────────────── */
.unread-badge {
    background: var(--danger);
    color: #fff;
    border-radius: 10px;
    padding: 0 6px;
    font-size: 0.68rem;
    font-weight: 700;
}

/* ── Modal ────────────────────────────────────────────────────────── */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}
.modal-content {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}
.modal-content h3 { font-size: 1.1rem; }
.modal-input {
    width: 100%;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
    font-family: inherit;
}
.modal-input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.25rem; }

.muted { font-size: 0.82rem; color: var(--text-muted); }
.error-msg { color: var(--danger); font-size: 0.82rem; }

/* ── Auth Tabs ────────────────────────────────────────────────────── */
.auth-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
}
.auth-tab {
    flex: 1;
    padding: 0.55rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.15s;
}
.auth-tab:hover  { color: var(--text); }
.auth-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Scrollbar ────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 700px) {
    .chat-layout { grid-template-columns: 1fr; }
    .panel-left  { display: none; }
}
