/* 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 composer: error banner, attachment strip, input row */
.chat-composer {
    background: var(--chat-bg);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.chat-input {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    gap: 0.5rem;
}

.chat-input input {
    flex: 1;
    min-width: 0;
    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);
}

.chat-input button:disabled {
    opacity: 0.5;
    cursor: progress;
}

.chat-input .attach-btn {
    background: transparent;
    color: var(--text-secondary);
}

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

/* 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));
    }
}

/* ---- Message attachments ---- */
.message-attachments {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    margin-bottom: 0.25rem;
    max-width: 320px;
}

.message-sent .message-attachments {
    margin-left: auto;
}

.message-attachments.is-multi {
    grid-template-columns: repeat(2, 1fr);
}

.attachment-image,
.attachment-video {
    display: block;
    border-radius: 12px;
    overflow: hidden;
    background: var(--message-received);
}

.attachment-image img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 320px;
    object-fit: cover;
}

.message-attachments.is-multi .attachment-image img {
    aspect-ratio: 1;
    height: 100%;
}

.attachment-video {
    width: 100%;
    max-height: 320px;
}

.attachment-file {
    display: inline-flex;
    gap: 0.5rem;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    background: var(--message-received);
    color: var(--text-primary);
}

.attachment-size {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ---- Composer attachments ---- */
[hidden] {
    display: none !important;
}

.composer-error {
    margin: 0.5rem 0.75rem 0;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    background: #5c2b33;
    color: #ffd7dc;
    font-size: 0.85rem;
}

.attachment-strip {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 0.75rem 0;
    overflow-x: auto;
    scroll-snap-type: x proximity;
}

.attachment-chip {
    position: relative;
    flex: 0 0 auto;
    width: 72px;
    height: 72px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    scroll-snap-align: start;
}

.attachment-chip img,
.attachment-chip video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.attachment-chip.is-processing img {
    opacity: 0.5;
}

.attachment-chip.is-processing::after {
    content: '';
    position: absolute;
    inset: 50% auto auto 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: famchat-spin 0.8s linear infinite;
}

@keyframes famchat-spin {
    to { transform: rotate(360deg); }
}

.attachment-chip-file {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 0.25rem;
    font-size: 0.65rem;
    text-align: center;
    word-break: break-all;
    color: var(--text-secondary);
}

.attachment-chip-badge {
    position: absolute;
    left: 4px;
    bottom: 4px;
    padding: 0 0.3rem;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 0.7rem;
}

.attachment-remove {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.65);
    color: white;
    font-size: 1rem;
    line-height: 22px;
    cursor: pointer;
}

.attachment-remove:hover,
.attachment-remove:focus-visible {
    background: #c0392b;
}

.upload-progress {
    height: 3px;
    margin: 0.5rem 0.75rem 0;
    border-radius: 2px;
    background: var(--input-bg);
    overflow: hidden;
}

.upload-progress span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--primary);
    transition: width 0.2s ease;
}

/* Drag-and-drop overlay over the whole chat pane */
.chat-main {
    position: relative;
}

.drop-hint {
    display: none;
    position: absolute;
    inset: 0.75rem;
    z-index: 20;
    align-items: center;
    justify-content: center;
    border: 3px dashed var(--primary);
    border-radius: 16px;
    background: rgba(30, 30, 48, 0.85);
    color: var(--text-primary);
    font-size: 1.25rem;
    pointer-events: none;
}

.chat-main.is-dragover .drop-hint {
    display: flex;
}

/* ---- Lightbox ---- */
body.lightbox-open {
    overflow: hidden;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.92);
}

.lightbox-img {
    max-width: calc(100vw - 2rem);
    max-height: calc(100vh - 6rem);
    object-fit: contain;
    border-radius: 6px;
    user-select: none;
}

.lightbox-btn {
    position: absolute;
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: white;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
}

.lightbox-btn:hover,
.lightbox-btn:focus-visible {
    background: rgba(255, 255, 255, 0.25);
}

.lightbox-close {
    top: calc(1rem + env(safe-area-inset-top, 0px));
    right: 1rem;
}

.lightbox-prev,
.lightbox-next {
    top: 50%;
    transform: translateY(-50%);
    display: none;
}

.lightbox.is-multi .lightbox-prev,
.lightbox.is-multi .lightbox-next {
    display: block;
}

.lightbox-prev {
    left: 1rem;
}

.lightbox-next {
    right: 1rem;
}

.lightbox-footer {
    position: absolute;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.lightbox-download {
    color: var(--primary-light);
}

/* ---- Links in message text ---- */
.message-bubble a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
}

/* ---- Message embeds (YouTube cards, image-link previews) ---- */
.message-embeds {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 0.25rem;
    max-width: 320px;
    width: 100%;
}

.message-sent .message-embeds {
    margin-left: auto;
}

.embed {
    display: block;
    border-radius: 12px;
    overflow: hidden;
    background: var(--message-received);
}

.embed-yt-thumb {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    cursor: pointer;
    background: #000;
    aspect-ratio: 16 / 9;
}

.embed-yt-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover; /* hqdefault is 4:3 with letterbox bars */
}

.embed-yt-play {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 64px;
    height: 44px;
    transform: translate(-50%, -50%);
    border-radius: 12px;
    background: rgba(255, 0, 0, 0.9);
    transition: transform 0.15s ease;
}

.embed-yt-play::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 54%;
    transform: translate(-50%, -50%);
    border-style: solid;
    border-width: 10px 0 10px 17px;
    border-color: transparent transparent transparent #fff;
}

.embed-yt-thumb:hover .embed-yt-play,
.embed-yt-thumb:focus-visible .embed-yt-play {
    transform: translate(-50%, -50%) scale(1.1);
}

.embed-yt-frame {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    border: 0;
}

/* Beat Bulma's `.message a:not(.button):not(.tag):not(.dropdown-item)` rule:
   our .message class collides with Bulma's message component. */
.message .message-embeds a.embed-meta:not(.button):not(.tag) {
    color: var(--text-primary);
    text-decoration: none;
}

.embed-meta {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0.75rem;
    color: var(--text-primary);
    line-height: 1.3;
}

.embed-meta:hover .embed-title {
    text-decoration: underline;
}

.embed-title {
    font-weight: 600;
    font-size: 0.9rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.embed-author {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.embed-image img {
    display: block;
    width: 100%;
    max-height: 320px;
    object-fit: cover;
}
