:root {
    color-scheme: light;
    --desktop: #d9dcdf;
    --window: #f0f0f0;
    --surface: #ffffff;
    --surface-2: #f7f7f7;
    --border: #9da6af;
    --border-dark: #66727d;
    --border-soft: #c8cdd2;
    --title-1: #2f74b5;
    --title-2: #1d5f9e;
    --title-dark: #174f83;
    --selection: #d9ecff;
    --selection-border: #4b96d1;
    --text: #1c1c1c;
    --muted: #5d6872;
    --success: #18854b;
    --warning: #a96500;
    --danger: #b42318;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--desktop); }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        linear-gradient(rgba(255,255,255,.22), rgba(255,255,255,0) 180px),
        var(--desktop);
    font-size: 14px;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
.muted { color: var(--muted); }
.eyebrow {
    margin: 0 0 4px;
    color: #245f94;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}

input, select, textarea {
    width: 100%;
    min-height: 30px;
    border: 1px solid #7f8b96;
    border-radius: 0;
    outline: none;
    color: var(--text);
    background: #fff;
    padding: 5px 7px;
    box-shadow: inset 1px 1px 2px rgba(0,0,0,.08);
}
textarea { min-height: 68px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    border-color: #2b78b9;
    box-shadow: 0 0 0 1px #82b8e6, inset 1px 1px 2px rgba(0,0,0,.08);
}
input[readonly] { color: #4d565e; background: #e9e9e9; }
label {
    display: grid;
    gap: 4px;
    color: #303840;
    font-size: 12px;
    font-weight: 600;
}
button, .button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 31px;
    border: 1px solid #667581;
    border-radius: 2px;
    color: #111;
    background: linear-gradient(#fff, #e2e6e9);
    padding: 5px 14px;
    font-weight: 600;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.7);
    cursor: pointer;
}
button:hover, .button-link:hover {
    border-color: #2b6da3;
    background: linear-gradient(#fdfefe, #cfe8fb);
}
button:active, .button-link:active {
    background: linear-gradient(#c6dff2, #edf6fc);
    box-shadow: inset 1px 1px 2px rgba(0,0,0,.15);
}
.button-link.secondary { color: #111; background: linear-gradient(#fff, #e2e6e9); }
.button-link.compact { min-height: 27px; padding: 3px 10px; font-size: 11px; }

.brand-mark {
    display: grid;
    place-items: center;
    width: 62px;
    height: 62px;
    border: 1px solid #124a79;
    border-radius: 4px;
    color: #fff;
    background: linear-gradient(135deg, #5aa2df, #23699f);
    font-size: 23px;
    font-weight: 700;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.3), 1px 2px 4px rgba(0,0,0,.2);
}
.brand-mark.small {
    width: 36px;
    height: 36px;
    border-radius: 3px;
    font-size: 14px;
}
.login-logo-plate {
    width: min(100%, 285px);
    border: 1px solid rgba(255,255,255,.55);
    border-radius: 4px;
    background: rgba(255,255,255,.97);
    padding: 12px 14px;
    box-shadow: 0 5px 16px rgba(11,43,70,.18);
}
.login-brand-logo {
    display: block;
    width: 100%;
    height: auto;
}
.topbar-logo {
    display: block;
    width: auto;
    height: 38px;
}
.pulse-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    border: 1px solid #0d6235;
    border-radius: 50%;
    background: #27a35f;
}

/* Login: ventana de escritorio */
.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
}
.login-shell {
    display: grid;
    grid-template-columns: 330px minmax(360px, 1fr);
    width: min(820px, 100%);
    min-height: 470px;
    overflow: hidden;
    border: 1px solid #53606a;
    border-radius: 5px;
    background: var(--window);
    box-shadow: 0 16px 42px rgba(25,35,45,.28), inset 0 0 0 1px #fff;
}
.brand-panel {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-right: 1px solid #355c7c;
    color: #fff;
    background:
        linear-gradient(155deg, rgba(255,255,255,.18), transparent 48%),
        linear-gradient(180deg, #3d82bd, #1f5c91);
    padding: 38px;
}
.brand-panel .eyebrow { color: #dceeff; }
.brand-panel h1 {
    margin: 14px 0 8px;
    font-size: 48px;
    line-height: 1;
    font-weight: 300;
    letter-spacing: -.04em;
}
.brand-copy { max-width: 260px; color: #edf7ff; line-height: 1.5; }
.system-note {
    border: 1px solid rgba(255,255,255,.35);
    background: rgba(0,0,0,.1);
    padding: 8px 10px;
    font-size: 12px;
}
.login-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 22px;
    padding: 48px 58px;
}
.login-card h2 { margin: 0; font-size: 24px; font-weight: 400; }
.login-card p { margin: 5px 0 0; }
.login-card form { display: grid; gap: 15px; }
.login-card form button {
    justify-self: start;
    min-width: 110px;
    border-color: #245e8d;
    color: #fff;
    background: linear-gradient(#4b91c9, #286da5);
}

.alert, .flash {
    border: 1px solid;
    border-radius: 2px;
    padding: 9px 11px;
    font-size: 12px;
}
.alert { border-color: #c45b55; color: #7b1913; background: #fde9e7; }
.flash { margin-bottom: 12px; border-color: #54a77b; color: #155d35; background: #e5f5ec; }
.flash.warning { border-color: #cf9a3c; color: #714700; background: #fff4d9; }
.flash.error { border-color: #c45b55; color: #7b1913; background: #fde9e7; }

/* Barra principal tipo formulario MDI */
.topbar {
    position: sticky;
    z-index: 10;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 54px;
    padding: 7px max(18px, calc((100vw - 1480px) / 2));
    border-bottom: 1px solid #123f65;
    color: #fff;
    background: linear-gradient(#377db8, #205f96);
    box-shadow: inset 0 1px rgba(255,255,255,.28), 0 2px 5px rgba(0,0,0,.16);
}
.brand-link, .user-menu { display: flex; align-items: center; gap: 10px; }
.brand-link {
    border: 1px solid rgba(255,255,255,.62);
    border-radius: 3px;
    background: rgba(255,255,255,.97);
    padding: 1px 7px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.6);
}
.brand-link:hover { background: #fff; }
.brand-link strong, .user-menu strong { display: block; }
.brand-link small, .user-menu small { display: block; margin-top: 1px; color: #dcefff; font-size: 10px; }
.user-menu { gap: 14px; text-align: right; font-size: 12px; }
.logout {
    border: 1px solid rgba(255,255,255,.5);
    border-radius: 2px;
    color: #fff;
    background: rgba(0,0,0,.08);
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 600;
}
.logout:hover { background: rgba(255,255,255,.15); }
.topbar-button {
    min-height: 29px;
    border: 1px solid rgba(255,255,255,.55);
    border-radius: 2px;
    color: #fff;
    background: rgba(0,0,0,.09);
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 600;
}
.topbar-button:hover { background: rgba(255,255,255,.16); }
button.topbar-button { box-shadow: none; }

.app-shell { width: min(1480px, calc(100% - 36px)); margin: 0 auto; padding: 22px 0 40px; }
.page-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    border: 1px solid var(--border);
    border-bottom-color: var(--border-dark);
    background: linear-gradient(#fff, #e8eaec);
    padding: 14px 16px;
    box-shadow: inset 0 0 0 1px #fff;
}
.page-heading h1 { margin: 0; font-size: 23px; font-weight: 400; }
.page-heading p:last-child { margin: 5px 0 0; }
.refresh-note { color: var(--muted); font-size: 11px; }

.metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 10px 0;
}
.metrics article {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 72px;
    border: 1px solid var(--border);
    background: linear-gradient(#fff, #eceeef);
    padding: 12px 15px;
    box-shadow: inset 0 0 0 1px #fff;
}
.metrics span { color: #40505c; font-size: 12px; font-weight: 600; }
.metrics strong { color: #1e5f94; font-size: 27px; font-weight: 400; }
.metrics .metric-online { border-color: #78a88d; background: linear-gradient(#f7fff9, #e2f1e7); }
.metrics .metric-online strong { color: var(--success); }

.workspace {
    display: grid;
    grid-template-columns: minmax(320px, .72fr) minmax(0, 1.65fr);
    min-height: 620px;
    overflow: hidden;
    border: 1px solid var(--border-dark);
    background: var(--window);
    box-shadow: inset 0 0 0 1px #fff;
}
.client-panel { min-width: 0; border-right: 1px solid var(--border); background: #eceff1; }
.panel-title, .client-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(#fff, #e4e7e9);
    padding: 12px 14px;
}
.panel-title h2, .client-header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.panel-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.count-pill {
    flex: 0 0 auto;
    border: 1px solid #8996a0;
    border-radius: 2px;
    color: #394650;
    background: #f7f7f7;
    padding: 3px 7px;
    font-size: 10px;
    font-weight: 600;
}
.search-form { display: flex; gap: 5px; padding: 9px; }
.search-form input { min-width: 0; }
.search-form button { min-height: 30px; padding: 4px 10px; font-size: 11px; }
.client-list { max-height: 680px; overflow: auto; border-top: 1px solid var(--border); background: #fff; }
.client-row {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    min-height: 54px;
    border-bottom: 1px solid #d7dadd;
    padding: 7px 10px;
}
.client-row:hover { background: #edf6fd; }
.client-row.selected {
    border-color: #93bce0;
    background: var(--selection);
    box-shadow: inset 3px 0 var(--selection-border);
}
.client-avatar {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: 1px solid #7d9bb4;
    border-radius: 2px;
    color: #fff;
    background: linear-gradient(#68a3d3, #347cb6);
    font-size: 11px;
    font-weight: 700;
}
.client-main { min-width: 0; }
.client-main strong, .client-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client-main strong { font-size: 12px; }
.client-main small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.account { color: #4d5d68; font-family: Consolas, monospace; font-size: 10px; }

.detail-panel { min-width: 0; padding: 0 14px 18px; background: #f7f7f7; }
.client-header { margin: 0 -14px; }
.client-header .muted { margin: 4px 0 0; font-size: 11px; }
.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 16px 0 7px;
}
.section-heading h3 { margin: 0; font-size: 13px; font-weight: 600; }
.section-heading span { color: var(--muted); font-size: 10px; }
.device-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.device-card {
    min-width: 0;
    border: 1px solid var(--border);
    background: linear-gradient(#fff, #eceeef);
    padding: 10px;
    box-shadow: inset 0 0 0 1px #fff;
}
.device-card-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.status { display: inline-flex; align-items: center; gap: 5px; font-size: 10px; font-weight: 600; }
.status i { width: 7px; height: 7px; border: 1px solid currentColor; border-radius: 50%; background: currentColor; }
.status.online { color: var(--success); }
.status.delayed { color: var(--warning); }
.status.offline { color: #6f7880; }
.device-type { color: var(--muted); font-size: 10px; }
.device-card h4 { overflow: hidden; margin: 12px 0 5px; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.device-card code { display: block; overflow: hidden; color: #455864; font: 10px Consolas, monospace; text-overflow: ellipsis; }
.device-card p { margin: 8px 0 0; color: var(--muted); font-size: 10px; }
.events-heading { margin-top: 18px; }
.event-list { overflow: hidden; border: 1px solid var(--border); background: #fff; }
.event-row {
    display: grid;
    grid-template-columns: 8px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    min-height: 43px;
    border-bottom: 1px solid #dadde0;
    padding: 6px 9px;
}
.event-row:nth-child(even) { background: #f5f7f8; }
.event-row:last-child { border-bottom: 0; }
.event-mark { width: 7px; height: 7px; border-radius: 50%; }
.event-mark.event-new { background: #c7362d; }
.event-mark.event-restore { background: #268f57; }
.event-row strong, .event-row small { display: block; }
.event-row strong { font: 11px Consolas, monospace; }
.event-row small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.event-row time { color: var(--muted); font-size: 10px; }
.empty, .empty-state { color: var(--muted); }
.empty { padding: 16px; text-align: center; font-size: 11px; }
.empty-state { display: grid; place-items: center; align-content: center; min-height: 520px; text-align: center; }
.empty-state h2 { margin: 12px 0 4px; color: var(--text); font-size: 18px; font-weight: 400; }
.empty-state p { margin: 0; }
.empty-icon {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    border: 1px solid #6f96b6;
    color: #fff;
    background: linear-gradient(#68a3d3, #347cb6);
    font-size: 17px;
    font-weight: 700;
}

/* Administración: GroupBox y grillas */
.admin-shell { width: min(1240px, calc(100% - 36px)); }
.admin-heading { margin-bottom: 10px; }
.admin-card {
    overflow: hidden;
    margin-bottom: 12px;
    border: 1px solid var(--border-dark);
    background: var(--window);
    box-shadow: inset 0 0 0 1px #fff;
}
.admin-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(#fff, #e3e6e8);
    padding: 11px 14px;
}
.admin-card-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.admin-alert { margin-bottom: 10px; }
.admin-form { padding: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 12px; }
.form-wide { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: center; gap: 7px; margin-top: 14px; }
.form-actions button { min-width: 130px; border-color: #245e8d; color: #fff; background: linear-gradient(#4b91c9, #286da5); }
.danger-zone {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-top: 1px solid #d7a09d;
    background: #f8eae9;
    padding: 10px 14px;
}
.danger-zone strong, .danger-zone small { display: block; }
.danger-zone small { margin-top: 2px; color: #76504d; font-size: 10px; }
.danger-button { border-color: #8f2b25; color: #fff; background: linear-gradient(#d05b52, #a9342c); font-size: 11px; }
.editor-box {
    margin: 10px 14px;
    border: 1px solid var(--border);
    background: #f8f8f8;
}
.editor-box summary, .function-row summary {
    cursor: pointer;
    list-style: none;
    color: #174f83;
    background: linear-gradient(#fff, #e6e9eb);
    padding: 8px 10px;
    font-size: 11px;
    font-weight: 600;
}
.editor-box summary::-webkit-details-marker, .function-row summary::-webkit-details-marker { display: none; }
.inline-form, .function-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: end;
    gap: 9px;
    border-top: 1px solid var(--border);
    padding: 10px;
}
.inline-form button, .function-form button { min-height: 30px; }
.admin-device-list { display: grid; gap: 10px; padding: 0 14px 14px; }
.admin-device {
    overflow: hidden;
    border: 1px solid var(--border);
    background: #fff;
}
.admin-device-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    background: linear-gradient(#fff, #eef0f1);
    padding: 11px 12px;
}
.admin-device-head h3 { margin: 7px 0 3px; font-size: 14px; }
.admin-device-head code { color: #405461; font: 11px Consolas, monospace; }
.compact-editor { margin: 0 10px 10px; }
.mini-danger { display: flex; justify-content: flex-end; border-top: 1px solid var(--border); background: #f6f6f6; padding: 7px 10px; }
.function-section { border-top: 1px solid var(--border); background: #f2f3f4; padding: 0 10px 10px; }
.function-list { display: grid; gap: 6px; }
.function-row { overflow: hidden; border: 1px solid var(--border); background: #fff; }
.function-row summary {
    display: grid;
    grid-template-columns: minmax(170px, .55fr) minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    color: var(--text);
}
.function-row[open] > summary { border-bottom: 1px solid var(--border); background: #ddecf8; }
.function-row summary strong, .function-row summary small { display: block; }
.function-row summary small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.function-row summary code { overflow: hidden; color: #425560; font: 10px Consolas, monospace; text-overflow: ellipsis; white-space: nowrap; }

/* Ejecuciones: consola operativa */
.execution-shell { width: min(1480px, calc(100% - 36px)); }
.execution-warning {
    border: 1px solid #c79232;
    color: #674400;
    background: #fff2ce;
    padding: 7px 10px;
    font-size: 11px;
}
.execution-workspace { grid-template-columns: 360px minmax(0, 1fr); margin-top: 10px; }
.execution-panel { padding-bottom: 18px; }
.execution-device-list { display: grid; gap: 10px; padding-top: 12px; }
.execution-device {
    overflow: hidden;
    border: 1px solid var(--border-dark);
    background: #f7f7f7;
    box-shadow: inset 0 0 0 1px #fff;
}
.execution-device > header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(#fff, #e4e7e9);
    padding: 10px 12px;
}
.execution-device h3 { margin: 6px 0 2px; font-size: 14px; }
.execution-device code { color: #425560; font: 10px Consolas, monospace; }
.command-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    padding: 10px;
}
.execution-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    min-height: 64px;
    border: 1px solid #9ca7b0;
    background: linear-gradient(#fff, #ebedef);
    padding: 9px 10px;
}
.execution-form:hover { border-color: #4f8aba; background: linear-gradient(#fff, #e0f0fc); }
.execution-form.command-sensitive { border-color: #c69246; background: linear-gradient(#fffdf7, #f7ead2); }
.execution-form strong, .execution-form small { display: block; }
.execution-form strong { font-size: 12px; }
.execution-form small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.execution-form button {
    min-width: 88px;
    border-color: #245e8d;
    color: #fff;
    background: linear-gradient(#4b91c9, #286da5);
}
.execution-form.command-sensitive button {
    border-color: #8d5d18;
    background: linear-gradient(#d59a3f, #a86f1e);
}
.execution-form button:disabled { cursor: wait; opacity: .7; }
.execution-link {
    border-color: #307348;
    color: #fff;
    background: linear-gradient(#56a770, #32834e);
}

@media (max-width: 1050px) {
    .device-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .workspace { grid-template-columns: 320px minmax(0, 1fr); }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .execution-workspace { grid-template-columns: 310px minmax(0, 1fr); }
    .command-grid { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
    .login-page { padding: 10px; }
    .login-shell { grid-template-columns: 1fr; }
    .brand-panel { min-height: 245px; border-right: 0; border-bottom: 1px solid #355c7c; padding: 24px; }
    .brand-panel h1 { font-size: 38px; }
    .login-card { padding: 30px 24px; }
    .topbar { padding: 6px 10px; }
    .topbar-logo { height: 34px; }
    .user-menu div { display: none; }
    .app-shell, .admin-shell { width: min(100% - 16px, 1480px); padding-top: 10px; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .metrics { grid-template-columns: 1fr; }
    .metrics article { min-height: 58px; }
    .workspace { display: block; }
    .client-panel { border-right: 0; }
    .client-list { max-height: 340px; }
    .detail-panel { border-top: 1px solid var(--border); }
    .form-grid, .inline-form, .function-form { grid-template-columns: 1fr; }
    .admin-device-head, .danger-zone { align-items: flex-start; flex-direction: column; }
    .function-row summary { grid-template-columns: 1fr; }
    .execution-workspace { display: block; }
}
@media (max-width: 520px) {
    .login-page { padding: 0; }
    .login-shell { min-height: 100vh; border: 0; border-radius: 0; }
    .device-grid { grid-template-columns: 1fr; }
    .client-header { align-items: flex-start; flex-direction: column; }
    .event-row { grid-template-columns: 8px minmax(0, 1fr); }
    .event-row time { grid-column: 2; }
}
