* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    color: #fff;
    padding: 20px;
    padding-bottom: 80px;
    max-width: 1400px;
    margin: 0 auto;
}

.header-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    margin-bottom: 20px;
}

h1 {
    font-size: 1.5rem;
    color: #e94560;
    margin: 0;
    text-align: center;
}

.logout-btn {
    justify-self: end;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.08);
    color: #94a3b8;
    text-decoration: none;
    border-radius: 6px;
    font-size: 13px;
    transition: all 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.logout-btn:hover {
    background: rgba(233, 69, 96, 0.15);
    color: #e94560;
    border-color: rgba(233, 69, 96, 0.3);
}

h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: #94a3b8;
}

/* === TABS === */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    overflow-x: auto;
}

.tab {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    background: rgba(255,255,255,0.1);
    color: #94a3b8;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.tab.active {
    background: linear-gradient(135deg, #e94560, #d63450);
    color: #fff;
}

.tab:hover:not(.active) {
    background: rgba(255,255,255,0.15);
}

/* === TAB CONTENT === */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* === CARD === */
.card {
    background: rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.name {
    font-size: 1.2rem;
    font-weight: 600;
}

.status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.dot.ready { background: #4ade80; }
.dot.running, .dot.checking { background: #60a5fa; }
.dot.terminated { background: #f87171; }
.dot.staging, .dot.stopping, .dot.starting {
    background: #fbbf24;
    animation: blink 0.5s infinite;
}

@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.3} }

.stage {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-top: 8px;
    min-height: 18px;
}

.link {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-bottom: 15px;
}

.link a {
    color: #60a5fa;
    text-decoration: none;
}

/* === BUTTONS === */
.btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-start {
    background: linear-gradient(135deg, #4ade80, #22c55e);
    color: #000;
}

.btn-stop {
    background: linear-gradient(135deg, #f87171, #ef4444);
    color: #fff;
}

.btn-action {
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
    color: #fff;
    padding: 8px 16px;
    font-size: 0.85rem;
    width: auto;
}

/* === FILTERS === */
.filters {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 8px 16px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    background: transparent;
    color: #94a3b8;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.filter-btn.active {
    background: rgba(96, 165, 250, 0.2);
    border-color: #60a5fa;
    color: #60a5fa;
}

.filter-btn:hover:not(.active) {
    background: rgba(255,255,255,0.1);
}

/* === PROCESS LIST === */
.process-list {
    padding-bottom: 20px;
}

.process-item {
    background: rgba(0,0,0,0.2);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    border-left: 3px solid transparent;
}

.process-item.cloudui {
    border-left-color: #60a5fa;
}

.process-item.vscode {
    border-left-color: #4ade80;
}

.process-item.stale {
    border-left-color: #fbbf24;
    opacity: 0.7;
}

.process-item.hidden {
    display: none;
}

.process-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.process-type {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.process-type.cloudui {
    background: rgba(96, 165, 250, 0.2);
    color: #60a5fa;
}

.process-type.vscode {
    background: rgba(74, 222, 128, 0.2);
    color: #4ade80;
}

.process-info {
    font-size: 0.85rem;
    color: #94a3b8;
    line-height: 1.5;
}

.process-info strong {
    color: #fff;
}

.tooltip {
    display: inline-block;
    cursor: help;
    margin-left: 4px;
    font-size: 0.8rem;
    color: #60a5fa;
    position: relative;
}

.tooltip:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 1000;
    margin-bottom: 5px;
    pointer-events: none;
}

.tooltip:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    margin-bottom: 0;
    z-index: 1000;
}

.process-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.process-actions button {
    flex: 1;
}

/* === SUBAGENTS === */
.subagents-container {
    margin-left: 20px;
    margin-top: 10px;
    margin-bottom: 10px;
    padding-left: 10px;
    border-left: 2px solid rgba(255,255,255,0.2);
}

.subagent {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    font-size: 0.85em;
    color: #64748b;
    margin-bottom: 4px;
    border-radius: 4px;
    background: rgba(0,0,0,0.1);
}

.subagent:last-child {
    margin-bottom: 0;
}

.subagent.active {
    color: #4ade80;
    background: rgba(74, 222, 128, 0.05);
}

.subagent.completed {
    color: #64748b;
}

.subagent .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.subagent .agent-id {
    font-family: monospace;
    font-size: 0.9em;
    font-weight: 600;
    color: #94a3b8;
    flex-shrink: 0;
}

.subagent .description {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 300px;
    color: inherit;
}

.subagent .runtime {
    font-family: monospace;
    font-size: 0.9em;
    font-weight: 500;
    color: #8b9dc3;
    flex-shrink: 0;
    min-width: 50px;
    text-align: right;
}

/* === SERVER STATS === */
.server-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.stat-item {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.7rem;
    color: #94a3b8;
    margin-bottom: 4px;
}

.stat-value {
    display: block;
    font-size: 1.1rem;
    font-weight: 600;
    color: #fff;
}

.stat-value.warning {
    color: #fbbf24;
}

.stat-value.critical {
    color: #f87171;
}

/* === PERIOD SELECTOR === */
.period-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
}

.period-btn {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    background: transparent;
    color: #94a3b8;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.period-btn.active {
    background: rgba(233, 69, 96, 0.2);
    border-color: #e94560;
    color: #e94560;
}

/* === CHARTS === */
.chart-container {
    margin-bottom: 30px;
}

.chart-container canvas {
    width: 100%;
    display: block;
    max-height: 200px;
}

.history-status {
    text-align: center;
    padding: 15px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    font-size: 0.85rem;
    color: #94a3b8;
}

/* === AUTO REFRESH === */
.auto-refresh {
    text-align: center;
    margin-top: 15px;
    font-size: 0.85rem;
    color: #94a3b8;
}

.auto-refresh input[type="checkbox"] {
    margin-right: 6px;
}

/* === LOADING === */
.loading {
    text-align: center;
    padding: 40px 20px;
    color: #94a3b8;
    font-size: 0.9rem;
}

.loading::after {
    content: '...';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* === VM OFFLINE MESSAGE === */
.vm-offline-message {
    text-align: center;
    padding: 60px 20px;
    color: #94a3b8;
}

.vm-offline-message .offline-icon {
    font-size: 64px;
    display: block;
    margin-bottom: 20px;
    opacity: 0.6;
}

.vm-offline-message h3 {
    color: #f87171;
    font-size: 1.3rem;
    margin-bottom: 12px;
    font-weight: 600;
}

.vm-offline-message p {
    color: #94a3b8;
    font-size: 0.95rem;
    margin: 0;
}

/* === FOOTER === */
.footer {
    text-align: center;
    color: #64748b;
    font-size: 0.75rem;
    margin-top: 20px;
    position: fixed;
    bottom: 60px;
    left: 0;
    right: 0;
}

/* === STATUS BAR === */
.status-bar {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.3s ease;
}

.status-bar.active {
    background: rgba(74, 222, 128, 0.2);
    color: #4ade80;
    border: 1px solid rgba(74, 222, 128, 0.3);
}

.status-bar.idle {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.status-bar.grace {
    background: rgba(251, 146, 60, 0.2);
    color: #fb923c;
    border: 1px solid rgba(251, 146, 60, 0.3);
}

.status-bar.sleeping {
    background: rgba(248, 113, 113, 0.2);
    color: #f87171;
    border: 1px solid rgba(248, 113, 113, 0.3);
}

.status-bar .icon { font-size: 1rem; }
.status-bar .timer { font-family: monospace; font-size: 0.9rem; }

.refresh-btn {
    background: rgba(248, 113, 113, 0.3);
    border: none;
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    margin-left: 8px;
}

/* === DEBUG PANEL === */
.debug-panel {
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    padding: 10px;
    margin-top: 20px;
    font-size: 0.7rem;
    font-family: monospace;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 100px;
}

.debug-panel.hidden { display: none; }

.debug-toggle {
    text-align: center;
    color: #64748b;
    font-size: 0.7rem;
    cursor: pointer;
    margin-top: 10px;
}

.log-entry {
    margin: 2px 0;
    padding: 2px 4px;
    border-radius: 2px;
}

.log-entry.ERROR { background: rgba(248, 113, 113, 0.2); }
.log-entry.WARN { background: rgba(251, 191, 36, 0.2); }
.log-entry.INFO { background: rgba(96, 165, 250, 0.1); }

/* === CLOUD UI CONTROL === */
.cloud-ui-control {
    background: rgba(96, 165, 250, 0.1);
    border: 1px solid rgba(96, 165, 250, 0.3);
}

.cloudui-buttons {
    display: flex;
    gap: 8px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.cloudui-buttons .btn {
    flex: 1;
    min-width: 140px;
}

.cloudui-info {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255,255,255,0.1);
    font-size: 0.85rem;
    color: #94a3b8;
}

.cloudui-info span {
    color: #fff;
    font-weight: 600;
}

#cloudui-status.running .dot {
    background: #4ade80;
}

#cloudui-status.stopped .dot {
    background: #64748b;
}

#cloudui-status.running #cloudui-status-text {
    color: #4ade80;
}

#cloudui-status.stopped #cloudui-status-text {
    color: #94a3b8;
}

/* === VM SHUTDOWN TIMER === */
.timer-description {
    font-size: 0.85rem;
    color: #94a3b8;
    margin-bottom: 15px;
    line-height: 1.4;
}

.timer-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.timer-input-group {
    display: flex;
    gap: 10px;
}

.timer-input-group input {
    flex: 1;
    padding: 12px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    background: rgba(0,0,0,0.2);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
}

.timer-input-group input:focus {
    outline: none;
    border-color: #60a5fa;
}

.timer-input-group input::placeholder {
    color: #64748b;
}

.timer-input-group .btn {
    flex: 1;
}

.btn-primary {
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
    color: #fff;
}

.btn-secondary {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #000;
}

.btn-restart {
    background: linear-gradient(135deg, #fb923c, #f97316);
    color: #fff;
    margin-top: 8px;
}

.btn-restart:hover:not(:disabled) {
    opacity: 0.9;
}

/* === VM BUTTONS CONTAINER === */
.vm-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.timer-info {
    margin-top: 15px;
    padding: 12px;
    background: rgba(96, 165, 250, 0.1);
    border: 1px solid rgba(96, 165, 250, 0.3);
    border-radius: 8px;
    text-align: center;
}

.timer-info span {
    font-size: 1.1rem;
    font-weight: 600;
    color: #60a5fa;
}

#vm-timer-status.active .dot {
    background: #fbbf24;
    animation: blink 0.5s infinite;
}

#vm-timer-status.inactive .dot {
    background: #64748b;
}

