/* ControlRed · estilo inspirado en la consola de AWS */
:root {
    --nav-bg: #232f3e;
    --nav-bg-2: #16191f;
    --accent: #ff9900;
    --primary: #0972d3;
    --primary-hover: #065299;
    --bg: #f2f3f3;
    --panel: #ffffff;
    --border: #d5dbdb;
    --border-strong: #7d8998;
    --text: #16191f;
    --muted: #5f6b7a;
    --green: #037f0c;
    --green-bg: #f2fcf3;
    --red: #d91515;
    --red-bg: #fff7f7;
    --blue-bg: #f2f8fd;
    --orange: #8d6605;
    --orange-bg: #fffce9;
    --radius: 8px;
    --shadow: 0 1px 1px rgba(0, 28, 36, .3), 1px 1px 1px rgba(0, 28, 36, .15), -1px 1px 1px rgba(0, 28, 36, .15);
    --font: "Amazon Ember", "Segoe UI", "Helvetica Neue", Roboto, Arial, sans-serif;
    --mono: "Cascadia Mono", Consolas, Monaco, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { width: 16px; height: 16px; flex: none; }
h1 { font-size: 24px; font-weight: 700; margin: 0 0 4px; }
h2 { font-size: 18px; font-weight: 700; margin: 0; }
code, .mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 12px; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.inline-form { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
[hidden] { display: none !important; }

/* ---------- Barra superior ---------- */
.topbar {
    position: sticky; top: 0; z-index: 10;
    height: 52px; padding: 0 20px;
    display: flex; align-items: center; justify-content: space-between;
    background: var(--nav-bg); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-flex; color: var(--accent); }
.brand-mark svg { width: 26px; height: 26px; }
.brand-name { font-weight: 700; font-size: 17px; }
.brand-sub { color: #aab7b8; font-size: 13px; padding-left: 10px; border-left: 1px solid #414d5c; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 16px;
    background: #2f3d4f; color: #d1d5db; font-size: 13px;
}
.chip-warn { background: var(--accent); color: var(--nav-bg-2); font-weight: 700; }
.btn-topbar {
    background: transparent; border: 1px solid #5f6b7a; color: #fff;
    border-radius: 16px; padding: 4px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.btn-topbar:hover { border-color: #fff; }

/* ---------- Estructura ---------- */
.shell { display: flex; min-height: calc(100vh - 52px); }
.sidebar {
    width: 240px; flex: none; padding: 16px 0;
    background: var(--panel); border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
}
.sidebar-title { padding: 14px 24px 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    margin: 1px 12px; padding: 8px 12px; border-radius: 6px;
    color: var(--text); font-weight: 500;
}
.nav-item:hover { background: #f4f4f4; text-decoration: none; color: var(--primary); }
.nav-item.active { background: var(--blue-bg); color: var(--primary); font-weight: 700; box-shadow: inset 3px 0 0 var(--primary); }
.sidebar-foot { margin-top: auto; padding: 16px 24px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }

.content { flex: 1; min-width: 0; padding: 20px 32px 48px; max-width: 1400px; }
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.breadcrumb .sep { margin: 0 6px; }
.breadcrumb span:last-child { color: var(--text); }
.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 20px; }
.page-header p { max-width: 760px; }

/* ---------- Paneles ---------- */
.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 20px; overflow: hidden; }
.panel-header {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px;
    padding: 16px 20px; border-bottom: 1px solid #eaeded;
}
.panel-header .count { color: var(--muted); font-weight: 400; }
.panel-tools { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.panel-body { padding: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 20px; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 28px; font-weight: 300; }
.stat-warn .stat-value { color: var(--red); font-weight: 500; }

/* ---------- Botones ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 6px 18px; min-height: 34px; border-radius: 20px;
    border: 2px solid transparent; font: inherit; font-weight: 700; cursor: pointer;
    text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-normal { background: #fff; color: var(--primary); border-color: var(--primary); }
.btn-normal:hover { background: var(--blue-bg); color: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger-outline { background: #fff; color: var(--red); border-color: var(--red); }
.btn-danger-outline:hover { background: var(--red-bg); }
.btn-link { background: transparent; color: var(--primary); }
.btn-link:hover { background: var(--blue-bg); }
.btn-sm { padding: 2px 10px; min-height: 28px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin: 0; }
.field-label { font-weight: 700; font-size: 14px; }
.field-hint { color: var(--muted); font-size: 12px; }
.field-error { color: var(--red); font-size: 12px; font-weight: 700; }
.field-error:empty { display: none; }
.optional { color: var(--muted); font-weight: 400; font-style: italic; }
.input {
    width: 100%; padding: 6px 10px; min-height: 34px;
    border: 2px solid var(--border-strong); border-radius: 8px;
    font: inherit; color: var(--text); background: #fff;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(9, 114, 211, .2); }
.input[readonly] { background: #f4f4f4; border-color: #b6bec9; color: var(--muted); }
.input.input-validation-error { border-color: var(--red); }
.input-search { width: 280px; }
select.input { cursor: pointer; }
.form-stack { display: flex; flex-direction: column; gap: 16px; margin-top: 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 12px; }
.checks { display: flex; gap: 20px; flex-wrap: wrap; padding-top: 6px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

.rule-grid { display: grid; grid-template-columns: 1.3fr .8fr 1fr 1.6fr 1fr; gap: 16px; align-items: start; }
.addr-input { margin-top: 6px; }
.summary {
    margin-top: 20px; padding: 12px 16px; border-radius: 8px;
    background: var(--blue-bg); border: 1px solid #b5d6f4; color: #033160;
}
.summary:empty { display: none; }
.summary strong { font-weight: 700; }

details.advanced { border-top: 1px solid #eaeded; }
details.advanced summary { padding: 14px 20px; cursor: pointer; font-weight: 700; color: var(--primary); }

/* Segmentado (filtros y Permitir/Bloquear) */
.segmented { display: inline-flex; border: 2px solid var(--border-strong); border-radius: 20px; overflow: hidden; }
.segmented a, .segmented label { padding: 5px 14px; color: var(--text); font-weight: 700; font-size: 13px; cursor: pointer; }
.segmented a + a, .segmented label + label { border-left: 1px solid var(--border); }
.segmented a:hover { text-decoration: none; background: #f4f4f4; }
.segmented a.on { background: var(--nav-bg); color: #fff; }
.segmented-input input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-input label { display: flex; align-items: center; min-height: 30px; }
.segmented-input label:has(input:checked).seg-allow { background: var(--green); color: #fff; }
.segmented-input label:has(input:checked).seg-block { background: var(--red); color: #fff; }
.segmented-input label:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: -2px; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left; padding: 10px 12px; font-weight: 700; font-size: 13px; color: var(--muted);
    background: #fafafa; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid #eaeded; vertical-align: middle; }
.table tbody tr:hover { background: #f9fafb; }
.table th.right, .table td.right { text-align: right; }
.row-disabled td { color: var(--muted); }
.rule-name { font-weight: 700; color: var(--text); }
.row-disabled .rule-name { color: var(--muted); }
.rule-desc { font-size: 12px; color: var(--muted); max-width: 320px; }
.cell-name { min-width: 200px; }
.cell-type { min-width: 120px; }
.cell-addr { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-details { max-width: 520px; font-size: 13px; color: #414d5c; word-break: break-word; }
.td-actions { display: flex; gap: 8px; justify-content: flex-end; }
.table td.right .inline-form { margin-left: 4px; }
.table td.right { width: 1%; }
.empty-filter { padding: 24px; text-align: center; color: var(--muted); }

.badge {
    display: inline-block; padding: 1px 10px; border-radius: 12px;
    font-size: 12px; font-weight: 700; border: 1px solid transparent; white-space: nowrap;
}
.badge-green { color: var(--green); background: var(--green-bg); border-color: #9ad6a0; }
.badge-red { color: var(--red); background: var(--red-bg); border-color: #f5b5b5; }
.badge-blue { color: var(--primary); background: var(--blue-bg); border-color: #b5d6f4; }
.badge-orange { color: var(--orange); background: var(--orange-bg); border-color: #f2d27d; }
.badge-grey { color: #414d5c; background: #f4f4f4; border-color: var(--border); }
.tag { display: inline-block; margin-top: 4px; padding: 0 8px; font-size: 11px; border-radius: 4px; font-weight: 700; }
.tag-system { background: #eaeded; color: #414d5c; }

/* Interruptor */
.switch {
    position: relative; width: 36px; height: 20px; padding: 0; flex: none;
    border: none; border-radius: 10px; background: #8c96a3; cursor: pointer; transition: background .15s;
}
.switch .knob {
    position: absolute; top: 3px; left: 3px; width: 14px; height: 14px;
    border-radius: 50%; background: #fff; transition: left .15s;
}
.switch.on { background: var(--primary); }
.switch.on .knob { left: 19px; }
.switch:disabled { opacity: .5; cursor: not-allowed; }
.status-text { font-size: 13px; white-space: nowrap; }

/* Vacío */
.empty { padding: 48px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty-title { font-weight: 700; font-size: 16px; }

/* Filtros auditoría */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 16px 20px; border-bottom: 1px solid #eaeded; }
.filters .field { min-width: 150px; }
.filters .field-grow { flex: 1; min-width: 200px; }
.filter-actions { display: flex; gap: 8px; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; }
.pager div { display: flex; gap: 8px; }

/* ---------- Alertas ---------- */
.alert { padding: 12px 16px; border-radius: 8px; border: 2px solid; margin-bottom: 16px; }
.alert-success { background: var(--green-bg); border-color: var(--green); }
.alert-error { background: var(--red-bg); border-color: var(--red); }
.alert-warning { background: var(--orange-bg); border-color: #f2b705; }
.alert-info { background: var(--blue-bg); border-color: var(--primary); }
.alert ul { margin: 0; padding-left: 18px; }
.validation-summary-valid { display: none; }
.alert.fade { opacity: 0; transition: opacity .6s; }

/* ---------- Login / MFA ---------- */
.auth-body { background: linear-gradient(160deg, var(--nav-bg) 0%, var(--nav-bg-2) 55%, #0f1b2a 100%); min-height: 100vh; }
.auth-wrap { max-width: 440px; margin: 0 auto; padding: 56px 16px; }
.auth-brand { display: flex; align-items: center; gap: 12px; color: #fff; margin-bottom: 20px; }
.auth-brand .brand-mark svg { width: 40px; height: 40px; }
.auth-brand-name { font-size: 22px; font-weight: 700; }
.auth-brand-sub { font-size: 13px; color: #aab7b8; }
.auth-card { background: #fff; border-radius: 12px; padding: 28px; box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
.auth-title { font-size: 22px; margin-bottom: 4px; }
.auth-card .alert { margin: 16px 0 0; }
.auth-foot { color: #8d99a8; font-size: 12px; text-align: center; margin-top: 16px; }
.input-otp { font-family: var(--mono); font-size: 26px; letter-spacing: 10px; text-align: center; padding: 10px; }

.steps-mini { display: flex; align-items: center; justify-content: center; gap: 8px; margin-bottom: 16px; }
.step-dot {
    width: 28px; height: 28px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; background: #eaeded; color: var(--muted);
}
.step-dot.on { background: var(--primary); color: #fff; }
.step-dot.done { background: var(--green); color: #fff; }
.step-line { width: 48px; height: 2px; background: #eaeded; }
.step-line.on { background: var(--green); }

.enroll-steps { padding-left: 20px; margin: 16px 0 0; display: flex; flex-direction: column; gap: 14px; }
.enroll-steps li { padding-left: 4px; }
.enroll-steps li strong { display: block; }
.qr-box { display: flex; justify-content: center; margin: 12px 0 8px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; }
.qr-box img { width: 200px; height: 200px; image-rendering: pixelated; }
.manual-key summary { cursor: pointer; color: var(--primary); font-size: 13px; }
.manual-key .key { display: block; margin-top: 8px; padding: 10px; background: #f4f4f4; border-radius: 6px; font-size: 15px; letter-spacing: 1px; word-break: break-all; }

/* ---------- Responsivo ---------- */
@media (max-width: 1100px) {
    .rule-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 800px) {
    .sidebar { display: none; }
    .content { padding: 16px; }
    .grid-2, .stat-row, .rule-grid { grid-template-columns: 1fr; }
    .brand-sub, .topbar .chip { display: none; }
    .page-header { flex-direction: column; }
    .input-search { width: 100%; }
}

/* ---------- Intentos de conexión ---------- */
.stat-row-4 { grid-template-columns: repeat(4, 1fr); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.log-status { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 10px; }
.log-chip {
    display: inline-flex; align-items: center; gap: 8px; padding: 3px 12px; border-radius: 16px;
    background: var(--green-bg); border: 1px solid #9ad6a0; color: var(--green); font-weight: 700; font-size: 13px;
}
.log-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.log-chip-off { background: #f4f4f4; border-color: var(--border); color: var(--muted); }
.log-chip-off .dot { background: #8c96a3; }
.bar-row {
    display: grid; grid-template-columns: minmax(150px, 190px) 1fr 56px 110px; gap: 12px; align-items: center;
    padding: 8px 20px; border-bottom: 1px solid #eaeded;
}
.bar-row:last-child { border-bottom: none; }
.bar-row-ports { grid-template-columns: minmax(150px, 190px) 1fr 56px; }
.bar-label { display: flex; flex-direction: column; min-width: 0; }
.bar { height: 10px; background: #eaeded; border-radius: 5px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--red); transition: width .4s; }
.bar-orange span { background: var(--accent); }
.bar-n { text-align: right; font-weight: 700; }
.geo-code {
    display: inline-block; min-width: 26px; margin-right: 4px; padding: 0 4px; border-radius: 3px;
    background: #eaeded; color: #414d5c; font-size: 11px; font-weight: 700; text-align: center;
}
.check-block { align-items: flex-start; }
.check-block input { margin-top: 3px; }
.form-stack-tight { display: flex; flex-direction: column; gap: 18px; }
.field-narrow { max-width: 320px; }

@media (max-width: 1100px) {
    .two-col, .stat-row-4 { grid-template-columns: 1fr 1fr; }
    .two-col { grid-template-columns: 1fr; }
}
