/* ==========================================================================
   Dice Dashboard — design tokens
   Estilo: dark "match-stats terminal" (analytics + gaming)
   ========================================================================== */

:root {
    --bg: #0b0e14;
    --surface: #131824;
    --surface-2: #1a2130;
    --border: #232c3d;
    --border-strong: #2e3950;

    --text: #e8ecf4;
    --text-muted: #8b96ab;
    --text-faint: #5c6778;

    --t-orange: #f0a03c;
    --t-orange-strong: #d97a2b;
    --ct-blue: #7c9cc9;
    --gold: #f5c842;

    --success: #4ade80;
    --danger: #f87171;
    --warn-bg: #2a2410;
    --warn-border: #6b5518;
    --warn-text: #e8d48b;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 8px 24px rgba(0, 0, 0, 0.35);

    --font-heading: "Space Grotesk", system-ui, sans-serif;
    --font-body: "DM Sans", system-ui, sans-serif;

    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

/* O fundo mora no <html>, não no <body>: aplicado ao body, o gradiente é
   dimensionado pela altura do conteúdo e páginas curtas (login) mostram um
   corte visível entre a área pintada e o resto da tela. No <html> com
   attachment fixo o degradê se ancora no viewport e cobre tudo. */
html {
    color-scheme: dark;
    background-color: var(--bg);
    background-image:
        radial-gradient(1200px 500px at 80% -10%, rgba(240, 160, 60, 0.05), transparent 60%),
        radial-gradient(900px 400px at 10% 110%, rgba(124, 156, 201, 0.04), transparent 60%);
    background-attachment: fixed;
    background-repeat: no-repeat;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    font-family: var(--font-heading);
    line-height: 1.2;
    letter-spacing: -0.01em;
}

h1 { font-size: 1.7rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 0.95rem; margin: 20px 0 4px; color: var(--text-muted); }

.container {
    max-width: 1140px;
    margin: 0 auto;
    padding: 28px 20px 80px;
}

.muted { color: var(--text-muted); font-size: 0.88em; }
.error { color: var(--danger); }
.success { color: var(--success); }

/* ==========================================================================
   Topbar
   ========================================================================== */

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: rgba(11, 14, 20, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.topbar-left { display: flex; align-items: center; gap: 20px; min-width: 0; }

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    text-decoration: none;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
}

.brand-logo { width: 30px; height: 30px; border-radius: 50%; }

.topbar nav { display: flex; gap: 4px; }

.topbar nav a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    padding: 7px 14px;
    border-radius: 999px;
    transition: color 0.18s var(--ease), background-color 0.18s var(--ease);
}

.topbar nav a:hover { color: var(--text); background: var(--surface-2); }

.topbar nav a.is-active {
    color: var(--t-orange);
    background: rgba(240, 160, 60, 0.12);
}

.logout-form { margin: 0; }

.logout-form button {
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-muted);
    padding: 7px 14px;
    border-radius: 999px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.18s var(--ease), border-color 0.18s var(--ease);
}

.logout-form button:hover { color: var(--text); border-color: var(--text-muted); }

/* ==========================================================================
   Cards e entrada animada
   ========================================================================== */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-1);
    transition: border-color 0.2s var(--ease), transform 0.2s var(--ease);
}

.card:hover { border-color: var(--border-strong); }

@media (prefers-reduced-motion: no-preference) {
    .anim-in {
        opacity: 0;
        transform: translateY(14px);
        animation: rise 0.55s var(--ease) forwards;
    }

    .anim-in:nth-child(2) { animation-delay: 0.06s; }
    .anim-in:nth-child(3) { animation-delay: 0.12s; }
    .anim-in:nth-child(4) { animation-delay: 0.18s; }
    .anim-in:nth-child(5) { animation-delay: 0.24s; }
    .anim-in:nth-child(6) { animation-delay: 0.3s; }
    .anim-in:nth-child(7) { animation-delay: 0.36s; }

    @keyframes rise {
        to { opacity: 1; transform: translateY(0); }
    }
}

