/* ═══════════════════════════════════════════════════════════
   Chat App — Modern Minimal Style
   ═══════════════════════════════════════════════════════════ */

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

:root {
    --bg:         #f0f2f5;
    --header-bg:  linear-gradient(135deg, #4a90d9 0%, #357abd 100%);
    --bubble-self:#4a90d9;
    --bubble-other:#ffffff;
    --text-self:  #ffffff;
    --text-other: #333333;
    --border:     #e0e0e0;
    --input-bg:   #ffffff;
    --shadow:     0 1px 3px rgba(0,0,0,0.12);
    --radius:     18px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: #333;
    overflow: hidden;
}

.hidden { display: none !important; }

/* ─── Screens ────────────────────────────────────────────── */
.screen {
    display: flex;
    flex-direction: column;
    height: 100vh;
}
.screen.hidden { display: none; }

/* ─── Login ──────────────────────────────────────────────── */
#login-screen {
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(1100px 700px at 88% -12%, rgba(74, 144, 217, 0.16), transparent 60%),
        radial-gradient(900px 620px at 6% 108%, rgba(120, 99, 190, 0.12), transparent 55%),
        linear-gradient(180deg, #f7f9fc 0%, #edf0f6 100%);
    position: relative;
    overflow: hidden;
}

#login-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.5;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
}

