:root {
    --bg: #f4f6f9;
    --card: #ffffff;
    --ink: #1c2330;
    --muted: #616c7c;
    --border: #e3e8ef;
    --accent: #067d5f;
    --accent-dark: #0a6e54;
    --danger: #d13438;
    --warn: #b45309;
    --ok: #1d8a4e;
}

* { box-sizing: border-box; }

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

a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Accesibilidad: foco visible y saltar al contenido ---------- */
a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible,
.btn:focus-visible, .pc-card:focus-visible {
    outline: 3px solid #101526;
    outline-offset: 2px;
    border-radius: 4px;
}
.topbar a:focus-visible, .topbar button:focus-visible {
    outline-color: #7cf2c8;
}
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: #fff;
    color: #0a6e54;
    padding: 8px 14px;
    border-radius: 0 0 8px 0;
    z-index: 100;
    font-weight: 600;
}
.skip-link:focus {
    left: 0;
    top: 0;
}
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
main { scroll-margin-top: 84px; }

/* ---------- Topbar ---------- */
.topbar {
    background: #101526;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 12px 20px;
}
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.brand-logo { height: 30px; width: auto; border-radius: 6px; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
    color: #cbd5e1;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: .95rem;
}
.topbar nav a:hover { color: #fff; text-decoration: none; background: rgba(255,255,255,.08); }
.topbar nav a.active { color: #fff; background: var(--accent); }
.badge {
    display: inline-block;
    min-width: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--danger);
    color: #fff;
    font-size: .75rem;
    text-align: center;
}
.logout-form { margin: 0; }

/* ---------- Layout ---------- */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px 80px;
}
.page-title { margin: 0 0 18px; font-size: 1.5rem; }
.back-link { display: inline-block; margin-bottom: 12px; font-size: .9rem; }
.muted { color: var(--muted); }

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 18px;
    box-shadow: 0 1px 3px rgba(16,21,38,.06);
}
.card-title { margin: 0 0 12px; font-size: 1.05rem; }

/* ---------- Stats ---------- */
.stats-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.stat {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
    flex: 1;
    min-width: 140px;
    font-size: .95rem;
}
.stat-on { border-left: 4px solid var(--ok); }
.stat-off { border-left: 4px solid var(--danger); }
.stat-warn { border-left: 4px solid var(--warn); }

/* ---------- Dashboard grid ---------- */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}
.pc-card {
    display: block;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    color: var(--ink);
    box-shadow: 0 1px 3px rgba(16,21,38,.06);
    transition: transform .12s ease, box-shadow .12s ease;
}
.pc-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(16,21,38,.12); text-decoration: none; }
.pc-card.online { border-top: 4px solid var(--ok); }
.pc-card.offline { border-top: 4px solid var(--danger); }
.pc-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.pc-host { font-weight: 700; font-size: 1.05rem; word-break: break-all; }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-on { background: var(--ok); box-shadow: 0 0 0 3px rgba(29,138,78,.25); }
.dot-off { background: var(--danger); box-shadow: 0 0 0 3px rgba(229,72,77,.2); }
.dot-lg { width: 16px; height: 16px; border-radius: 50%; display: inline-block; }

