:root {
    --bg: #0e1621;
    --surface: #17212b;
    --surface2: #1e2c3a;
    --text: #e1e3e6;
    --text-muted: #6c7883;
    --accent: #2b5278;
    --incoming: #182533;
    --outgoing: #2b5278;
    --deleted-bg: #3a1c1c;
    --border: #1e2c3a;
    --link: #6ab2f2;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.navbar {
    background: var(--surface);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 2rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--link);
    text-decoration: none;
}

.nav-links { display: flex; gap: 1.25rem; }
.nav-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
}
.nav-links a:hover { color: var(--text); }

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

h1 {
    font-size: 1.3rem;
    margin-bottom: 1rem;
}

/* Chat list */
.chat-list { display: flex; flex-direction: column; gap: 2px; }
.chat-item {
    display: block;
    text-decoration: none;
    color: var(--text);
    background: var(--surface);
    padding: 0.85rem 1rem;
    border-radius: 8px;
    transition: background 0.15s;
}
.chat-item:hover { background: var(--surface2); }
.chat-name { font-weight: 600; margin-bottom: 0.2rem; }
.chat-username { color: var(--text-muted); font-weight: 400; font-size: 0.85rem; }
.chat-preview {
    color: var(--text-muted);
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

/* Messages */
.chat-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.chat-header a {
    color: var(--link);
    text-decoration: none;
    font-size: 0.9rem;
}
.chat-header h1 { margin-bottom: 0; }
.msg-total { color: var(--text-muted); font-size: 0.85rem; }

.message-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 700px;
    margin: 0 auto;
}

.bubble {
    padding: 6px 10px;
    border-radius: 12px;
    word-wrap: break-word;
    width: fit-content;
    max-width: 75%;
    position: relative;
}
.bubble.incoming {
    background: var(--incoming);
    align-self: flex-start;
    border-top-left-radius: 2px;
}
.bubble.outgoing {
    background: var(--outgoing);
    align-self: flex-end;
    border-top-right-radius: 2px;
}
.bubble.deleted {
}
.bubble.highlight {
    animation: msg-highlight 2s ease-out;
}
@keyframes msg-highlight {
    0%   { box-shadow: 0 0 0 3px var(--link); }
    100% { box-shadow: 0 0 0 0 transparent; }
}

/* Sender name in group bubbles */
.bubble-sender {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--link);
    margin-bottom: 2px;
}

/* Chat type badges */
.chat-type-badge {
    display: inline-block;
    font-size: 0.7rem;
    padding: 0.05rem 0.4rem;
    border-radius: 4px;
    vertical-align: middle;
    margin-right: 0.2rem;
}
.chat-type-badge.group { background: #2b4a2b; color: #8fc98f; }
.chat-type-badge.channel { background: #2b3a5a; color: #8fb8f2; }

.bubble-media { margin-bottom: 4px; }
.bubble-media img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    display: block;
}
.bubble-media video {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    display: block;
}
.bubble-media audio { width: 100%; max-width: 280px; }
.file-link {
    color: var(--link);
    text-decoration: none;
    font-size: 0.85rem;
}
.file-link:hover { text-decoration: underline; }

.bubble-body {
    font-size: 0.9rem;
    line-height: 1.4;
    white-space: pre-wrap;
}
.bubble-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 2px;
}
.bubble-time {
    font-size: 0.68rem;
    color: var(--text-muted);
}
.badge-e {
    font-size: 0.65rem;
    color: #8fc98f;
    text-decoration: none;
    background: rgba(50,80,50,0.5);
    padding: 0 4px;
    border-radius: 3px;
}
.badge-d {
    display: none;
}

