:root {
    --primary: #075e54;
    --primary-dark: #054d44;
    --primary-light: #128c7e;
    --bg: #e5ddd5;
    --bg-light: #efeae2;
    --white: #ffffff;
    --sent-bubble: #dcf8c6;
    --received-bubble: #ffffff;
    --text-primary: #111b21;
    --text-secondary: #667781;
    --text-muted: #8696a0;
    --border: #e9edef;
    --danger: #ea0038;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --transition: 0.2s ease;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #111;
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

#app {
    max-width: 900px;
    margin: 0 auto;
    height: 100vh;
    height: 100dvh;
    background: var(--white);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

@media (min-width: 768px) {
    #app {
        height: 96vh;
        height: 96dvh;
        margin: 2vh auto;
        border-radius: 16px;
    }
}

.screen {
    display: none;
    flex-direction: column;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background: var(--white);
    transition: transform var(--transition), opacity var(--transition);
    z-index: 1;
}

.screen.active {
    display: flex;
    z-index: 2;
}

/* ---------- Login Screen Enhancements ---------- */
#login-screen {
    background: linear-gradient(135deg, #075e54 0%, #128c7e 50%, #25d366 100%);
    justify-content: flex-start;
    align-items: center;
    padding: 24px;
    overflow-y: auto;
    text-align: center;
}

.login-logo {
    font-size: 72px;
    color: #fff;
    text-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    margin-top: 30px;
    margin-bottom: 10px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-10px);
    }

    100% {
        transform: translateY(0px);
    }
}

.login-title {
    font-size: 36px;
    font-weight: 800;
    color: #fff;
    letter-spacing: 2px;
    text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    margin-bottom: 4px;
}

.login-subtitle {
    color: rgba(255, 255, 255, 0.9);
    font-size: 16px;
    margin-bottom: 30px;
    font-weight: 400;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
    margin-bottom: 20px;
}

.login-card label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.login-card label i {
    margin-right: 6px;
    color: var(--primary-light);
}

.login-card input,
.login-card textarea {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid #e0e0e0;
    border-radius: var(--radius-sm);
    font-size: 15px;
    margin-bottom: 16px;
    transition: border var(--transition);
    font-family: inherit;
    background: #f8f9fa;
    resize: none;
}

.login-card input:focus,
.login-card textarea:focus {
    outline: none;
    border-color: var(--primary-light);
    background: #fff;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    letter-spacing: 0.2px;
    white-space: nowrap;
}

.btn i {
    font-size: 1em;
}

.btn-primary {
    background: var(--primary-light);
    color: #fff;
    width: 100%;
    padding: 14px;
    font-size: 16px;
}

.btn-primary:hover {
    background: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(7, 94, 84, 0.3);
}

.btn-primary:active {
    transform: scale(0.97);
}

.btn-outline {
    background: transparent;
    color: var(--primary-light);
    border: 2px solid var(--primary-light);
    width: 100%;
    padding: 12px;
    font-size: 14px;
    margin-top: 8px;
}

.btn-outline:hover {
    background: rgba(18, 140, 126, 0.06);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
    border-radius: 20px;
    width: auto;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
    color: #fff;
}

.btn-icon i {
    font-size: 18px;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-icon.dark {
    color: var(--text-secondary);
}

.btn-icon.dark:hover {
    background: rgba(0, 0, 0, 0.06);
}

.divider-text {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    margin: 12px 0;
    position: relative;
}

.divider-text::before,
.divider-text::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 35%;
    height: 1px;
    background: #e0e0e0;
}

.divider-text::before {
    left: 0;
}

.divider-text::after {
    right: 0;
}

/* ---------- Header with brand icon ---------- */
.header {
    background: var(--primary);
    color: #fff;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 56px;
    z-index: 10;
    flex-shrink: 0;
}

.header-brand {
    font-size: 24px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-subtitle {
    font-size: 12px;
    opacity: 0.85;
    font-weight: 400;
}

/* ---------- Main Layout ---------- */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.sidebar {
    width: 100%;
    max-width: 380px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: #fff;
    flex-shrink: 0;
    z-index: 5;
}

@media (min-width: 768px) {
    .sidebar {
        width: 35%;
        min-width: 300px;
    }
}

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    position: relative;
    z-index: 4;
}