.login-card {
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border: 1px solid rgba(255, 255, 255, 0.85);
    border-radius: 20px;
    padding: 44px 36px;
    width: 372px;
    max-width: 90vw;
    box-shadow:
        0 32px 80px -20px rgba(64, 90, 130, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    text-align: center;
    position: relative;
    z-index: 1;
    animation: cardIn 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

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

.login-card h1 {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #1c2333;
    margin-bottom: 6px;
}

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

.subtitle {
    color: #8a94a6;
    font-size: 14px;
    margin-bottom: 30px;
    letter-spacing: 0.01em;
}

.input-group { margin-bottom: 16px; }

.input-group input {
    width: 100%;
    padding: 13px 16px;
    border: 1.5px solid #e3e8f0;
    border-radius: 12px;
    font-size: 15px;
    outline: none;
    background: rgba(255, 255, 255, 0.85);
    color: #1c2333;
    transition: border-color 0.25s, box-shadow 0.25s;
}

.input-group input::placeholder { color: #a7b0bf; }

.input-group input:focus {
    border-color: #4a90d9;
    box-shadow: 0 0 0 4px rgba(74, 144, 217, 0.14);
}

.btn-primary {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: 12px;
    background: #3b82d4;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background 0.25s, transform 0.15s, box-shadow 0.25s;
    box-shadow: 0 8px 24px -8px rgba(59, 130, 212, 0.55);
}
.btn-primary:hover { background: #2f74c2; }
.btn-primary:active { transform: scale(0.985); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.error-msg {
    margin-top: 12px;
    color: #e74c3c;
    font-size: 13px;
}

/* ─── Chat Header ────────────────────────────────────────── */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--header-bg);
    color: #fff;
    flex-shrink: 0;
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-title {
    font-size: 18px;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-label {
    font-size: 13px;
    opacity: 0.9;
    font-weight: 500;
}

.btn-logout {
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
    padding: 4px;
}
.btn-logout:hover { opacity: 1; }

/* ─── Chat Messages Area ─────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}

/* ─── Message Bubbles ────────────────────────────────────── */
.msg-row {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    animation: fadeSlideIn 0.25s ease-out;
}

.msg-row.self  { align-self: flex-end; align-items: flex-end; }
.msg-row.other { align-self: flex-start; align-items: flex-start; }

.msg-sender {
    font-size: 11px;
    font-weight: 600;
    color: #888;
    margin-bottom: 2px;
    padding: 0 12px;
}

.bubble {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 15px;
    line-height: 1.45;
    word-break: break-word;
    box-shadow: var(--shadow);
    position: relative;
}

.self .bubble {
    background: var(--bubble-self);
    color: var(--text-self);
    border-bottom-right-radius: 6px;
}

.other .bubble {
    background: var(--bubble-other);
    color: var(--text-other);
    border-bottom-left-radius: 6px;
}

.msg-time {
    font-size: 11px;
    color: #aaa;
    margin-top: 3px;
    padding: 0 12px;
}

.self .msg-time { text-align: right; }

/* ─── Image in bubble ────────────────────────────────────── */
.bubble img.chat-img {
    display: block;
    max-width: 300px;
    max-height: 300px;
    border-radius: 12px;
    cursor: pointer;
    object-fit: cover;
    margin-bottom: 4px;
    transition: transform 0.15s;
}
.bubble img.chat-img:hover {
    transform: scale(1.02);
}

.bubble a {
    color: inherit;
    text-decoration: underline;
    word-break: break-all;
}

.self .bubble a { color: #fff; }
.other .bubble a { color: #4a90d9; }

.btn-delete {
    background: none;
    border: none;
    color: #ccc;
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
}
.btn-delete:hover { color: #e74c3c; }
.msg-row:hover .btn-delete { opacity: 1; }

/* ─── Input Area ─────────────────────────────────────────── */
.chat-input-area {
    flex-shrink: 0;
    background: #fff;
    border-top: 1px solid var(--border);
    padding: 12px 16px;
}

.paste-preview {
    position: relative;
    margin-bottom: 10px;
    display: inline-block;
}
.paste-preview img {
    max-height: 120px;
    max-width: 200px;
    border-radius: 8px;
    border: 2px solid var(--border);
    object-fit: cover;
}
.paste-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #e74c3c;
    color: #fff;
    border: none;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-upload {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #f0f2f5;
    color: #666;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
}
.btn-upload:hover { background: #e0e2e5; }

#msg-input {
    flex: 1;
    padding: 10px 16px;
    border: 1.5px solid var(--border);
    border-radius: 22px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}
#msg-input:focus { border-color: #4a90d9; }

.btn-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--bubble-self);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
}
.btn-send:hover { opacity: 0.85; }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Image Modal ────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.75);
}

.modal-content {
    position: relative;
    z-index: 1;
    max-width: 90vw;
    max-height: 90vh;
}

.modal-content img {
    max-width: 90vw;
    max-height: 85vh;
    border-radius: 8px;
    object-fit: contain;
}

.modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: #fff;
    font-size: 32px;
    cursor: pointer;
    opacity: 0.8;
    line-height: 1;
}
.modal-close:hover { opacity: 1; }

/* ─── Admin Screen ──────────────────────────────────────── */
.admin-body {
    flex: 1;
    overflow-y: auto;
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
}

.admin-card {
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow);
}

.admin-card h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: #1c2333;
}

.admin-add-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

.admin-add-form input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.admin-add-form input:focus { border-color: #4a90d9; }

.btn-primary.btn-small {
    width: auto;
    padding: 10px 20px;
    font-size: 14px;
    flex-shrink: 0;
}

.admin-hint {
    color: #8a94a6;
    font-size: 13px;
    padding: 8px 0;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.admin-table th {
    text-align: left;
    padding: 10px 12px;
    color: #8a94a6;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}

.admin-table td {
    padding: 12px;
    border-bottom: 1px solid #f0f2f5;
    color: #1c2333;
}

.admin-table tr:last-child td { border-bottom: none; }

.badge-admin,
.badge-user {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge-admin {
    background: rgba(74, 144, 217, 0.12);
    color: #2f74c2;
}

.badge-user {
    background: rgba(120, 130, 150, 0.1);
    color: #6b7686;
}

.btn-action {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    color: #4a90d9;
    margin-right: 8px;
    transition: background 0.2s, border-color 0.2s;
}
.btn-action:hover { background: rgba(74, 144, 217, 0.08); border-color: #4a90d9; }

.btn-action-danger { color: #e74c3c; }
.btn-action-danger:hover {
    background: rgba(231, 76, 60, 0.08);
    border-color: #e74c3c;
}

/* ─── Password Modal ────────────────────────────────────── */
.pwd-content {
    background: #fff;
    border-radius: 16px;
    padding: 32px;
    width: 340px;
    max-width: 90vw;
    box-shadow: 0 24px 64px rgba(20, 30, 50, 0.25);
}

.pwd-content .modal-close {
    top: 12px;
    right: 16px;
    color: #8a94a6;
    font-size: 24px;
}

.pwd-title {
    font-size: 17px;
    font-weight: 600;
    color: #1c2333;
    margin-bottom: 20px;
}

.pwd-content input {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    margin-bottom: 8px;
    transition: border-color 0.2s;
}
.pwd-content input:focus { border-color: #4a90d9; }

/* ─── Animations ─────────────────────────────────────────── */
@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Scrollbar ──────────────────────────────────────────── */
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 600px) {
    .msg-row { max-width: 88%; }
    .login-card { padding: 28px 20px; }
    .chat-messages { padding: 12px; }
    .bubble { font-size: 14px; padding: 8px 12px; }
    .user-label { display: none; }
}
