/* ============================================================
   SysLog Analyzer — hoja de estilos
   ============================================================ */

:root {
    --bg:           #0b1120;
    --surface:      #111a2e;
    --surface-2:    #16203a;
    --sidebar:      #0e1626;
    --border:       #243149;
    --text:         #e6ecf7;
    --text-dim:     #93a2bd;
    --text-faint:   #64748b;
    --primary:      #4f8cff;
    --primary-600:  #3b74e6;
    --primary-soft: rgba(79, 140, 255, 0.14);
    --success:      #2fbf71;
    --danger:       #ef4d5a;
    --warning:      #f2b23e;
    --radius:       12px;
    --radius-sm:    8px;
    --shadow:       0 10px 30px -12px rgba(0, 0, 0, 0.6);
    --sidebar-w:    250px;
    --sidebar-mini: 74px;
    --ease:         cubic-bezier(.4, 0, .2, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

.icon { width: 20px; height: 20px; flex: 0 0 20px; }

/* ---------- Layout base ---------- */
.app {
    --gap: var(--sidebar-mini);
    min-height: 100%;
}

.content {
    margin-left: var(--gap);
    min-height: 100vh;
    transition: margin-left .25s var(--ease);
}

/* Menú fijado (pin) -> deja espacio completo */
.app.pinned { --gap: var(--sidebar-w); }

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-mini);
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 50;
    overflow: hidden;
    transition: width .25s var(--ease);
}

/* Expandir: al pasar el mouse, al enfocar dentro, o si está fijado */
.sidebar:hover,
.sidebar:focus-within,
.app.pinned .sidebar {
    width: var(--sidebar-w);
    box-shadow: var(--shadow);
}
.app.pinned .sidebar { box-shadow: none; }

.sidebar__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    height: 64px;
    padding: 0 18px 0 22px;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    overflow: hidden;
}
.brand__mark {
    flex: 0 0 32px;
    width: 32px; height: 32px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, var(--primary), #7a5cff);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: .5px;
    border-radius: 9px;
}
.brand__text {
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
}

/* Elementos que solo aparecen cuando el menú está expandido */
.brand__text,
.nav__label,
.userbox__meta,
.pin { opacity: 0; transition: opacity .18s var(--ease); }

.sidebar:hover .brand__text,
.sidebar:focus-within .brand__text,
.app.pinned .brand__text,
.sidebar:hover .nav__label,
.sidebar:focus-within .nav__label,
.app.pinned .nav__label,
.sidebar:hover .userbox__meta,
.sidebar:focus-within .userbox__meta,
.app.pinned .userbox__meta,
.sidebar:hover .pin,
.sidebar:focus-within .pin,
.app.pinned .pin { opacity: 1; }

/* Pin */
.pin {
    flex: 0 0 auto;
    display: grid; place-items: center;
    width: 32px; height: 32px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    border-radius: 8px;
    cursor: pointer;
    transition: color .15s, background .15s, border-color .15s, transform .15s;
}
.pin:hover { color: var(--text); background: var(--surface-2); }
.app.pinned .pin {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-soft);
    transform: rotate(0deg);
}
.app.pinned .pin .icon { transform: rotate(-30deg); }

