/* Tiny Chat v0.25.0 */

:root {
    --primary-color: #3949AB;
    --primary-dark: #303B9F;
    --accent-color: #FFC107;
    --text-color: #212121;
    --text-secondary: #757575;
    --border-color: #E0E0E0;
    --message-bg-own: #E3F2FD;
    --message-bg-other: #F5F5F5;
    --error-color: #D32F2F;
    --success-color: #388E3C;
    --sidebar-width: 300px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: #FAFAFA;
    color: var(--text-color);
    height: 100%;
}

#app {
    height: 100vh;
    display: flex;
}

/* ============================================================================
   AUTHENTICATION SCREEN
   ============================================================================ */

.auth-container {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
}

.auth-card {
    background: white;
    border-radius: 8px;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
}

.auth-card h1 {
    text-align: center;
    margin: 0 0 30px 0;
    color: var(--primary-color);
    font-size: 28px;
}

.form-group {
    margin-bottom: 20px;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.3s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(57, 73, 171, 0.1);
}

.loading {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

.btn-primary {
    background: var(--primary-color);
    color: white;
    width: 100%;
}

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

.btn-send {
    background: var(--primary-color);
    color: white;
    padding: 8px 16px;
    min-width: 80px;
}

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

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    padding: 8px;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.btn-icon:hover {
    color: var(--text-color);
}

.messages-area {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.btn-scroll-bottom {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.2s;
    z-index: 10;
}

.btn-scroll-bottom:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transform: scale(1.1);
}

.btn-scroll-bottom:active {
    transform: scale(0.95);
}

.btn-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-secondary);
    padding: 0;
    margin-left: auto;
}

/* ============================================================================
   MESSAGING SCREEN LAYOUT
   ============================================================================ */

.messaging-container {
    display: flex;
    height: 100%;
    width: 100%;
    background: white;
}

.sidebar {
    width: var(--sidebar-width);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background: #FAFAFA;
    overflow: hidden;
}

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

.sidebar-header h2 {
    margin: 0;
    font-size: 20px;
    color: var(--text-color);
}

.groups-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.group-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.2s;
}

.group-item:hover {
    background: #f5f5f5;
}

.group-item.active {
    background: var(--message-bg-own);
    border-left: 4px solid var(--primary-color);
    padding-left: 12px;
}

.group-title {
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 4px;
}

.group-meta {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    gap: 8px;
    align-items: center;
}

.group-type {
    background: #E0E0E0;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
}

.unread-badge {
    background: var(--accent-color);
    color: #000;
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

/* ============================================================================
   CHAT PANEL
   ============================================================================ */

.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
}

.chat-panel.empty {
    align-items: center;
    justify-content: center;
}

.empty-state {
    color: var(--text-secondary);
    font-size: 16px;
    text-align: center;
}

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

.chat-header h3 {
    margin: 0;
    font-size: 18px;
    color: var(--text-color);
}

/* ============================================================================
   MESSAGES
   ============================================================================ */

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

.message-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    display: flex;
    margin-bottom: 4px;
    align-items: flex-end;
    gap: 8px;
}

.message.own {
    justify-content: flex-end;
}

.message.other {
    justify-content: flex-start;
}

.bubble {
    max-width: 60%;
    padding: 8px 12px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    justify-content: space-between;
}

.message.own .bubble {
    background: var(--message-bg-own);
    border-bottom-right-radius: 4px;
}

.message.other .bubble {
    background: var(--message-bg-other);
    border-bottom-left-radius: 4px;
}

.bubble .sender-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 2px;
}

.bubble .content {
    word-wrap: break-word;
    line-height: 1.4;
}

.bubble .meta {
    display: flex;
    gap: 4px;
    align-items: center;
    justify-content: flex-end;
    font-size: 11px;
    color: #999;
    margin-top: 4px;
}

.bubble .time {
    cursor: help;
    white-space: nowrap;
}

/* Date Separator */
.date-separator {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 16px 0 8px 0;
    list-style: none;
}

.separator-text {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.5px;
}

/* ============================================================================
    SEND FORM
    ============================================================================ */

.send-form {
    border-top: 1px solid var(--border-color);
    padding: 12px 16px;
    background: white;
}

.reply-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    margin-bottom: 8px;
    background: #F5F5F5;
    border-left: 3px solid var(--primary-color);
    border-radius: 4px;
    font-size: 13px;
}

