/* ── Reset & Variables ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:       #0d0f1e;
    --surface:  #141628;
    --surface2: #1e2140;
    --surface3: #252848;
    --border:   #2a2d4a;
    --accent:   #F0B90B;
    --text:     #c9cdd8;
    --text-dim: #6b7280;
    --radius:   8px;

    /* Colores por tipo de mensaje (spec Godot) */
    --c-chat:        #FFFFFF;
    --c-system:      #FFD966;
    --c-bet:         #D7FF77;
    --c-prize-total: #FFED00;
    --c-prize-top:   #FFED00;
    --c-tip:         #00FF7F;
    --c-error:       #EF4F85;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    overflow: hidden;
}

.hidden { display: none !important; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── Inputs & Buttons ────────────────────────────────────────────────────── */
input, select, textarea {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 8px 12px;
    font-size: .9rem;
    width: 100%;
    outline: none;
    transition: border-color .15s;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-dim); }
select option { background: var(--surface2); }

button {
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: var(--radius);
    padding: 9px 20px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity .15s, background .15s;
    font-size: .9rem;
    font-family: inherit;
}
button:hover  { opacity: .85; }
button:active { opacity: .7; }
button:disabled { opacity: .4; cursor: default; }

.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    font-weight: 400;
}
.btn-ghost:hover { background: var(--surface2); opacity: 1; }

.btn-danger { background: #c0304d; color: #fff; }
.btn-danger:hover { background: #EF4F85; opacity: 1; }

.btn-neutral { background: var(--surface3); color: var(--text); border: 1px solid var(--border); font-weight: 500; }
.btn-neutral:hover { background: var(--surface2); opacity: 1; }

.btn-sm  { padding: 5px 12px; font-size: .8rem; }
.btn-xs  { padding: 3px 8px;  font-size: .75rem; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.75);
    display: flex; align-items: center; justify-content: center;
    z-index: 200;
    backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }

.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 36px 32px;
    width: 340px;
    display: flex; flex-direction: column; gap: 14px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal-icon { font-size: 2.5rem; }
.modal-box h2 { color: var(--accent); font-size: 1.3rem; }
.modal-box p  { color: var(--text-dim); font-size: .88rem; }

.field-error { color: var(--c-error); font-size: .82rem; text-align: center; }

/* ── CHAT PAGE ───────────────────────────────────────────────────────────── */
.chat-page #app {
    display: flex; flex-direction: column; height: 100dvh;
}

.chat-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 11px 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.logo { font-size: 1rem; font-weight: 700; color: var(--accent); }

.header-right { display: flex; align-items: center; gap: 8px; }

.chip {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 12px;
    font-size: .82rem;
    color: var(--text);
}

.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--c-tip);
    box-shadow: 0 0 6px var(--c-tip);
    flex-shrink: 0;
    transition: background .3s;
}
.status-dot.offline { background: var(--c-error); box-shadow: 0 0 6px var(--c-error); }
.status-dot.connecting { background: var(--c-system); box-shadow: 0 0 6px var(--c-system); }

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    display: flex; flex-direction: column; gap: 5px;
}

.empty-state {
    flex: 1; display: flex; align-items: center; justify-content: center;
    color: var(--text-dim); font-size: .88rem; text-align: center;
}

/* ── Mensaje ─────────────────────────────────────────────────────────────── */
.msg {
    padding: 7px 11px;
    border-radius: 6px;
    border-left: 3px solid;
    background: var(--surface);
    font-size: .88rem;
    line-height: 1.5;
    animation: fadeUp .2s ease;
    word-break: break-word;
}
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: none; }
}

.msg .sender { font-weight: 700; margin-right: 5px; }

.msg.type-CHAT        { border-color: var(--c-chat);        color: var(--c-chat); }
.msg.type-SYSTEM      { border-color: var(--c-system);      color: var(--c-system); }
.msg.type-BET         { border-color: var(--c-bet);         color: var(--c-bet); }
.msg.type-PRIZE_TOTAL { border-color: var(--c-prize-total); color: var(--c-prize-total); }
.msg.type-PRIZE_TOP   { border-color: var(--c-prize-top);   color: var(--c-prize-top); }
.msg.type-TIP         { border-color: var(--c-tip);         color: var(--c-tip); }
.msg.type-ERROR       { border-color: var(--c-error);       color: var(--c-error); }

.input-bar {
    display: flex; gap: 8px;
    padding: 10px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.input-bar input { flex: 1; }

/* ── ADMIN PAGE ──────────────────────────────────────────────────────────── */
.admin-page { overflow: hidden; }

.screen {
    position: fixed; inset: 0;
    background: var(--bg);
    display: flex; align-items: center; justify-content: center;
}
.screen.hidden { display: none; }

#screen-admin {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
}

/* Login */
.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 40px 36px;
    width: 360px;
    display: flex; flex-direction: column; gap: 16px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.login-box h1 { color: var(--accent); font-size: 1.4rem; }
.login-box .dim { color: var(--text-dim); font-size: .88rem; }

