/* SecureChat — Design System + Mobile-first */

:root {
    --color-bg-primary: #fafbfc;
    --color-bg-secondary: #f0f4f8;
    --color-bg-tertiary: #e2e8f0;
    --color-text-primary: #1a202c;
    --color-text-secondary: #4a5568;
    --color-text-muted: #718096;
    --color-accent: #6366f1;
    --color-accent-hover: #4f46e5;
    --color-accent-soft: rgba(99, 102, 241, 0.12);
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-error: #ef4444;
    --color-border: #e2e8f0;

    --color-bubble-own: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --color-bubble-own-text: #ffffff;
    --color-bubble-other: #ffffff;
    --color-bubble-other-text: #1a202c;
    --color-bubble-other-border: #e2e8f0;

    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.25rem;
    --radius-2xl: 1.5rem;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 24px rgba(0,0,0,0.1);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);

    --safe-top: env(safe-area-inset-top, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
    --safe-left: env(safe-area-inset-left, 0);
    --safe-right: env(safe-area-inset-right, 0);
}

[data-theme="dark"] {
    --color-bg-primary: #0f172a;
    --color-bg-secondary: #1e293b;
    --color-bg-tertiary: #334155;
    --color-text-primary: #f1f5f9;
    --color-text-secondary: #cbd5e1;
    --color-text-muted: #94a3b8;
    --color-accent: #818cf8;
    --color-accent-hover: #6366f1;
    --color-accent-soft: rgba(129, 140, 248, 0.15);
    --color-border: #334155;

    --color-bubble-own: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    --color-bubble-other: #334155;
    --color-bubble-other-text: #f1f5f9;
    --color-bubble-other-border: #475569;
}

* {
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    box-sizing: border-box;
}

#app {
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
}

/* Touch targets — min 44px for mobile */
.touch-target {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

@media (min-width: 768px) {
    .touch-target {
        min-width: 40px;
        min-height: 40px;
    }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--color-text-muted);
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-text-secondary); }

/* Message animations */
@keyframes message-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.message-enter {
    animation: message-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Chat area — ограничение высоты, прокрутка */
.chat-messages {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Textarea auto-resize */
.auto-resize {
    resize: none;
    overflow: hidden;
    min-height: 44px;
    max-height: 160px;
}

@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
    animation: spin 0.6s linear infinite;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    width: 20px;
    height: 20px;
}

/* Focus ring */
input:focus, textarea:focus, select:focus, button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--color-bg-primary), 0 0 0 4px var(--color-accent);
}

/* Toast */
@keyframes toast-in {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
.toast { animation: toast-in 0.3s ease-out; }

/* Reply quote */
.reply-quote {
    position: relative;
    padding: 6px 10px 6px 12px;
    margin-bottom: 6px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.15s;
}
.reply-quote::before {
    content: '';
    position: absolute;
    left: 0;
    top: 4px;
    bottom: 4px;
    width: 3px;
    border-radius: 3px;
    background: var(--color-accent);
}
.reply-quote-own { background: rgba(255,255,255,0.2); }
.reply-quote-other { background: rgba(0,0,0,0.06); }
[data-theme="dark"] .reply-quote-other { background: rgba(255,255,255,0.08); }

/* Reply bar */
.reply-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--color-bg-secondary);
    border-top: 1px solid var(--color-border);
    animation: reply-bar-in 0.2s ease-out;
}
@keyframes reply-bar-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Message actions */
.msg-actions {
    position: absolute;
    bottom: 100%;
    margin-bottom: 4px;
    display: flex;
    gap: 1px;
    padding: 3px;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s, transform 0.15s;
    transform: translateY(4px);
    z-index: 20;
}
.msg-actions-own { right: 0; }
.msg-actions-other { left: 0; }
.msg-row:hover .msg-actions,
.message-enter:hover .msg-actions,
.msg-actions.touch-show { opacity: 1; pointer-events: auto; transform: translateY(0); }
.msg-actions button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    color: var(--color-text-secondary);
    transition: background-color 0.15s, color 0.15s;
}
.msg-actions button:hover {
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
}
.msg-actions button.pin-active { color: #d97706; }

/* Bubble — gradient for own */
.bubble-own {
    background: var(--color-bubble-own);
    color: var(--color-bubble-own-text);
    border: none;
    box-shadow: var(--shadow-sm);
}
.bubble-other {
    background: var(--color-bubble-other);
    color: var(--color-bubble-other-text);
    border: 1px solid var(--color-bubble-other-border);
    box-shadow: var(--shadow-sm);
}

/* Voice message */
.voice-msg {
    min-width: 200px;
}
.voice-audio {
    height: 36px;
    max-width: 100%;
}
.voice-audio::-webkit-media-controls-panel { background: transparent; }

/* Scroll FAB */
.scroll-fab {
    position: absolute;
    bottom: calc(16px + var(--safe-bottom));
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 15;
    transition: transform 0.2s, box-shadow 0.2s;
}
.scroll-fab:hover, .scroll-fab:active {
    transform: scale(1.05);
    box-shadow: var(--shadow-glow);
}
.scroll-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: var(--color-accent);
    color: white;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Lightbox */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.92);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
    animation: lightbox-in 0.2s ease-out;
}
@keyframes lightbox-in { from { opacity: 0; } to { opacity: 1; } }
.lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 12px;
    cursor: default;
}
.lightbox-close {
    position: absolute;
    top: calc(16px + var(--safe-top));
    right: calc(16px + var(--safe-right));
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.25); }

