/* Base */
:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #1d2733;
    --muted: #667085;
    --line: #d9e0e8;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --danger: #b42318;
    --success: #067647;
    --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);

    /* Tipografia unificada (maximo 5 tamanos) */
    --fs-xs: 13px;
    --fs-sm: 14px;
    --fs-base: 15px;
    --fs-lg: 20px;
    --fs-xl: 28px;

    /* Colores de barras de oportunidad */
    --bar-negro: #18212b;
    --bar-rojo: #b42318;
    --bar-verde: #067647;
    --bar-azul: #1d4ed8;
    --bar-naranja: #c2410c;
    --bar-gris: #98a2b3;
    --bar-track: #eef1f4;
    --bar-footprint: #cbd2da;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: var(--fs-base);
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input {
    font: inherit;
}

h1,
h2,
p {
    margin: 0;
}

/* Buttons */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
    font-size: var(--fs-sm);
}

.button:hover {
    border-color: #b7c4d2;
}

.button-primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

.button-primary:hover {
    border-color: var(--primary-dark);
    background: var(--primary-dark);
}

.button-ghost {
    background: transparent;
}

.button-danger {
    border-color: #f5c2bd;
    color: var(--danger);
}

.button-small {
    min-height: 34px;
    padding: 0 12px;
    font-size: var(--fs-xs);
}

.button-full {
    width: 100%;
}

/* Auth */
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #eaf0f2;
}

.auth-wrap {
    width: min(100%, 420px);
}

.login-panel {
    padding: 32px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.login-intro {
    display: grid;
    gap: 8px;
    margin-bottom: 28px;
}

.login-intro h1 {
    font-size: var(--fs-xl);
}

.login-intro p,
.eyebrow,
.metric-card span {
    color: var(--muted);
    font-size: var(--fs-xs);
}

.brand-mark {
    display: inline-grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    font-weight: 800;
    font-size: var(--fs-lg);
}

/* App Layout */
.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 24px 16px;
    background: #18212b;
    color: #ffffff;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 800;
    font-size: var(--fs-lg);
    flex-shrink: 0;
    padding: 0 8px;
}

.nav {
    display: grid;
    gap: 2px;
    margin-top: 24px;
    flex: 1;
}

.nav-link {
    padding: 9px 14px;
    border-radius: 6px;
    color: #c8d2df;
    font-weight: 600;
    font-size: var(--fs-sm);
}

