﻿:root {
    --bg: #1e1b1a;
    --surface: #2c2522;
    --border: #4a3f3a;
    --text: #f5e6d3;
    --text-secondary: #c4a88b;
    --primary: #f97316;
    --primary-hover: #ea580c;
    --primary-text: #1e1b1a;
    --message-mine: #4a3525;
    --message-other: #2c2522;
    --pinned-bg: #33261e;
    --shadow: 0 4px 12px rgba(0,0,0,0.4);
    --radius: 14px;
    --transition: 0.2s ease;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body.light {
    --bg: #f5f7fa;
    --surface: #ffffff;
    --border: #dce1e8;
    --text: #1e293b;
    --text-secondary: #64748b;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-text: #ffffff;
    --message-mine: #e0e7ff;
    --message-other: #ffffff;
    --pinned-bg: #fffbeb;
    --shadow: 0 4px 12px rgba(0,0,0,0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: stretch;
    transition: background var(--transition), color var(--transition);
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* ==================== Layout ==================== */
#app {
    width: 100%;
    max-width: 1100px;
    display: flex;
    background: var(--surface);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    height: 100%;
    margin: 0 auto;
    overflow: hidden;
    transition: background var(--transition), border var(--transition);
}

@media (min-width: 701px) {
    #app {
        height: 95vh;
        margin: 2.5vh auto;
        border-radius: var(--radius);
    }
}

/* ==================== Sidebar Toggle Button ==================== */
.hidden {
    display: none !important;
}
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 100;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

@media (max-width: 700px) {
    .sidebar-toggle {
        display: block;
    }
}

/* ==================== Sidebar ==================== */
.sidebar {
    width: 100%;
    max-width: 320px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    transition: background var(--transition), border var(--transition), transform 0.3s ease;
    flex-shrink: 0;
}

@media (max-width: 700px) {
    .sidebar {
        max-width: 100%;
        width: 100%;
        border-right: none;
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
    }

    .sidebar.visible {
        transform: translateX(0);
    }

    .main {
        display: flex;
        width: 100%;
        flex: 1;
        flex-direction: column;
        transition: transform 0.3s ease;
    }

    .main.shifted {
        transform: scale(0.95);
        opacity: 0.5;
        pointer-events: none;
    }

    .sidebar.hidden {
        display: flex;
    }
}

.sidebar-header {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.app-title {
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--primary);
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text);
    transition: all var(--transition);
}

.icon-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.contact-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    -webkit-overflow-scrolling: touch;
}

.contact-item {
    padding: 14px 16px;
    cursor: pointer;
    border-radius: var(--radius);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background var(--transition);
    color: var(--text);
    position: relative;
}

.contact-item:active {
    background: rgba(0,0,0,0.05);
}

.contact-item.active {
    background: var(--primary);
    color: var(--primary-text);
}

.contact-avatar {
    font-size: 2rem;
    line-height: 1;
}

.contact-name {
    flex: 1;
    font-weight: 500;
}

.delete-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition);
    padding: 4px;
    border-radius: 50%;
    color: inherit;
}

.contact-item:hover .delete-btn {
    opacity: 0.5;
}

.delete-btn:hover {
    opacity: 1;
    background: rgba(255,255,255,0.2);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

@media (min-width: 701px) and (max-width: 1024px) {
    #app {
        height: 100vh;
        margin: 0;
        border-radius: 0;
        max-width: 100%;
    }
    
    .sidebar {
        max-width: 280px;
    }
    
    .message {
        max-width: 80%;
    }
}

/* Модальное окно мастер-пароля */
.master-password-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

.master-password-content {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 32px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow);
}

.master-password-content h2 {
    margin-bottom: 8px;
    color: var(--primary);
}

.master-password-content p {
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.master-password-content input {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    margin-bottom: 12px;
    background: var(--bg);
    color: var(--text);
    text-align: center;
    letter-spacing: 2px;
}

.master-password-content input:focus {
    outline: none;
    border-color: var(--primary);
}

.master-password-content .btn-primary {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
}

.master-error {
    color: #ef4444;
    font-size: 0.85rem;
    margin-top: 8px;
}

/* Индикатор верификации отпечатка */
.fingerprint-verify {
    padding: 16px;
    background: var(--pinned-bg);
    border-radius: var(--radius);
    margin: 12px 0;
    text-align: center;
}

.fingerprint-verify .fp-words {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 2px;
    margin: 12px 0;
}

.fingerprint-verify .fp-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 12px;
}
/* ==================== Main Chat Area ==================== */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    font-size: 2rem;
}

