/* ============================================================
   MySmartBreaker — Portal layout
   ============================================================ */

.sb-shell {
    display: grid;
    grid-template-areas: "header header" "sidebar main" "sidebar footer";
    grid-template-columns: 248px 1fr;
    grid-template-rows: 62px 1fr auto;
    min-height: 100vh;
    background: var(--color-bg, #f4f6f9);
    font-family: var(--font-sans);
}

/* ── Header ─────────────────────────────────────────────── */
.sb-header {
    grid-area: header;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 18px;
    background: var(--grad-brand, #0b5fa5);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 40;
    box-shadow: 0 2px 14px rgba(11, 61, 110, .35);
}

.sb-logo { color: #fff; font-weight: 800; letter-spacing: -.01em; text-decoration: none; font-size: 1.08rem; display: inline-flex; align-items: center; gap: 6px; }
.sb-logo:hover { color: #fff; text-decoration: none; opacity: .95; }
.sb-burger { background: none; border: 0; color: #fff; font-size: 1.35rem; cursor: pointer; border-radius: 8px; padding: 2px 8px; }
.sb-burger:hover { background: rgba(255,255,255,.12); }
.sb-header-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }

.sb-lang-selector {
    background: rgba(255,255,255,.12);
    color: #fff;
    border: 1px solid rgba(255,255,255,.3);
    border-radius: 8px;
    padding: 5px 9px;
    font-family: var(--font-sans);
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
}
.sb-lang-selector:focus { outline: none; border-color: #7ef3ec; box-shadow: 0 0 0 3px rgba(22,179,172,.25); }
.sb-lang-selector option { color: #333; }

.sb-bell { position: relative; color: #fff; text-decoration: none; font-size: 1.1rem; border-radius: 8px; padding: 4px 7px; transition: background .15s ease; }
.sb-bell:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.sb-bell-badge {
    position: absolute; top: -4px; right: -6px;
    background: linear-gradient(135deg, #ef4444, #dc2626); color: #fff;
    border-radius: 10px; font-size: .65rem; padding: 1px 5px; font-weight: 700;
    box-shadow: 0 2px 6px rgba(220,38,38,.5);
}

.sb-usermenu { position: relative; cursor: pointer; padding: 8px 2px; }
.sb-username { font-size: .9rem; font-weight: 600; }
/* Puente invisible entre el nombre y el menú: evita que se cierre al mover el mouse. */
.sb-usermenu::after {
    content: ""; position: absolute; right: 0; top: 100%;
    width: 100%; min-width: 200px; height: 14px; display: none;
}
.sb-usermenu:hover::after, .sb-usermenu:focus-within::after { display: block; }
.sb-usermenu-drop {
    display: none; position: absolute; right: 0; top: calc(100% + 10px);
    background: #fff; color: #333; border-radius: 12px; min-width: 200px;
    box-shadow: 0 14px 40px rgba(2,12,27,.22); overflow: hidden;
    border: 1px solid #e6ecf3; z-index: 45;
}
.sb-usermenu:hover .sb-usermenu-drop, .sb-usermenu:focus-within .sb-usermenu-drop { display: block; }
.sb-usermenu-drop a { display: flex; align-items: center; gap: 9px; padding: 11px 15px; color: #333; text-decoration: none; font-size: .9rem; }
.sb-usermenu-drop a i { width: 16px; text-align: center; color: #1A5F9E; }
.sb-usermenu-drop a:hover { background: #eef4fb; color: #0B3D6E; }

/* ── Sidebar (oscuro premium con gradiente) ─────────────── */
.sb-sidebar {
    grid-area: sidebar;
    background: linear-gradient(180deg, #0B3D6E 0%, #10314f 100%);
    padding: 14px 10px;
    transition: width .2s ease;
    overflow: hidden;
}
.sb-nav-item {
    display: flex; align-items: center; gap: 11px;
    color: #e8f1fa; text-decoration: none;
    padding: 10px 14px; font-size: .92rem; font-weight: 500; white-space: nowrap;
    border-radius: 10px; margin-bottom: 2px;
    transition: background .15s ease, color .15s ease, transform .15s ease;
}
.sb-nav-item:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; transform: translateX(2px); }
.sb-nav-item.is-active, .sb-nav-item.sb-active {
    background: linear-gradient(90deg, rgba(22,179,172,.35), rgba(22,179,172,.1));
    color: #fff; box-shadow: inset 3px 0 0 #16B3AC;
}
.sb-nav-icon {
    width: 20px; text-align: center; display: inline-block;
    font-size: .95rem; opacity: .9; flex-shrink: 0;
}
.sb-shell.sb-collapsed { grid-template-columns: 60px 1fr; }
.sb-shell.sb-collapsed .sb-nav-text { display: none; }

/* ── Main / breadcrumb / footer ─────────────────────────── */
.sb-main { grid-area: main; padding: 22px 26px; min-width: 0; }
.sb-page-title { font-weight: 800; letter-spacing: -.02em; color: #0f172a; }
.sb-breadcrumb { font-size: .84rem; color: #6b7c8d; margin-bottom: 16px; }
.sb-breadcrumb a { color: var(--color-accent, #1A5F9E); text-decoration: none; font-weight: 500; }
.sb-crumb-current { font-weight: 700; color: #33475b; }

.sb-footer {
    grid-area: footer;
    display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px;
    padding: 14px 26px; font-size: .8rem; color: #6b7c8d;
    border-top: 1px solid #e1e7ee; background: #fff;
}
.sb-footer a { color: #6b7c8d; }

/* ── Toasts ─────────────────────────────────────────────── */
.sb-toasts { position: fixed; bottom: 18px; right: 18px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.sb-toast { padding: 12px 16px; border-radius: 12px; color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.28); animation: sbToastIn .25s ease; max-width: 380px; font-weight: 500; }
.sb-toast-success { background: linear-gradient(135deg, #15803d, #22c55e); }
.sb-toast-error   { background: linear-gradient(135deg, #b91c1c, #ef4444); }
.sb-toast-warning { background: linear-gradient(135deg, #c2410c, #f97316); }
.sb-toast-info    { background: linear-gradient(135deg, #1d4ed8, #3b82f6); }
@keyframes sbToastIn { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Cards / KPI / grids ────────────────────────────────── */
.sb-card {
    background: var(--grad-card, #fff);
    border: 1px solid #e6ecf3;
    border-radius: 14px;
    box-shadow: 0 1px 2px rgba(15,23,42,.05), 0 1px 3px rgba(15,23,42,.06);
    padding: 20px;
    margin-bottom: 18px;
    transition: box-shadow .18s ease, transform .18s ease;
}
.sb-card:hover { box-shadow: 0 8px 24px rgba(11,61,110,.10); }
.sb-card h2, .sb-card h3 { margin-top: 0; color: #10314f; font-weight: 700; letter-spacing: -.01em; }
.sb-card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }

.sb-kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 14px; margin-bottom: 18px; }
.sb-kpi {
    position: relative; overflow: hidden;
    background: #fff; border: 1px solid #e6ecf3; border-radius: 14px; padding: 16px 18px;
    box-shadow: 0 1px 2px rgba(15,23,42,.05), 0 1px 3px rgba(15,23,42,.06);
    transition: transform .18s ease, box-shadow .18s ease;
}
.sb-kpi:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(11,61,110,.10); }
.sb-kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--grad-brand); }
.sb-kpi .sb-kpi-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -.03em; color: #0B3D6E; line-height: 1.15; }
.sb-kpi .sb-kpi-label { font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #6b7c8d; }
/* Acentos por tipo de KPI */
.sb-kpi-energy::before  { background: linear-gradient(180deg, #f59e0b, #fbbf24); }
.sb-kpi-fault::before   { background: linear-gradient(180deg, #b91c1c, #ef4444); }
.sb-kpi-offline::before { background: linear-gradient(180deg, #475569, #94a3b8); }
.sb-kpi-online::before  { background: linear-gradient(180deg, #15803d, #22c55e); }
.sb-kpi-temp::before    { background: linear-gradient(180deg, #c2410c, #fb923c); }
.sb-kpi-rssi::before    { background: linear-gradient(180deg, #6d28d9, #a78bfa); }
.sb-kpi-load::before    { background: linear-gradient(180deg, #0e7490, #22d3ee); }
.sb-grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.sb-dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }

/* ── Tablas ─────────────────────────────────────────────── */
.sb-table { width: 100%; border-collapse: collapse; font-size: .9rem; background: #fff; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(15,23,42,.06); }
.sb-table th {
    text-align: left; color: #5a6b7b; font-weight: 700; font-size: .72rem;
    letter-spacing: .08em; text-transform: uppercase;
    padding: 11px 12px; border-bottom: 1px solid #e1e7ee;
    background: linear-gradient(180deg, #f8fafc, #eef3f9);
}
.sb-table td { padding: 10px 12px; border-bottom: 1px solid #eef2f6; }
.sb-table tr:last-child td { border-bottom: 0; }
.sb-table tr:hover td { background: #eef4fb; }

/* ── Badges / semáforo EATON (P5.10) ────────────────────── */
.sb-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 11px; border-radius: 999px; font-size: .76rem; font-weight: 700; letter-spacing: .02em; color: #fff; }
.sb-badge-green  { background: #2e7d32; }
.sb-badge-yellow { background: #f9a825; color: #3a2f00; }
.sb-badge-orange { background: #ef6c00; }
.sb-badge-red    { background: #d32f2f; }
.sb-badge-gray   { background: #90a4ae; }
.sb-badge-online  { background: #2e7d32; }
.sb-badge-offline { background: #90a4ae; }
.sb-badge-tripped { background: #d32f2f; }

/* ── Formularios / botones ──────────────────────────────── */
.sb-form-row { margin-bottom: 14px; }
.sb-form-row label { display: block; font-size: .84rem; color: #33475b; margin-bottom: 5px; font-weight: 600; }
.sb-input, .sb-select { width: 100%; max-width: 420px; padding: 9px 12px; border: 1px solid #d3dbe4; border-radius: 9px; font-size: .92rem; box-sizing: border-box; font-family: var(--font-sans); transition: border-color .15s ease, box-shadow .15s ease; }
.sb-input:focus, .sb-select:focus { outline: none; border-color: #1A5F9E; box-shadow: 0 0 0 3px rgba(26,95,158,.14); }
.sb-field-error { color: #d32f2f; font-size: .8rem; font-weight: 600; }

.sb-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px; border-radius: 9px; border: 0; cursor: pointer;
    font-size: .92rem; font-weight: 600; text-decoration: none; font-family: var(--font-sans);
    transition: filter .15s ease, transform .15s ease, box-shadow .15s ease;
}
.sb-btn:hover { text-decoration: none; filter: brightness(1.07); transform: translateY(-1px); }
.sb-btn-primary { background: var(--grad-brand, #0b5fa5); color: #fff; box-shadow: 0 2px 8px rgba(11,61,110,.28); }
.sb-btn-secondary { background: #fff; color: #33475b; border: 1px solid #d3dbe4; box-shadow: 0 1px 3px rgba(15,23,42,.06); }
.sb-btn-danger { background: linear-gradient(135deg, #b91c1c, #ef4444); color: #fff; box-shadow: 0 2px 8px rgba(220,38,38,.3); }
.sb-btn-success { background: linear-gradient(135deg, #15803d, #22c55e); color: #fff; box-shadow: 0 2px 8px rgba(22,163,74,.3); }
.sb-btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.sb-btn-google { background: #fff; color: #444; border: 1px solid #d3dbe4; }

/* ── Auth (P5.3) ────────────────────────────────────────── */
.sb-auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px;
    background: radial-gradient(1200px 600px at 85% -10%, rgba(22,179,172,.28), transparent 60%),
                linear-gradient(160deg, #0a1f38 0%, #0B3D6E 60%, #10314f 100%);
}
.sb-auth-card { background: #fff; border-radius: 18px; padding: 34px 32px; width: 100%; max-width: 410px; box-shadow: 0 24px 60px rgba(2,12,27,.45); }
.sb-auth-card h1 { margin: 0 0 18px; font-size: 1.3rem; font-weight: 800; letter-spacing: -.02em; color: #10314f; }
.sb-auth-links { margin-top: 14px; font-size: .85rem; }
.sb-auth-lang { position: fixed; top: 14px; right: 16px; }

/* ── Alertas de guía al usuario ─────────────────────────── */
.sb-alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 14px; margin: 12px 0; border-radius: 10px;
    font-size: .9rem; font-weight: 600; line-height: 1.45;
    border: 1px solid transparent; border-left-width: 4px;
}
.sb-alert i { margin-top: 2px; font-size: 1.05rem; flex-shrink: 0; }
.sb-alert-danger  { background: #fef2f2; color: #991b1b; border-color: #fecaca; border-left-color: #dc2626; }
.sb-alert-danger i { color: #dc2626; }
.sb-alert-success { background: #f0fdf4; color: #166534; border-color: #bbf7d0; border-left-color: #16a34a; }
.sb-alert-success i { color: #16a34a; }
.sb-alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; border-left-color: #d97706; }
.sb-alert-warning i { color: #d97706; }
.sb-alert-link { color: inherit; text-decoration: underline; font-weight: 700; }
.sb-alert-link:hover { filter: brightness(1.15); }
/* Compatibilidad con clases anteriores */
.sb-auth-error { color: #b91c1c; font-size: .88rem; font-weight: 600; margin: 10px 0; }
.sb-auth-ok { color: #15803d; font-size: .88rem; font-weight: 600; margin: 10px 0; }

/* ── Modal de confirmación (P5.6/P5.10) ─────────────────── */
.sb-modal-backdrop { display: none; position: fixed; inset: 0; background: rgba(10,22,38,.6); backdrop-filter: blur(2px); z-index: 70; align-items: center; justify-content: center; }
.sb-modal-backdrop.sb-open { display: flex; }
.sb-modal { background: #fff; border-radius: 16px; padding: 26px; max-width: 460px; width: 92%; box-shadow: 0 24px 70px rgba(0,0,0,.4); }
/* Caja blanca del modal dentro del backdrop centrado. Incluye scroll interno para
   pantallas bajas: la caja nunca excede el 90% del alto del viewport. */
.sb-modal-box { background: #fff; border-radius: 16px; padding: 26px; max-width: 460px; width: 92%; max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 70px rgba(0,0,0,.4); }
.sb-modal-box h3 { margin-top: 0; color: #10314f; font-weight: 700; }
.sb-modal h3 { margin-top: 0; color: #10314f; font-weight: 700; }
.sb-modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
/* Modal "autónomo" (sin backdrop externo): <div class="sb-modal" hidden><div class="sb-modal-card">…</div></div>.
   sbConfirm() le quita [hidden] y agrega .sb-open: se convierte en overlay a pantalla completa. */
.sb-modal.sb-open { display: flex; position: fixed; inset: 0; z-index: 70; background: rgba(10,22,38,.6); backdrop-filter: blur(2px); align-items: center; justify-content: center; padding: 0; max-width: none; width: auto; border-radius: 0; box-shadow: none; }
.sb-modal:not(.sb-open)[hidden] { display: none; }
.sb-modal-card { background: #fff; border-radius: 16px; padding: 26px; max-width: 460px; width: 92%; max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 70px rgba(0,0,0,.4); color: #10314f; }
.sb-modal-card p { margin-top: 0; }

/* ── Tabs (P5.9) ────────────────────────────────────────── */
.sb-tabs, .sb-tabs-inline { display: flex; gap: 4px; border-bottom: 2px solid #e1e7ee; margin-bottom: 18px; flex-wrap: wrap; }
.sb-tab { padding: 9px 16px; cursor: pointer; border: 0; background: none; font-size: .9rem; font-weight: 500; color: #6b7c8d; border-bottom: 3px solid transparent; transition: color .15s ease; }
.sb-tab:hover { color: #0B3D6E; }
.sb-tab.active, .sb-tab.sb-active { color: var(--color-primary, #0b5fa5); border-bottom-color: #16B3AC; font-weight: 700; }

/* ── Gráficos (Chart.js) ────────────────────────────────── */
.sb-chart { background: #fff; border: 1px solid #e6ecf3; border-radius: 14px; padding: 18px; box-shadow: 0 1px 3px rgba(15,23,42,.06); }

/* ── Responsive (breakpoints P0.5) ──────────────────────── */
@media (max-width: 1024px) {
    .sb-grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .sb-shell { grid-template-areas: "header" "main" "footer"; grid-template-columns: 1fr; grid-template-rows: 62px 1fr auto; }
    .sb-sidebar { position: fixed; left: -260px; top: 62px; bottom: 0; width: 250px; z-index: 50; transition: left .2s ease; box-shadow: 8px 0 30px rgba(0,0,0,.25); }
    .sb-sidebar.sb-open { left: 0; }
    .sb-username { display: none; }
    .sb-main { padding: 14px; }
    .sb-footer { padding: 12px 14px; }
}


/* ── Espaciado profesional de formularios y secciones (P0.1) ── */
.sb-field { margin-bottom: 16px; }
.sb-field label { display: block; font-size: .84rem; font-weight: 600; color: #33475b; margin-bottom: 6px; }
.sb-field-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.sb-field-row .sb-field { margin-bottom: 0; }
.sb-card h2 { margin: 22px 0 12px; font-size: 1.06rem; }
.sb-card h2:first-child { margin-top: 0; }
.sb-card .sb-btn { margin-top: 4px; }
.sb-card p { line-height: 1.55; }

/* ── 2FA (P0.1) ─────────────────────────────────────────── */
.sb-2fa-qr { margin: 14px 0; padding: 12px; background: #fff; border: 1px solid #e1e7ee; border-radius: 12px; display: inline-block; }
.sb-2fa-steps { margin: 10px 0 14px; padding-left: 20px; }
.sb-2fa-steps li { margin-bottom: 6px; font-size: .9rem; color: #33475b; }
.sb-hint { font-size: .82rem; color: #6b7c8d; margin: 6px 0 10px; }
.sb-code { font-family: ui-monospace, Menlo, Consolas, monospace; background: #eef4fb; border: 1px solid #d3dbe4; border-radius: 8px; padding: 4px 10px; font-size: .88rem; color: #0B3D6E; letter-spacing: .06em; word-break: break-all; display: inline-block; }
.sb-input-code { max-width: 180px; text-align: center; letter-spacing: .25em; font-weight: 700; font-size: 1.05rem; }

/* ── Plan actual (P0.1) ─────────────────────────────────── */
.sb-plan-name { font-size: 1.15rem; font-weight: 800; color: #0B3D6E; }
.sb-plan-meta { font-size: .86rem; color: #6b7c8d; margin-top: 4px; }

/* Enlace de acción destructiva (p. ej. eliminar breaker) */
.sb-link-danger { color: #d32f2f; font-weight: 600; }
.sb-link-danger:hover { color: #b71c1c; text-decoration: underline; }


/* ── Agente local: pasos de vinculación y código generado ─────────────── */
.sb-agent-steps { margin: 10px 0 14px; padding-left: 20px; }
.sb-agent-steps li { margin-bottom: 6px; font-size: .9rem; color: #33475b; }
.sb-agent-code { margin-top: 14px; }
.sb-agent-token {
    width: 100%; box-sizing: border-box; margin-bottom: 8px;
    font-family: Consolas, Menlo, monospace; font-size: .78rem;
    word-break: break-all; resize: vertical;
}
