/* ========================================================
   ESTILOS DE CONTROL PANEL (SOBRIO / RESPONSIVE)
   ======================================================== */

:root {
    --bg-app: #0d1117;
    --bg-panel: #161b22;
    --bg-panel-hover: #1c2128;
    --bg-input: #0b0e14;
    --bg-subtle: #21262d;

    --border: #30363d;
    --border-hover: #484f58;
    --border-focus: #58a6ff;

    --text: #e6edf3;
    --text-muted: #8b949e;
    --text-dim: #6e7681;

    --green: #3fb950;
    --green-bg: rgba(46, 160, 67, 0.15);
    --green-border: rgba(46, 160, 67, 0.4);

    --amber: #d29922;
    --amber-bg: rgba(187, 128, 9, 0.15);
    --amber-border: rgba(187, 128, 9, 0.4);

    --red: #f85149;
    --red-bg: rgba(248, 81, 73, 0.15);
    --red-border: rgba(248, 81, 73, 0.4);

    --blue: #2f81f7;
    --blue-hover: #388bfd;

    --radius: 8px;
    --radius-sm: 6px;
    --radius-lg: 12px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    min-height: 100%;
}

body {
    background-color: var(--bg-app);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

.mono {
    font-family: 'JetBrains Mono', monospace;
}

/* ========================================================
   LOGIN GATE (RESPONSIVE)
   ======================================================== */
.login-gate {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 1.25rem;
    padding-top: max(1.25rem, env(safe-area-inset-top));
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
}

.login-box {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 320px;
    padding: 1.75rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.login-box.shake {
    animation: shake 0.35s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

.login-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--radius);
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    margin-bottom: 0.85rem;
}

.login-box h1 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text);
}

.login-box form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.input-wrap {
    position: relative;
    width: 100%;
}

.input-password {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 2.5rem 0.75rem 0.85rem;
    color: var(--text);
    /* 16px previene el zoom forzado de iOS Safari al tocar el input */
    font-size: 16px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.15s;
}

.input-password:focus {
    border-color: var(--border-focus);
}

.btn-eye {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 0.25rem;
}

.btn-eye:hover {
    color: var(--text);
}

.remember-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.remember-label input {
    accent-color: var(--blue);
    width: 16px;
    height: 16px;
}

.error-msg {
    background: var(--red-bg);
    border: 1px solid var(--red-border);
    color: #ff7b72;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 12px;
    text-align: center;
}

.btn-submit {
    background: #238636;
    border: 1px solid rgba(240, 246, 252, 0.1);
    border-radius: var(--radius);
    color: #fff;
    padding: 0.75rem;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
    transition: background-color 0.15s;
}

.btn-submit:hover {
    background: #2ea043;
}

/* ========================================================
   DASHBOARD LAYOUT (RESPONSIVE)
   ======================================================== */
.app {
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    padding: 1.25rem 1rem 3rem 1rem;
    padding-top: max(1.25rem, env(safe-area-inset-top));
    padding-bottom: max(3rem, env(safe-area-inset-bottom));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* HEADER */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 0.75rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.pc-name-group {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.pc-name {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text);
    word-break: break-word;
}

.status-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.2rem 0.65rem;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    color: var(--text-muted);
    white-space: nowrap;
}

.status-tag.tag-online {
    background: var(--green-bg);
    border-color: var(--green-border);
    color: var(--green);
}

.status-tag.tag-booting {
    background: var(--amber-bg);
    border-color: var(--amber-border);
    color: var(--amber);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-dim);
    flex-shrink: 0;
}

.tag-online .status-dot {
    background: var(--green);
}

.tag-booting .status-dot {
    background: var(--amber);
    animation: blink 1s infinite alternate;
}

@keyframes blink {
    from { opacity: 0.4; }
    to { opacity: 1; }
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.cluster-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.device-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.55rem;
    border-radius: var(--radius-sm);
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-panel);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-dim);
    flex-shrink: 0;
}

.dot-on {
    background: var(--green);
}

.btn-logout {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    min-height: 32px;
}

.btn-logout:hover {
    color: var(--red);
    border-color: var(--red-border);
}

/* PANELS */
.content {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    width: 100%;
}

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    width: 100%;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.panel-header h2 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.state-label, .count-label {
    font-size: 11px;
    color: var(--text-dim);
}

.state-label.online {
    color: var(--green);
}

/* POWER CONTROL PANEL */
.power-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1.25rem 0;
    gap: 0.85rem;
    width: 100%;
}

