:root {
    --bg-main: #09090b;
    --bg-card: #18181b;
    --bg-input: #27272a;
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --danger: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
}

*::selection {
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
}

body {
    background:
        radial-gradient(circle at top, rgba(37, 99, 235, 0.14), transparent 38%),
        radial-gradient(circle at bottom right, rgba(255, 255, 255, 0.06), transparent 24%),
        var(--bg-main);
    color: var(--text-primary);
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

#app {
    width: 100%;
    height: 100%;
    display: flex;
}

/* Global Elements */
button {
    border: none;
    outline: none;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.14s ease, background-color 0.14s ease, color 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease, opacity 0.14s ease;
}

input, textarea {
    border: none;
    outline: none;
    font-family: inherit;
    transition: background-color 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease, color 0.14s ease;
}

/* View Control */
.view {
    display: none;
    flex-direction: column;
    width: 100%;
    height: 100%;
}
.view.active {
    display: flex;
    animation: fadeInScale 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.985) translateY(14px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

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

@keyframes softSlideIn {
    from { opacity: 0; transform: translateY(12px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes overlayFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Auth View */
#auth-view {
    align-items: center;
    justify-content: center;
}
.hero-content {
    text-align: center;
    max-width: 400px;
    width: 100%;
    padding: 2rem;
    animation: riseIn 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}
.logo {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    letter-spacing: -1px;
}
.logo span { color: var(--text-secondary); }
.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

.auth-tabs {
    position: relative;
    display: flex;
    background: var(--bg-card);
    border-radius: 100px;
    padding: 0.3rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
    overflow: hidden;
}
.auth-tabs::before {
    content: "";
    position: absolute;
    top: 0.3rem;
    left: 0.3rem;
    width: calc(50% - 0.3rem);
    height: calc(100% - 0.6rem);
    border-radius: 999px;
    background: var(--text-primary);
    box-shadow: 0 10px 22px rgba(255, 255, 255, 0.12);
    transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
.auth-tabs[data-mode="signup"]::before {
    transform: translateX(100%);
}
.tab-btn {
    position: relative;
    z-index: 1;
    flex: 1;
    background: transparent;
    color: var(--text-secondary);
    padding: 0.6rem;
    border-radius: 100px;
    font-size: 0.95rem;
    transition: color 0.18s ease, transform 0.18s ease;
}
.tab-btn.active {
    color: var(--bg-main);
}
.tab-btn:hover:not(.active) {
    color: var(--text-primary);
    transform: translateY(-1px);
}

.input-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.24);
}
.input-form input {
    background: var(--bg-input);
    color: var(--text-primary);
    padding: 1rem 1.2rem;
    border-radius: 12px;
    font-size: 1rem;
    border: 1px solid transparent;
    transition: border-color 0.2s;
}
.input-form input:focus {
    border-color: var(--text-secondary);
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.06);
}
.input-form button {
    background: var(--text-primary);
    color: var(--bg-main);
    padding: 1rem;
    border-radius: 12px;
    margin-top: 0.5rem;
    font-size: 1.05rem;
}
.input-form button:hover {
    background: #e4e4e7;
    transform: translateY(-1px);
}

/* Dashboard View */
#dashboard-view {
    overflow-y: auto;
    align-items: center;
}
#dashboard-view > header {
    width: 100%;
    max-width: 800px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2rem 1rem;
}
.logo-small { font-size: 1.5rem; font-weight: 700; }
.logo-small span { color: var(--text-secondary); }

.primary-btn {
    background: var(--text-primary);
    color: var(--bg-main);
    padding: 0.6rem 1.2rem;
    border-radius: 100px;
}
.primary-btn:hover {
    background: #e4e4e7;
    transform: translateY(-1px);
    box-shadow: 0 12px 26px rgba(255, 255, 255, 0.1);
}
.secondary-btn {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.6rem 1.2rem;
    border-radius: 100px;
}
.secondary-btn:hover {
    background: var(--bg-card);
    transform: translateY(-1px);
}

#dashboard-view > main {
    width: 100%;
    max-width: 800px;
    padding: 0 1rem 4rem 1rem;
}
.dashboard-banner {
    margin: 2rem 0 3rem 0;
    text-align: center;
    animation: riseIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
.dashboard-banner h2 { font-size: 2rem; margin-bottom: 0.5rem; }
.dashboard-banner p { color: var(--text-secondary); }

.group-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.group-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    animation: softSlideIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    transition: transform 0.14s ease, background-color 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}
.group-card:hover {
    transform: translateY(-3px);
    background: #202024;
    border-color: rgba(255, 255, 255, 0.14);
    box-shadow: 0 16px 30px rgba(0, 0, 0, 0.2);
}
.group-card h3 { font-size: 1.2rem; margin-bottom: 0.2rem; }
.group-card .admin { color: var(--text-secondary); font-size: 0.85rem; }

.status-pill {
    padding: 0.3rem 0.8rem;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}