#vm-timer-status.active #vm-timer-status-text {
    color: #fbbf24;
    font-weight: 600;
}

#vm-timer-status.inactive #vm-timer-status-text {
    color: #94a3b8;
}

/* Timer active state highlighting */
#vm-timer-status.active {
    background: rgba(251, 191, 36, 0.1);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(251, 191, 36, 0.3);
}

/* === CHART TOOLTIPS === */
.chart-tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    pointer-events: none;
    z-index: 10000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

.tooltip-time {
    font-weight: bold;
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
    padding-bottom: 4px;
}

.tooltip-value {
    font-size: 12px;
    color: #e0e0e0;
}

/* === RESPONSIVE === */

/* Mobile devices (small screens) */
@media (max-width: 768px) {
    body {
        padding: 10px;
        padding-bottom: 80px;
        max-width: 100%;
    }
    h1 { font-size: 1.2rem; }
    .card { padding: 15px; }
    .server-stats { grid-template-columns: repeat(2, 1fr); }
    .status-bar { left: 10px; right: 10px; }
    .cloudui-buttons { flex-direction: column; }
    .cloudui-buttons .btn { width: 100%; }

    /* Subagents mobile adjustments */
    .subagents-container {
        margin-left: 10px;
        padding-left: 8px;
    }
    .subagent {
        font-size: 0.8em;
        padding: 3px 6px;
        gap: 6px;
    }
    .subagent .description {
        max-width: 150px;
    }
    .subagent .runtime {
        min-width: 40px;
        font-size: 0.85em;
    }
}

/* Tablets (medium screens) */
@media (min-width: 769px) and (max-width: 1440px) {
    body {
        max-width: 100%;
        padding: 20px 30px;
        padding-bottom: 80px;
    }
}

/* Large desktops (very wide screens) */
@media (min-width: 1441px) {
    body {
        max-width: 1400px;
        padding: 20px 40px;
        padding-bottom: 80px;
    }
}
