.hidden { display: none !important; }

:root {
    --bg-dark: #111b21;
    --sidebar-bg: #202c33;
    --message-bg-out: #005c4b;
    --message-bg-in: #202c33;
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --primary-color: #00a884;
    --border-color: #222d34;
    --font-family: 'Roboto', -apple-system, sans-serif;
    --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font-family);
    background-color: #0a1014;
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

.hidden { display: none !important; }

/* Layout */
.app-container {
    display: flex;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    background-color: var(--bg-dark);
}

.sidebar-sessions {
    width: 300px;
    background-color: #111b21;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.sidebar-chats {
    width: 380px;
    background-color: #111b21;
    border-right: 1px solid #222d34;
    display: flex;
    flex-direction: column;
}

.main-chat {
    flex: 1;
    background-color: #0b141a;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Headers */
.header {
    height: 60px;
    background-color: var(--sidebar-bg);
    display: flex;
    align-items: center;
    padding: 10px 16px;
    gap: 15px;
    flex-shrink: 0;
}

.header h2 {
    font-size: 16px;
    font-weight: 500;
}

/* Forms & Inputs */
.session-form {
    padding: 16px;
    background-color: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
}

.session-form input, .chat-input-area input {
    flex: 1;
    background-color: #2a3942;
    border: none;
    color: var(--text-primary);
    padding: 9px 12px;
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
}

.btn-primary:disabled { opacity: 0.5; }

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

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s;
}

.icon-btn:hover {
    background: rgba(255,255,255,0.05);
    color: var(--primary-color);
}

.new-chat-area {
    padding: 12px;
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
    background: var(--sidebar-bg);
}

.new-chat-area input {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 10px;
    color: var(--text-primary);
    font-size: 0.9em;
}

.new-chat-area button {
    background: var(--primary-color);
    border: none;
    border-radius: 6px;
    color: white;
    padding: 6px 12px;
    cursor: pointer;
    font-weight: 500;
}

/* Lists */
.sessions-list, .chats-list {
    flex: 1;
    overflow-y: auto;
}

.list-item {
    display: flex;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    align-items: center;
}

.list-item:hover { background-color: var(--sidebar-bg); }
.list-item.active { background-color: #2a3942; }

.item-info { flex: 1; display:flex; flex-direction:column; overflow:hidden;}
.item-title { font-size: 16px; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-subtitle { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Screens & Messages */
.welcome-screen, .qr-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-secondary);
}

.welcome-screen h2 {
    font-weight: 300;
    font-size: 32px;
    margin: 20px 0 10px;
}

.chat-interface {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    height: 60px;
    background-color: var(--sidebar-bg);
    display: flex;
    align-items: center;
    padding: 10px 16px;
}

.chat-messages {
    flex: 1;
    padding: 20px 5%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-repeat: repeat;
    background-size: 400px;
    background-color: #0c151b;
}

.message-bubble {
    max-width: 65%;
    width: fit-content;
    padding: 6px 7px 8px 9px;
    border-radius: 7.5px;
    margin-bottom: 10px;
    font-size: 14.2px;
    line-height: 19px;
    position: relative;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.message-bubble .body {
    white-space: pre-wrap;
    display: inline-block;
}

.message-bubble.inbound {
    align-self: flex-start;
    background-color: var(--message-bg-in);
    border-top-left-radius: 0;
}

.message-bubble.outbound {
    align-self: flex-end;
    background-color: var(--message-bg-out);
    border-top-right-radius: 0;
}

.message-time {
    display: block;
    text-align: right;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: -4px;
    float: right;
    margin-left: 10px;
    margin-bottom: -5px;
    display: flex;
    align-items: center;
    gap: 3px;
}

/* Status Ticks */
.status-ticks {
    display: flex;
    align-items: center;
}

.status-ticks svg {
    width: 16px;
    height: 16px;
}

.status-ticks.read {
    color: #53bdeb; /* Blue ticks */
}

/* Media Containers */
.media-content {
    margin-bottom: 5px;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    background-color: rgba(0,0,0,0.1);
    min-width: 200px;
}

.media-content img {
    max-width: 100%;
    display: block;
}

.media-content.audio {
    background: transparent;
}

.media-content audio {
    width: 220px;
    height: 35px;
}

.document-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background-color: rgba(0,0,0,0.1);
    border-radius: 6px;
    text-decoration: none;
    color: inherit;
}

.document-info {
    flex: 1;
    overflow: hidden;
}

.document-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.document-meta {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Reactions */
.message-reactions {
    position: absolute;
    bottom: -10px;
    left: 10px;
    display: flex;
    gap: 2px;
    background-color: #202c33;
    border: 1px solid #374045;
    padding: 2px 4px;
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.reaction-item {
    font-size: 12px;
}

.outbound .message-reactions {
    left: auto;
    right: 10px;
}

/* Location */
.location-item {
    display: block;
    text-decoration: none;
    color: inherit;
    background-color: rgba(0,0,0,0.1);
    border-radius: 6px;
    overflow: hidden;
}

.location-map-preview {
    height: 100px;
    background-color: #2a3942;
    display: flex;
    align-items: center;
    justify-content: center;
}

.location-details {
    padding: 8px;
    font-size: 13px;
}

/* Chat Input */
.chat-input-area {
    min-height: 62px;
    background-color: var(--sidebar-bg);
    display: flex;
    align-items: flex-end;
    padding: 10px 16px;
    gap: 10px;
}

#msg-body {
    flex: 1;
    background-color: var(--bg-primary);
    border: none;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 15px;
    line-height: 20px;
    max-height: 120px;
    resize: none;
    overflow-y: auto;
    font-family: inherit;
}

#msg-body:focus {
    outline: none;
}

.send-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.1s;
}