/* ---------- Meters ---------- */
.meter { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: .85rem; }
.meter-label { width: 40px; color: var(--muted); }
.meter-bar { flex: 1; background: #eef1f5; border-radius: 6px; height: 10px; overflow: hidden; }
.bar { display: block; height: 100%; border-radius: 6px; }
.bar.cpu { background: var(--accent); }
.bar.ram { background: #7c6cf0; }
.meter-val { width: 46px; text-align: right; font-variant-numeric: tabular-nums; }
.pc-meta { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; color: var(--muted); font-size: .82rem; }

/* ---------- PC page ---------- */
.pc-head { display: flex; justify-content: space-between; align-items: center; }
.pc-head-left { display: flex; align-items: center; gap: 12px; }
.pc-head-left h1 { margin: 0; font-size: 1.4rem; }
.pc-head-right { color: var(--muted); font-size: .9rem; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.info-grid > div { display: flex; flex-direction: column; }
.lbl { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }

.pc-admin { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.inline-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-form label { font-size: .82rem; color: var(--muted); }
.mt { margin-top: 14px; }
.mt-8 { margin-top: 8px; }

/* Gráfica histórica CPU/RAM */
.hist-chart { position: relative; }
.hist-svg { width: 100%; height: auto; }
.hist-grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 3; }
.hist-txt { fill: var(--muted); font-size: 12px; }
.hist-line { fill: none; stroke-width: 2; }
.hist-cpu { stroke: #3b82f6; }
.hist-ram { stroke: #ef4444; }
.hist-legend { display: flex; gap: 14px; margin-bottom: 6px; font-size: .8rem; }
.hl { display: inline-flex; align-items: center; gap: 5px; }
.hl::before { content: ''; width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.hl-cpu::before { background: #3b82f6; }
.hl-ram::before { background: #ef4444; }

/* ---------- Lists ---------- */
.alert-list, .event-list { list-style: none; margin: 0; padding: 0; }
.alert-list li, .event-list li {
    display: flex; gap: 10px; align-items: flex-start;
    padding: 10px 0; border-bottom: 1px solid var(--border);
}
.alert-list li:last-child, .event-list li:last-child { border-bottom: none; }
.alert-list div, .event-body { display: flex; flex-direction: column; }
.alert-icon { font-size: 1.1rem; }
.alert-resolved .alert-icon { opacity: .65; }
.event-emoji { font-size: 1.1rem; }

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
    text-align: left; color: var(--muted); font-weight: 600;
    padding: 10px 8px; border-bottom: 2px solid var(--border);
}
.table td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:hover td { background: #f8fafc; }
.msg-cell { max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Tags ---------- */
.tag { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: .78rem; font-weight: 600; }
.tag-ok { background: rgba(29,138,78,.15); color: #0e6b3e; }
.tag-warn { background: rgba(180,83,9,.18); color: #7c4a03; }

/* ---------- Forms ---------- */
label { display: block; margin: 10px 0 4px; font-size: .9rem; font-weight: 600; }
input[type=text], input[type=password], select {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .95rem;
    background: #fff;
    color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 14px; }
textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .95rem;
    background: #fff;
    color: var(--ink);
    resize: vertical;
}
.pc-admin-slim { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.btn {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 12px;
}
.btn:hover { background: var(--accent-dark); }
.btn-small { padding: 7px 12px; margin-top: 0; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-danger { background: var(--danger); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters select { width: auto; }
.filters input[type=text] { flex: 1; min-width: 220px; }
.pagination { display: flex; gap: 16px; align-items: center; margin-top: 16px; justify-content: center; }
.key-box {
    display: block;
    background: #101526;
    color: #7cf2c8;
    padding: 10px 12px;
    border-radius: 8px;
    word-break: break-all;
    font-size: .85rem;
}

/* ---------- Flash ---------- */
.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: .9rem;
}
.flash-ok { background: rgba(29,138,78,.15); color: #0e6b3e; }
.flash-error { background: rgba(229,72,77,.12); color: #b3262b; }
.flash-key { background: #101526; color: #7cf2c8; font-family: monospace; }

/* ---------- Login ---------- */
.login-body { background: linear-gradient(135deg, #101526 0%, #12313a 100%); min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; }
.login-wrap { width: 100%; max-width: 380px; }
.login-card { padding: 28px; }
.login-title { margin: 0; text-align: center; font-size: 1.6rem; }
.login-logo { display: block; max-width: 220px; margin: 0 auto 12px; border-radius: 14px; }
.login-sub { text-align: center; color: var(--muted); margin: 6px 0 18px; }
.login-card label { margin-top: 0; }

/* ---------- Footer ---------- */
.footer {
    margin-top: 2.5rem;
    padding: 1.4rem 1rem 1rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    width: 100%;
    text-align: center;
    color: var(--muted);
    font-size: .8rem;
}
.footer-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    justify-content: center;
    color: var(--muted);
}
.footer-logo {
    height: 48px;
    width: auto;
}
.footer-inner a { color: var(--accent-dark); }
.footer-licenses {
    display: flex;
    gap: 0.85rem;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 0.4rem;
}
.footer-licenses img {
    border-radius: 6px;
    background: rgba(255,255,255,0.04);
    padding: 2px;
}
.footer .scWidget { opacity: 0.85; filter: invert(0.88) hue-rotate(180deg) brightness(0.92); }
.login-body .footer { color: rgba(255,255,255,.55); }

@media (max-width: 640px) {
    .topbar-inner { flex-wrap: wrap; }
    .topbar nav { order: 3; width: 100%; }
    .topbar nav a { padding: 10px 12px; min-height: 44px; display: inline-flex; align-items: center; }
    .btn-small { padding: 9px 12px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
    .day-nav a { min-height: 44px; }
    .msg-cell { white-space: normal; max-width: none; }
}

/* ---------- Grid de encendido (dashboard) ---------- */
.day-nav { display: flex; gap: 12px; align-items: center; justify-content: center; margin-bottom: 14px; }
.day-title { font-size: 1.05rem; }
.grid-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.usage-grid { border-collapse: separate; border-spacing: 1px; }
.usage-grid th, .usage-grid td { padding: 2px; }
.grid-pc-col {
    position: sticky; left: 0;
    background: var(--card);
    font-size: .82rem;
    white-space: nowrap;
    padding-right: 10px !important;
    z-index: 1;
}
.grid-hour {
    font-size: .75rem;
    color: var(--muted);
    font-weight: 600;
    text-align: center;
    border-bottom: 2px solid var(--border);
}
.grid-cell {
    width: 14px; height: 18px;
    border-radius: 2px;
    background: #eef1f5;
}
.grid-cell.on { background: var(--accent); }
.grid-cell.now { box-shadow: inset 0 0 0 2px var(--accent-dark); }
.note { font-size: .78rem; margin-top: 10px; }

/* ---------- Comandos en vivo (ficha PC) ---------- */
.cmd-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.cmd-actions .btn { margin-top: 4px; }
.cmd-panel {
    margin-top: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    background: #f8fafc;
}
.cmd-status-line { display: flex; justify-content: space-between; gap: 10px; font-weight: 600; margin-bottom: 8px; }
.cmd-content { font-size: .9rem; }
.metric-big { display: inline-block; margin-right: 14px; font-size: .95rem; }

/* ---------- API key generada ---------- */
.key-new { border: 1px solid var(--accent); }
.key-big { font-size: 1rem; margin-top: 8px; }