/* ========================================
   Chatfree - Dark Theme Styles
   ======================================== */

/* --- CSS Variables --- */
:root {
    --bg-primary: #1b1b1f;
    --bg-secondary: #232328;
    --bg-tertiary: #2a2a30;
    --bg-input: #28282e;
    --bg-hover: #303038;
    --text-primary: #fff6cf;
    --text-secondary: #a0a0a8;
    --text-muted: #65656e;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --msg-sent: #1e3a5f;
    --msg-received: #2a2a30;
    --border-color: #38383f;
    --success: #009955;
    --male-color: #4a9eff;
    --female-color: #f472b6;
    --navbar-height: 56px;
    --footer-height: 48px;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    --radius: 8px;
    --radius-lg: 16px;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
}

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--accent-hover);
}

/* --- Screen reader only (SEO h1) --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --- Navbar --- */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navbar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 200;
    box-shadow: var(--shadow);
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 1px;
}

.navbar-brand:hover {
    color: var(--accent-hover);
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.navbar-icon {
    width: 20px;
    height: 20px;
    filter: brightness(0) invert(1) sepia(1) saturate(350%) hue-rotate(10deg) brightness(107%);
    transition: filter 0.2s;
}

.navbar-btn:hover .navbar-icon {
    filter: brightness(0) invert(0.45) sepia(1) saturate(10) hue-rotate(330deg);
}

.chat-icon {
    width: 18px;
    height: 18px;
    filter: brightness(0) invert(1);
}

.navbar-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius);
    transition: background 0.2s, color 0.2s;
    position: relative;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.navbar-btn:hover {
    background: var(--bg-hover);
    color: var(--accent);
}

.navbar-btn .badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: var(--success);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.badge.hidden {
    display: none;
}

.btn-logout {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 6px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-logout:hover {
    background: var(--accent-hover);
}

/* --- Main Content --- */
main {
    flex: 1;
    margin-top: var(--navbar-height);
    margin-bottom: var(--footer-height);
}

/* --- Footer --- */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--footer-height);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    z-index: 200;
}

.footer a {
    color: var(--text-secondary);
}

.footer a:hover {
    color: var(--accent);
}

/* --- Chat Layout (Desktop) --- */
.chat-layout {
    display: grid;
    grid-template-columns: 500px 260px;
    justify-content: center;
    height: calc(100vh - var(--navbar-height) - var(--footer-height));
}

/* --- Chat Panel --- */
.chat-panel {
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    background: var(--bg-primary);
    overflow: hidden;
}

.chat-header {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
}

.chat-header .gender-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.chat-header .partner-name {
    font-weight: 600;
}

.chat-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.95rem;
    padding: 20px;
    text-align: center;
}

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

.messages-container::-webkit-scrollbar {
    width: 6px;
}

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

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* --- Messages --- */
.message {
    display: flex;
    max-width: 80%;
}

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

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

.message-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    font-size: 0.9rem;
    line-height: 1.4;
    position: relative;
}

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

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

.message-time {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: right;
}

.message-bubble a {
    color: var(--accent-hover);
    text-decoration: underline;
    word-break: break-all;
}

.message-bubble a:hover {
    color: #fff;
}

.message-bubble img {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius);
    cursor: pointer;
    display: block;
    margin-top: 4px;
}

/* --- Chat Input --- */
.chat-input-area {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-input-area input[type="text"] {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input-area input[type="text"]:focus {
    border-color: var(--accent);
}

.chat-input-area input[type="text"]::placeholder {
    color: var(--text-muted);
}

.btn-send,
.btn-image {
    background: var(--accent);
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: background 0.2s;
    flex-shrink: 0;
}

.btn-send:hover,
.btn-image:hover {
    background: var(--accent-hover);
}

#image-input {
    display: none;
}

/* Image preview */
.image-preview {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: none;
    align-items: center;
    gap: 8px;
}

.image-preview.active {
    display: flex;
}

.image-preview img {
    max-height: 60px;
    border-radius: var(--radius);
}

.image-preview .btn-remove-image {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 4px;
}

/* --- User List Panel --- */
.user-list-panel {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.user-list-header {
    padding: 12px 16px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border-color);
}

.user-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
}

.user-item {
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid rgba(42, 42, 74, 0.5);
    font-size: 0.9rem;
}

.user-item:hover {
    background: var(--bg-hover);
}

.user-item.active {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--accent);
}

.user-item.user-self {
    cursor: default;
    color: var(--text-muted);
    font-style: italic;
}

.user-item.user-self:hover {
    background: transparent;
}

.user-item .gender-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.gender-dot.ferfi {
    background: var(--male-color);
}

.gender-dot.no {
    background: var(--female-color);
}

.user-item .username {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-item .unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
    display: none;
}

.user-item .unread-dot.visible {
    display: block;
}

/* --- Conversation List Dropdown --- */
.conversations-dropdown {
    position: fixed;
    top: var(--navbar-height);
    right: 20px;
    width: 300px;
    max-height: 400px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow);
    overflow-y: auto;
    z-index: 300;
    display: none;
}