#attach-btn:hover {
    color: var(--primary-color);
}

/* Utils */
.center-p { text-align: center; padding: 20px; color: var(--text-secondary); font-size: 14px;}
.badge { background: var(--primary-color); color: white; padding: 2px 6px; border-radius: 10px; font-size: 11px; }

/* Status & QR */
.qr-container { padding: 20px; background: white; border-radius: 8px; }
.qr-container img { max-width: 250px; }
.spinner {
    width: 40px; height: 40px; border: 4px solid #f3f3f3; 
    border-top: 4px solid var(--primary-color); border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.status-indicator { display: flex; align-items: center; gap: 8px; padding: 10px 16px; background: var(--sidebar-bg); border-bottom:1px solid #222d34; font-size: 13px;}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background-color: var(--text-secondary); }

/* Sidebar Enhancement Styles */
.item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.item-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.item-subtitle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.sidebar-reaction {
    font-size: 11px;
    margin-right: 4px;
}

.unread-badge {
    background-color: var(--primary-color);
    color: #111;
    font-size: 12px;
    font-weight: bold;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}
.status-dot.scanning { background-color: #eab308; animation: pulse 1.5s infinite; }
.status-dot.connected { background-color: var(--primary-color); }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }

/* ── Login Overlay ── */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0a1014 0%, #111b21 50%, #0d1a22 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.login-card {
    background: rgba(32, 44, 51, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 48px 40px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
    animation: slideUp 0.4s ease-out;
}

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

.login-icon {
    margin-bottom: 16px;
}

.login-card h2 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 28px;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-card input {
    background-color: #2a3942;
    border: 1px solid transparent;
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: var(--font-family);
}

.login-card input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 168, 132, 0.15);
}

.login-card input::placeholder {
    color: var(--text-secondary);
}

.btn-login {
    background: linear-gradient(135deg, #00a884, #008f72);
    color: white;
    border: none;
    padding: 13px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    margin-top: 4px;
    font-family: var(--font-family);
}

.btn-login:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(0, 168, 132, 0.3);
}

.btn-login:active {
    transform: translateY(0);
}

.login-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #f87171;
    padding: 10px;
    border-radius: 8px;
    font-size: 13px;
}

/* ── Session Delete Button ── */
.session-item {
    position: relative;
}

.session-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 6px 8px;
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
    flex-shrink: 0;
}

.session-item:hover .session-delete-btn {
    opacity: 0.7;
}

.session-delete-btn:hover {
    opacity: 1 !important;
    background: rgba(239, 68, 68, 0.15);
}