@media (max-width: 767px) {
    .sidebar {
        max-width: 100%;
        width: 100%;
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 6;
        transition: transform var(--transition);
    }

    .sidebar.hidden-mobile {
        transform: translateX(-100%);
    }

    .chat-area {
        width: 100%;
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
    }

    .chat-area.hidden-mobile {
        transform: translateX(100%);
        pointer-events: none;
    }
}

.search-bar {
    padding: 8px 12px;
    background: #f6f6f6;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.search-bar input {
    width: 100%;
    padding: 10px 16px 10px 38px;
    border: none;
    border-radius: 20px;
    background: #fff;
    font-size: 14px;
    outline: none;
    border: 1px solid transparent;
    transition: border var(--transition);
    font-family: inherit;
}

.search-bar input:focus {
    border-color: var(--primary-light);
}

.search-bar .search-icon {
    position: absolute;
    left: 22px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    color: #999;
    pointer-events: none;
    z-index: 1;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background var(--transition);
    border-bottom: 1px solid #f5f5f5;
}

.chat-item:hover {
    background: #f0f2f5;
}

.chat-item.active {
    background: #e8f5e9;
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.avatar.sm {
    width: 36px;
    height: 36px;
    font-size: 14px;
}

.chat-item-info {
    flex: 1;
    min-width: 0;
}

.chat-item-name {
    font-size: 16px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.chat-item-time {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    align-self: flex-start;
    margin-top: 2px;
}

.pin-btn {
    background: none;
    border: none;
    color: #ccc;
    cursor: pointer;
    padding: 4px;
    font-size: 14px;
    transition: color var(--transition);
    flex-shrink: 0;
}
.pin-btn:hover, .pin-btn.pinned {
    color: var(--primary-light);
}

.unread-badge {
    background: #25d366;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    flex-shrink: 0;
}

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
    background: repeating-linear-gradient(0deg, transparent, transparent 30px, rgba(0, 0, 0, 0.015) 30px, rgba(0, 0, 0, 0.015) 31px);
}

.message-row {
    display: flex;
    margin-bottom: 4px;
    max-width: 85%;
    animation: fadeInUp 0.25s ease;
}

.message-row.sent {
    align-self: flex-end;
    margin-left: auto;
}

.message-row.received {
    align-self: flex-start;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.45;
    word-break: break-word;
    position: relative;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.05);
}

.message-row.sent .message-bubble {
    background: var(--sent-bubble);
    border-top-right-radius: 4px;
}

.message-row.received .message-bubble {
    background: var(--received-bubble);
    border-top-left-radius: 4px;
}

.message-time {
    font-size: 10px;
    color: var(--text-muted);
    text-align: right;
    margin-top: 2px;
    padding-right: 2px;
}

.message-row.sent .message-time {
    color: #6b8e6b;
}

.message-bubble img {
    max-width: 200px;
    border-radius: 8px;
    margin: 4px 0;
}

.date-divider {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin: 12px 0;
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    display: inline-block;
    align-self: center;
}

.empty-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 12px;
    font-size: 15px;
    padding: 40px;
}

.empty-chat-icon {
    font-size: 56px;
    opacity: 0.3;
}

/* Input */
.input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 12px;
    background: #f0f0f0;
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0;
    padding-bottom: calc(8px + var(--safe-bottom));
}

.input-area input {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 24px;
    font-size: 15px;
    outline: none;
    background: #fff;
    font-family: inherit;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.btn-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary-light);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(18, 140, 126, 0.3);
}

.btn-send i {
    font-size: 18px;
}

.btn-send:hover {
    background: var(--primary);
    transform: scale(1.05);
}

.btn-send:disabled {
    background: #ccc;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

/* Modals, tables, toggles, toast, etc. (unchanged except minor icon spacing) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: 16px;        /* rounded on all sides */
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 8px 0 24px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
    animation: fadeIn 0.3s ease;
    margin: 0;                  /* reset any margin */
}
.modal-small {
    max-width: 380px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-handle {
    display: none;   /* hide the drag handle */
}

.modal h3 {
    font-size: 18px;
    font-weight: 700;
    padding: 0 20px;
    margin-bottom: 16px;
}

.modal-section {
    padding: 0 20px;
    margin-bottom: 20px;
}

.modal-section label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 6px;
}

