/* ==========================================================================
   pages.css — CSS untuk semua route SPA (login, register, account, password,
   notifications, highscore, guilds, guild, skin, search, friends, battle
   lobby). Di-extract dari blok <style> inline yang tadinya ada di pages.js.

   Catatan:
   - Semua class pakai prefix "spa-" / "bl-" biar gak bentrok sama index.css.
   - Inline style="..." di string HTML pages.js TIDAK dipindah ke sini —
     itu pattern codebase, biar tetap maintainable.
   - wrapDialog() sekarang cuma inject HTML, stylingnya lewat class
     .spa-no-bg / .spa-route-* yang didefinisikan di bawah.
   ========================================================================== */


/* ==========================================================================
   WRAP DIALOG OVERLAY
   ========================================================================== */

#spa-loginOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 499;
    display: flex;
    align-items: center;
    justify-content: center;
    background-image: url('../img/background_V3.png');
    background-size: cover;
    background-position: center;
}

/* Diterapkan waktu user udah pernah Play → canvas game harus keliatan */
#spa-loginOverlay.spa-no-bg {
    background-image: none;
    background-color: transparent;
}

#spa-loginOverlay #helloDialog {
    position: relative;
}

/* Varian tinggi dialog per-route */
#spa-loginOverlay.spa-route-highscore #helloDialog,
#spa-loginOverlay.spa-route-guilds #helloDialog {
    min-height: 600px !important;
}

#spa-loginOverlay.spa-route-guild #helloDialog {
    min-height: 600px !important;
    max-height: 92vh !important;
    overflow-y: auto !important;
}

#spa-loginOverlay.spa-route-notifications #helloDialog {
    overflow: hidden;
}


/* ==========================================================================
   NOTIFICATIONS
   ========================================================================== */

.spa-notif-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 6px;
    border-bottom: 1px solid #f0f0f0;
    animation: spa-fadeIn 0.25s ease;
}

@keyframes spa-fadeIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.spa-notif-item.removing {
    animation: spa-fadeOut 0.2s ease forwards;
}

@keyframes spa-fadeOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(30px); }
}

