/* Unified Test UI Shared Styles */
:root {
    --primary: #10b981;
    --primary-dark: #059669;
    --secondary: #6366f1;
    --bg-gradient: linear-gradient(135deg, #f0fdf4 0%, #d1fae5 100%);
    --card-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --sidebar-bg: #111827;
    --sidebar-text: #f3f4f6;
}

[data-theme='transfer'] {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --bg-gradient: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 15px rgba(0,0,0,0.1);
    z-index: 100;
}

.sidebar h2 { font-size: 1.2rem; margin-bottom: 20px; color: var(--primary); }

.credential-panel {
    margin-bottom: 18px;
    padding: 12px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    background: rgba(255,255,255,0.06);
}
.credential-label {
    display: block;
    margin-bottom: 6px;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 800;
}
.credential-select {
    width: 100%;
    padding: 9px;
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 8px;
    background: #ffffff;
    color: #111827;
    font-size: 0.82rem;
    font-weight: 700;
}
.credential-meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 8px;
    color: rgba(243,244,246,0.72);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.68rem;
    word-break: break-all;
}
.credential-empty {
    color: #fca5a5;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.5;
}

.user-list { flex: 1; overflow-y: auto; margin-top: 20px; }
.user-item {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 10px;
    cursor: pointer;
    background: rgba(255,255,255,0.05);
    transition: all 0.2s;
    border: 1px solid transparent;
}
.user-item:hover { background: rgba(255,255,255,0.1); }
.user-item.active {
    background: rgba(16, 185, 129, 0.2);
    border-color: var(--primary);
}
.user-item .id { font-weight: 600; font-size: 0.9rem; }
.user-item .bal { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
.user-item.active .bal { color: var(--primary); }

/* Main Content */
.main-content {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

.card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
    margin-bottom: 24px;
}

h1 { font-size: 2rem; margin-bottom: 8px; }
.subtitle { color: var(--text-muted); margin-bottom: 30px; }

/* Components */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-outline { background: transparent; border: 2px solid var(--primary); color: var(--primary); }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }

/* Modal */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); display: none; align-items: center; justify-content: center;
    z-index: 1000;
}
.modal {
    background: white; padding: 30px; border-radius: 16px; width: 400px;
}

/* Powerball Lotto monitoring */
.muted { color: var(--text-muted); }

.event-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 10px;
}

.lotto-event {
    border-left-color: #7c3aed;
    background: #faf5ff;
}

.lotto-event.win {
    border-left-color: #10b981;
    background: #ecfdf5;
}

.lotto-event.loss {
    border-left-color: #ef4444;
    background: #fff7ed;
}

.lotto-event-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 10px;
}

.lotto-event-grid > div,
.lotto-mini-card,
.lotto-summary-row > div {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.72);
}

.lotto-balls {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
}

.lotto-ball {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 800;
    border: 1px solid rgba(17, 24, 39, 0.08);
}

.lotto-ball.main { background: #dbeafe; color: #1e40af; }
.lotto-ball.power { background: #fef3c7; color: #92400e; }

.lotto-chip {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 3px 8px;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3;
    font-size: 0.72rem;
    font-weight: 800;
}

.lotto-prize-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.json-details summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 700;
}

.json-details pre {
    margin-top: 8px;
    max-height: 260px;
    overflow: auto;
    background: #111827;
    color: #d1d5db;
    padding: 12px;
    border-radius: 8px;
    font-size: 0.75rem;
}

.lotto-results-block {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid #e5e7eb;
}

.lotto-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.lotto-toolbar h3 {
    margin-bottom: 4px;
}

.lotto-toolbar p {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.inline-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-main);
    font-size: 0.84rem;
    font-weight: 700;
    white-space: nowrap;
}

.lotto-summary-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.limit-notice {
    margin-bottom: 12px;
    padding: 10px 12px;
    border: 1px solid #fde68a;
    border-radius: 10px;
    background: #fffbeb;
    color: #92400e;
    font-size: 0.82rem;
    font-weight: 700;
}

.table-scroll {
    overflow-x: auto;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
}

.lotto-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.lotto-table th {
    text-align: left;
    padding: 10px;
    background: #f9fafb;
    color: #374151;
    border-bottom: 1px solid #e5e7eb;
}

.lotto-table td {
    padding: 10px;
    border-bottom: 1px solid #f1f5f9;
}

.lotto-table tr:last-child td {
    border-bottom: 0;
}

.lotto-table .num {
    text-align: right;
    white-space: nowrap;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.76rem;
    color: #475569;
}

.status-pill {
    display: inline-flex;
    padding: 3px 8px;
    border-radius: 999px;
    background: #e5e7eb;
    font-weight: 800;
    font-size: 0.72rem;
}