/* Admin header */
.admin-header {
    display: flex; align-items: center; gap: 0;
    padding: 0 20px 0 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    height: 48px;
}
.admin-header .logo {
    padding: 0 20px;
    height: 100%;
    display: flex; align-items: center;
    border-right: 1px solid var(--border);
    margin-right: 8px;
}

/* Tabs */
.tabs { display: flex; flex: 1; height: 100%; }
.tab {
    background: transparent;
    color: var(--text-dim);
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    padding: 0 18px;
    height: 100%;
    font-size: .88rem;
    font-weight: 500;
    transition: color .15s, border-color .15s;
    cursor: pointer;
}
.tab:hover  { color: var(--text); background: transparent; opacity: 1; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }

.header-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

/* Tab content */
.tab-content { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.tab-content.active { display: flex; }

/* ── Live Tab ─────────────────────────────────────────────────────────────── */
.live-layout { display: flex; flex: 1; overflow: hidden; }

.live-feed {
    flex: 1; overflow-y: auto;
    padding: 12px 16px;
    display: flex; flex-direction: column; gap: 5px;
}

.live-sidebar {
    width: 290px; flex-shrink: 0;
    overflow-y: auto;
    padding: 14px;
    border-left: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 14px;
    background: var(--surface);
}

.sidebar-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    display: flex; flex-direction: column; gap: 8px;
}
.sidebar-card h3 {
    font-size: .8rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 2px;
}

/* Admin msg row (msg + meta + delete btn) */
.msg-row {
    display: flex; align-items: flex-start; gap: 6px;
    animation: fadeUp .2s ease;
}
.msg-row .msg { flex: 1; }
.msg-row .msg-meta { font-size: .72rem; color: var(--text-dim); margin-top: 3px; }
.msg-row .del-btn { flex-shrink: 0; margin-top: 2px; }

/* ── History Tab ─────────────────────────────────────────────────────────── */
.history-controls {
    display: flex; gap: 8px; align-items: center;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.history-controls input  { flex: 1; }
.history-controls select { width: 160px; flex-shrink: 0; }

.table-wrapper { flex: 1; overflow-y: auto; }

.data-table {
    width: 100%; border-collapse: collapse; font-size: .84rem;
}
.data-table th, .data-table td {
    padding: 9px 14px; text-align: left;
    border-bottom: 1px solid var(--border);
}
.data-table th {
    color: var(--text-dim); font-weight: 600;
    background: var(--surface);
    position: sticky; top: 0; z-index: 1;
}
.data-table tr:hover td { background: var(--surface2); }
.data-table td:last-child { width: 48px; text-align: center; }

.pagination {
    display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
    padding: 8px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.page-btn {
    background: var(--surface2); color: var(--text);
    border: 1px solid var(--border); font-weight: 400;
    padding: 4px 10px; border-radius: 4px; font-size: .8rem;
}
.page-btn.active { background: var(--accent); color: #000; font-weight: 700; border-color: var(--accent); }
.page-sep { color: var(--text-dim); padding: 0 4px; }
.page-info { color: var(--text-dim); font-size: .78rem; margin-left: auto; }

/* ── Bans Tab ─────────────────────────────────────────────────────────────── */
#tab-bans { overflow-y: auto; }

.bans-top {
    display: flex; gap: 8px; align-items: flex-end;
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.bans-top .ban-field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 120px; }
.bans-top label { font-size: .75rem; color: var(--text-dim); }

/* ── Type badges ─────────────────────────────────────────────────────────── */
.badge {
    display: inline-block; font-size: .7rem; font-weight: 700;
    padding: 2px 7px; border-radius: 999px; text-transform: uppercase;
    letter-spacing: .03em;
}
.badge-CHAT        { background: #ffffff18; color: var(--c-chat); }
.badge-SYSTEM      { background: #FFD96618; color: var(--c-system); }
.badge-BET         { background: #D7FF7718; color: var(--c-bet); }
.badge-PRIZE_TOTAL { background: #FFED0018; color: var(--c-prize-total); }
.badge-PRIZE_TOP   { background: #FFED0018; color: var(--c-prize-top); }
.badge-TIP         { background: #00FF7F18; color: var(--c-tip); }
.badge-ERROR       { background: #EF4F8518; color: var(--c-error); }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast {
    position: fixed; bottom: 24px; right: 24px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    padding: 11px 18px;
    font-size: .88rem;
    z-index: 999;
    min-width: 200px;
    max-width: 340px;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
    animation: slideIn .2s ease;
}
#toast.error { border-left-color: var(--c-error); }
@keyframes slideIn {
    from { transform: translateX(16px); opacity: 0; }
    to   { transform: none; opacity: 1; }
}

/* ── Stats bar ───────────────────────────────────────────────────────────── */
.stats-bar {
    display: flex; gap: 20px;
    padding: 6px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    font-size: .78rem;
    color: var(--text-dim);
    flex-shrink: 0;
}
.stat-val { color: var(--accent); font-weight: 700; }
