* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.header-main {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-name {
    font-weight: 600;
}

.user-role {
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.role-admin {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.role-user {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary);
}

.impersonation-badge {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: rgba(245, 158, 11, 0.2);
    border: 1px solid var(--warning);
    border-radius: 0.5rem;
    color: var(--warning);
}

header h1 {
    font-size: 2rem;
    background: linear-gradient(135deg, var(--primary), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.actions-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.status-indicator {
    margin-left: auto;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-warning {
    background: var(--warning);
    color: #000;
}

.btn-full {
    width: 100%;
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.instances-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.instance-card {
    background: var(--bg-card);
    border-radius: 0.75rem;
    padding: 1.5rem;
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
}

.instance-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.instance-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.instance-name {
    font-size: 1.125rem;
    font-weight: 600;
}

.instance-id {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
}

.status-running {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.status-stopped {
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-muted);
}

.status-pending {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

.status-error {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.status-starting, .status-stopping {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary);
}

/* Instance Metrics */
.instance-metrics {
    display: flex;
    gap: 1rem;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.metric {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.metric.uptime {
    flex: 0 0 auto;
    min-width: 70px;
    align-items: flex-end;
}

.metric-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}

.metric-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.metric-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.metric-fill.cpu-fill {
    background: linear-gradient(90deg, var(--success), var(--warning));
}

.metric-fill.mem-fill {
    background: linear-gradient(90deg, var(--primary), #a855f7);
}

.metric-value {
    font-size: 0.75rem;
    font-family: monospace;
    color: var(--text);
}

.instance-details {
    margin-bottom: 1rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.375rem 0;
    font-size: 0.875rem;
}

.detail-label {
    color: var(--text-muted);
}

.detail-value {
    font-family: monospace;
}

.instance-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.instance-actions .btn {
    flex: 1;
    min-width: 70px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 0.75rem;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 900px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.25rem;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

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

form {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text);
    font-size: 0.875rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group small {
    display: block;
    margin-top: 0.375rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding-top: 0.5rem;
}

/* Console Modal */
.console-info {
    padding: 1rem 1.5rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.vnc-details {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.75rem 0;
}

.vnc-details code {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--bg-card);
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

.hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.vnc-container {
    height: 600px;
    background: #000;
}

.vnc-container iframe {
    width: 100%;
    height: 100%;
}

/* Loading */
.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.empty-state h3 {
    margin-bottom: 0.5rem;
    color: var(--text);
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 2000;
    animation: slideIn 0.3s ease;
}

.toast.success {
    border-color: var(--success);
}

.toast.error {
    border-color: var(--danger);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Input with button */
.input-with-button {
    display: flex;
    gap: 0.5rem;
}

.input-with-button input {
    flex: 1;
}

.input-with-button .btn {
    white-space: nowrap;
}

/* ISO Browser */
.iso-list {
    max-height: 400px;
    overflow-y: auto;
    padding: 1rem;
}

.iso-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.iso-item:hover {
    border-color: var(--primary);
    background: var(--bg-hover);
}

.iso-item-name {
    font-weight: 500;
}

.iso-item-size {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Auth Modal */
.auth-modal {
    background: var(--bg);
}

.auth-modal.active {
    display: flex;
}

.auth-content {
    max-width: 400px;
    width: 90%;
}

.auth-header {
    text-align: center;
    padding: 2rem 1.5rem 1rem;
}

.auth-header h1 {
    font-size: 2rem;
    background: linear-gradient(135deg, var(--primary), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.auth-tab {
    flex: 1;
    padding: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}

.auth-tab:hover {
    color: var(--text);
}

.auth-tab.active {
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
    margin-bottom: -1px;
}

.auth-form {
    padding: 1.5rem;
}

.form-error {
    color: var(--danger);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    min-height: 1.25rem;
}

/* Admin Panel */
.admin-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    margin-bottom: 2rem;
    overflow: hidden;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: rgba(239, 68, 68, 0.1);
    border-bottom: 1px solid var(--border);
}

.admin-header h2 {
    font-size: 1.125rem;
    color: var(--danger);
}

.admin-content {
    padding: 1.5rem;
}

.admin-content h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.users-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.user-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
}

.user-card-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.user-card-name {
    font-weight: 600;
}

.user-card-role {
    font-size: 0.75rem;
    text-transform: uppercase;
}

.user-card-email {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 640px) {
    .container {
        padding: 1rem;
    }

    .actions-bar {
        flex-wrap: wrap;
    }

    .instances-grid {
        grid-template-columns: 1fr;
    }
}