/* ==========================================================================
   Page header + disclaimer
   ========================================================================== */

.page-head { margin-bottom: 20px; }
.page-head .muted { margin: 0; }

.note-bar {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: var(--warn-bg);
    border: 1px solid var(--warn-border);
    color: var(--warn-text);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 0.85rem;
    line-height: 1.5;
}

.note-bar svg { flex-shrink: 0; margin-top: 2px; }

/* Achado que contraria o esperado. Deliberadamente diferente do aviso comum:
   marca "isto merece investigação", não "cuidado ao ler". */
.note-bar.is-alert {
    background: rgba(74, 222, 128, 0.09);
    border-color: rgba(74, 222, 128, 0.45);
    color: #86efac;
}

/* Retorno acima/abaixo do ponto de virada (1,00 = empatar com a casa). */
.is-above { color: #4ade80; }
.is-below { color: #f87171; }

.return-cell strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Stat tiles
   ========================================================================== */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

.stat-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    transition: border-color 0.2s var(--ease), transform 0.2s var(--ease);
}

.stat-tile:hover { border-color: var(--border-strong); transform: translateY(-2px); }

.stat-label {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat-value {
    font-family: var(--font-heading);
    font-variant-numeric: tabular-nums;
    font-size: 1.9rem;
    font-weight: 700;
    line-height: 1.1;
}

.stat-value small {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-left: 2px;
}

.stat-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }

.stat-accent-orange .stat-value { color: var(--t-orange); }
.stat-accent-blue .stat-value { color: var(--ct-blue); }
.stat-accent-gold .stat-value { color: var(--gold); }

/* ==========================================================================
   Recent rolls (match history)
   ========================================================================== */

.roll-strip {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 2px 10px;
    scrollbar-width: thin;
}

.roll-chip {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: 48px;
    padding: 7px 0 6px;
    border-radius: 10px;
    transition: transform 0.15s var(--ease);
}

.roll-chip:hover { transform: translateY(-3px); }

.roll-chip-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
}

.roll-chip-number {
    font-family: var(--font-heading);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 0.95rem;
    line-height: 1;
}

/* Sem fundo nem borda: o ícone já é o portador da cor. A cor do número
   mantém a leitura por cor sem competir com o ícone. */
.roll-chip-orange .roll-chip-number { color: var(--t-orange); }
.roll-chip-gray .roll-chip-number { color: var(--ct-blue); }
.roll-chip-zero .roll-chip-number { color: var(--gold); }

/* ==========================================================================
   Filtros
   ========================================================================== */

.filters {
    display: flex;
    gap: 14px;
    align-items: end;
    flex-wrap: wrap;
    padding: 16px 18px;
}

.filters .field label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.quick-ranges { display: flex; gap: 6px; flex-wrap: wrap; }

.quick-ranges a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 500;
    padding: 7px 13px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    transition: all 0.18s var(--ease);
}

.quick-ranges a:hover { color: var(--text); border-color: var(--text-muted); }

.quick-ranges a.is-active {
    color: var(--t-orange);
    border-color: rgba(240, 160, 60, 0.5);
    background: rgba(240, 160, 60, 0.1);
}

/* ==========================================================================
   Formulários
   ========================================================================== */

input[type="text"],
input[type="password"],
input[type="date"] {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.95rem;
    transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
    outline: 2px solid var(--t-orange);
    outline-offset: 2px;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
textarea:focus {
    border-color: var(--t-orange);
    box-shadow: 0 0 0 3px rgba(240, 160, 60, 0.15);
    outline: none;
}

textarea {
    width: 100%;
    min-height: 240px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 0.85rem;
    line-height: 1.7;
    resize: vertical;
    transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

button, .btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(160deg, #f2ab52, var(--t-orange-strong));
    color: #23150a;
    border: none;
    padding: 11px 22px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 0.92rem;
    cursor: pointer;
    text-decoration: none;
    transition: filter 0.18s var(--ease), transform 0.12s var(--ease);
}

button:hover, .btn:hover { filter: brightness(1.08); }
button:active, .btn:active { transform: scale(0.97); }

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    filter: grayscale(0.4);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-strong);
    font-weight: 500;
}

