/* ============================================================
   PipGram Messenger — Visual Identity
   Palette:
     --navy-950  #0B1220  deep sidebar background
     --navy-800  #142238  panel / hover surfaces
     --navy-700  #1D3252  borders on dark surfaces
     --signal     #17D9A3  brand accent (trading "uptick" green)
     --signal-dim #0EA982  pressed/hover state of accent
     --paper      #F6F8FB  chat panel background
     --ink        #101828  primary text
     --ink-soft   #5B6B85  secondary text
   Type: Sora (display/headings), Inter (body/UI)
   ============================================================ */

:root {
    --navy-950: #0B1220;
    --navy-800: #142238;
    --navy-700: #1D3252;
    --signal: #17D9A3;
    --signal-dim: #0EA982;
    --paper: #F6F8FB;
    --ink: #101828;
    --ink-soft: #5B6B85;
    --danger: #E5484D;
    --radius: 14px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--ink);
    background: var(--paper);
}

h1, h2, h3, .chat-title, .me-name { font-family: 'Sora', sans-serif; }

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

.hidden { display: none !important; }

/* ---------------- Auth pages ---------------- */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 20% 20%, #16243D 0%, var(--navy-950) 55%);
}

.auth-card {
    width: 380px;
    max-width: 90vw;
    background: #fff;
    border-radius: 20px;
    padding: 36px 32px;
    box-shadow: 0 30px 60px rgba(0,0,0,0.35);
}

.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand h1 { margin: 0; font-size: 24px; color: var(--ink); }

.brand-mark {
    width: 40px; height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--signal), var(--signal-dim));
    color: var(--navy-950);
    display: flex; align-items: center; justify-content: center;
    font-family: 'Sora', sans-serif;
    font-weight: 800;
    font-size: 16px;
}
.brand-mark-lg { width: 64px; height: 64px; font-size: 24px; border-radius: 18px; margin: 0 auto 16px; }

.auth-tagline { color: var(--ink-soft); margin: 6px 0 24px; font-size: 14px; }

.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form label { font-size: 13px; color: var(--ink-soft); display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.auth-form input {
    padding: 11px 13px;
    border: 1.5px solid #E3E8EF;
    border-radius: 10px;
    font-size: 14px;
    color: var(--ink);
    outline: none;
    transition: border-color .15s;
}
.auth-form input:focus { border-color: var(--signal); }

.auth-form button {
    margin-top: 4px;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: var(--navy-950);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    transition: background .15s;
}
.auth-form button:hover { background: var(--signal-dim); color: var(--navy-950); }

.form-error { color: var(--danger); font-size: 13px; min-height: 0; }
.form-success { color: var(--signal-dim); font-size: 13px; }

.auth-switch { margin-top: 20px; font-size: 13px; color: var(--ink-soft); text-align: center; }
.auth-switch a { color: var(--signal-dim); text-decoration: none; font-weight: 600; }

/* ---------------- App shell ---------------- */
.app-shell {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 100vh;
}

.sidebar {
    background: var(--navy-950);
    color: #fff;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--navy-700);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 16px;
    border-bottom: 1px solid var(--navy-700);
}

.me { display: flex; align-items: center; gap: 10px; }
.me-name { font-size: 14px; font-weight: 600; }

.avatar {
    border-radius: 50%;
    background: linear-gradient(135deg, var(--signal), var(--signal-dim));
    color: var(--navy-950);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}
.avatar-sm { width: 36px; height: 36px; font-size: 14px; }
.avatar::before { content: attr(data-initials); text-transform: uppercase; }

.icon-btn {
    width: 32px; height: 32px;
    border-radius: 8px;
    border: none;
    background: var(--navy-800);
    color: var(--signal);
    font-size: 18px;
    line-height: 1;
    display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--navy-700); }