/* Pin bar */
.pin-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: linear-gradient(135deg, rgba(234,179,8,0.1), rgba(234,179,8,0.04));
    border-bottom: 1px solid rgba(234,179,8,0.2);
    cursor: pointer;
    transition: background-color 0.2s;
}
.pin-bar:hover { background: linear-gradient(135deg, rgba(234,179,8,0.15), rgba(234,179,8,0.06)); }

/* Staff card */
.staff-card {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 16px;
    padding: 20px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.staff-card:hover {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 1px var(--color-accent), var(--shadow-md);
}
.staff-card-disabled { opacity: 0.6; }

/* Role badge */
.role-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
}
.role-admin { background: #dbeafe; color: #1d4ed8; }
.role-manager { background: #f3e8ff; color: #7c3aed; }
.role-super_admin { background: #fce7f3; color: #be185d; }
[data-theme="dark"] .role-admin { background: rgba(59,130,246,0.2); color: #93c5fd; }
[data-theme="dark"] .role-manager { background: rgba(124,58,237,0.2); color: #c4b5fd; }
[data-theme="dark"] .role-super_admin { background: rgba(190,24,93,0.2); color: #f9a8d4; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(6px);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
}
.modal-card {
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 460px;
    overflow: hidden;
}
.modal-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: 20px 24px 24px; }

/* Scroll highlight */
@keyframes scroll-highlight {
    0% { background: var(--color-accent-soft); }
    100% { background: transparent; }
}
.msg-highlight {
    animation: scroll-highlight 2s ease-out;
    border-radius: 12px;
}

/* Toggle switch */
.toggle-switch {
    position: relative;
    width: 48px;
    height: 28px;
    border-radius: 14px;
    background: var(--color-border);
    cursor: pointer;
    transition: background-color 0.2s;
}
.toggle-switch.active { background: var(--color-accent); }
.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: white;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s;
}
.toggle-switch.active::after { transform: translateX(20px); }

/* Pinned bubble */
@keyframes pin-glow {
    0% { box-shadow: 0 0 0 0 rgba(234,179,8,0.3); }
    50% { box-shadow: 0 0 0 4px rgba(234,179,8,0.1); }
    100% { box-shadow: 0 0 0 0 rgba(234,179,8,0); }
}
.pinned-bubble {
    border: 1px solid rgba(234,179,8,0.35);
    animation: pin-glow 2s ease-out 1;
}

/* Drop zone */
.drop-zone-active {
    border: 2px dashed var(--color-accent);
    background: var(--color-accent-soft);
}

/* Mobile — chat layout */
@media (max-width: 640px) {
    .chat-messages {
        padding-left: 12px;
        padding-right: 12px;
        padding-bottom: calc(12px + var(--safe-bottom));
    }
    .scroll-fab {
        right: 12px;
        bottom: calc(12px + var(--safe-bottom));
    }
}

@media (max-height: 500px) {
    .client-layout .chat-messages { max-height: 60vh; }
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