.status-pill.win,
.status-pill.won,
.status-pill.settled {
    background: #dcfce7;
    color: #166534;
}

.status-pill.loss,
.status-pill.lost {
    background: #fee2e2;
    color: #991b1b;
}

.empty-state,
.error-state {
    padding: 18px;
    text-align: center;
    border: 1px dashed #d1d5db;
    border-radius: 10px;
    color: var(--text-muted);
    background: #f9fafb;
}

.error-state {
    color: #b91c1c;
    border-color: #fecaca;
    background: #fef2f2;
}

@media (max-width: 900px) {
    .lotto-event-grid,
    .lotto-summary-row {
        grid-template-columns: 1fr 1fr;
    }

    .lotto-toolbar {
        align-items: stretch;
        flex-direction: column;
    }
}


.stats-page {
    display: block;
    min-height: 100vh;
    background: #f3f4f6;
}

.stats-test-shell {
    width: min(1480px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 40px;
}

.stats-test-header,
.stats-test-toolbar,
.stats-preview-panel {
    background: #ffffff;
    border: 1px solid #dfe3e8;
    border-radius: 8px;
}

.stats-test-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px 20px;
    margin-bottom: 14px;
}

.stats-test-header h1 {
    margin: 0 0 4px;
    font-size: 1.35rem;
}

.stats-test-header p {
    color: var(--text-muted);
    font-size: 0.86rem;
}

.stats-home-link {
    color: #374151;
    text-decoration: none;
    font-weight: 700;
    white-space: nowrap;
}

.stats-test-toolbar {
    display: grid;
    grid-template-columns: minmax(260px, 1.3fr) minmax(180px, 0.8fr) minmax(180px, 0.8fr) auto;
    align-items: end;
    gap: 14px;
    padding: 18px 20px;
    margin-bottom: 14px;
}

.stats-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 0;
}

.stats-field label {
    color: #4b5563;
    font-size: 0.78rem;
    font-weight: 800;
}

.stats-field select {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    border: 1px solid #cfd5dc;
    border-radius: 6px;
    background: #ffffff;
    color: #111827;
    font: inherit;
}

.stats-load-button {
    min-height: 42px;
    padding: 0 20px;
    border: 0;
    border-radius: 6px;
    background: #047857;
    color: #ffffff;
    font-weight: 800;
    cursor: pointer;
}

.stats-load-button:hover { background: #065f46; }
.stats-load-button:disabled { opacity: 0.55; cursor: wait; }

.stats-origin-row {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding-top: 2px;
    color: #6b7280;
    font-size: 0.78rem;
}

.stats-origin-row code {
    overflow: hidden;
    text-overflow: ellipsis;
    color: #1f2937;
}

.stats-status {
    margin-bottom: 14px;
    padding: 11px 14px;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    background: #eff6ff;
    color: #1e40af;
    font-size: 0.84rem;
    font-weight: 700;
}

.stats-status.error {
    border-color: #fecaca;
    background: #fef2f2;
    color: #b91c1c;
}

.stats-status.success {
    border-color: #a7f3d0;
    background: #ecfdf5;
    color: #047857;
}

.stats-preview-panel {
    min-height: 720px;
    overflow: hidden;
}

.stats-preview-empty {
    display: grid;
    min-height: 720px;
    place-items: center;
    color: #6b7280;
    text-align: center;
}

.stats-preview-frame {
    display: block;
    width: 100%;
    min-height: 900px;
    border: 0;
    background: #ffffff;
}

.stats-preview-empty[hidden],
.stats-preview-frame[hidden] { display: none; }

@media (max-width: 900px) {
    .stats-test-toolbar { grid-template-columns: 1fr 1fr; }
    .stats-load-button { width: 100%; }
}

@media (max-width: 620px) {
    .stats-test-shell { width: min(100% - 20px, 1480px); padding-top: 10px; }
    .stats-test-header { align-items: flex-start; flex-direction: column; }
    .stats-test-toolbar { grid-template-columns: 1fr; }
    .stats-preview-panel,
    .stats-preview-empty { min-height: 620px; }
    .stats-preview-frame { min-height: 760px; }
}

/* Game launch viewport controls */
.game-launch-panel {
    grid-column: span 2;
    min-width: 0;
}

.game-launch-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
    flex-wrap: wrap;
}

.game-type-select {
    flex: 1 1 220px;
    min-width: 180px;
    min-height: 42px;
    padding: 10px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #ffffff;
    color: var(--text-main);
    font: inherit;
}

.game-viewport-switch {
    display: inline-grid;
    grid-template-columns: 1fr 1fr;
    min-width: 152px;
    padding: 3px;
    border: 1px solid #d1d5db;
    border-radius: 9px;
    background: #f3f4f6;
}