.nav-link:hover,
.nav-link.is-active {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.workspace {
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 24px 32px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.topbar h1 {
    font-size: var(--fs-xl);
}

.content {
    display: grid;
    gap: 24px;
    padding: 32px;
}

/* Panels */
.panel,
.metric-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel {
    padding: 24px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.panel-header h2 {
    margin-top: 4px;
    font-size: var(--fs-lg);
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.metric-card {
    display: grid;
    gap: 8px;
    padding: 22px;
}

.metric-card strong {
    font-size: var(--fs-lg);
}

.alert {
    padding: 14px 16px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
}

.alert-success {
    border-color: #abefc6;
    color: var(--success);
    background: #ecfdf3;
}

/* Forms */
.form {
    display: grid;
    gap: 18px;
}

.form-panel {
    max-width: 760px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.field {
    display: grid;
    gap: 8px;
}

.field label,
.check {
    font-weight: 700;
    font-size: var(--fs-sm);
}

.field input {
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

.field input:focus {
    outline: 3px solid rgba(15, 118, 110, 0.14);
    border-color: var(--primary);
}

.field-error {
    color: var(--danger);
    font-size: var(--fs-xs);
}

.check {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Tables */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

.table th,
.table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.table th {
    background: var(--surface-soft);
    color: var(--muted);
    font-size: var(--fs-xs);
    text-transform: uppercase;
}

.table tr:last-child td {
    border-bottom: 0;
}

.actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.actions-cell {
    text-align: right;
}

.pagination {
    margin-top: 18px;
}

.pagination nav {
    display: flex;
    gap: 8px;
}

/* Responsive */
@media (max-width: 820px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
    }

    .topbar,
    .panel-header,
    .form-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .content,
    .topbar {
        padding: 22px;
    }

    .metrics-grid,
    .metrics-grid-4,
    .grid-2,
    .grid-3,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .ficha-grid {
        grid-template-columns: 1fr;
    }
}

/* Pantallas medianas: las grillas de 3 y 4 columnas pasan a 2 */
@media (min-width: 821px) and (max-width: 1100px) {
    .metrics-grid-4,
    .grid-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Nav sections */
.nav-section {
    margin-top: 16px;
    margin-bottom: 2px;
    padding: 0 14px;
    color: #8794a3;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* Badges / estados */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface-soft);
    color: var(--muted);
    font-size: var(--fs-xs);
    font-weight: 700;
}

.badge-on {
    border-color: #abefc6;
    background: #ecfdf3;
    color: var(--success);
}

.badge-off {
    border-color: #f5c2bd;
    background: #fef3f2;
    color: var(--danger);
}

.badge-group {
    border-color: #d9e0e8;
    background: #18212b;
    color: #ffffff;
}

/* Alertas (variantes) */
.alert-danger {
    border-color: #f5c2bd;
    color: var(--danger);
    background: #fef3f2;
}

.alert-info {
    border-color: #b9d6fb;
    color: #1d4ed8;
    background: #eff6ff;
}

/* Utilidades de grid */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

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

.metrics-grid-4 {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.muted {
    color: var(--muted);
    font-size: var(--fs-xs);
}

.text-right {
    text-align: right;
}

/* Forms: select y textarea (reusan estilo de .field input) */
.field select,
.field textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

.field textarea {
    min-height: 160px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    line-height: 1.45;
    resize: vertical;
}

.field select:focus,
.field textarea:focus {
    outline: 3px solid rgba(15, 118, 110, 0.14);
    border-color: var(--primary);
}

.field-hint {
    color: var(--muted);
    font-size: var(--fs-xs);
}

.code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: var(--fs-xs);
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 2px 6px;
}

/* Switch (toggle) */
.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background: var(--bar-gris);
    border-radius: 999px;
    transition: background 0.15s ease;
}

.switch .slider::before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    top: 3px;
    background: #ffffff;
    border-radius: 50%;
    transition: transform 0.15s ease;
}

.switch input:checked + .slider {
    background: var(--success);
}

.switch input:checked + .slider::before {
    transform: translateX(20px);
}

/* ===========================================================
   FICHAS DE ACCIONES
   =========================================================== */
.ficha-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.ficha {
    display: grid;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
    min-width: 0;
}

.ficha-head {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
}

.ficha-logo {
    display: inline-grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 8px;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    font-weight: 800;
    font-size: var(--fs-xs);
    color: var(--text);
    flex: 0 0 38px;
}

/* ticker + nombre ocupan el espacio central con truncado correcto */
.ficha-id {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
}

.ficha-ticker {
    font-weight: 800;
    font-size: var(--fs-base);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ficha-name {
    color: var(--muted);
    font-size: var(--fs-xs);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

/* precio: ancla a la derecha, no comprime el nombre, no desborda */
.ficha-price {
    flex: 0 0 auto;
    text-align: right;
    font-weight: 800;
    font-size: var(--fs-sm);
    white-space: nowrap;
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ficha-price small {
    display: block;
    color: var(--muted);
    font-size: var(--fs-xs);
    font-weight: 600;
    white-space: nowrap;
}

/* ===========================================================
   BARRAS DE OPORTUNIDAD (sin bordes redondeados)
   =========================================================== */
.bars {
    display: grid;
    gap: 8px;
}

.bar {
    position: relative;
}

.bar-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: var(--fs-xs);
    font-weight: 700;
    color: var(--muted);
}

.bar-track {
    position: relative;
    height: 16px;
    background: var(--bar-track);
    border-radius: 0; /* sin bordes redondeados (requisito) */
    overflow: hidden;
}

.bar-fill {
    position: absolute;
    inset: 0 auto 0 0;
    height: 100%;
    border-radius: 0;
}

/* Huella gris: porcentaje que bajo respecto al valor anterior */
.bar-footprint {
    position: absolute;
    top: 0;
    bottom: 0;
    height: 100%;
    background: var(--bar-footprint);
    border-radius: 0;
}

.bar-c-negro { background: var(--bar-negro); }
.bar-c-rojo { background: var(--bar-rojo); }
.bar-c-verde { background: var(--bar-verde); }
.bar-c-azul { background: var(--bar-azul); }
.bar-c-naranja { background: var(--bar-naranja); }
.bar-c-gris { background: var(--bar-gris); }

/* Tooltip / rollover de condiciones */
.bar-tip {
    position: absolute;
    z-index: 20;
    left: 0;
    top: calc(100% + 6px);
    width: max(100%, 240px);
    padding: 12px 14px;
    background: #18212b;
    color: #ffffff;
    border-radius: 8px;
    box-shadow: var(--shadow);
    font-size: var(--fs-xs);
    line-height: 1.5;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.12s ease;
    pointer-events: none;
}

.bar:hover .bar-tip {
    opacity: 1;
    visibility: visible;
}

.bar-tip ul {
    margin: 6px 0 0;
    padding-left: 16px;
}

.bar-tip .ok { color: #7ee2a8; }
.bar-tip .no { color: #f7a59c; }

/* ===========================================================
   VISTA PUBLICA
   =========================================================== */
.public-shell {
    min-height: 100vh;
    background: var(--bg);
}

.public-wrap {
    width: min(100%, 1200px);
    margin: 0 auto;
    padding: 32px 24px;
}

.public-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.public-head h1 {
    font-size: var(--fs-xl);
}

/* Utilidades de ancho/posicion de barras (evitan estilos inline) */
.bw-0 { width: 0%; }
.bw-5 { width: 5%; }
.bw-10 { width: 10%; }
.bw-15 { width: 15%; }
.bw-20 { width: 20%; }
.bw-25 { width: 25%; }
.bw-30 { width: 30%; }
.bw-35 { width: 35%; }
.bw-40 { width: 40%; }
.bw-45 { width: 45%; }
.bw-50 { width: 50%; }
.bw-55 { width: 55%; }
.bw-60 { width: 60%; }
.bw-65 { width: 65%; }
.bw-70 { width: 70%; }
.bw-75 { width: 75%; }
.bw-80 { width: 80%; }
.bw-85 { width: 85%; }
.bw-90 { width: 90%; }
.bw-95 { width: 95%; }
.bw-100 { width: 100%; }
.bl-0 { left: 0%; }
.bl-5 { left: 5%; }
.bl-10 { left: 10%; }
.bl-15 { left: 15%; }
.bl-20 { left: 20%; }
.bl-25 { left: 25%; }
.bl-30 { left: 30%; }
.bl-35 { left: 35%; }
.bl-40 { left: 40%; }
.bl-45 { left: 45%; }
.bl-50 { left: 50%; }
.bl-55 { left: 55%; }
.bl-60 { left: 60%; }
.bl-65 { left: 65%; }
.bl-70 { left: 70%; }
.bl-75 { left: 75%; }
.bl-80 { left: 80%; }
.bl-85 { left: 85%; }
.bl-90 { left: 90%; }
.bl-95 { left: 95%; }
.bl-100 { left: 100%; }
