/* ==========================================================================
   Simulador de Trading — estilos
   Tema oscuro moderno, adaptado a móvil.
   ========================================================================== */
:root {
    --bg:        #0b1120;
    --bg-2:      #111a2e;
    --card:      #16213e;
    --card-2:    #1c2947;
    --border:    #24324f;
    --text:      #e6ecf5;
    --muted:     #93a2bd;
    --accent:    #3b82f6;
    --accent-2:  #2563eb;
    --green:     #22c55e;
    --green-bg:  rgba(34,197,94,.12);
    --red:       #ef4444;
    --red-bg:    rgba(239,68,68,.12);
    --gold:      #f59e0b;
    --radius:    14px;
    --shadow:    0 8px 30px rgba(0,0,0,.35);
}

/* Tema claro: se activa cuando el usuario lo elige en su perfil */
:root[data-tema="claro"] {
    --bg:        #f3f6fb;
    --bg-2:      #ffffff;
    --card:      #ffffff;
    --card-2:    #eef2f9;
    --border:    #d7deea;
    --text:      #16213e;
    --muted:     #5c6b85;
    --shadow:    0 8px 30px rgba(20,40,80,.10);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: radial-gradient(1200px 600px at 80% -10%, #16294d 0%, var(--bg) 55%);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Barra de navegación ---- */
.nav {
    display: flex; align-items: center; gap: 18px;
    padding: 14px 22px;
    background: rgba(11,17,32,.85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 50;
    flex-wrap: wrap;
}
.brand { font-weight: 800; font-size: 1.15rem; letter-spacing: .3px; display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.brand:hover { text-decoration: none; opacity: .85; }
.brand .logo { color: var(--accent); }
.brand-logo { height: 34px; width: 34px; border-radius: 9px; object-fit: cover; display: block; }
.nav .spacer { flex: 1; }
.nav a.navlink { color: var(--muted); font-weight: 600; padding: 6px 10px; border-radius: 8px; }
.nav a.navlink:hover { color: var(--text); background: var(--card); text-decoration: none; }
.nav a.navlink.active { color: var(--text); background: var(--card-2); }
.nav .user { color: var(--muted); font-size: .9rem; }
.nav a.user-link { display: inline-flex; align-items: center; gap: 8px; }
/* Los enlaces van en su propio bloque para poder plegarlos en el móvil */
.nav-links { display: flex; align-items: center; gap: 18px; flex: 1; flex-wrap: wrap; }
.nav-toggle { display: none; }

@media (max-width: 820px) {
    .nav { gap: 10px; padding: 10px 16px; }
    .nav-toggle {
        display: block; margin-left: auto;
        background: var(--card-2); color: var(--text);
        border: 1px solid var(--border); border-radius: 10px;
        font-size: 1.4rem; line-height: 1; padding: 6px 12px; cursor: pointer;
    }
    .nav-toggle[aria-expanded="true"] { background: var(--accent); color: #fff; border-color: transparent; }
    .nav-links { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 2px; margin-top: 6px; }
    .nav-links.open { display: flex; }
    .nav-links .spacer { display: none; }
    .nav a.navlink { padding: 12px 14px; font-size: 1rem; }   /* dedos, no ratones */
    .nav .user { padding: 10px 14px; border-top: 1px solid var(--border); margin-top: 6px; }
}

/* ---- Contenedores ---- */
.container { max-width: 1100px; margin: 0 auto; padding: 24px 18px 60px; }
.center-box { max-width: 420px; margin: 8vh auto; padding: 0 18px; }

/* ---- Tarjetas ---- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }
h1,h2,h3 { margin: 0 0 14px; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---- Tiles de resumen ---- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat {
    background: linear-gradient(160deg, var(--card-2), var(--card));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 1.5rem; font-weight: 800; margin-top: 6px; }

/* ---- Tablas ---- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; font-weight: 700; }
tbody tr:hover { background: var(--card-2); }
.table-wrap { overflow-x: auto; }

.asset { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
a.asset:hover { text-decoration: none; }
a.asset:hover strong { color: var(--accent); }
a.asset:hover .sub { color: var(--text); }

/* ---- Noticias ---- */
.news { display: flex; flex-direction: column; }
.news-item { display: block; padding: 12px 10px; border-radius: 10px; color: inherit; text-decoration: none; border-bottom: 1px solid var(--border); }
.news-item:last-child { border-bottom: none; }
.news-item:hover { background: var(--card-2); text-decoration: none; }
.news-title { font-weight: 600; line-height: 1.35; }
.news-meta { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.badge {
    display: inline-block; width: 34px; height: 34px; line-height: 34px;
    text-align: center; border-radius: 9px; font-weight: 800; font-size: .62rem;
    letter-spacing: -.3px; overflow: hidden; white-space: nowrap;
    background: var(--accent); color: #fff;
}
.badge.stock { background: #ff6a00; color: #fff; }
.asset .sub { color: var(--muted); font-size: .8rem; }

.up { color: var(--green); }
.down { color: var(--red); }
.pill { padding: 3px 9px; border-radius: 999px; font-size: .82rem; font-weight: 700; }
.pill.up { background: var(--green-bg); }
.pill.down { background: var(--red-bg); }

/* ---- Botones ---- */
.btn {
    display: inline-block; cursor: pointer; border: none;
    padding: 10px 16px; border-radius: 10px; font-weight: 700; font-size: .92rem;
    background: var(--accent); color: #fff; transition: filter .15s;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.buy { background: var(--green); }
.btn.sell { background: var(--red); }
.btn.ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--border); }
.btn.sm { padding: 6px 12px; font-size: .82rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Formularios ---- */
label { display: block; margin: 12px 0 6px; font-weight: 600; font-size: .9rem; }
input, select {
    width: 100%; padding: 11px 12px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--bg-2); color: var(--text);
    font-size: 1rem;
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; }

/* ---- Mensajes ---- */
.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 600; }
.alert.err { background: var(--red-bg); color: #fecaca; border: 1px solid rgba(239,68,68,.35); }
.alert.ok  { background: var(--green-bg); color: #bbf7d0; border: 1px solid rgba(34,197,94,.35); }

/* ---- Ranking ---- */
.rank-num { font-weight: 800; color: var(--muted); }
.rank-1 { color: var(--gold); }
.jugador .rank-num { margin-right: 8px; display: inline-block; min-width: 1.5em; text-align: center; }
/* Fechas de alta y de reinicio, debajo del nombre y alineadas con él */
.jugador .avatar { margin-right: 8px; }
/* Podio: una barrita de color a la izquierda de los tres primeros */
tbody tr.podio-1 td.jugador { box-shadow: inset 5px 0 0 #f5b301; }   /* oro */
tbody tr.podio-2 td.jugador { box-shadow: inset 5px 0 0 #c2cad6; }   /* plata */
tbody tr.podio-3 td.jugador { box-shadow: inset 5px 0 0 #cd7f32; }   /* bronce */
tbody tr.podio td.jugador { padding-left: 16px; }
/* "Tú": fondo suave para reconocerte en la lista */
tbody tr.fila-yo { background: var(--card-2); }
.jugador .fechas { margin-left: calc(1.5em + 46px); margin-top: 2px; white-space: nowrap; }
@media (max-width: 600px) { .jugador .fechas { margin-left: 0; white-space: normal; } }
/* ---- Botón de borrado del panel de admin ---- */
.inline-form { display: inline; }
.btn-danger {
    background: transparent; color: var(--red, #ef4444);
    border: 1px solid var(--red, #ef4444); border-radius: 8px;
    padding: 5px 12px; font-weight: 700; font-size: .82rem; cursor: pointer;
}
.btn-danger:hover { background: var(--red, #ef4444); color: #fff; }
.btn-mini {
    background: transparent; color: var(--muted);
    border: 1px solid var(--border); border-radius: 8px;
    padding: 4px 10px; font-weight: 600; font-size: .78rem; cursor: pointer; margin-left: 6px;
}
.btn-mini:hover { color: var(--text); background: var(--card-2); }
.aviso-modal { max-width: 460px; text-align: center; }
.aviso-img { max-width: 100%; height: auto; border-radius: 10px; margin: 6px 0; }
.aviso-texto { font-size: 1.05rem; margin: 10px 0; }
.aviso-form { display: flex; flex-direction: column; gap: 12px; max-width: 460px; margin-top: 12px; }
.aviso-form label { display: flex; flex-direction: column; gap: 5px; }
.aviso-form label span { font-size: .82rem; color: var(--muted); font-weight: 700; }
.saldo-form { display: inline-flex; gap: 6px; align-items: center; }
.saldo-input { width: 90px; padding: 4px 8px; }
.badge-admin {
    background: var(--green-bg); color: var(--green);
    border-radius: 6px; padding: 2px 8px; font-size: .78rem; font-weight: 700;
}

/* ---- Gráfico de tarta de la cartera ---- */
.tarta-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; margin: 4px 0 18px; }
.tarta-svg { flex: 0 0 auto; }
.tarta-leyenda { display: flex; flex-direction: column; gap: 6px; min-width: 180px; flex: 1; }
.tarta-item { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.tarta-punto { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.tarta-nombre { color: var(--text); }
.tarta-pct { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (max-width: 600px) { .tarta-wrap { justify-content: center; } .tarta-leyenda { min-width: 100%; } }

/* ---- Formulario de cambiar contraseña (en el perfil) ---- */
.pass-form label { display: block; margin: 10px 0 4px; font-size: .9rem; color: var(--muted); }
.pass-form input { width: 100%; max-width: 320px; }
.tema-form { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

/* ---- Noticias en los márgenes de los lados (solo en pantallas anchas) ---- */
.news-margin { display: none; }
.nm-titulo { font-weight: 800; color: var(--text); margin-bottom: 10px; font-size: 1rem; }
.nm-item { display: block; padding: 8px 0; border-bottom: 1px solid var(--border); }
.nm-item:hover { text-decoration: none; }
.nm-tit { font-size: .82rem; line-height: 1.3; color: var(--text); }
.nm-item:hover .nm-tit { color: var(--accent); }
.nm-meta { font-size: .72rem; color: var(--muted); margin-top: 2px; }
/* Solo aparecen cuando la pantalla es lo bastante ancha para que quepan
   en el hueco sin tapar el contenido del centro. */
@media (min-width: 1750px) {
    .news-margin {
        display: block; position: fixed; top: 80px; width: 280px;
        max-height: calc(100vh - 100px); overflow-y: auto; padding-bottom: 20px;
    }
    .news-margin-izq { left: 20px; }
    .news-margin-der { right: 20px; }
}

/* ---- Avatares ---- */
.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 50%;
    font-size: 1rem; line-height: 1; color: #fff; font-weight: 700;
    flex: 0 0 auto; vertical-align: middle;
}
.avatar-xl { width: 64px; height: 64px; font-size: 2rem; }
.avatar-sm { width: 24px; height: 24px; font-size: .85rem; }

.avatar-grupo { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 18px 0 0; }
.avatar-grupo:first-of-type { margin-top: 10px; }
.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; margin-top: 8px; }
.avatar-op input, .color-op input { position: absolute; opacity: 0; pointer-events: none; }
.avatar-op span {
    display: flex; align-items: center; justify-content: center;
    height: 52px; font-size: 1.6rem; cursor: pointer;
    background: var(--bg-2); border: 2px solid var(--border); border-radius: 12px;
}
.avatar-op input:checked + span { border-color: var(--accent); background: var(--card-2); }
.avatar-op input:focus-visible + span,
.color-op input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.color-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.color-op span {
    display: block; width: 40px; height: 40px; border-radius: 50%;
    cursor: pointer; border: 3px solid transparent;
}
.color-op input:checked + span { border-color: var(--text); }

/* ---- Formulario de apuestas ---- */
.bet-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-top: 12px; }
.bet-form label { display: flex; flex-direction: column; gap: 5px; flex: 1 1 180px; }
.bet-form label span { font-size: .82rem; color: var(--muted); font-weight: 700; }
@media (max-width: 600px) { .bet-form label, .bet-form .btn { flex: 1 1 100%; } }

/* Ganancia y % en la misma celda, sin que el flex del móvil los separe */
.gan-pct { white-space: nowrap; }
.pct-inline { font-size: .85em; opacity: .85; }

/* ---- Modal de operar ---- */
.modal-back {
    position: fixed; inset: 0; background: rgba(3,7,18,.7);
    display: none; align-items: center; justify-content: center; z-index: 100; padding: 18px;
}
.modal-back.show { display: flex; }
.modal { width: 100%; max-width: 420px; }
.modal .close { float: right; cursor: pointer; color: var(--muted); font-size: 1.4rem; line-height: 1; }
.op-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.op-tabs button {
    flex: 1; padding: 9px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--bg-2); color: var(--muted); font-weight: 700; cursor: pointer;
}
.op-tabs button.active-buy { background: var(--green); color: #fff; border-color: transparent; }
.op-tabs button.active-sell { background: var(--red); color: #fff; border-color: transparent; }
.op-mode { display: flex; gap: 8px; margin: 4px 0 2px; }
.op-mode button {
    flex: 1; padding: 8px; border-radius: 9px; border: 1px solid var(--border);
    background: var(--bg-2); color: var(--muted); font-weight: 700; font-size: .82rem; cursor: pointer;
}
.op-mode button.active { background: var(--accent); color: #fff; border-color: transparent; }
/* ---- Gráfico del activo ---- */
.op-chart { background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px; min-height: 110px; display: flex; flex-direction: column; justify-content: center; }
.chart-msg { color: var(--muted); font-size: .85rem; text-align: center; padding: 40px 0; }
/* Globito de precio al pasar el ratón por el gráfico */
.chart-tip {
    position: absolute; pointer-events: none; z-index: 5;
    background: var(--card-2); border: 1px solid var(--border);
    border-radius: 8px; padding: 4px 9px; line-height: 1.2;
    display: flex; flex-direction: column; white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
.chart-tip strong { font-size: .82rem; }
.chart-tip span { color: var(--muted); font-size: .72rem; }
.chart-info { display: flex; justify-content: space-between; padding: 4px 4px 0; }
.op-range { display: flex; gap: 6px; margin: 10px 0; }
.op-range button {
    flex: 1; padding: 6px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--bg-2); color: var(--muted); font-weight: 700; font-size: .8rem; cursor: pointer;
}
.op-range button.active { background: var(--accent); color: #fff; border-color: transparent; }

.op-summary { background: var(--bg-2); border-radius: 10px; padding: 12px; margin: 12px 0; font-size: .9rem; }
.op-summary .row { display: flex; justify-content: space-between; padding: 3px 0; }
.op-summary .row .k { color: var(--muted); }

/* ---- Utilidades ---- */
.flex { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.mt { margin-top: 16px; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs button {
    padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border);
    background: var(--card); color: var(--muted); font-weight: 700; cursor: pointer;
}
.tabs button.active { background: var(--accent); color: #fff; border-color: transparent; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 6px; }
.updated { color: var(--muted); font-size: .8rem; }

/* ---- Barra de ordenar ---- */
.sortbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.sortbar label { margin: 0; font-weight: 600; font-size: .85rem; color: var(--muted); }
.sortbar select { width: auto; min-width: 210px; padding: 8px 10px; font-size: .9rem; }
.market-search { flex: 1 1 240px; min-width: 180px; padding: 9px 12px; font-size: .95rem; }
/* (ES) / (US) junto al nombre de la acción, para saber su horario */
.pais { color: var(--muted); font-weight: 700; font-size: .72rem; letter-spacing: .3px; cursor: help; }
@media (max-width: 600px) { .market-search { flex-basis: 100%; } }

/* ---- Listas dentro de tarjetas ---- */
.card ul { margin: 6px 0; padding-left: 20px; line-height: 1.65; }
.card li { margin: 5px 0; }

/* ---- Disponibilidad (instrucciones) ---- */
.disp { display: flex; flex-direction: column; gap: 10px; }
.disp-row { display: grid; grid-template-columns: 1.4fr auto 1.7fr; gap: 12px; align-items: center; padding: 12px 14px; background: var(--bg-2); border-radius: 10px; }
.disp-name .sub { color: var(--muted); font-size: .8rem; }
.disp-time { color: var(--muted); font-size: .9rem; }
@media (max-width: 640px) {
    .disp-row { grid-template-columns: 1fr; gap: 6px; }
}

@media (max-width: 720px) {
    .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 16px; }
    .stat { padding: 10px 12px; }
    .stat .label { font-size: .66rem; }
    .stat .value { font-size: 1.1rem; white-space: nowrap; margin-top: 2px; }
    .stat .value .small { font-size: .72rem; }
    h1 { font-size: 1.25rem; margin-bottom: 12px; }
    .container { padding: 14px 10px 46px; }
    .card { padding: 14px; }
    .card + .card { margin-top: 14px; }
    h2 { font-size: 1.1rem; }
    .hide-sm { display: none; }
    /* Barra de navegación más compacta */
    .nav { padding: 9px 12px; gap: 8px 10px; }
    .nav .user { display: none; }
    .brand { font-size: 1.05rem; }
    .brand-logo { height: 30px; width: 30px; }
    .navlink { padding: 5px 9px; }
}

/* Móvil pequeño: las tablas se muestran como tarjetas apiladas (sin scroll lateral) */
@media (max-width: 600px) {
    .table-wrap { overflow-x: visible; }
    table thead { position: absolute; left: -9999px; top: -9999px; }
    table, tbody, tr, td { display: block; width: 100%; }
    tbody tr {
        margin-bottom: 10px; border: 1px solid var(--border);
        border-radius: 12px; background: var(--card-2); overflow: hidden;
    }
    tbody tr:hover { background: var(--card-2); }
    td {
        display: flex; justify-content: space-between; align-items: center;
        gap: 12px; text-align: right; border: none;
        border-bottom: 1px solid var(--border); padding: 7px 12px; white-space: nowrap;
    }
    tr td:last-child { border-bottom: none; }
    td .small { font-size: .78rem; }
    td::before {
        content: attr(data-label); color: var(--muted); font-weight: 700;
        font-size: .72rem; text-transform: uppercase; letter-spacing: .3px;
        text-align: left; white-space: nowrap;
    }
    td:first-child { justify-content: flex-start; background: var(--card); padding: 9px 12px; white-space: normal; }
    td:first-child::before { display: none; }
    td.hide-sm { display: none; }
    .op-mode button, .op-range button { font-size: .78rem; }
}
