/* ═══════════════════════════════════════════════════════════════
   Panel de administración ServerCentral · estética EC Factory
   Sin dependencias externas. Paleta: fondo #e9eaff, primario #2b7de9.
   ═══════════════════════════════════════════════════════════════ */

:root {
    --bg: #e9eaff;
    --surface: #ffffff;
    --primary: #2b7de9;
    --primary-dark: #2068c6;
    --text: #0f2745;
    --muted: #6b7a90;
    --border: #e1ecff;
    --sidebar-bg: #1a1d23;
    --sidebar-text: #aab2c0;
    --green: #1e9e5a;
    --green-bg: #e3f6ec;
    --amber: #b45309;
    --amber-bg: #fdf0dd;
    --red: #d13438;
    --red-bg: #fdecec;
    --gray: #6b7a90;
    --gray-bg: #eef1f6;
    --purple: #7c3aed;
    --purple-bg: #f1eafd;
    --shadow: 0 2px 10px rgba(15, 39, 69, .07);
    --shadow-lg: 0 10px 40px rgba(15, 39, 69, .18);
    --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
}

h1, h2, h3 { margin: 0; font-weight: 600; }
a { color: var(--primary); text-decoration: none; }
p { margin: 0 0 .6em; }

/* ── Layout general ─────────────────────────────────────────── */

#app { height: 100%; }

.layout {
    display: flex;
    min-height: 100vh;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.content {
    flex: 1;
    padding: 22px;
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
}

/* ── Sidebar ────────────────────────────────────────────────── */

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}

.sidebar-brand .logo {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-brand .brand-name {
    color: #fff;
    font-weight: 600;
    font-size: 15px;
    line-height: 1.15;
}

.sidebar-brand .brand-sub {
    font-size: 11px;
    color: var(--sidebar-text);
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: 9px;
    color: var(--sidebar-text);
    font-weight: 500;
    transition: background .12s, color .12s;
}

.nav-item:hover {
    background: rgba(255, 255, 255, .06);
    color: #fff;
}

.nav-item.active {
    background: rgba(43, 125, 233, .18);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--primary);
}

.nav-item svg { flex-shrink: 0; opacity: .9; }

.sidebar-foot {
    padding: 14px 16px;
    border-top: 1px solid rgba(255, 255, 255, .07);
    font-size: 12px;
    color: #7d8696;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 39, 69, .45);
    z-index: 35;
}

/* ── Topbar ─────────────────────────────────────────────────── */

