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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1b2e;
    color: #e0e0e0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('/static/bg.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.06;
    pointer-events: none;
    z-index: 0;
    filter: saturate(0.3) brightness(0.8) hue-rotate(220deg);
}

nav, main, footer {
    position: relative;
    z-index: 1;
}

nav {
    background: #12132a;
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #2a2b4a;
}

.nav-brand {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(90deg, #a855f7, #ec4899, #a855f7);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: wave 3s ease-in-out infinite;
}

@keyframes wave {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.nav-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-server-stats {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: #8888a8;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.discord-icon {
    flex-shrink: 0;
}

.online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #43b581;
    border-radius: 50%;
    margin-left: 2px;
}

.nav-links a {
    color: #a0a0b8;
    text-decoration: none;
    margin-left: 24px;
    font-size: 14px;
    transition: color 0.2s;
}

.nav-links a:hover {
    color: #fff;
}

.mute-btn {
    background: none;
    border: 1px solid #2a2b4a;
    border-radius: 6px;
    padding: 6px 8px;
    cursor: pointer;
    color: #a0a0b8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 16px;
    transition: all 0.2s;
    vertical-align: middle;
}

.mute-btn:hover {
    color: #fff;
    border-color: #7c6cff;
}

.mute-icon {
    display: block;
}

.mute-cross {
    stroke: #ef4444;
    stroke-width: 2.5;
}

.page-layout {
    display: flex;
    flex: 1;
    position: relative;
    z-index: 1;
}

main {
    max-width: 960px;
    margin: 32px auto;
    padding: 0 20px;
    flex: 1;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #1e1f3a;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    border: 1px solid #2a2b4a;
}

.stat-number {
    font-size: 32px;
    font-weight: 700;
    color: #fff;
}

.stat-label {
    font-size: 13px;
    color: #8888a8;
    margin-top: 4px;
}

.stat-card.open .stat-number { color: #4ade80; }
.stat-card.closed .stat-number { color: #f87171; }

.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.filter-btn {
    padding: 8px 18px;
    border-radius: 8px;
    background: #1e1f3a;
    color: #a0a0b8;
    text-decoration: none;
    font-size: 13px;
    border: 1px solid #2a2b4a;
    transition: all 0.2s;
}

.filter-btn:hover { background: #2a2b4a; color: #fff; }
.filter-btn.active { background: #7c6cff; color: #fff; border-color: #7c6cff; }

.ticket-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ticket-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: #1e1f3a;
    border-radius: 10px;
    border: 1px solid #2a2b4a;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
}

.ticket-row:hover {
    border-color: #7c6cff;
    background: #22234a;
}

.ticket-id {
    font-size: 14px;
    font-weight: 600;
    color: #7c6cff;
    min-width: 48px;
}

.ticket-info { flex: 1; }

.ticket-subject {
    font-weight: 600;
    font-size: 15px;
    color: #fff;
}

.ticket-meta {
    font-size: 12px;
    color: #8888a8;
    margin-top: 2px;
}

.ticket-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.ticket-status.open { background: #064e3b; color: #4ade80; }
.ticket-status.closed { background: #450a0a; color: #f87171; }
.ticket-status.archived { background: #1e1b4b; color: #a5b4fc; }

.empty {
    text-align: center;
    padding: 48px;
    color: #8888a8;
    font-size: 15px;
}

/* Ticket detail */
.ticket-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    gap: 16px;
}

.ticket-header h1 {
    font-size: 22px;
    color: #fff;
    margin-bottom: 8px;
}

.ticket-header-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #8888a8;
}

.ticket-actions form { display: inline; }

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-close { background: #dc2626; color: #fff; }
.btn-close:hover { background: #b91c1c; }
.btn-reopen { background: #16a34a; color: #fff; }
.btn-reopen:hover { background: #15803d; }
.btn-reply { background: #7c6cff; color: #fff; }
.btn-reply:hover { background: #6b5ce7; }
.btn-archive { background: #4338ca; color: #fff; }
.btn-archive:hover { background: #3730a3; }

.page-title {
    font-size: 22px;
    color: #fff;
    margin-bottom: 24px;
}

/* Chat container */
.chat-container {
    background: #1a1b2e;
    border-radius: 12px;
    border: 1px solid #2a2b4a;
    display: flex;
    flex-direction: column;
    margin-bottom: 24px;
    overflow: hidden;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px;
    max-height: 600px;
    overflow-y: auto;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: #3a3b5a; border-radius: 3px; }

/* Chat message row */
.chat-msg {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background 0.15s;
}

.chat-msg:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Avatar */
.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #2d2e4a;
    color: #8888c0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 2px;
}

.avatar-admin {
    background: #3b2d6b;
    color: #7c6cff;
}

/* Chat bubble */
.chat-bubble {
    flex: 1;
    min-width: 0;
}

.bubble-admin .chat-text {
    color: #c0b8ff;
}

.chat-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}

.chat-name {
    font-weight: 600;
    font-size: 14px;
    color: #fff;
}

.chat-admin .chat-name {
    color: #7c6cff;
}

.chat-time {
    font-size: 11px;
    color: #5a5a7a;
}

.chat-text {
    font-size: 14px;
    line-height: 1.5;
    color: #d0d0e0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Attachments */
.chat-attachments {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chat-image {
    max-width: 320px;
    max-height: 240px;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.15s;
    display: block;
}

.chat-image:hover {
    opacity: 0.85;
}

.chat-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #2a2b4a;
    color: #7c6cff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    text-decoration: none;
    transition: background 0.15s;
}

.chat-file:hover {
    background: #3a3b5a;
}

/* Chat input bar */
.chat-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid #2a2b4a;
    background: #161728;
}

.chat-input-bar textarea {
    flex: 1;
    background: #1e1f3a;
    border: 1px solid #2a2b4a;
    border-radius: 8px;
    padding: 10px 14px;
    color: #e0e0e0;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    overflow-y: auto;
    min-height: 20px;
    max-height: 120px;
}

.chat-input-bar textarea:focus {
    outline: none;
    border-color: #7c6cff;
}

.chat-send-btn {
    background: #7c6cff;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}

.chat-send-btn:hover {
    background: #6b5ce7;
}

.back-link {
    color: #7c6cff;
    text-decoration: none;
    font-size: 14px;
}

.back-link:hover { text-decoration: underline; }

footer {
    text-align: center;
    padding: 32px 20px;
    margin-top: 48px;
    border-top: 1px solid #2a2b4a;
}

.footer-copyright {
    font-size: 12px;
    color: #686888;
    margin-bottom: 4px;
}

.footer-credit {
    font-size: 12px;
    color: #8888a8;
}

/* Typing animation */
.typer {
    color: #8888a8;
}

.typer-cursor {
    color: #4ade80;
    animation: blink 0.7s step-end infinite;
    font-weight: 300;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* Chat relay sidebar - Twitch style */
.relay-sidebar {
    width: 280px;
    flex-shrink: 0;
    padding: 16px 0 16px 16px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    align-self: flex-start;
}

.relay-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: #12132a;
    border: 1px solid #2a2b4a;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    user-select: none;
}

.relay-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: #8888a8;
}

.relay-live-dot {
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    animation: pulse-live 1.5s ease-in-out infinite;
}

@keyframes pulse-live {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
    50% { opacity: 0.7; box-shadow: 0 0 0 4px rgba(239, 68, 68, 0); }
}

.relay-box {
    background: #0e0f1e;
    border: 1px solid #2a2b4a;
    border-radius: 0 0 8px 8px;
    overflow: hidden;
    transition: max-height 0.3s ease;
    max-height: 500px;
}

.relay-box.collapsed {
    max-height: 0;
    border-width: 0 1px;
}

.relay-messages {
    height: 400px;
    overflow-y: auto;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.relay-messages::-webkit-scrollbar { width: 4px; }
.relay-messages::-webkit-scrollbar-track { background: transparent; }
.relay-messages::-webkit-scrollbar-thumb { background: #2a2b4a; border-radius: 2px; }

.relay-line {
    font-size: 13px;
    line-height: 1.5;
    padding: 1px 0;
    word-wrap: break-word;
}

.relay-mc {
    color: #4ade80;
    font-weight: 700;
}

.relay-dc {
    color: #7c6cff;
    font-weight: 700;
}

.relay-text {
    color: #c0c0d8;
}

/* ===== Auth pages ===== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    background: #1e1f3a;
    border: 1px solid #2a2b4a;
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.auth-brand {
    font-size: 24px;
    font-weight: 700;
    background: linear-gradient(90deg, #a855f7, #ec4899, #a855f7);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: wave 3s ease-in-out infinite;
    text-align: center;
    margin-bottom: 8px;
}

.auth-title {
    color: #fff;
    font-size: 18px;
    text-align: center;
    margin-bottom: 24px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth-field label {
    display: block;
    font-size: 13px;
    color: #8888a8;
    margin-bottom: 6px;
}

.auth-field input {
    width: 100%;
    padding: 10px 14px;
    background: #12132a;
    border: 1px solid #2a2b4a;
    border-radius: 8px;
    color: #e0e0e0;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.auth-field input:focus {
    outline: none;
    border-color: #7c6cff;
}

.auth-btn {
    width: 100%;
    padding: 12px;
    background: #7c6cff;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 4px;
}

.auth-btn:hover {
    background: #6b5ce7;
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 13px;
    color: #8888a8;
}

.auth-footer a {
    color: #7c6cff;
    text-decoration: none;
}

.auth-footer a:hover {
    text-decoration: underline;
}

.auth-flash {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
}

.auth-flash.error {
    background: #450a0a;
    color: #f87171;
    border: 1px solid #7f1d1d;
}

.auth-flash.success {
    background: #064e3b;
    color: #4ade80;
    border: 1px solid #065f46;
}

/* ===== Admin panel ===== */
.admin-section {
    background: #1e1f3a;
    border: 1px solid #2a2b4a;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.admin-subtitle {
    font-size: 16px;
    color: #fff;
    margin-bottom: 16px;
}

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

.invite-select {
    padding: 8px 14px;
    background: #12132a;
    border: 1px solid #2a2b4a;
    border-radius: 8px;
    color: #e0e0e0;
    font-size: 13px;
    font-family: inherit;
}

.invite-select.small {
    padding: 6px 10px;
    font-size: 12px;
}

.invite-select:focus {
    outline: none;
    border-color: #7c6cff;
}

.admin-table {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.admin-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: #12132a;
    border-radius: 8px;
    border: 1px solid #2a2b4a;
    flex-wrap: wrap;
}

.invite-code {
    background: #0e0f1e;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 13px;
    color: #4ade80;
    user-select: all;
}

.admin-meta {
    font-size: 12px;
    color: #8888a8;
}

.admin-user-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
}

.admin-user-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.inline-form {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.nav-user-menu {
    position: relative;
    display: inline-flex;
    margin-left: 24px;
}

.nav-user-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #a0a0b8;
    font-size: 14px;
    cursor: pointer;
    transition: color 0.2s;
}

.nav-user-trigger svg {
    flex-shrink: 0;
}

.nav-user-trigger:hover {
    color: #fff;
}

.nav-user-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    padding-top: 6px;
    min-width: 140px;
    z-index: 100;
}

.nav-user-dropdown-inner {
    background: #12132a;
    border: 1px solid #2a2b4a;
    border-radius: 8px;
    overflow: hidden;
}

.nav-user-menu:hover .nav-user-dropdown {
    display: block;
}

.nav-user-dropdown a {
    display: block;
    padding: 10px 16px;
    color: #a0a0b8;
    text-decoration: none;
    font-size: 13px;
    margin-left: 0;
    transition: all 0.15s;
}

.nav-user-dropdown a:hover {
    background: #1e1f3a;
    color: #f87171;
}

/* ===== Mobile responsive ===== */
@media (max-width: 768px) {
    /* Nav */
    nav {
        flex-direction: column;
        align-items: flex-start;
        padding: 12px 16px;
        gap: 10px;
    }

    .nav-links {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }

    .nav-links a {
        margin-left: 0;
        font-size: 13px;
    }

    .mute-btn {
        margin-left: 0;
    }

    /* Layout: stack sidebar above main */
    .page-layout {
        flex-direction: column;
    }

    .relay-sidebar {
        width: 100%;
        padding: 12px 12px 0;
        position: relative;
    }

    .relay-messages {
        height: 180px;
    }

    .relay-box {
        max-height: 250px;
    }

    /* Main content */
    main {
        margin: 16px auto;
        padding: 0 12px;
    }

    /* Stats grid */
    .stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .stat-card {
        padding: 14px 8px;
    }

    .stat-number {
        font-size: 24px;
    }

    .stat-label {
        font-size: 11px;
    }

    /* Filter bar */
    .filter-bar {
        flex-wrap: wrap;
    }

    .filter-btn {
        padding: 6px 14px;
        font-size: 12px;
    }

    /* Ticket rows */
    .ticket-row {
        flex-wrap: wrap;
        padding: 12px 14px;
        gap: 8px;
    }

    .ticket-id {
        min-width: auto;
    }

    .ticket-info {
        width: 100%;
        order: 3;
    }

    /* Ticket detail */
    .ticket-header {
        flex-direction: column;
    }

    .ticket-header h1 {
        font-size: 18px;
    }

    .ticket-header-meta {
        flex-wrap: wrap;
        gap: 6px;
    }

    .ticket-actions {
        display: flex;
        gap: 8px;
    }

    .btn {
        padding: 8px 14px;
        font-size: 12px;
    }

    /* Chat messages (ticket detail) */
    .chat-messages {
        padding: 10px;
        max-height: 450px;
    }

    .chat-avatar {
        width: 30px;
        height: 30px;
        font-size: 12px;
    }

    .chat-name {
        font-size: 13px;
    }

    .chat-text {
        font-size: 13px;
    }

    .chat-image {
        max-width: 100%;
        max-height: 200px;
    }

    .chat-input-bar {
        padding: 10px 12px;
    }

    .chat-input-bar textarea {
        font-size: 14px;
        padding: 8px 10px;
    }

    .chat-send-btn {
        padding: 8px 14px;
        font-size: 13px;
    }

    /* Footer */
    footer {
        padding: 20px 12px;
        margin-top: 24px;
    }
}

@media (max-width: 400px) {
    .stats {
        grid-template-columns: 1fr;
    }

    .nav-brand {
        font-size: 17px;
    }

    .nav-server-stats {
        flex-direction: column;
        gap: 4px;
    }

    .ticket-row {
        padding: 10px 12px;
    }

    .ticket-subject {
        font-size: 14px;
    }
}
