/* ═══════════════════════════════════════════
   Controller Panel — Premium Dark Theme
   ═══════════════════════════════════════════ */

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a1f2e;
    --bg-card-hover: #222838;
    --bg-input: #0f1520;
    --border: rgba(99, 102, 241, 0.12);
    --border-hover: rgba(99, 102, 241, 0.3);
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --accent-light: #818cf8;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --radius: 12px;
    --radius-lg: 16px;
    --transition: 0.2s ease;
    --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* ─── Login ─── */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.login-bg {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 30% 20%, rgba(99, 102, 241, .08) 0%, transparent 60%),
        radial-gradient(ellipse at 70% 80%, rgba(139, 92, 246, .06) 0%, transparent 60%);
    animation: bgPulse 8s ease-in-out infinite alternate;
}

@keyframes bgPulse {
    0% {
        opacity: 0.6;
    }

    100% {
        opacity: 1;
    }
}

.login-card {
    position: relative;
    background: linear-gradient(165deg, rgba(26, 31, 46, .95), rgba(17, 24, 39, .98));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    width: 380px;
    text-align: center;
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
    animation: cardIn 0.5s ease;
}

@keyframes cardIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.login-logo {
    margin-bottom: 16px;
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 28px;
}

.login-error {
    color: var(--error);
    font-size: 0.85rem;
    margin-top: 12px;
    min-height: 20px;
}

/* ─── Forms ─── */
.form-group {
    margin-bottom: 16px;
    text-align: left;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}

.form-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font);
    transition: border-color var(--transition);
    outline: none;
}

.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

select.form-input {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

textarea.form-input {
    resize: vertical;
    font-family: monospace;
    font-size: 0.8rem;
}

.form-row {
    display: flex;
    gap: 12px;
}

.flex-grow {
    flex: 1;
}

/* ─── Buttons ─── */
.btn-login,
.btn-primary {
    width: 100%;
    padding: 11px 20px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-login:hover,
.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 18px rgba(99, 102, 241, .35);
}

.btn-secondary {
    padding: 10px 20px;
    background: rgba(148, 163, 184, .1);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    transition: all var(--transition);
}

.btn-secondary:hover {
    background: rgba(148, 163, 184, .2);
    color: var(--text-primary);
}

.btn-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-icon:hover {
    background: rgba(99, 102, 241, .1);
    border-color: var(--border-hover);
    color: var(--accent-light);
}

.btn-icon.danger:hover {
    background: rgba(239, 68, 68, .1);
    color: var(--error);
}

.btn-connect {
    width: 100%;
    padding: 9px 16px;
    background: rgba(99, 102, 241, .08);
    border: 1px solid rgba(99, 102, 241, .15);
    border-radius: 10px;
    color: var(--accent-light);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
}

.btn-connect:hover {
    background: rgba(99, 102, 241, .15);
    border-color: rgba(99, 102, 241, .3);
    transform: translateY(-1px);
}

.btn-back {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all var(--transition);
}

.btn-back:hover {
    background: rgba(99, 102, 241, .1);
    color: var(--accent-light);
}

.btn-logout {
    width: 100%;
    padding: 10px 16px;
    background: transparent;
    border: 1px solid rgba(239, 68, 68, .15);
    border-radius: 10px;
    color: var(--error);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    font-family: var(--font);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all var(--transition);
}

.btn-logout:hover {
    background: rgba(239, 68, 68, .08);
}

/* ─── App Layout ─── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 12px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.logo-text {
    font-size: 1.1rem;
    font-weight: 700;
    background: linear-gradient(135deg, #6366f1, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-nav {
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    transition: all var(--transition);
}

.nav-item:hover {
    background: rgba(99, 102, 241, .08);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(99, 102, 241, .12);
    color: var(--accent-light);
}

.sidebar-footer {
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* ─── Main Content ─── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
}

.page-title {
    font-size: 1.2rem;
    font-weight: 700;
}

.content-area {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
}

/* ─── Server Grid ─── */
.server-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.server-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    transition: all var(--transition);
}

.server-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}

.server-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.server-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: rgba(99, 102, 241, .08);
    color: var(--accent-light);
    transition: all 0.3s;
}

.server-icon.testing {
    animation: pulse 1s ease-in-out infinite;
    color: var(--warning);
}

.server-icon.connected {
    background: rgba(16, 185, 129, .12);
    color: var(--success);
}