.search-box { padding: 12px 16px; position: relative; }
.search-box input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: none;
    background: var(--navy-800);
    color: #fff;
    font-size: 13px;
    outline: none;
}
.search-box input::placeholder { color: #7C8AA6; }

.search-results {
    position: absolute;
    left: 16px; right: 16px; top: 54px;
    background: var(--navy-800);
    border-radius: 10px;
    max-height: 260px;
    overflow-y: auto;
    z-index: 10;
    box-shadow: 0 12px 24px rgba(0,0,0,0.4);
}

.search-result-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--navy-700);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--navy-700); cursor: pointer; }
.search-result-name { font-weight: 600; }
.search-result-username { color: #7C8AA6; font-size: 12px; }

.conversation-list { flex: 1; overflow-y: auto; padding: 6px 8px; }

.empty-hint { color: #7C8AA6; font-size: 13px; padding: 20px 12px; text-align: center; }

.conversation-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 10px;
    border-radius: 12px;
    margin-bottom: 2px;
}
.conversation-item:hover, .conversation-item.active { background: var(--navy-800); cursor: pointer; }
.conversation-item.active { background: var(--navy-700); }

.conv-texts { flex: 1; min-width: 0; }
.conv-title-row { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.conv-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: #7C8AA6; flex-shrink: 0; }
.conv-preview { font-size: 12.5px; color: #9AA7C0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.unread-badge {
    background: var(--signal);
    color: var(--navy-950);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    flex-shrink: 0;
}

.logout-btn {
    margin: 10px 16px 16px;
    padding: 10px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: #9AA7C0;
    font-size: 13px;
    border: 1px solid var(--navy-700);
}
.logout-btn:hover { color: #fff; border-color: var(--signal); }

/* ---------------- Chat panel ---------------- */
.chat-panel { position: relative; display: flex; flex-direction: column; background: var(--paper); }

.chat-empty-state {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--ink-soft);
    text-align: center;
    padding: 40px;
}
.chat-empty-state h2 { margin: 0 0 8px; color: var(--ink); }

.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-header {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 22px;
    background: #fff;
    border-bottom: 1px solid #E7EBF1;
}
.chat-title { font-size: 15px; font-weight: 700; }
.chat-subtitle { font-size: 12.5px; color: var(--ink-soft); }
.back-btn { display: none; }

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.msg-row { display: flex; margin-bottom: 6px; }
.msg-row.mine { justify-content: flex-end; }

.bubble {
    max-width: 62%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    position: relative;
    word-wrap: break-word;
}
.msg-row:not(.mine) .bubble {
    background: #fff;
    border: 1px solid #E7EBF1;
    border-bottom-left-radius: 4px;
}
.msg-row.mine .bubble {
    background: linear-gradient(135deg, var(--signal), var(--signal-dim));
    color: var(--navy-950);
    border-bottom-right-radius: 4px;
}
.bubble .sender-name { display: block; font-size: 11.5px; font-weight: 700; margin-bottom: 3px; color: var(--signal-dim); }
.msg-row.mine .bubble .sender-name { color: rgba(11,18,32,0.65); }
.bubble .msg-time { display: block; font-size: 10.5px; opacity: .6; margin-top: 4px; text-align: right; }
.bubble img.msg-image { max-width: 260px; border-radius: 10px; display: block; margin-bottom: 4px; }
.bubble a.msg-file { color: inherit; font-weight: 600; text-decoration: underline; }

.message-form {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 22px;
    background: #fff;
    border-top: 1px solid #E7EBF1;
}
.message-form input[type=text] {
    flex: 1;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1.5px solid #E3E8EF;
    font-size: 14px;
    outline: none;
}
.message-form input[type=text]:focus { border-color: var(--signal); }
.message-form button {
    padding: 11px 20px;
    border: none;
    border-radius: 12px;
    background: var(--navy-950);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
}
.message-form button:hover { background: var(--signal-dim); color: var(--navy-950); }
.attach-btn {
    font-size: 18px;
    padding: 8px;
    border-radius: 10px;
    background: var(--paper);
    display: flex; align-items: center; justify-content: center;
}
.attach-btn:hover { background: #E7EBF1; }

.attachment-preview {
    padding: 8px 22px 14px;
    background: #fff;
    font-size: 12.5px;
    color: var(--ink-soft);
    display: flex; align-items: center; gap: 8px;
}
.attachment-preview button { border: none; background: none; color: var(--danger); font-size: 13px; }

/* ---------------- Modal ---------------- */
.modal {
    position: fixed; inset: 0;
    background: rgba(11,18,32,0.55);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
}
.modal-card {
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    width: 380px;
    max-width: 90vw;
    display: flex; flex-direction: column; gap: 14px;
}
.modal-card h3 { margin: 0; }
.modal-card label { font-size: 13px; color: var(--ink-soft); font-weight: 500; display: flex; flex-direction: column; gap: 6px; }
.modal-card input {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1.5px solid #E3E8EF;
    font-size: 14px;
    outline: none;
}
.modal-card input:focus { border-color: var(--signal); }
.modal-card .search-results { position: static; background: var(--paper); color: var(--ink); max-height: 160px; }
.modal-card .search-result-item:hover { background: #E7EBF1; }
.modal-card .search-result-username { color: var(--ink-soft); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    background: var(--paper);
    border: 1px solid #E3E8EF;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 12.5px;
    display: flex; align-items: center; gap: 6px;
}
.chip button { border: none; background: none; color: var(--danger); font-weight: 700; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.btn-secondary, .btn-primary {
    padding: 10px 16px;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    font-size: 13.5px;
}
.btn-secondary { background: var(--paper); color: var(--ink-soft); }
.btn-primary { background: var(--navy-950); color: #fff; }
.btn-primary:hover { background: var(--signal-dim); color: var(--navy-950); }

/* ---------------- Responsive ---------------- */
@media (max-width: 760px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: absolute; inset: 0; z-index: 20; }
    .sidebar.chat-open { display: none; }
    .back-btn { display: inline-flex; }
}