.conversations-dropdown.open {
    display: block;
}

.conversations-dropdown .conv-header {
    padding: 12px 16px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.conv-item {
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid rgba(42, 42, 74, 0.3);
}

.conv-item:hover {
    background: var(--bg-hover);
}

.conv-item .conv-name {
    flex: 1;
    font-size: 0.9rem;
}

.conv-item .conv-unread {
    background: var(--success);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

.conv-item .conv-unread.hidden {
    display: none;
}

.conv-empty {
    padding: 20px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

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

@media (max-width: 1000px) {
    .overlay.active {
        display: block;
    }
}

/* --- Welcome Page --- */
.welcome-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--navbar-height) - var(--footer-height));
    padding: 20px;
}

.welcome-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 40px;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow);
    text-align: center;
}

.welcome-box h1 {
    font-size: 2rem;
    color: var(--accent);
    margin-bottom: 8px;
    letter-spacing: 1px;
}

.welcome-box .subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 0.9rem;
    line-height: 1.6;
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.form-group input[type="text"] {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 12px 14px;
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input[type="text"]:focus {
    border-color: var(--accent);
}

.form-group input[type="text"]::placeholder {
    color: var(--text-muted);
}

.gender-select {
    display: flex;
    gap: 12px;
}

.gender-option {
    flex: 1;
    position: relative;
}

.gender-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.gender-option label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    font-size: 0.9rem;
}

.gender-option input[type="radio"]:checked + label {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

.gender-option label:hover {
    border-color: var(--accent);
}

.btn-login {
    width: 100%;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 12px;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 8px;
}

.btn-login:hover {
    background: var(--accent-hover);
}

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

.form-error {
    color: var(--accent);
    font-size: 0.8rem;
    margin-top: 8px;
    display: none;
}

.form-error.visible {
    display: block;
}

/* --- Error Pages --- */
.error-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - var(--navbar-height) - var(--footer-height));
    padding: 20px;
    text-align: center;
}

.error-code {
    font-size: 6rem;
    font-weight: 800;
    color: var(--accent);
    line-height: 1;
    margin-bottom: 16px;
}

.error-message {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.btn-home {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    padding: 10px 24px;
    border-radius: var(--radius);
    font-weight: 600;
    transition: background 0.2s;
}

.btn-home:hover {
    background: var(--accent-hover);
    color: #fff;
}

/* --- Info Page --- */
.info-container {
    max-width: 700px;
    margin: 0 auto;
    padding: 40px 20px;
}

.info-container h1 {
    font-size: 1.8rem;
    color: var(--accent);
    margin-bottom: 32px;
}

.info-container h2 {
    font-size: 1.15rem;
    color: var(--text-primary);
    margin-top: 28px;
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
}

.info-container p {
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-size: 0.9rem;
    line-height: 1.7;
}

.info-container a {
    color: var(--accent);
}

/* --- Cookie Banner --- */
.cookie-banner {
    position: fixed;
    bottom: -120px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 500;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
    max-width: 600px;
    width: calc(100% - 32px);
    transition: bottom 0.4s ease;
}

.cookie-banner.visible {
    bottom: 0;
}

.cookie-banner p {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.5;
}

.cookie-banner a {
    color: var(--accent);
}

.btn-cookie-accept {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-cookie-accept:hover {
    background: var(--accent-hover);
}

@media (max-width: 500px) {
    .cookie-banner {
        flex-direction: column;
        text-align: center;
        gap: 12px;
        padding: 14px 16px;
    }
}

/* --- Mobile User List Toggle (hidden on desktop) --- */
.btn-toggle-users {
    display: none;
}

/* ========================================
   Responsive - 1000px alatt
   ======================================== */
@media (max-width: 1000px) {
    .chat-layout {
        grid-template-columns: 1fr 260px;
    }

    .chat-panel {
        border-left: none;
    }
}

/* ========================================
   Responsive - Tablet (max 768px)
   ======================================== */
@media (max-width: 768px) {
    .chat-layout {
        grid-template-columns: 1fr;
    }

    .chat-panel {
        border-left: none;
        border-right: none;
    }

    .user-list-panel {
        position: fixed;
        top: var(--navbar-height);
        right: -280px;
        width: 280px;
        height: calc(100vh - var(--navbar-height));
        border-right: none;
        border-left: 1px solid var(--border-color);
        transition: right 0.3s ease;
        z-index: 100;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
    }

    .user-list-panel.open {
        right: 0;
    }

    .btn-toggle-users {
        display: flex;
    }

    .conversations-dropdown {
        right: 10px;
        width: 280px;
    }
}

/* ========================================
   Responsive - Mobile (max 500px)
   ======================================== */
@media (max-width: 500px) {
    .navbar {
        padding: 0 12px;
    }

    .welcome-box {
        padding: 24px 20px;
    }

    .welcome-box h1 {
        font-size: 1.5rem;
    }

    .conversations-dropdown {
        right: 0;
        left: 0;
        width: 100%;
        border-radius: 0;
    }

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