.topbar {
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar h1 {
    font-size: 17px;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar .hamburger { display: none; }

.user-chip {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--muted);
    font-size: 13px;
}

.user-chip .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-chip .user-name { color: var(--text); font-weight: 600; }
.user-chip .user-role { font-size: 11px; }

/* ── Tarjetas / KPI ─────────────────────────────────────────── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.card-header h2 { font-size: 15px; }
.card-body { padding: 18px; }

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.kpi-icon {
    width: 42px;
    height: 42px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kpi-icon.blue   { background: #e4effd; color: var(--primary); }
.kpi-icon.green  { background: var(--green-bg); color: var(--green); }
.kpi-icon.amber  { background: var(--amber-bg); color: var(--amber); }
.kpi-icon.red    { background: var(--red-bg); color: var(--red); }
.kpi-icon.purple { background: var(--purple-bg); color: var(--purple); }

.kpi-value { font-size: 24px; font-weight: 700; line-height: 1.1; }
.kpi-label { font-size: 12px; color: var(--muted); }

/* ── Toolbar de vista ───────────────────────────────────────── */

.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.toolbar .spacer { flex: 1; }

.search-box {
    position: relative;
}

.search-box input { padding-left: 34px; min-width: 220px; }

.search-box svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

/* ── Tablas ─────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

th {
    text-align: left;
    padding: 11px 14px;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f7faff; }

td.empty {
    text-align: center;
    color: var(--muted);
    padding: 34px 14px;
}

.mono {
    font-family: Consolas, "Cascadia Mono", Menlo, monospace;
    font-size: 12.5px;
}

.cell-sub { font-size: 11.5px; color: var(--muted); }
.nowrap { white-space: nowrap; }

.row-actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}

/* ── Badges y chips ─────────────────────────────────────────── */

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-green  { background: var(--green-bg); color: var(--green); }
.badge-amber  { background: var(--amber-bg); color: var(--amber); }
.badge-red    { background: var(--red-bg); color: var(--red); }
.badge-gray   { background: var(--gray-bg); color: var(--gray); }
.badge-blue   { background: #e4effd; color: var(--primary-dark); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }

.dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: baseline;
}

.dot-green { background: var(--green); }
.dot-gray  { background: #c3ccd9; }

/* Chips de módulos P/C/M/S */
.mod-chips { display: inline-flex; gap: 4px; }

.mod-chip {
    width: 24px;
    height: 24px;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11.5px;
    font-weight: 700;
    cursor: default;
}

.mod-chip.off {
    background: var(--gray-bg);
    color: #b6c0cd;
    text-decoration: line-through;
}

.mod-chip.on.mod-production  { background: #e4effd; color: var(--primary-dark); }
.mod-chip.on.mod-quality     { background: var(--green-bg); color: var(--green); }
.mod-chip.on.mod-maintenance { background: var(--amber-bg); color: var(--amber); }
.mod-chip.on.mod-scada       { background: var(--purple-bg); color: var(--purple); }

/* ── Botones ────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 15px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background .12s, border-color .12s, color .12s;
    white-space: nowrap;
}

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-ghost {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { background: #f2f7ff; border-color: #cfe0f7; }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b62b2f; }

.btn-sm { padding: 5px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }

.btn-icon {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 8px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .12s, color .12s;
}

.btn-icon:hover { background: #eaf2fe; color: var(--primary-dark); }
.btn-icon.danger:hover { background: var(--red-bg); color: var(--red); }

/* Acción no disponible en este estado (p. ej. borrar una versión activa): se deja
   visible y con tooltip explicativo en vez de ocultarla, para que se entienda el porqué. */
.btn-icon:disabled { opacity: .3; cursor: not-allowed; }
.btn-icon:disabled:hover { background: transparent; color: var(--muted); }

/* ── Formularios ────────────────────────────────────────────── */

label.field {
    display: block;
    margin-bottom: 13px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
}

label.field > span { display: block; margin-bottom: 5px; }

input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="date"], input[type="url"],
select, textarea {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid #cdd9ea;
    border-radius: 9px;
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: border-color .12s, box-shadow .12s;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(43, 125, 233, .15);
}

textarea { resize: vertical; min-height: 64px; }

select { cursor: pointer; }

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
}

.check input {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

fieldset.modules {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    margin: 0 0 13px;
}

fieldset.modules legend {
    font-size: 12.5px;
    font-weight: 600;
    padding: 0 5px;
}

fieldset.modules .mod-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 14px;
}

.form-error {
    background: var(--red-bg);
    color: var(--red);
    border-radius: 9px;
    padding: 9px 12px;
    font-size: 13px;
    margin-bottom: 13px;
}

/* ── Modales ────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 39, 69, .5);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 48px 16px;
    overflow-y: auto;
    z-index: 100;
    animation: fadeIn .13s ease;
}

.modal {
    background: var(--surface);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    animation: slideUp .16s ease;
}

.modal.modal-wide { max-width: 760px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 15.5px; }

.modal-body { padding: 20px; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
}

.modal-close {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 7px;
    display: flex;
}

.modal-close:hover { background: var(--gray-bg); color: var(--text); }

/* Clave de licencia generada en grande */
.key-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: #f2f7ff;
    border: 1px dashed #9cc0ee;
    border-radius: 11px;
    padding: 18px 14px;
    margin: 10px 0 16px;
    font-family: Consolas, "Cascadia Mono", Menlo, monospace;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: .5px;
    color: var(--primary-dark);
    word-break: break-all;
    text-align: center;
}

/* ── Paginación ─────────────────────────────────────────────── */

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    font-size: 12.5px;
    color: var(--muted);
}

.pager-btns {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ── Toasts ─────────────────────────────────────────────────── */

#toasts {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    z-index: 200;
    max-width: min(380px, calc(100vw - 40px));
}

.toast {
    background: #1f2733;
    color: #fff;
    padding: 11px 16px;
    border-radius: 10px;
    font-size: 13.5px;
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--green);
    animation: slideUp .18s ease;
}

.toast-error { border-left-color: var(--red); }
.toast-info  { border-left-color: var(--primary); }
.toast.out { opacity: 0; transition: opacity .3s; }

/* ── Login ──────────────────────────────────────────────────── */

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(160deg, #e9eaff 0%, #dbe7fb 55%, #e9eaff 100%);
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    padding: 30px 28px;
}

.login-brand {
    text-align: center;
    margin-bottom: 24px;
}

.login-brand .logo {
    width: 52px;
    height: 52px;
    border-radius: 13px;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 21px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.login-brand h1 { font-size: 19px; }

.login-brand p {
    font-size: 12.5px;
    color: var(--muted);
    margin: 4px 0 0;
}

/* Enlace discreto bajo el login hacia la página pública de descarga */
.login-alt {
    text-align: center;
    margin: 14px 0 0;
    font-size: 12.5px;
}

/* ── Estados de carga ───────────────────────────────────────── */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 48px;
    color: var(--muted);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #cfe0f7;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } }

/* ── Barra de progreso (subida de paquetes de release) ─────────── */

.progress {
    width: 100%;
    height: 10px;
    background: var(--gray-bg);
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar {
    width: 0%;
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
    transition: width .15s ease;
}

/* ── Responsive ─────────────────────────────────────────────── */

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }

    .sidebar.open { transform: translateX(0); }

    .sidebar-backdrop.show { display: block; }

    .topbar .hamburger {
        display: inline-flex;
    }

    .content { padding: 14px; }

    .user-chip .user-meta { display: none; }

    .form-row { grid-template-columns: 1fr; }
    fieldset.modules .mod-grid { grid-template-columns: 1fr; }
}