/* Navegación */
.nav {
    flex: 1;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav__item {
    display: flex;
    align-items: center;
    gap: 14px;
    height: 46px;
    padding: 0 13px;
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    white-space: nowrap;
    position: relative;
    transition: background .15s, color .15s;
}
.nav__item:hover { background: var(--surface-2); color: var(--text); }
.nav__item.active { background: var(--primary-soft); color: #cfe0ff; }
.nav__item.active::before {
    content: "";
    position: absolute;
    left: -12px; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 22px;
    background: var(--primary);
    border-radius: 0 3px 3px 0;
}
.nav__label { font-weight: 500; font-size: 14.5px; }

/* Pie del sidebar */
.sidebar__foot {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.userbox {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 9px;
    overflow: hidden;
}
.avatar {
    flex: 0 0 34px;
    width: 34px; height: 34px;
    display: grid; place-items: center;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 50%;
    font-weight: 600;
    color: var(--primary);
}
.userbox__meta { display: flex; flex-direction: column; min-width: 0; }
.userbox__name {
    font-size: 13.5px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.userbox__role { font-size: 11.5px; color: var(--text-faint); text-transform: capitalize; }
.nav__item--logout:hover { color: var(--danger); background: rgba(239, 77, 90, .1); }

/* ============================================================
   Topbar
   ============================================================ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: 64px;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 28px;
    background: rgba(11, 17, 32, .82);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.topbar__title { font-size: 18px; font-weight: 650; margin: 0; }
.topbar__spacer { flex: 1; }
.topbar__toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 40px; height: 40px;
    border: 1px solid var(--border);
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    padding: 0 10px;
}
.topbar__toggle span { display: block; height: 2px; background: var(--text); border-radius: 2px; }

/* ============================================================
   Main / componentes
   ============================================================ */
.main { padding: 28px; max-width: 1240px; }

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
    border: 1px solid transparent;
}
.alert--success { background: rgba(47,191,113,.12); border-color: rgba(47,191,113,.35); color: #8ff0bd; }
.alert--error   { background: rgba(239,77,90,.12);  border-color: rgba(239,77,90,.35);  color: #ffb3ba; }
.alert--info    { background: var(--primary-soft);  border-color: rgba(79,140,255,.35); color: #cfe0ff; }

/* Tarjetas */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
}
.card__head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; margin-bottom: 18px;
}
.card__title { font-size: 16px; font-weight: 650; margin: 0; }

/* Grid de métricas */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px; margin-bottom: 26px; }
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.stat__label { color: var(--text-dim); font-size: 13px; }
.stat__value { font-size: 30px; font-weight: 700; margin-top: 6px; }
.stat__hint  { font-size: 12.5px; color: var(--text-faint); margin-top: 4px; }

/* Tabla */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td {
    text-align: left;
    padding: 13px 14px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.data th {
    color: var(--text-dim);
    font-weight: 600;
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: .4px;
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.actions { text-align: right; }

/* Badges */
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid transparent;
}
.badge--admin  { background: rgba(122,92,255,.14); color: #c3b4ff; border-color: rgba(122,92,255,.4); }
.badge--user   { background: var(--surface-2); color: var(--text-dim); border-color: var(--border); }
.badge--on     { background: rgba(47,191,113,.14); color: #8ff0bd; border-color: rgba(47,191,113,.4); }
.badge--off    { background: rgba(239,77,90,.12); color: #ffb3ba; border-color: rgba(239,77,90,.35); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* Botones */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s, opacity .15s;
}
.btn:hover { background: #1d2942; }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-600); }
.btn--danger { background: transparent; border-color: rgba(239,77,90,.5); color: #ffb3ba; }
.btn--danger:hover { background: rgba(239,77,90,.12); }
.btn--ghost { background: transparent; }
.btn--sm { padding: 7px 12px; font-size: 13px; }
.btn .icon { width: 17px; height: 17px; }

/* Formularios */
.form { display: flex; flex-direction: column; gap: 18px; max-width: 560px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 13.5px; font-weight: 600; color: var(--text-dim); }
.field input, .field select {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
    font-size: 14.5px;
    transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.field__hint { font-size: 12.5px; color: var(--text-faint); }
.field--row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form__actions { display: flex; gap: 10px; margin-top: 6px; }

/* Toggle switch */
.switch { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { display: none; }
.switch__track {
    width: 42px; height: 24px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    position: relative;
    transition: background .15s, border-color .15s;
}
.switch__track::after {
    content: ""; position: absolute; top: 2px; left: 2px;
    width: 18px; height: 18px; border-radius: 50%;
    background: var(--text-dim);
    transition: transform .18s var(--ease), background .15s;
}
.switch input:checked + .switch__track { background: var(--primary-soft); border-color: var(--primary); }
.switch input:checked + .switch__track::after { transform: translateX(18px); background: var(--primary); }

/* Consola de salida (SSH) */
.console {
    background: #060b16;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin: 12px 0 0;
    max-height: 340px;
    overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.55;
    color: #b8c6e0;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Modal */
.modal {
    position: fixed; inset: 0;
    background: rgba(3, 7, 16, .66);
    backdrop-filter: blur(3px);
    display: grid; place-items: center;
    z-index: 100;
    padding: 24px;
}
.modal[hidden] { display: none; }
.modal__box {
    width: 100%; max-width: 640px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-height: 88vh;
    display: flex; flex-direction: column;
}
.modal__head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal__title { margin: 0; font-size: 16px; font-weight: 650; }
.modal__close {
    background: none; border: none; color: var(--text-dim);
    font-size: 24px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.modal__close:hover { color: var(--text); }
.modal__body { padding: 18px 20px; overflow: auto; }

/* Spinner en botones ocupados */
.btn:disabled { opacity: .7; cursor: progress; }

/* ============================================================
   Login
   ============================================================ */
.login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(1000px 500px at 80% -10%, rgba(79,140,255,.18), transparent 60%),
        radial-gradient(800px 500px at -10% 110%, rgba(122,92,255,.16), transparent 55%),
        var(--bg);
}
.login__card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 36px 32px;
    box-shadow: var(--shadow);
}
.login__brand {
    display: flex; align-items: center; gap: 12px;
    justify-content: center; margin-bottom: 6px;
}
.login__brand .brand__mark { width: 40px; height: 40px; flex-basis: 40px; font-size: 15px; }
.login__title { text-align: center; font-size: 21px; font-weight: 700; margin: 14px 0 4px; }
.login__sub { text-align: center; color: var(--text-dim); font-size: 14px; margin: 0 0 26px; }
.login .form { max-width: none; }
.login .btn { width: 100%; justify-content: center; }
.login__foot { text-align: center; margin-top: 20px; font-size: 12.5px; color: var(--text-faint); }

/* ============================================================
   Responsive
   ============================================================ */
.scrim { display: none; }

@media (max-width: 860px) {
    .content { margin-left: 0; }
    .topbar__toggle { display: flex; }

    .sidebar { transform: translateX(-100%); width: var(--sidebar-w); }
    .sidebar:hover, .sidebar:focus-within { width: var(--sidebar-w); box-shadow: none; }
    .brand__text, .nav__label, .userbox__meta, .pin { opacity: 1; }
    .pin { display: none; }

    .app.nav-open .sidebar { transform: translateX(0); box-shadow: var(--shadow); }
    .app.nav-open .scrim {
        display: block; position: fixed; inset: 0;
        background: rgba(0,0,0,.5); z-index: 40;
    }
    .field--row { grid-template-columns: 1fr; }
}

/* ============================================================
   Módulo de logs (visor de syslog)
   ============================================================ */
.tag {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 9px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    vertical-align: middle;
}

/* Selector de fuentes */
.src-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}
.src {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: border-color .15s, background .15s;
}
.src:hover { border-color: var(--primary); background: var(--surface-2); }
.src--active { border-color: var(--primary); background: var(--primary-soft); }
.src__name { font-weight: 650; color: var(--text); font-size: 14px; }
.src__ip   { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; color: var(--text-dim); }
.src__meta { font-size: 12px; color: var(--text-faint); }

/* Barra de filtros */
.log-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin: 0 0 14px;
}
.log-filters .input {
    padding: 9px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    transition: border-color .15s, box-shadow .15s;
}
.log-filters .input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.log-filters input[type="search"] { flex: 1 1 260px; min-width: 200px; }

/* Tabla de logs */
.logtable td { vertical-align: top; }
.logtable .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
    color: var(--text-dim);
    white-space: nowrap;
}
.logtable .logmsg {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
}

/* Badges de severidad */
.badge.sev { font-family: inherit; white-space: nowrap; }
.sev--crit { background: rgba(239,77,90,.18);  color: #ffb3ba; border-color: rgba(239,77,90,.5); }
.sev--err  { background: rgba(239,77,90,.12);  color: #ffb3ba; border-color: rgba(239,77,90,.35); }
.sev--warn { background: rgba(242,178,62,.15);  color: #f6cd7e; border-color: rgba(242,178,62,.45); }
.sev--note { background: rgba(79,140,255,.14);  color: #a9c6ff; border-color: rgba(79,140,255,.4); }
.sev--info { background: var(--surface-2);      color: var(--text-dim); border-color: var(--border); }
.sev--dbg  { background: var(--surface-2);      color: var(--text-faint); border-color: var(--border); }
.sev--unk  { background: var(--surface-2);      color: var(--text-faint); border-color: var(--border); }

/* ============================================================
   Nodo IA — alertas
   ============================================================ */
.nav__badge {
    margin-left: auto;
    min-width: 18px; height: 18px;
    padding: 0 5px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; line-height: 1;
    color: #fff; background: var(--danger);
    border-radius: 999px;
}

/* Tarjetas de resumen */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.stat {
    display: flex; flex-direction: column; gap: 4px;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    transition: border-color .15s, transform .1s;
}
.stat:hover { border-color: var(--primary); }
.stat--active { border-color: var(--primary); background: var(--primary-soft); }
.stat__num { font-size: 26px; font-weight: 700; color: var(--text); }
.stat__lbl { font-size: 13px; color: var(--text-dim); }
.stat--crit .stat__num { color: #ffb3ba; }
.stat--warn .stat__num { color: #f6cd7e; }

/* Lista de alertas */
.alert-list { display: flex; flex-direction: column; gap: 14px; }
.alertc {
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    padding: 14px 16px;
}
.alertc--crit { border-left-color: var(--danger); }
.alertc--warn { border-left-color: var(--warning); }
.alertc--info { border-left-color: var(--primary); }
.alertc--done { opacity: .6; }
.alertc__head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.alertc__title { margin: 0; font-size: 15px; font-weight: 650; color: var(--text); flex: 1; }
.alertc__state {
    font-size: 11.5px; font-weight: 600; padding: 2px 9px;
    border-radius: 999px; border: 1px solid var(--border); color: var(--text-dim);
}
.state--new { color: #a9c6ff; border-color: rgba(79,140,255,.4); background: var(--primary-soft); }
.state--resolved { color: #8ff0bd; border-color: rgba(47,191,113,.4); background: rgba(47,191,113,.12); }
.alertc__meta {
    display: flex; flex-wrap: wrap; gap: 14px;
    margin: 8px 0 10px; font-size: 12.5px; color: var(--text-faint);
}
.alertc__meta .mono { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--text-dim); }
.alertc__section { margin: 0 0 10px; font-size: 13.5px; line-height: 1.6; color: var(--text); }
.alertc__section strong { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.alertc__evidence { margin-top: 6px; }
.alertc__evidence summary { cursor: pointer; font-size: 12.5px; color: var(--text-dim); }
.alertc__evidence .console { max-height: 200px; }
.alertc__actions { display: flex; gap: 8px; margin-top: 12px; }