.pill-open { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
.pill-locked { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }

/* Chat View */
#chat-view {
    align-items: center;
}
.chat-header {
    width: 100%;
    display: flex;
    justify-content: center;
    border-bottom: 1px solid var(--border-color);
    background: rgba(9, 9, 11, 0.8);
    backdrop-filter: blur(12px);
    z-index: 10;
    animation: riseIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.chat-header-content {
    width: 100%;
    max-width: 900px;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
}
.icon-btn {
    background: transparent;
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover { background: var(--bg-card); }
.group-details { display: flex; align-items: center; gap: 0.8rem; }
.group-details h2 { font-size: 1.2rem; }
.group-details .pill {
    background: var(--bg-card);
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.messages {
    width: 100%;
    max-width: 900px;
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.message {
    max-width: 75%;
    padding: 0.38rem 0.68rem;
    position: relative;
    animation: softSlideIn 0.16s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.9rem;
    line-height: 1.35;
    transform-origin: bottom;
}
.message.sent {
    align-self: flex-end;
    background: var(--accent);
    color: white;
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 14px 24px rgba(37, 99, 235, 0.22);
}
.message.received {
    align-self: flex-start;
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: 16px 16px 16px 4px;
    border: 1px solid var(--border-color);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.14);
}
.message .sender {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    margin-bottom: 0.18rem;
    cursor: pointer;
    transition: color 0.2s ease, opacity 0.2s ease;
}
.message.sent .sender { display: none; } /* Don't show name for own messages */
.message.received .sender { color: var(--text-secondary); }
.message.received .sender:hover {
    color: var(--text-primary);
}
.message .time {
    display: block;
    font-size: 0.6rem;
    margin-top: 0.25rem;
    opacity: 0.7;
    text-align: right;
}

/* Chat Input Styling */
.chat-input-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 0.75rem 1.25rem 1.25rem 1.25rem;
}
.chat-input-area {
    width: 100%;
    max-width: 900px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    display: flex;
    align-items: flex-end;
    padding: 0.5rem 0.8rem;
    gap: 0.5rem;
    transition: border-color 0.14s ease, box-shadow 0.14s ease, transform 0.14s ease;
}
.chat-input-area:focus-within {
    border-color: rgba(255, 255, 255, 0.16);
    box-shadow: 0 16px 30px rgba(0, 0, 0, 0.22), 0 0 0 4px rgba(255, 255, 255, 0.04);
}

.icon-action-btn {
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.2rem;
    padding: 0.6rem;
    border-radius: 50%;
}
.icon-action-btn:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
    transform: translateY(-1px);
}

#file-preview-container {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255,255,255,0.1);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-primary);
    margin: 0.2rem 0 0.5rem 0.4rem;
    align-self: flex-start;
    animation: softSlideIn 0.16s ease;
}
.icon-btn-small {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 0 0.2rem;
}
.icon-btn-small:hover { color: var(--danger); }
#file-preview-container.hidden { display: none; }

#message-input {
    flex: 1;
    background: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    resize: none;
    line-height: 1.35;
    max-height: 72px;
    overflow-y: auto;
    padding: 0.45rem 0.5rem;
    margin-bottom: 0.1rem;
}
#message-input::placeholder {
    color: rgba(244, 244, 245, 0.48);
    transition: color 0.2s ease;
}
#message-input:focus::placeholder {
    color: rgba(244, 244, 245, 0.32);
}

#send-btn {
    background: var(--accent);
    color: white;
    padding: 0.6rem 1.2rem;
    border-radius: 100px;
    font-size: 0.95rem;
    margin-bottom: 0.1rem;
}
#send-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 14px 26px rgba(37, 99, 235, 0.24);
}
#send-btn:disabled {
    opacity: 0.7;
    transform: none;
    box-shadow: none;
}

/* File Rendering */
.message-image {
    max-width: 100%;
    max-height: 250px;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    display: block;
    object-fit: cover;
    transition: transform 0.16s ease, box-shadow 0.16s ease;
}
.message-image:hover {
    transform: scale(1.015);
    box-shadow: 0 16px 28px rgba(0, 0, 0, 0.18);
}
.message-file {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    color: inherit;
    text-decoration: underline;
    margin-bottom: 0.5rem;
    font-weight: 600;
    transition: background-color 0.14s ease, transform 0.14s ease;
}
.message-file:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-1px);
}

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: overlayFade 0.14s ease;
}
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 2rem;
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    animation: popIn 0.18s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes popIn {
    0% { opacity: 0; transform: scale(0.9) translateY(20px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}
.modal h3 { font-size: 1.5rem; margin-bottom: 1.5rem; }
.modal-body { display: flex; flex-direction: column; gap: 1rem; margin-bottom: 2rem; }
.modal-body input {
    background: var(--bg-main);
    color: var(--text-primary);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}
.modal-body input:focus { border-color: var(--text-secondary); }
.modal-body input:focus {
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.05);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 1rem; }
.hint { font-size: 0.8rem; color: var(--text-secondary); }
.error-text { color: var(--danger); font-size: 0.85rem; }
.hidden { display: none; }
.empty-state {
    color: var(--text-secondary);
    padding: 1rem 0;
}

.sync-textarea {
    min-height: 110px;
    background: var(--bg-main);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.9rem 1rem;
    resize: vertical;
}

.local-net-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.local-thread-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.local-thread-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 14px;
}

.local-thread-meta {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.local-thread-meta span {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

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

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

.site-footer {
    position: fixed;
    bottom: 1rem;
    left: 0;
    width: 100%;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.75rem;
    pointer-events: none;
    z-index: 10;
}

.dashboard-section {
    margin-bottom: 2rem;
}
.dashboard-section h2 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3rem;
    display: inline-block;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: -320px;
    width: 320px;
    height: 100vh;
    background: rgba(9, 9, 11, 0.95);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    z-index: 200;
    transition: left 0.18s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}
.sidebar.open {
    left: 0;
    box-shadow: 18px 0 42px rgba(0, 0, 0, 0.3);
}
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}
.sidebar-header h2 { font-size: 1.2rem; }
.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.sidebar-list .group-card { background: transparent; border: 1px solid var(--border-color); margin-bottom: 0px;}
.sidebar-list .group-card:hover { background: rgba(255,255,255,0.05); }

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

@media (max-width: 760px) {
    .chat-header-content {
        flex-wrap: wrap;
    }

    .local-thread-item {
        flex-direction: column;
        align-items: stretch;
    }

    .local-thread-actions {
        width: 100%;
    }

    .local-thread-actions button {
        flex: 1;
    }
}