.badge {
    font-size: 0.7rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    text-decoration: none;
}
.badge.edited { background: #2b4a2b; color: #8fc98f; }
.badge.deleted-badge { }
.badge.reply { background: var(--surface2); color: var(--text-muted); }

/* Search */
.search-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.search-form input[type="text"] {
    flex: 1;
    padding: 0.6rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
}
.search-form input:focus {
    outline: none;
    border-color: var(--link);
}
.search-form button {
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: var(--text);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
}
.search-form button:hover { opacity: 0.9; }

.search-meta { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }

.search-results { display: flex; flex-direction: column; gap: 2px; }
.search-item {
    display: block;
    text-decoration: none;
    color: var(--text);
    background: var(--surface);
    padding: 0.75rem 1rem;
    border-radius: 8px;
}
.search-item:hover { background: var(--surface2); }
.search-item.deleted-item { }
.search-sender { font-weight: 600; font-size: 0.9rem; }
.search-text { font-size: 0.9rem; margin: 0.2rem 0; color: var(--text-muted); }
.search-date { font-size: 0.8rem; color: var(--text-muted); }

/* Edits */
.edit-list { display: flex; flex-direction: column; gap: 0.75rem; }
.edit-item {
    background: var(--surface);
    padding: 0.75rem 1rem;
    border-radius: 8px;
}
.edit-time { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.3rem; }
.edit-old { color: #c98f8f; font-size: 0.9rem; }
.edit-new { color: #8fc98f; font-size: 0.9rem; margin-top: 0.2rem; }

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.pg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 6px;
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text);
    text-decoration: none;
    background: var(--surface);
    transition: background 0.15s;
}
.pg-btn:hover { background: var(--surface2); }
.pg-btn.active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    pointer-events: none;
}
.pg-btn.disabled {
    opacity: 0.3;
    pointer-events: none;
}
.pg-dots {
    display: inline-flex;
    align-items: center;
    min-width: 24px;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}
.pg-jump {
    display: flex;
    align-items: center;
    margin-left: 10px;
    background: var(--surface);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    transition: border-color 0.15s;
}
.pg-jump:focus-within { border-color: var(--link); }
.pg-jump input {
    width: 48px;
    height: 30px;
    padding: 0 4px;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.85rem;
    text-align: center;
    outline: none;
    -moz-appearance: textfield;
}
.pg-jump input::-webkit-outer-spin-button,
.pg-jump input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.pg-jump button {
    height: 30px;
    padding: 0 10px;
    background: var(--accent);
    color: var(--text-muted);
    border: none;
    font-size: 0.78rem;
    cursor: pointer;
    letter-spacing: 0.5px;
    transition: color 0.15s, background 0.15s;
}
.pg-jump button:hover { background: #345e8a; color: var(--text); }

.empty { color: var(--text-muted); text-align: center; padding: 3rem 0; }

/* Login page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.login-card {
    background: var(--surface);
    padding: 2.5rem 2rem;
    border-radius: 12px;
    width: 100%;
    max-width: 360px;
}
.login-card h1 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--link);
}

/* Form elements */
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}
.form-input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
}
.form-input:focus {
    outline: none;
    border-color: var(--link);
}
.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: var(--text);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    text-decoration: none;
    text-align: center;
}
.btn:hover { opacity: 0.9; }
.btn-block { display: block; width: 100%; }
.btn-danger {
    background: #7a4040;
}
.btn-danger:hover { background: #994040; }
.btn-sm {
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
}

/* Navbar right */
.nav-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
}
.nav-right a {
    color: var(--text-muted);
    text-decoration: none;
}
.nav-right a:hover { color: var(--text); }
.nav-user { color: var(--text); font-weight: 500; }

/* Admin table */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}
.admin-table th,
.admin-table td {
    padding: 0.6rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.admin-table th {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
}
.admin-table tr:hover td {
    background: var(--surface);
}

/* Checkbox grid */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.5rem;
    margin-top: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
    padding: 0.5rem;
    background: var(--surface2);
    border-radius: 8px;
}
.checkbox-grid label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    cursor: pointer;
}

/* Flash messages */
.flash {
    padding: 0.6rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.flash.success { background: #2b4a2b; color: #8fc98f; }
.flash.error { background: #4a2b2b; color: #c98f8f; }

/* Admin create form */
.admin-create {
    background: var(--surface);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}
.admin-create h2 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
}
.inline-form {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    flex-wrap: wrap;
}
.inline-form .form-group { margin-bottom: 0; }
.inline-form .form-input { width: 160px; }
.checkbox-inline {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.9rem;
}
