@import url('https://fonts.googleapis.com/css2?family=Newsreader:opsz,wght@6..72,400;6..72,600&family=Sora:wght@400;500;600;700&display=swap');

:root {
    --bg: #1f244c;
    --bg-ink: #0b0f1e;
    --panel: #ffffff;
    --panel-soft: #f2f4fb;
    --border: #e0e4f1;
    --shadow: none;
    --accent: #ff2e8b;
    --accent-dark: #c71f6a;
    --accent-2: #2b2f5b;
    --muted: #5b647a;
    --success: #16a34a;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: #ffffff;
    color: var(--bg-ink);
    font-family: "Sora", "Segoe UI", sans-serif;
    letter-spacing: -0.01em;
}
.app {
    min-height: 100%;
    padding: 0;
    position: relative;
}
.app::before {
    content: none;
}
.card {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto 1fr auto;
    background: var(--panel);
    border-radius: 0;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: visible;
}
.header {
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    background: #f6f7fb;
    color: #111827;
    font-family: "Newsreader", serif;
    font-size: 18px;
}
.brand-header {
    display: flex;
    align-items: center;
    gap: 12px;
}
.brand-logo {
    height: 28px;
    width: auto;
    display: block;
    filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.12));
}
.brand-title {
    font-weight: 600;
}
.messages {
    background: linear-gradient(180deg, #f7f9fc 0%, #eef2f8 100%);
    overflow-y: auto;
    padding: 14px 16px 20px;
    position: relative;
}
.messages::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(450px 160px at 70% -20%, rgba(255, 46, 139, 0.12), transparent 60%);
    pointer-events: none;
}
.bubble {
    max-width: min(92%, 980px);
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px 14px;
    background: #ffffff;
    line-height: 1.5;
    box-shadow: none;
    position: relative;
    animation: rise .18s ease-out;
}
.bubble.customer {
    margin-left: auto;
    background: linear-gradient(135deg, #1c2146 0%, #2b2f5b 100%);
    color: #fff;
    border-color: #2b2f5b;
}
.bubble.admin {
    margin-right: auto;
    max-width: 100%;
    background: #f7f8fe;
    border-color: #e0e4f1;
}
.meta {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    opacity: .8;
    margin-bottom: 6px;
    align-items: center;
}
.bubble.customer .meta { color: rgba(255, 255, 255, 0.85); }
.bubble.admin .meta { color: #3b4259; }
.channel-pill {
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(43, 47, 91, 0.12);
    color: #2b2f5b;
}
.channel-pill.email {
    background: rgba(255, 46, 139, 0.14);
    color: #b71560;
}
.bubble.customer .channel-pill {
    background: rgba(255, 255, 255, 0.16);
    color: rgba(255, 255, 255, 0.92);
}
.text {
    white-space: pre-wrap;
    word-break: break-word;
}
.composer {
    border-top: 1px solid var(--border);
    background: var(--panel);
    padding: 14px 16px 18px;
}
.row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
}
.attach-row {
    grid-template-columns: 1fr;
    margin-top: 6px;
}
.file-hint {
    font-size: 12px;
    color: var(--muted);
}
.file-size {
    margin-top: 4px;
    font-size: 12px;
    color: var(--muted);
}
.file-preview {
    display: block;
    margin-top: 8px;
    max-width: 100%;
    max-height: 260px;
    border-radius: 10px;
    border: 1px solid var(--border);
    cursor: zoom-in;
}
.file-preview-hint {
    margin-top: 6px;
    font-size: 12px;
    color: #b45309;
}
.file-list {
    display: grid;
    gap: 10px;
}
.file-item {
    display: grid;
    gap: 4px;
}
.file-badge {
    align-self: start;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 999px;
    background: #eef2ff;
    color: #1f2a44;
    display: inline-flex;
    width: fit-content;
}
.file-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--border);
}
.file-count {
    align-self: start;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 999px;
    background: #eef2ff;
    color: #1f2a44;
    display: inline-flex;
    margin-bottom: 4px;
}
.file-exif {
    font-size: 12px;
    color: #4b5563;
    margin-top: 4px;
    display: none;
}
.file-exif.open {
    display: block;
}
.sidebar-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}
.filter-btn {
    border: 1px solid var(--border);
    background: #fff;
    color: #1f2a44;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 999px;
    cursor: pointer;
}
.filter-btn.active {
    background: #1f244c;
    color: #fff;
    border-color: #1f244c;
}
.chat-snippet {
    font-size: 12px;
    color: #4b5563;
    margin-top: 6px;
}
.chat-meta-row {
    font-size: 11px;
    color: #6b7280;
    margin-top: 2px;
}
.toast {
    position: fixed;
    right: 20px;
    bottom: 24px;
    background: #111827;
    color: #fff;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 13px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .2s ease, transform .2s ease;
    z-index: 1000;
    pointer-events: none;
}
.toast.show {
    opacity: 1;
    transform: translateY(0);
}
.file-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}
.file-action-btn {
    border: 1px solid var(--border);
    background: #fff;
    color: #1f2a44;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 999px;
    text-decoration: none;
    cursor: pointer;
}
.file-action-btn:hover {
    border-color: #c9d2ea;
}
.media-count {
    border: 1px solid var(--border);
    background: #fff;
    color: #1f2a44;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 999px;
}
.subject-line {
    font-size: 12px;
    color: #4b5563;
    margin: 2px 0 6px;
    font-weight: 600;
}
.chat-item.needs-reply {
    border-left: 3px solid #ff2e8b;
}
.chat-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: #f6f7fb;
}
.chat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.link-btn {
    border: 1px solid var(--border);
    background: #fff;
    color: #1f2a44;
    font-size: 12px;
    padding: 6px 10px;
    border-radius: 999px;
    text-decoration: none;
}
.message-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.lightbox {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
}
.lightbox.open { display: flex; }
.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 18, 40, 0.6);
}
.lightbox-image {
    position: relative;
    max-width: 92vw;
    max-height: 92vh;
    border-radius: 12px;
    box-shadow: none;
    cursor: zoom-out;
    z-index: 1;
}
input[type="email"],
input[type="password"],
textarea,
button {
    border: 1px solid #cfd5e3;
    border-radius: 14px;
    font: inherit;
    padding: 12px 14px;
    background: #fff;
    transition: border-color .15s ease, box-shadow .15s ease, transform .1s ease;
}
textarea {
    width: 100%;
    min-height: 52px;
    max-height: 170px;
    resize: vertical;
}
button {
    border: 0;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    padding: 12px 18px;
    box-shadow: none;
}
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }
button:disabled {
    opacity: .6;
    cursor: not-allowed;
    box-shadow: none;
}
input:focus,
textarea:focus {
    outline: none;
    border-color: rgba(46, 108, 255, 0.65);
    box-shadow: 0 0 0 4px rgba(46, 108, 255, 0.12);
}
.status {
    min-height: 18px;
    margin-top: 6px;
    color: #dc2626;
    font-size: 13px;
}
.status.ok { color: var(--success); }
.status.info { color: var(--muted); }
.start-wrap {
    padding: 28px 22px 26px;
}
.start-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}
.admin-layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 340px 1fr;
}
.sidebar {
    border-right: 1px solid var(--border);
    background: linear-gradient(180deg, #f2f4fb 0%, #e9edf8 100%);
    overflow-y: auto;
    padding: 12px;
    position: sticky;
    top: 12px;
    height: calc(100vh - 72px);
    align-self: start;
}
.sidebar-top {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--panel-soft);
    padding-bottom: 10px;
}
.sidebar-top input[type="search"] {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #cfd5e3;
    border-radius: 12px;
    background: #fff;
}
.sidebar-meta {
    font-size: 12px;
    color: var(--muted);
    margin-top: 8px;
    padding: 0 2px;
}
.chat-list {
    padding-top: 2px;
}
.chat-item {
    width: 100%;
    text-align: left;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #ffffff;
    padding: 10px 11px;
    margin-bottom: 8px;
    cursor: pointer;
    color: #0f172a;
    transition: border-color .15s ease, box-shadow .15s ease, transform .1s ease;
}
.chat-item:hover {
    border-color: rgba(46, 108, 255, 0.4);
    box-shadow: none;
}
.chat-item:active { transform: translateY(1px); }
.chat-item.active {
    border-color: var(--accent-2);
    box-shadow: none;
    background: #f6f7ff;
}
.alias-row-list {
    font-size: 12px;
    color: #6b7280;
}
.pill { display: inline-block; margin-top: 6px; padding: 4px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.pill.online { background: rgba(255, 46, 139, 0.12); color: #b71560; }
.pill.offline { background: #e6e9f4; color: #3b4259; }
.main-chat {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    min-width: 0;
}
.main-chat .header {
    position: sticky;
    top: 0;
    z-index: 3;
}
.alias-panel {
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    padding: 10px 16px 12px;
    display: grid;
    gap: 8px;
}
.alias-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}
.alias-list {
    display: grid;
    gap: 6px;
}
.alias-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    padding: 6px 8px;
    border-radius: 10px;
    border: 1px solid #d7dbe8;
    background: #f4f6fb;
}
.alias-empty {
    font-size: 12px;
    color: var(--muted);
}
.alias-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}
.alias-form input[type="email"] {
    padding: 8px 10px;
    border: 1px solid #cfd5e3;
    border-radius: 10px;
    background: #fff;
}
.alias-remove {
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 8px;
    border: 1px solid #d7dbe8;
    background: #fff;
    color: #333;
}
.alias-status {
    font-size: 12px;
    color: var(--muted);
}
.alias-status.success { color: var(--success); }

a {
    color: var(--accent-2);
    text-decoration: none;
}
a:hover { text-decoration: underline; }

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

@media (max-width: 920px) {
    .admin-layout { grid-template-columns: 1fr; }
    .sidebar { border-right: 0; border-bottom: 1px solid var(--border); max-height: 250px; }
}

@media (max-width: 560px) {
    .brand-logo { height: 22px; }
    .start-row { grid-template-columns: 1fr; }
    .app { padding: 12px; }
    .card { min-height: calc(100vh - 24px); border-radius: 16px; }
    .row { grid-template-columns: 1fr; }
    button { width: 100%; }
}