.btn-power {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    background: #238636;
    border: 1px solid rgba(240, 246, 252, 0.1);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    padding: 0.85rem 2.25rem;
    border-radius: var(--radius);
    cursor: pointer;
    min-height: 48px;
    transition: background-color 0.15s, transform 0.05s;
    user-select: none;
}

.btn-power:hover:not(:disabled) {
    background: #2ea043;
}

.btn-power:active:not(:disabled) {
    transform: scale(0.98);
}

.btn-power:disabled {
    background: var(--bg-subtle);
    border-color: var(--border);
    color: var(--text-dim);
    cursor: not-allowed;
}

.power-info {
    display: flex;
    gap: 0.75rem 1.25rem;
    font-size: 12px;
    color: var(--text-muted);
    flex-wrap: wrap;
    justify-content: center;
}

.pc-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.35rem;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    max-width: 400px;
}

.btn-action {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.55rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    min-height: 36px;
    flex: 1 1 auto;
    text-align: center;
    transition: background-color 0.15s;
}

.btn-action:hover {
    background: var(--bg-panel-hover);
    border-color: var(--border-hover);
}

.btn-action.btn-danger {
    color: #ff7b72;
}

.btn-action.btn-danger:hover {
    background: var(--red-bg);
    border-color: var(--red-border);
}

/* STATS GRID */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    width: 100%;
}

.stat-card {
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0;
}

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
}

.stat-value {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-bar {
    width: 100%;
    height: 4px;
    background: var(--bg-subtle);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 0.2rem;
}

.stat-bar-fill {
    height: 100%;
    background: var(--blue);
    border-radius: 2px;
    transition: width 0.3s;
}

.stat-detail {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 0.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* LOGS */
.log-list {
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 180px;
    overflow-y: auto;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}

.log-item {
    display: flex;
    gap: 0.65rem;
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    word-break: break-word;
}

.log-time {
    color: var(--text-dim);
    flex-shrink: 0;
}

.log-msg {
    color: var(--text);
    flex: 1;
}

.log-empty {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-dim);
    font-style: italic;
}

/* SHORTCUTS */
.shortcut-rows {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.shortcut-item {
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.shortcut-desc {
    flex: 1;
    min-width: 0;
}

.shortcut-desc strong {
    font-size: 13px;
    color: var(--text);
    display: block;
}

.shortcut-desc p {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 0.15rem;
    line-height: 1.4;
}

.btn-copy {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem 0.95rem;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    min-height: 36px;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.btn-copy:hover {
    background: var(--bg-panel-hover);
    border-color: var(--border-hover);
}

.btn-copy.copied {
    color: var(--green);
    border-color: var(--green-border);
    background: var(--green-bg);
}

/* TOAST (RESPONSIVE) */
.toast-wrap {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 1000;
    max-width: 380px;
    pointer-events: none;
}

.toast {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.65rem 1rem;
    font-size: 13px;
    color: var(--text);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
}

.toast.toast-success {
    border-left: 3px solid var(--green);
}

.toast.toast-error {
    border-left: 3px solid var(--red);
}

.toast.toast-warn {
    border-left: 3px solid var(--amber);
}

/* ========================================================
   MEDIA QUERIES (TABLET Y MÓVIL)
   ======================================================== */

/* Tablets / Pantallas Medianas */
@media (max-width: 768px) {
    .app {
        padding: 1rem 0.85rem 2.5rem 0.85rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .shortcut-item {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .btn-copy {
        width: 100%;
        text-align: center;
    }
}

/* Móviles / Teléfonos */
@media (max-width: 480px) {
    .header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .header-left {
        justify-content: space-between;
        width: 100%;
    }

    .header-right {
        justify-content: space-between;
        width: 100%;
    }

    .btn-power {
        width: 100%;
        padding: 0.85rem 1.5rem;
    }

    .pc-actions {
        width: 100%;
        gap: 0.4rem;
    }

    .btn-action {
        font-size: 12px;
        padding: 0.5rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .stat-card {
        padding: 0.75rem;
    }

    .stat-value {
        font-size: 1.05rem;
    }

    .panel {
        padding: 1rem;
        border-radius: var(--radius);
    }

    .toast-wrap {
        left: 0.85rem;
        right: 0.85rem;
        bottom: max(1rem, env(safe-area-inset-bottom));
        max-width: none;
    }

    .toast {
        text-align: center;
    }
}

/* Móviles muy compactos (<= 360px) */
@media (max-width: 360px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .pc-actions {
        flex-direction: column;
    }

    .btn-action {
        width: 100%;
    }
}