.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); filter: none; }

/* ==========================================================================
   Login
   ========================================================================== */

.login-box {
    max-width: 380px;
    margin: 11vh auto 0;
    text-align: center;
    position: relative;
}

.login-box::before {
    content: "";
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    width: 320px;
    height: 220px;
    background: radial-gradient(closest-side, rgba(245, 200, 66, 0.14), transparent);
    pointer-events: none;
}

.login-logo {
    display: block;
    width: 76px;
    height: 76px;
    margin: 0 auto 14px;
    border-radius: 50%;
    filter: drop-shadow(0 0 18px rgba(245, 200, 66, 0.3));
}

.login-box h1 { margin-bottom: 20px; }
.login-box form { text-align: left; }
.login-box p { margin: 0 0 14px; }
.login-box label { font-size: 0.85rem; color: var(--text-muted); }
.login-box button { width: 100%; justify-content: center; margin-top: 6px; }

/* ==========================================================================
   Tabelas
   ========================================================================== */

.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}

td { font-variant-numeric: tabular-nums; }

th {
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.09em;
}

tbody tr { transition: background-color 0.15s var(--ease); }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

/* Barras comparativas observado vs teórico */
.bar-pair { min-width: 130px; }

.bar-track {
    position: relative;
    height: 6px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 6px;
}

.bar-fill {
    position: absolute;
    inset: 0 auto 0 0;
    border-radius: 999px;
    transition: width 0.7s var(--ease);
}

.bar-fill-orange { background: var(--t-orange); }
.bar-fill-blue { background: var(--ct-blue); }
.bar-fill-gold { background: var(--gold); }

.bar-marker {
    position: absolute;
    top: -3px;
    width: 2px;
    height: 12px;
    background: var(--text-muted);
    border-radius: 1px;
}

/* ==========================================================================
   Ícones de cor
   ========================================================================== */

.color-icon {
    width: 20px;
    height: 20px;
    vertical-align: -4px;
    border-radius: 50%;
}

.color-cell { display: flex; align-items: center; gap: 8px; }

/* ==========================================================================
   Grids
   ========================================================================== */

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* ==========================================================================
   Chi-square verdict
   ========================================================================== */

.verdict {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.verdict-ok {
    background: rgba(74, 222, 128, 0.12);
    color: var(--success);
    border: 1px solid rgba(74, 222, 128, 0.3);
}

.verdict-warn {
    background: rgba(248, 113, 113, 0.1);
    color: var(--danger);
    border: 1px solid rgba(248, 113, 113, 0.3);
}

/* ==========================================================================
   Ingestão
   ========================================================================== */

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

details.lines-detail {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    background: var(--bg);
}

details.lines-detail summary {
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--warn-text);
    font-weight: 500;
}

details.lines-detail ul {
    margin: 10px 0 4px;
    padding-left: 20px;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.form-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; }

/* ==========================================================================
   Barra de status da coleta
   ========================================================================== */

.collection-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    margin-bottom: 20px;
    font-size: 0.85rem;
}

.collection-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}

.collection-active { border-color: rgba(74, 222, 128, 0.35); }
.collection-active .collection-dot { background: var(--success); }

@media (prefers-reduced-motion: no-preference) {
    .collection-active .collection-dot {
        animation: pulse 2s var(--ease) infinite;
    }

    @keyframes pulse {
        0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5); }
        50% { box-shadow: 0 0 0 6px rgba(74, 222, 128, 0); }
    }
}