.spa-notif-text {
    flex: 1;
    font-size: 13px;
    color: #333;
    line-height: 1.4;
}
.spa-notif-text strong { color: #337ab7; }
.spa-notif-text small {
    display: block;
    color: #aaa;
    font-size: 11px;
    margin-top: 2px;
}

.spa-notif-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.spa-notif-title {
    font-size: 15px;
    font-weight: bold;
    color: #333;
}
.spa-notif-count-badge {
    background: #d9534f;
    color: white;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: bold;
}


/* ==========================================================================
   SHARED — empty state & toast
   ========================================================================== */

.spa-empty-state {
    text-align: center;
    padding: 30px 20px;
    color: #bbb;
    font-size: 13px;
}
.spa-empty-state div {
    font-size: 32px;
    margin-bottom: 8px;
}

.spa-toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(60px);
    background: #333;
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 13px;
    z-index: 9999;
    transition: transform 0.3s ease;
    pointer-events: none;
}
.spa-toast.show    { transform: translateX(-50%) translateY(0); }
.spa-toast.success { background: #5cb85c; }
.spa-toast.error   { background: #d9534f; }


/* ==========================================================================
   HIGHSCORE
   ========================================================================== */

.spa-score-row {
    display: flex;
    align-items: center;
    padding: 8px 4px;
    border-bottom: 1px solid #eee;
    gap: 10px;
    font-size: 13px;
}
.spa-score-rank {
    color: #333;
    width: 24px;
    text-align: center;
    flex-shrink: 0;
    font-weight: bold;
}
.spa-score-rank.top1 { color: #f5c518; }
.spa-score-rank.top2 { color: #aaa; }
.spa-score-rank.top3 { color: #cd7f32; }
.spa-score-name {
    flex: 1;
    font-weight: bold;
    color: #333;
}
.spa-score-time {
    color: #000000;
    font-weight: normal;
    width: 60px;
    text-align: right;
}


/* ==========================================================================
   GUILD DETAIL
   ========================================================================== */

.spa-gtab {
    padding: 6px 14px;
    font-size: 15px;
    cursor: pointer;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    color: #347bb7;
    background: transparent;
    font-family: Arial, sans-serif;
    margin-bottom: -2px;
}
.spa-gtab.active {
    background: #fff;
    border-color: #ddd;
    color: #333;
    border-bottom: 1px solid #fff;
}
.spa-gtab:hover:not(.active) { background: #f5f5f5; }

.spa-member-row {
    display: flex;
    align-items: center;
    padding: 7px 4px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 13px;
    gap: 10px;
}
.spa-member-row.is-leader { background: #ffec95; }

.spa-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 4px;
    font-size: 14px;
    line-height: 1;
    border-radius: 4px;
    transition: background 0.15s;
}
.spa-icon-btn:hover { background: #f0f0f0; }

.spa-btn-action {
    padding: 6px 14px;
    border-radius: 6px;
    border: none;
    font-size: 14px;
    cursor: pointer;
    color: white;
}

.spa-log-row {
    padding: 8px 4px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 12px;
    color: #333;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}


/* ==========================================================================
   SEARCH
   ========================================================================== */

.spa-search-tabs {
    display: flex;
    border-bottom: 1px solid #ddd;
    margin-bottom: 10px;
    gap: 2px;
}
.spa-search-tab {
    padding: 6px 14px;
    font-size: 15px;
    cursor: pointer;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    color: #347bb7;
    background: transparent;
    font-family: Arial, sans-serif;
}
.spa-search-tab.active {
    background: #fff;
    border-color: #ddd;
    color: #333;
    margin-bottom: -1px;
    border-bottom: 1px solid #fff;
}
.spa-search-tab:hover:not(.active) { background: #f5f5f5; }

.spa-tab-pane        { display: none; }
.spa-tab-pane.active { display: block; }

#helloDialog table                { width: 100%; margin-top: 10px; }
#helloDialog table td             { padding: 6px 4px; border-bottom: 1px solid #eee; }
#helloDialog table td:first-child { color: #000000; width: 90px; }

.spa-msg {
    font-size: 13px;
    color: #aaa;
    text-align: center;
    padding: 20px 0;
}
.spa-msg.error { color: #e55; }

.spa-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #ddd;
    border-top-color: #4a9eff;
    border-radius: 50%;
    animation: spa-spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 4px;
}
@keyframes spa-spin { to { transform: rotate(360deg); } }

.spa-match-item {
    padding: 5px 0;
    border-bottom: 1px solid #eee;
    font-size: 13px;
}
.spa-match-item:last-child { border-bottom: none; }

.spa-m2-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    column-gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid #eee;
    background: #fff;
    font-size: 14px;
    font-family: Arial, sans-serif;
}
.spa-m2-row.alt { background: #f7f7f7; }
.spa-m2-row.win { color: #222; }
.spa-m2-row.draw { color: #8a6d00; }
.spa-m2-row.lose { color: #c51b1a; }
.spa-m2-side {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.4;
}
.spa-m2-side span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.spa-m2-side.left { align-items: flex-end; text-align: right; font-weight: bold; }
.spa-m2-side.right { align-items: flex-start; text-align: left; font-weight: 500; }
.spa-m2-score {
    text-align: center;
    font-weight: bold;
    padding: 0 4px;
}

.spa-search-row {
    position: absolute;
    bottom: 50px;
    left: 0;
    right: 0;
    padding: 0 15px;
    margin: 0;
    display: flex;
    z-index: 20; /* tambah ini */
}
.spa-search-row input {
    flex: 1;
    padding: 6px 10px;
    font-size: 15px;
    font-family: Arial, sans-serif;
    border: 1px solid #ccc;
    border-right: none;
    border-radius: 4px 0 0 4px;
    outline: none;
}
.spa-search-row input:focus { border-color: #3c82f5; }
.spa-search-row button {
    padding: 6px 12px;
    background: #3c82f5;
    border: none;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    color: white;
    font-size: 14px;
}

.spa-status-premium { color: green; font-weight: bold; }
.spa-status-free    { color: #aaa; }


/* ==========================================================================
   FRIENDS
   ========================================================================== */

.spa-friend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.spa-friend-title   { font-size: 15px; font-weight: bold; color: #333; }
.spa-friend-refresh { cursor: pointer; color: #337ab7; font-size: 15px; }
.spa-friend-addbtn {
    display: block;
    text-align: center;
    color: #337ab7;
    font-size: 14px;
    text-decoration: none;
    margin-bottom: 12px;
}

.spa-friend-list-box {
    min-height: 150px;
    max-height: 340px;
    overflow-y: auto;
}

.spa-friend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    animation: spa-fadeIn 0.25s ease;
}
.spa-friend-name {
    flex: 1;
    font-size: 14px;
    color: #333;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.spa-friend-tag {
    color: #000;
    font-weight: bold;
    margin-right: 6px;
    font-size: 13px;
}
.spa-friend-sub {
    font-size: 11px;
    color: #aaa;
}

.spa-friend-remove  { color: #d9534f; cursor: pointer; font-size: 13px; flex-shrink: 0; }
.spa-friend-actions { display: flex; gap: 8px; flex-shrink: 0; }
.spa-friend-accept  { color: #5cb85c; cursor: pointer; font-size: 16px; }
.spa-friend-reject  { color: #d9534f; cursor: pointer; font-size: 16px; }

.spa-friend-avatar {
    position: relative;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #337ab7;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 15px;
    overflow: hidden;
}
.spa-friend-avatar.pending {
    background: #e0e0e0;
    color: #e0e0e0;
}
.spa-friend-avatar.pending::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid #ccc;
    border-top-color: #888;
    animation: spa-spin 0.8s linear infinite;
}

.spa-status-icon {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.spa-status-icon .spa-status-dot        { width: 11px; height: 11px; border-radius: 50%; background: #bbb; }
.spa-status-icon .spa-status-dot.online { background: #5cb85c; }
.spa-status-icon .fa-gamepad            { color: #5b9ebe; font-size: 15px; }


/* ==========================================================================
   BATTLE LOBBY MODAL (blEnsureDom() di pages.js)
   Layout: overlay gelap > panel putih fixed 800x704 > header + grid 2 kolom.
   Kolom kiri: Settings + Chat. Kolom kanan: Players + Friends.
   ========================================================================== */

.bl-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    align-items: center;
    justify-content: center;
}

.bl-modal {
    width: 800px;
    height: 704px;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, .38);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    font-family: Arial, Helvetica, sans-serif;
    color: #444;
}

/* Header */
.bl-header {
    height: 57px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    border-bottom: 1px solid #e5e5e5;
}
.bl-header-title {
    margin: 0;
    font-size: 18px;
    font-weight: 400;
    color: #444;
}
.bl-close-btn {
    border: 0;
    background: transparent;
    color: #c9c9c9;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

/* Grid isi: 2 kolom */
.bl-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 20px 6px 0;
    overflow: hidden;
}
.bl-column {
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 0;
}

/* Panel dasar */
.bl-box {
    position: relative;
    height: 283px;
    border: 1px solid #d8d8d8;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
    display: flex;
    flex-direction: column;
}
.bl-box-header {
    height: 41px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 14px;
    background: #f3f3f3;
    border-bottom: 1px solid #d6d6d6;
    color: #707070;
    font-size: 14px;
}
.bl-box-title {
    display: flex;
    align-items: center;
    gap: 5px;
    font-weight: 400;
    color: #707070;
    font-size: 14px;
}
.bl-box-title strong { font-weight: 700; color: #555; }

/* Kotak 1: Settings */
.bl-settings-body {
    flex: 1;
    font-size: 14px;
    overflow-y: auto;
}
.bl-settings-table {
    width: 100%;
    border-collapse: collapse;
}
.bl-settings-table tr {
    border-bottom: 1px solid #ddd;
}
.bl-settings-table tr:last-child {
    border-bottom: none;
}
.bl-settings-table td.bl-key {
    padding: 0 8px;
    height: 37px;
    width: 117px;
    color: #444;
    vertical-align: middle;
}
.bl-settings-table td.bl-val {
    padding: 0 8px;
    vertical-align: middle;
}
.bl-settings-link {
    color: #4169b1;
    text-decoration: none;
    border-bottom: 1px dotted #4169b1;
}
.bl-settings-link.bl-danger {
    color: red;
    border-bottom-color: red;
}

/* Kotak 2: Players */
.bl-players-header {
    height: 41px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding: 0 14px;
    background: #f3f3f3;
    border-bottom: 1px solid #d6d6d6;
}
.bl-players-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 0;
}
.bl-players-list {
    padding: 0;
    flex: 1;
    overflow-y: auto;
}

.bl-start-btn {
    position: absolute;
    bottom: 0;
    left: -1px;
    width: calc(100% + 2px);
    height: 35px;
    border: 0;
    border-radius: 4px;
    background: #e98d8d;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

/* Kotak 3: Chat */
.bl-chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.bl-chat-messages {
    flex: 1;
    overflow-y: auto;
    font-size: 13px;
    color: #aaa;
    margin-bottom: 10px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bl-chat-input {
    height: 36px;
    flex-shrink: 0;
    width: 100%;
    border: 0;
    border-top: 1px dotted #ddd;
    padding: 0 12px;
    font: inherit;
    font-size: 14px;
    outline: 0;
    box-sizing: border-box;
}

/* Kotak 4: Friends */
.bl-friends-header {
    height: 41px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    background: #f3f3f3;
    border-bottom: 1px solid #d6d6d6;
}
.bl-friends-toggle-label {
    font-size: 12px;
    color: #888;
    font-weight: normal;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
.bl-friends-toggle-box {
    width: 15px;
    height: 15px;
    background: #ccc;
    border-radius: 3px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.bl-friends-toggle-check {
    font-size: 9px;
    color: white;
    display: none;
}
.bl-friends-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}
.bl-friends-placeholder {
    padding: 20px 12px;
    text-align: center;
    color: #aaa;
    font-size: 12px;
}

/* Player row — kartu nick di kotak Players */
.bl-player-row {
    height: 42px;
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 0 8px;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
}
.bl-player-row:last-child { border-bottom: none; }
.bl-player-avatar {
    width: 38px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    font-size: 16px;
    font-weight: bold;
    flex-shrink: 0;
}
.bl-player-name {
    flex: 1;
    font-weight: 500;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bl-player-winrate {
    font-size: 12px;
    flex-shrink: 0;
}
.bl-player-winrate.wr-low  { color: #f44336; }
.bl-player-winrate.wr-mid  { color: #ffb300; }
.bl-player-winrate.wr-high { color: #2196f3; }
.bl-player-winrate.wr-max  { color: #4caf50; }

/* Friend row — kartu friend di kotak Friends */
.bl-friend-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-bottom: 1px solid #f5f5f5;
}
.bl-friend-row:last-child { border-bottom: none; }
.bl-friend-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    color: white;
    font-weight: bold;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.bl-friend-name {
    flex: 1;
    font-size: 13px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bl-friend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.bl-friend-dot.online  { background: #5cb85c; }
.bl-friend-dot.offline { background: #ccc; }
.bl-friend-invite-btn {
    background: none;
    border: none;
    font-size: 15px;
    color: #337ab7;
    flex-shrink: 0;
    cursor: pointer;
    padding: 0 4px;
}
.bl-friend-invite-btn:disabled {
    cursor: not-allowed;
    opacity: 0.4;
    color: #aaa;
}
.bl-friend-pending-text {
    font-size: 11px;
    color: #aaa;
    flex-shrink: 0;
}

/* Mobile fallback — fixed 800x704 gak muat, jadikan stack */
@media (max-width: 820px) {
    .bl-modal {
        width: calc(100vw - 24px);
        height: auto;
        max-height: 92vh;
    }
    .bl-grid {
        grid-template-columns: 1fr;
        padding-bottom: 10px;
    }
    .bl-column {
        gap: 10px;
    }
    .bl-box {
        height: 250px;
    }
}

#spa-loginOverlay:has(#spa-stab-1v1.active) #helloDialog,
#spa-loginOverlay:has(#spa-stab-2v2.active) #helloDialog {
    min-height: 640px !important;
    max-height: 92vh !important;
}