/* FamChat - Responsive CSS with Sidebar Layout */

:root {
    /* Dark mode color scheme */
    --primary: #7289da;
    --primary-light: #8ea1e1;
    --primary-dark: #5b6eae;
    --background: #1a1a2e;
    --sidebar-bg: #16213e;
    --sidebar-text: #e8e8e8;
    --sidebar-hover: #1f3460;
    --sidebar-active: #1e2a4a;
    --chat-bg: #1e1e30;
    --message-sent: #4a5d8a;
    --message-received: #2d2d44;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0a0;
    --text-muted: #6c6c7e;
    --border-color: #2d2d44;
    --input-bg: #2d2d44;
    --sidebar-width: 300px;
    --header-height: 56px;
}

/* Reset and base */
* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    background: var(--background);
    color: var(--text-primary);
}

/* App container */
.famchat-app {
    height: 100%;
}

/* Chat Layout - Desktop sidebar + main content */
.chat-layout {
    display: flex;
    height: 100%;
    overflow: hidden;
}

/* Sidebar Styles */
.chat-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100%;
}

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

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    color: var(--text-primary);
}

.sidebar-brand strong {
    color: inherit;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
}

.sidebar-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: rgba(0,0,0,0.2);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-name {
    font-weight: 500;
}

.user-actions {
    display: flex;
    gap: 0.5rem;
}

.sidebar-link {
    color: var(--sidebar-text);
    text-decoration: none;
    padding: 0.25rem;
    border-radius: 4px;
    font-size: 1.1rem;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.sidebar-link:hover {
    opacity: 1;
}

.sidebar-conversations {
    flex: 1;
    overflow-y: auto;
}

.sidebar-new-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border-color);
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;
    transition: background 0.2s;
}

.sidebar-new-chat:hover {
    background: var(--sidebar-hover);
    color: white;
}

/* Conversation items in sidebar */
.conversation-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    transition: background 0.2s;
}

.conversation-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

.conversation-item.is-active {
    background: var(--sidebar-active);
}

.conversation-item .avatar {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.conversation-info {
    flex: 1;
    min-width: 0;
    margin-left: 0.75rem;
}

.conversation-name {
    font-weight: 600;
    margin-bottom: 0.125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-preview {
    font-size: 0.8rem;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

.sidebar-overlay.is-visible {
    display: block;
}

/* Main content area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--chat-bg);
}

.chat-main-header {
    display: flex;
    align-items: center;
    padding: 0 1rem;
    height: var(--header-height);
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    flex-shrink: 0;
}

.hamburger-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 0.5rem;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
}

.conversation-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.conversation-title {
    font-weight: 600;
    font-size: 1.1rem;
}

.chat-main-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.welcome-message {
    text-align: center;
    color: var(--text-secondary);
}

.welcome-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.welcome-message h2 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.welcome-message p {
    margin-bottom: 1.5rem;
}

/* Chat messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: var(--background);
    display: flex;
    flex-direction: column;
}

.message {
    max-width: 70%;
    margin-bottom: 0.75rem;
    animation: fadeIn 0.3s ease;
}

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

.message-sent {
    align-self: flex-end;
}

.message-received {
    align-self: flex-start;
}

.message-bubble {
    padding: 0.75rem 1rem;
    border-radius: 18px;
    word-wrap: break-word;
}

.message-sent .message-bubble {
    background: var(--message-sent);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-received .message-bubble {
    background: var(--message-received);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    padding: 0 0.5rem;
}

.message-sent .message-meta {
    text-align: right;
}

.message-sender {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    padding-left: 0.5rem;
}

/* Message input */
.chat-input {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    background: var(--chat-bg);
    border-top: 1px solid var(--border-color);
    gap: 0.5rem;
    flex-shrink: 0;
}

.chat-input input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    font-size: 1rem;
    outline: none;
    background: var(--input-bg);
    color: var(--text-primary);
}

.chat-input input:focus {
    border-color: var(--primary);
}

.chat-input input::placeholder {
    color: var(--text-muted);
}

.chat-input button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-input button:active {
    background: var(--primary-light);
}

/* Avatar styles */
.avatar-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 14px;
}

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    font-size: 24px;
}

.avatar-large {
    width: 64px;
    height: 64px;
    font-size: 32px;
}

/* Login page */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}

.login-box {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    background: var(--chat-bg);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
    border: 1px solid var(--border-color);
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo .icon {
    font-size: 4rem;
}

.login-logo h1 {
    margin-top: 0.5rem;
    color: var(--text-primary);
}

.login-divider {
    display: flex;
    align-items: center;
    margin: 1.5rem 0;
}

.login-divider::before,
.login-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}

.login-divider span {
    padding: 0 1rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* QR Code */
.qr-container {
    text-align: center;
    padding: 2rem;
}

.qr-code {
    display: inline-block;
    padding: 1rem;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.qr-code img {
    width: 200px;
    height: 200px;
}

/* Family list */
.family-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    padding: 1rem;
}

.family-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem 1rem;
    background: var(--chat-bg);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    text-decoration: none;
    color: var(--text-primary);
    transition: transform 0.2s, box-shadow 0.2s;
}

.family-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.family-card .avatar {
    margin-bottom: 0.75rem;
}

.family-card .name {
    font-weight: 600;
    text-align: center;
}

/* New conversation */
.member-select {
    padding: 1rem;
}

.member-option {
    display: flex;
    align-items: center;
    padding: 1rem;
    background: var(--chat-bg);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    color: var(--text-primary);
}

.member-option input {
    margin-right: 1rem;
}

.member-option:hover {
    background: var(--sidebar-hover);
}

/* Success/Error messages */
.result-container {
    text-align: center;
    padding: 3rem 2rem;
}

.result-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.result-success .result-icon {
    color: #48c774;
}

.result-error .result-icon {
    color: #f14668;
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.empty-state-small {
    padding: 2rem;
    text-align: center;
    color: rgba(255,255,255,0.5);
}

/* Mobile styles */
@media (max-width: 768px) {
    .chat-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        z-index: 100;
        transition: left 0.3s ease;
    }

    .chat-sidebar.is-open {
        left: 0;
    }

    .sidebar-close {
        display: block;
    }

    .hamburger-btn {
        display: block;
    }

    .header-title {
        display: none;
    }

    .message {
        max-width: 85%;
    }
}

/* Desktop styles */
@media (min-width: 769px) {
    .sidebar-close {
        display: none;
    }

    .hamburger-btn {
        display: none;
    }
}

/* Safe area for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
    .chat-main-header {
        padding-top: env(safe-area-inset-top);
        height: calc(var(--header-height) + env(safe-area-inset-top));
    }

    .sidebar-header {
        padding-top: calc(1rem + env(safe-area-inset-top));
    }

    .chat-input {
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    }
}
