* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: #eef2f7;
    color: #1f2937;
}

/* Dark Theme */
.theme-dark {
    background: #0f172a;
    color: #e5e7eb;
}

.theme-dark .panel,
.theme-dark .chat-panel,
.theme-dark .sidebar,
.theme-dark .auth-card,
.theme-dark .installer-card,
.theme-dark .stat-card {
    background: #111827;
    color: #e5e7eb;
}

.theme-dark textarea,
.theme-dark input,
.theme-dark .admin-table td,
.theme-dark .admin-table th {
    background: #1f2937;
    color: #e5e7eb;
    border-color: #334155;
}

.theme-dark .chat-messages {
    background: #0b1220;
}

.theme-dark .nav-pill {
    background: #1f2937;
    color: #e5e7eb;
}

.theme-dark .nav-pill.active {
    background: #2563eb;
    color: #fff;
}

.theme-dark .smiley-item {
    background: #1f2937;
    color: #e5e7eb;
}

/* App Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: #1e293b;
    color: #fff;
}

.app-header a {
    color: #fff;
    text-decoration: none;
    margin-left: 14px;
}

/* App Layout */
.app-layout {
    display: grid;
    grid-template-columns: 260px 1fr 260px;
    gap: 16px;
    padding: 16px;
    min-height: calc(100vh - 56px);
}

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Panels & Cards */
.panel,
.chat-panel,
.auth-card,
.installer-card,
.stat-card {
    background: #fff;
    border-radius: 14px;
    padding: 16px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.chat-panel {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 100px);
}

/* Chat Topbar */
.chat-topbar {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 12px;
    margin-bottom: 12px;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow: auto;
    padding: 8px;
    background: #f8fafc;
    border-radius: 10px;
}

/* Message Row - Alles in einer Reihe */
.message-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: #fff;
    border-radius: 12px;
    margin-bottom: 12px;
    border-left: 4px solid #2563eb;
}

.theme-dark .message-row {
    background: #1f2937;
}

/* Avatar */
.message-row .avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: #d1d5db;
    border: 2px solid #dbeafe;
}

/* Message Content - horizontal */
.message-content {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    flex: 1;
    flex-wrap: wrap;
}

/* Topline mit Name + Zeit */
.message-topline {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.message-username {
    font-size: 15px;
    font-weight: bold;
    color: #111827;
}

.theme-dark .message-username {
    color: #e5e7eb;
}

.message-time {
    font-size: 12px;
    color: #6b7280;
}

.theme-dark .message-time {
    color: #94a3b8;
}

/* Message Body - Text und Smileys in einer Reihe */
.message-body {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 14px;
    line-height: 1.45;
    color: #1f2937;
    word-break: break-word;
}

.theme-dark .message-body {
    color: #e5e7eb;
}

/* Smiley Bilder im Chat deutlich größer */
.message-body img.smiley-inline,
.message-body img.smiley,
.message-body img.inline-smiley,
.message-body .smiley,
.message-body .inline-smiley {
    width: auto !important;
    height: 72px !important;
    min-width: 72px !important;
    min-height: 72px !important;
    max-width: 96px !important;
    max-height: 96px !important;
    object-fit: contain;
    vertical-align: middle;
    display: inline-block;
}

/* Leerer Chat */
.empty-chat {
    padding: 20px;
    color: #6b7280;
    text-align: center;
}

.theme-dark .empty-chat {
    color: #94a3b8;
}

/* Nachrichten-Tools */
.message-tools {
    margin-top: 10px;
}

.message-tools button {
    margin-right: 8px;
}

/* Chat Input */
.chat-input textarea {
    width: 100%;
    min-height: 90px;
    padding: 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
}

.chat-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}

/* Navigation Pills */
.nav-pill {
    display: block;
    padding: 10px 12px;
    border-radius: 10px;
    background: #e2e8f0;
    color: #0f172a;
    text-decoration: none;
    margin-bottom: 8px;
}