.chat-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.chat-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.chat-actions {
    display: flex;
    gap: 8px;
}

/* Restore panel */
.restore-panel {
    display: none;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.restore-panel.visible {
    display: block;
}

/* Pinned messages panel */
.pinned-panel {
    display: none;
    padding: 12px 16px;
    background: var(--pinned-bg);
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.pinned-panel.visible {
    display: block;
}

.pinned-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.icon-btn-small {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.message {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 18px;
    position: relative;
    animation: fadeIn 0.2s ease;
}

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

.my-message {
    background: var(--message-mine);
    align-self: flex-end;
    border-bottom-right-radius: 6px;
}

.other-message {
    background: var(--message-other);
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    border: 1px solid var(--border);
}

.message-content {
    word-break: break-word;
}

.message-content img {
    max-width: 250px;
    border-radius: 12px;
    margin: 4px 0;
    cursor: pointer;
    display: block;
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.key-display {
    padding: 8px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 16px;
    font-size: 0.8rem;
    overflow-x: auto;
}

.key-row {
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.key-label {
    color: var(--text-secondary);
}

.key-value {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
}

.message-input-container {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    align-items: center;
}

.attach-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background var(--transition);
    color: var(--text-secondary);
}

.attach-btn:hover {
    background: var(--bg);
}

#message-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 10px 16px;
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    background: var(--bg);
    color: var(--text);
    transition: border var(--transition);
    -webkit-appearance: none;
}

#message-input:focus {
    outline: none;
    border-color: var(--primary);
}

.send-btn {
    width: 44px;
    height: 44px;
    background: var(--primary);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--transition);
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--primary-hover);
}

.send-icon {
    color: white;
    font-size: 1.2rem;
}

/* ==================== Modal ==================== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 24px;
}

/* ==================== Новый флоу создания чата ==================== */
.chat-role-options {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 20px 0;
}

.role-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    color: var(--text);
}

.role-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.role-icon {
    font-size: 2.5rem;
    line-height: 1;
}

.role-title {
    font-weight: 700;
    font-size: 1.2rem;
    display: block;
}

.role-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.step-indicator {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.step-content {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.4s ease, opacity 0.3s ease, margin 0.3s ease;
    margin-top: 0;
}

.step-content.visible {
    max-height: 500px;
    opacity: 1;
    margin-top: 16px;
}

.alert {
    padding: 12px;
    border-radius: 8px;
    margin: 12px 0;
    font-size: 0.9rem;
}

.alert-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.alert-info {
    background: #e0f2fe;
    color: #075985;
    border: 1px solid #bae6fd;
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.sdp-word-display {
    padding: 16px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    border-radius: 12px;
    text-align: center;
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: 1px;
    margin: 12px 0;
    word-break: break-word;
}

.sdp-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: monospace;
    font-size: 0.8rem;
    resize: vertical;
    min-height: 80px;
    background: var(--bg);
    color: var(--text);
    margin: 8px 0;
}

details {
    margin: 12px 0;
}

details summary {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 8px;
    border-radius: 6px;
    transition: background var(--transition);
}

details summary:hover {
    background: var(--bg);
}

.divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0;
}

.divider span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.button-group {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.btn-primary {
    flex: 1;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    flex: 1;
    padding: 12px;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-secondary:hover {
    background: var(--bg);
}

.btn-text {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-weight: 500;
    padding: 8px;
    font-size: 0.9rem;
}

/* ==================== Настройки ==================== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text);
}

.form-group input[type="text"] {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--bg);
    color: var(--text);
}

.toggle-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toggle-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}
.btn-danger {
    flex: 1;
    padding: 12px;
    background: transparent;
    color: #ef4444;
    border: 1px solid #ef4444;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-danger:hover {
    background: #ef4444;
    color: white;
}