.game-viewport-switch button {
    min-height: 34px;
    padding: 0 12px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #6b7280;
    font: inherit;
    font-size: 0.82rem;
    font-weight: 800;
    cursor: pointer;
}

.game-viewport-switch button.active {
    background: #ffffff;
    color: var(--primary-dark);
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.14);
}

.game-launch-row > .btn {
    min-height: 42px;
    white-space: nowrap;
}

.transfer-balance-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 10px;
}

.amount-action {
    display: flex;
    gap: 5px;
    min-width: 0;
}

.amount-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 10px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font: inherit;
}

.history-action-row,
.history-query-row {
    flex-wrap: wrap;
}

.history-query-row > div {
    flex: 1 1 180px;
    min-width: 0;
}

.history-query-row input {
    width: 100%;
    max-width: 100%;
}

.game-iframe-container {
    width: 100%;
    margin: 0 auto;
    transition: width 160ms ease, padding 160ms ease, background-color 160ms ease;
}

.game-iframe {
    display: block;
    width: 100%;
    height: 800px;
    border: 0;
    border-radius: 12px;
    background: #0f172a;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.game-iframe-container[data-viewport-mode='mobile'] {
    width: 414px;
    max-width: 100%;
    padding: 12px;
    border: 1px solid #cbd5e1;
    border-radius: 18px;
    background: #e2e8f0;
    box-shadow: 0 16px 36px rgba(15, 23, 42, 0.14);
}

.game-iframe-container[data-viewport-mode='mobile'] .game-iframe {
    width: 390px !important;
    max-width: 100%;
    height: 844px !important;
    margin: 0 auto;
    border-radius: 12px;
}

.game-iframe-empty {
    padding: 100px 24px;
    color: var(--text-muted);
    text-align: center;
}

/* Legacy test pages were desktop-only. Keep the controls usable on narrow screens. */
@media (max-width: 900px) {
    body:not(.stats-page) {
        display: flex;
        flex-direction: column;
        width: 100%;
        overflow-x: hidden;
    }

    body:not(.stats-page) .sidebar {
        width: 100%;
        min-width: 0;
        padding: 16px;
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
        flex: none;
    }

    body:not(.stats-page) .sidebar h2 {
        margin-bottom: 12px;
    }

    body:not(.stats-page) .user-list {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 8px;
        max-height: 220px;
        margin-top: 12px;
    }

    body:not(.stats-page) .user-item {
        min-width: 0;
        margin-bottom: 0;
    }

    body:not(.stats-page) .main-content {
        width: 100%;
        min-width: 0;
        padding: 16px;
        overflow: visible;
        flex: none;
    }

    body:not(.stats-page) .container {
        width: 100%;
        min-width: 0;
    }

    body:not(.stats-page) .grid-3 {
        grid-template-columns: minmax(0, 1fr);
    }

    body:not(.stats-page) .grid-3 > * {
        grid-column: auto !important;
        min-width: 0;
    }

    body:not(.stats-page) .card {
        padding: 18px;
        border-radius: 12px;
    }

    body:not(.stats-page) .tabs {
        display: flex;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-width: thin;
    }

    body:not(.stats-page) .tab {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    body:not(.stats-page) .tab-content {
        min-width: 0;
    }

    body:not(.stats-page) .modal {
        width: calc(100vw - 24px);
        max-height: calc(100dvh - 24px);
        padding: 20px;
        overflow: auto;
    }
}

@media (max-width: 620px) {
    body:not(.stats-page) .main-content {
        padding: 10px;
    }

    body:not(.stats-page) h1 {
        font-size: 1.5rem;
        line-height: 1.25;
    }

    body:not(.stats-page) .subtitle {
        margin-bottom: 18px;
    }

    body:not(.stats-page) .card {
        padding: 14px;
        margin-bottom: 14px;
    }

    .game-type-select,
    .game-viewport-switch {
        flex-basis: 100%;
        width: 100%;
    }

    .game-launch-row > .btn {
        flex: 1 1 calc(50% - 4px);
        padding-inline: 12px;
    }

    .transfer-balance-actions {
        grid-template-columns: minmax(0, 1fr);
    }

    .history-query-row > div,
    .history-query-row > .btn {
        flex-basis: 100%;
        width: 100%;
    }

    .history-action-row > .btn {
        flex: 1 1 160px;
    }

    .game-iframe-container[data-viewport-mode='mobile'] {
        width: 100%;
        padding: 6px;
        border-radius: 12px;
    }

    .game-iframe-container[data-viewport-mode='mobile'] .game-iframe {
        width: 100% !important;
        min-height: 667px;
    }

    .game-iframe-empty {
        padding: 64px 16px;
    }
}

@media (max-width: 430px) {
    .game-launch-row > .btn {
        flex-basis: 100%;
        width: 100%;
    }
}