.reply-header {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.reply-content {
    padding: 4px 0;
    color: var(--text-secondary);
    font-size: 12px;
}

.input-group {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.message-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    min-height: 36px;
    max-height: 100px;
}

.message-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(57, 73, 171, 0.1);
}

/* ============================================================================
   NOTIFICATIONS
   ============================================================================ */

.notifications {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 400px;
}

.notification {
    padding: 12px 16px;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.notification.error {
    background: var(--error-color);
    color: white;
}

.notification.success {
    background: var(--success-color);
    color: white;
}

/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

@media (max-width: 768px) {
    .sidebar {
        display: none;
        width: 100%;
        position: absolute;
        height: 100%;
        z-index: 100;
    }

    .sidebar.open {
        display: flex;
    }

    .messaging-container {
        position: relative;
    }

    .bubble {
        max-width: 85%;
    }

    .chat-header {
        padding: 12px;
    }

    .messages-container {
        padding: 12px;
    }

    .auth-card {
        margin: 20px;
    }
}

@media (max-width: 480px) {
    :root {
        --sidebar-width: 100%;
    }

    .bubble {
        max-width: 90%;
    }

    .send-form {
        padding: 8px 12px;
    }

    .input-group {
        flex-direction: column;
    }

    .btn-send {
        width: 100%;
    }

    .notifications {
        width: calc(100% - 32px);
        max-width: none;
        right: 16px;
    }
}

/* ============================================================================
   DARK MODE
   ============================================================================ */

@media (prefers-color-scheme: dark) {
    :root {
        --text-color: #E0E0E0;
        --text-secondary: #B0B0B0;
        --border-color: #424242;
        --message-bg-own: #1A237E;
        --message-bg-other: #424242;
    }

    html, body {
        background-color: #121212;
        color: var(--text-color);
    }

    .auth-container {
        background: linear-gradient(135deg, #1A237E 0%, #283593 100%);
    }

    .auth-card {
        background: #1E1E1E;
    }

    .auth-card h1 {
        color: #90CAF9;
    }

    .form-input {
        background: #2C2C2C;
        color: #E0E0E0;
        border-color: #424242;
    }

    .form-input:focus {
        box-shadow: 0 0 0 3px rgba(144, 202, 249, 0.1);
    }

    .messaging-container,
    .sidebar,
    .chat-panel {
        background: #121212;
    }

    .sidebar {
        background: #1E1E1E;
    }

    .sidebar-header,
    .chat-header {
        background: #2C2C2C;
        border-color: #424242;
    }

    .groups-list {
        background: #1E1E1E;
    }

    .group-item {
        border-color: #2C2C2C;
    }

    .group-item:hover {
        background: #2C2C2C;
    }

    .group-item.active {
        background: rgba(25, 35, 126, 0.3);
    }

    .group-type {
        background: #424242;
        color: #E0E0E0;
    }

    .message-input {
        background: #2C2C2C;
        color: #E0E0E0;
        border-color: #424242;
    }

    .message-input:focus {
        box-shadow: 0 0 0 2px rgba(144, 202, 249, 0.1);
    }

    .reply-preview {
        background: #2C2C2C;
        border-left-color: #90CAF9;
    }

    .empty-state {
        color: var(--text-secondary);
    }

    .btn-primary {
        background: #1976D2;
    }

    .btn-primary:hover:not(:disabled) {
        background: #1565C0;
    }

    .btn-send {
        background: #1976D2;
    }

    .btn-send:hover:not(:disabled) {
        background: #1565C0;
    }

    .btn-icon {
        color: var(--text-secondary);
    }

    .btn-icon:hover {
        color: var(--text-color);
    }
}

/* ============================================================================
   SCROLLBAR STYLING
   ============================================================================ */

.groups-list::-webkit-scrollbar,
.messages-container::-webkit-scrollbar {
    width: 8px;
}

.groups-list::-webkit-scrollbar-track,
.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.groups-list::-webkit-scrollbar-thumb,
.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.groups-list::-webkit-scrollbar-thumb:hover,
.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================================================
   ATTACHMENT POPUP
   ============================================================================ */

.attachment-container:hover .attachment-popup,
.attachment-popup:hover {
    display: block !important;
}

.attachment-popup {
    z-index: 100;
}

.attachment-popup button:hover {
    background: #f5f5f5 !important;
}

@media (prefers-color-scheme: dark) {
    .attachment-popup {
        background: #2C2C2C !important;
        border-color: #424242 !important;
    }

    .attachment-popup button {
        color: #E0E0E0 !important;
    }

    .attachment-popup button:hover {
        background: #424242 !important;
    }
}