.modal-section input,
.modal-section textarea {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e0e0e0;
    border-radius: var(--radius-sm);
    font-size: 14px;
    margin-bottom: 10px;
    background: #f8f9fa;
}

.modal-section input:focus,
.modal-section textarea:focus {
    outline: none;
    border-color: var(--primary-light);
    background: #fff;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
}

.toggle-switch {
    width: 50px;
    height: 30px;
    background: #ccc;
    border-radius: 15px;
    position: relative;
    cursor: pointer;
    transition: background var(--transition);
}

.toggle-switch.active {
    background: #25d366;
}

.toggle-switch::after {
    content: '';
    width: 26px;
    height: 26px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform var(--transition);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-switch.active::after {
    transform: translateX(20px);
}

.settings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.settings-table th,
.settings-table td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid #f0f0f0;
}

.settings-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
}

.gif-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 12px;
}

.gif-grid img {
    width: 100%;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s;
}

.gif-grid img:hover {
    transform: scale(1.03);
}

.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    opacity: 0;
    pointer-events: none;
    background: #333;
    color: #fff;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    z-index: 200;
    transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.35s ease;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.toast.success {
    background: #25d366;
}

.toast.error {
    background: #ea0038;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid #ccc;
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

.text-center {
    text-align: center;
}

.mt-2 {
    margin-top: 8px;
}

.mt-3 {
    margin-top: 16px;
}

.text-xs {
    font-size: 11px;
    color: var(--text-muted);
}

/* Privacy link on login screen */
.privacy-link {
    margin-top: 20px;
    text-align: center;
}
.privacy-link a {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: color var(--transition);
}
.privacy-link a:hover {
    color: #fff;
    text-decoration: underline;
}
.privacy-link a i {
    margin-right: 6px;
}

/* Privacy content (modal) */
.privacy-content h4 {
    font-size: 16px;
    margin-top: 20px;
    margin-bottom: 8px;
    color: var(--primary);
}
.privacy-content h4 i {
    width: 24px;
    color: var(--primary-light);
}
.privacy-content p {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: 12px;
}
.privacy-content code {
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 13px;
}

/* Wider modal for better readability */
.modal-wide {
    max-width: 580px;
}

/* Context Menu */
.message-context-menu {
    z-index: 999;
    position: fixed;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    padding: 4px 0;
    display: none;
    flex-direction: column;
    min-width: 160px;
}
.message-context-menu.active {
    display: flex;
}
.context-menu-item {
    background: none;
    border: none;
    padding: 10px 16px;
    text-align: left;
    font-size: 14px;
    cursor: pointer;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.1s;
}
.context-menu-item:hover {
    background: #f0f2f5;
}
.context-menu-item i {
    width: 20px;
    text-align: center;
}
.context-menu-reactions {
    display: flex;
    justify-content: space-around;
    padding: 8px 12px;
    border-top: 1px solid #e0e0e0;
}
.reaction-emoji {
    font-size: 20px;
    cursor: pointer;
    transition: transform 0.1s;
    padding: 4px;
    border-radius: 8px;
}
.reaction-emoji:hover {
    transform: scale(1.3);
    background: #f0f2f5;
}

/* Reaction bar on message */
.reaction-bar {
    display: flex;
    gap: 4px;
    margin-top: 2px;
    font-size: 14px;
}
.reaction-bar span {
    background: rgba(0,0,0,0.05);
    border-radius: 12px;
    padding: 1px 6px;
    font-size: 13px;
}

/* Mark all read button */
.btn-mark-read {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 8px;
    font-size: 18px;
    transition: opacity 0.2s;
}
.btn-mark-read:hover {
    opacity: 0.8;
}

/* Add at the end of your existing style.css */
.remember-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}
.remember-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary-light);
    margin: 0;
}
.remember-label {
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #fff;
    z-index: 999;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
}
.loading-overlay p {
    font-size: 16px;
    color: var(--text-secondary);
    font-weight: 500;
}