.nav-pill.active {
    background: #2563eb;
    color: #fff;
}

.nav-pill-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Online Users */
.online-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

/* Avatar Styles allgemein */
.avatar {
    display: block;
    object-fit: cover;
    border-radius: 999px;
    background: #d1d5db;
    flex-shrink: 0;
}

.avatar-chat {
    width: 44px;
    height: 44px;
    border: 2px solid #dbeafe;
}

.avatar-online {
    width: 34px;
    height: 34px;
    border: 2px solid #bbf7d0;
}

.avatar-nav {
    width: 30px;
    height: 30px;
    border: 2px solid rgba(255, 255, 255, 0.35);
}

/* Popup Backdrop */
.popup-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    justify-content: center;
    align-items: center;
}

.popup-backdrop.hidden {
    display: none;
}

/* Popup Card */
.popup-card {
    background: #fff;
    padding: 16px;
    border-radius: 14px;
    max-width: 900px;
    width: min(92vw, 900px);
    max-height: 85vh;
    overflow: auto;
}

/* Smiley Tabs & Grid */
.smiley-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
}

.smiley-tab,
.smiley-item,
button,
.secondary-button {
    border: none;
    border-radius: 10px;
    background: #2563eb;
    color: #fff;
    padding: 10px 14px;
    cursor: pointer;
}

.smiley-tab.active {
    background: #1d4ed8;
}

.smiley-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 10px;
}

.smiley-item {
    background: #f8fafc;
    color: #111827;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.smiley-item img {
    max-width: 36px;
    max-height: 36px;
}

.inline-smiley {
    width: 52px;
    height: 52px;
    object-fit: contain;
    vertical-align: middle;
}

/* Auth & Installer Pages */
.auth-page,
.installer-body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-card.large,
.installer-wrap.wide {
    width: min(960px, 100%);
}

.auth-form,
.installer-form {
    display: grid;
    gap: 12px;
}

.installer-form.two-col {
    grid-template-columns: 1fr 1fr;
}

.form-row,
.section-title,
.button-row,
.form-row-full {
    display: grid;
    gap: 6px;
}

.form-row-full,
.section-title,
.button-row {
    grid-column: 1 / -1;
}

.section-title {
    font-size: 20px;
    font-weight: bold;
    margin-top: 6px;
}

/* Notice Messages */
.notice {
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 12px;
}

.notice-success {
    background: #dcfce7;
    color: #166534;
}

.notice-error {
    background: #fee2e2;
    color: #991b1b;
}

/* Checkbox Row */
.checkbox-row label {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Admin Area */
.admin-wrap {
    padding: 16px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 14px;
    overflow: hidden;
}

.admin-table th,
.admin-table td {
    padding: 10px;
    border: 1px solid #e5e7eb;
    text-align: left;
    vertical-align: top;
}

.inline-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.stat-card h3 {
    margin: 0 0 8px;
}

/* Profile Avatar */
.profile-avatar {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    margin: 12px 0;
}

/* Responsive Design */
@media (max-width: 1000px) {
    .app-layout {
        grid-template-columns: 1fr;
    }

    .sidebar.right {
        order: 3;
    }

    .installer-form.two-col,
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Smiley Popup (draggable) */
.smiley-popup {
    position: fixed;
    top: 110px;
    left: 110px;
    z-index: 9999;
    display: block;
    width: min(92vw, 900px);
    max-width: 900px;
    max-height: 85vh;
}

.smiley-popup.hidden {
    display: none;
}

.smiley-popup-card {
    width: min(92vw, 900px);
    max-width: 900px;
    max-height: 85vh;
    overflow: auto;
}

.smiley-popup-header {
    cursor: move;
    user-select: none;
    touch-action: none;
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.popup-close {
    font-size: 24px;
    line-height: 1;
    padding: 6px 10px;
    background: #e2e8f0;
    color: #0f172a;
}

.theme-dark .popup-close {
    background: #334155;
    color: #e5e7eb;
}

.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}