.collection-stale { border-color: rgba(245, 200, 66, 0.35); }
.collection-stale .collection-dot { background: var(--gold); }

.collection-idle { border-color: rgba(248, 113, 113, 0.3); }
.collection-idle .collection-dot { background: var(--danger); }

/* ==========================================================================
   Fact list (resumo)
   ========================================================================== */

.fact-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.fact-list li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}

.fact-list li:last-child { border-bottom: none; }
.fact-list li > span:first-child { color: var(--text-muted); }
.fact-list strong { font-variant-numeric: tabular-nums; text-align: right; }

/* ==========================================================================
   Odds chips (possibilidades teóricas do zero)
   ========================================================================== */

.odds-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin: 10px 0 12px;
}

.odds-chip {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    text-align: center;
}

.odds-n {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
}

.odds-value {
    font-family: var(--font-heading);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--gold);
}

/* ==========================================================================
   Number chips (quentes/frios)
   ========================================================================== */

.number-chips {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 8px 0 4px;
}

.number-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 78px;
    padding: 10px 14px;
    border-radius: 10px;
    transition: transform 0.15s var(--ease);
}

.number-chip:hover { transform: translateY(-2px); }

.number-chip-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
}

.number-chip-value {
    font-family: var(--font-heading);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 1.3rem;
    line-height: 1;
}

.number-chip-orange .number-chip-value,
.roll-chip-orange .number-chip-value { color: var(--t-orange); }

.roll-chip-gray .number-chip-value { color: var(--ct-blue); }
.roll-chip-zero .number-chip-value { color: var(--gold); }

.number-chip-count { font-size: 0.7rem; color: var(--text-muted); }

/* Frios se distinguem por atenuação, não por caixa — o ícone continua sendo
   o único elemento com fundo próprio. */
.number-chip-cold { color: var(--text-muted); }
.number-chip-cold .number-chip-icon { opacity: 0.5; }
.number-chip-cold .number-chip-value { color: var(--text-muted); }

/* ==========================================================================
   Padrões / combinações
   ========================================================================== */

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}

.pattern-seq {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.pattern-token {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.pattern-token img {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}

/* Token solto dentro de um parágrafo: acompanha a linha do texto. */
p .pattern-token img { width: 19px; height: 19px; vertical-align: -4px; }

/* ==========================================================================
   Fórmula (provably fair)
   ========================================================================== */

.formula {
    margin: 4px 0 20px;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.82rem;
    line-height: 1.7;
    color: var(--text-muted);
    overflow-x: auto;
}

.formula-arg { color: var(--t-orange); }

code {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.88em;
    color: var(--text);
}

/* Os tokens são só o ícone; sem caixa em volta a sequência lê como uma
   linha de símbolos, que é o que ela representa. */

tr.group-row td {
    padding-top: 16px;
    padding-bottom: 4px;
    border-bottom: none;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-faint);
}

tr.group-row:hover { background: transparent; }

/* ==========================================================================
   Empty state
   ========================================================================== */

.empty-state {
    text-align: center;
    padding: 56px 20px;
}

.empty-state img { width: 64px; height: 64px; opacity: 0.75; margin-bottom: 14px; }
.empty-state h2 { margin-bottom: 6px; }
.empty-state p { color: var(--text-muted); margin: 0 0 20px; }

/* ==========================================================================
   Charts
   ========================================================================== */

.chart-box { position: relative; min-height: 220px; }

canvas { max-width: 100%; }

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
    margin-top: 40px;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-faint);
}

/* ==========================================================================
   Responsivo
   ========================================================================== */

@media (max-width: 900px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 720px) {
    .grid-2 { grid-template-columns: 1fr; }
    .preview-stats { grid-template-columns: 1fr; }
    .brand span { display: none; }
    .container { padding: 20px 14px 60px; }
    h1 { font-size: 1.4rem; }
}

@media (max-width: 460px) {
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-value { font-size: 1.5rem; }
}