.server-icon.error {
    background: rgba(239, 68, 68, .12);
    color: var(--error);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.server-actions {
    display: flex;
    gap: 4px;
}

.server-name {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.server-info {
    display: flex;
    gap: 12px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.server-host::before {
    content: '🌐 ';
}

.server-user::before {
    content: '👤 ';
}

/* ─── Loading / Empty ─── */
.loading-state,
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    grid-column: 1 / -1;
}

.empty-state h3 {
    margin: 16px 0 8px;
    color: var(--text-secondary);
}

.empty-state .btn-primary {
    width: auto;
    margin-top: 16px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ─── Modal ─── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open {
    display: flex;
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-card {
    background: linear-gradient(165deg, var(--bg-card), var(--bg-secondary));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 420px;
    max-height: 85vh;
    overflow-y: auto;
    animation: modalSlide 0.3s ease;
}

@keyframes modalSlide {
    from {
        transform: translateY(10px) scale(0.95);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.modal-card h2 {
    font-size: 1.15rem;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.modal-actions .btn-primary {
    width: auto;
}

/* ─── Terminal Page ─── */
.terminal-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: #000;
}

.terminal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    min-height: 48px;
}

.terminal-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.terminal-header-right {
    display: flex;
    gap: 8px;
}

.terminal-info {
    display: flex;
    flex-direction: column;
}

.terminal-title {
    font-size: 0.9rem;
    font-weight: 600;
}

.terminal-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--warning);
    transition: background 0.3s;
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 6px rgba(16, 185, 129, .4);
}

.status-dot.disconnected {
    background: var(--error);
}

.terminal-container {
    flex: 1;
    padding: 4px;
    overflow: hidden;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .sidebar {
        display: none;
    }

    .server-grid {
        grid-template-columns: 1fr;
    }

    .agents-grid {
        grid-template-columns: 1fr;
    }

    .modal-card {
        width: 95vw;
    }
}

/* ─── Agent Cards ─── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
}

.agent-count {
    background: rgba(99, 102, 241, .1);
    border: 1px solid rgba(99, 102, 241, .2);
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-light);
}

.agents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.agent-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    gap: 16px;
    align-items: flex-start;
    transition: all var(--transition);
}

.agent-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}

.agent-status {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 6px;
}

.agent-status.online {
    background: var(--success);
    box-shadow: 0 0 8px rgba(16, 185, 129, .4);
    animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {

    0%,
    100% {
        box-shadow: 0 0 4px rgba(16, 185, 129, .3);
    }

    50% {
        box-shadow: 0 0 12px rgba(16, 185, 129, .6);
    }
}

.agent-info {
    flex: 1;
    min-width: 0;
}

.agent-info h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agent-details {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.agent-details .detail {
    display: flex;
    align-items: center;
    gap: 4px;
}

.agent-details .detail i {
    font-style: normal;
}

.agent-actions {
    flex-shrink: 0;
}

.agent-actions .btn-primary {
    width: auto;
    padding: 8px 18px;
    font-size: 0.85rem;
    white-space: nowrap;
}

.container {
    padding: 24px;
}

.empty-state {
    flex-direction: column;
    align-items: center;
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

/* ─── Commands Page ─── */
.cmd-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

.section-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
}

.cmd-execute-form {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.result-badge {
    background: var(--accent-glow);
    color: var(--accent-light);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.results-list {
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.result-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    animation: cardIn 0.3s ease;
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.result-agent {
    font-weight: 600;
    font-size: 0.85rem;
}

.result-exit {
    font-size: 0.75rem;
    padding: 2px 10px;
    border-radius: 12px;
    font-weight: 600;
}

.result-exit.success {
    background: rgba(16, 185, 129, .12);
    color: var(--success);
}

.result-exit.error {
    background: rgba(239, 68, 68, .12);
    color: var(--error);
}

.result-output {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    font-size: 0.78rem;
    font-family: monospace;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 200px;
    overflow-y: auto;
    margin: 0;
    direction: ltr;
    text-align: left;
}

/* Periodic Commands */
.periodic-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.periodic-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    transition: all var(--transition);
}

.periodic-card:hover {
    border-color: var(--border-hover);
    background: var(--bg-card-hover);
}

.periodic-info {
    flex: 1;
    min-width: 0;
}

.periodic-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.periodic-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.periodic-status-dot.active {
    background: var(--success);
    box-shadow: 0 0 6px rgba(16, 185, 129, .4);
}

.periodic-status-dot.inactive {
    background: var(--text-muted);
}

.periodic-cmd {
    display: block;
    font-size: 0.78rem;
    color: var(--accent-light);
    background: var(--bg-input);
    padding: 4px 8px;
    border-radius: 6px;
    margin: 4px 0;
    direction: ltr;
    text-align: left;
}

.periodic-meta {
    display: flex;
    gap: 16px;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.periodic-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.btn-action {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all var(--transition);
}

.btn-action:hover {
    background: rgba(99, 102, 241, .1);
    border-color: var(--border-hover);
}

.btn-action.run:hover {
    background: rgba(16, 185, 129, .12);
}

.btn-action.delete:hover {
    background: rgba(239, 68, 68, .1);
}

/* History */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 500px;
    overflow-y: auto;
}

.history-entry {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.history-header {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.history-agent {
    font-weight: 600;
    font-size: 0.85rem;
}

.history-exit {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.history-exit.success {
    background: rgba(16, 185, 129, .12);
    color: var(--success);
}

.history-exit.error {
    background: rgba(239, 68, 68, .12);
    color: var(--error);
}

.history-time {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-left: auto;
}

.history-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.history-badge.periodic {
    background: rgba(99, 102, 241, .12);
    color: var(--accent-light);
}

.history-badge.manual {
    background: rgba(245, 158, 11, .12);
    color: var(--warning);
}

.history-cmd {
    display: block;
    font-size: 0.75rem;
    color: var(--accent-light);
    background: var(--bg-input);
    padding: 3px 8px;
    border-radius: 6px;
    margin-bottom: 6px;
    direction: ltr;
    text-align: left;
}

.history-output-details {
    margin-top: 4px;
}

.history-output-details summary {
    font-size: 0.78rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 0;
}

.history-output-details summary:hover {
    color: var(--accent-light);
}

.history-output {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    font-size: 0.75rem;
    font-family: monospace;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 200px;
    overflow-y: auto;
    margin: 6px 0 0;
    direction: ltr;
    text-align: left;
}