:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-glow: rgba(59, 130, 246, 0.3);
    --danger: #ef4444;
    --danger-dark: #dc2626;
    --success: #22c55e;
    --success-dark: #16a34a;
    --warning: #f59e0b;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #263347;
    --surface-alt: #334155;
    --text: #e2e8f0;
    --text-light: #94a3b8;
    --text-muted: #64748b;
    --border: #1e3a5f;
    --border-dark: #475569;
    --input-bg: #0f172a;
    --input-border: #334155;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: 'Inter', "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Loading */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 16px;
    color: var(--text-light);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.inline-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 32px 20px;
    color: var(--text-muted);
    font-size: 13px;
}

.inline-loader .spinner-sm {
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

.panel-loading-bar {
    height: 2px;
    background: var(--border);
    overflow: hidden;
    position: relative;
}

.panel-loading-bar::after {
    content: "";
    position: absolute;
    top: 0;
    left: -40%;
    width: 40%;
    height: 100%;
    background: var(--primary);
    animation: loadingSlide 1s ease-in-out infinite;
}

@keyframes loadingSlide {
    0% { left: -40%; }
    100% { left: 100%; }
}

/* Error Screen */
.error-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

.error-card {
    background: var(--surface);
    padding: 40px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    text-align: center;
    max-width: 400px;
}

.error-card h2 { margin-bottom: 12px; color: var(--danger); }
.error-card p { margin-bottom: 20px; color: var(--text-light); }

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    color: var(--text);
    padding: 0 24px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header h1 {
    font-size: 16px;
    font-weight: 600;
    background: linear-gradient(135deg, var(--primary), #60a5fa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-right { display: flex; align-items: center; gap: 12px; }
.user-info { font-size: 13px; color: var(--text-light); }

.role-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    background: var(--primary-glow);
    color: var(--primary);
    font-weight: 600;
    text-transform: uppercase;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Main */
.main-content { max-width: 1400px; margin: 24px auto; padding: 0 24px; }

.main-layout {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 24px;
    align-items: start;
}

.content-left { min-width: 0; }

.content-right {
    position: sticky;
    top: 76px;
    max-height: calc(100vh - 100px);
    display: flex;
    flex-direction: column;
}

.content-right .panel {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 100px);
    margin-bottom: 0;
    overflow: hidden;
}

/* Panel */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: visible;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}

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

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.3);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); box-shadow: 0 0 20px rgba(59, 130, 246, 0.4); }

.btn-secondary {
    background: var(--surface-alt);
    color: var(--text);
    border-color: var(--border-dark);
}
.btn-secondary:hover:not(:disabled) { background: var(--border-dark); }

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn-danger:hover:not(:disabled) { background: var(--danger); color: white; }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 10px 24px; font-size: 15px; }

/* VM List */
.vm-list { padding: 0; }

.vm-card {
    display: grid;
    grid-template-columns: 1fr auto auto auto auto;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.vm-card:last-child { border-bottom: none; }
.vm-card:hover { background: var(--surface-hover); cursor: pointer; }

.vm-card-name {
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    color: #60a5fa;
}

.vm-card-name:hover { text-decoration: underline; color: #93bbfd; }

.vm-card-meta {
    font-size: 12px;
    color: var(--text-light);
}

.status-badge {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-running { background: rgba(34, 197, 94, 0.15); color: #4ade80; border: 1px solid rgba(34, 197, 94, 0.3); }
.status-deploying { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.status-stopped { background: rgba(100, 116, 139, 0.15); color: var(--text-light); border: 1px solid rgba(100, 116, 139, 0.3); }
.status-deleting { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); }
.status-failed { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); }

.empty-state {
    padding: 48px 20px;
    text-align: center;
    color: var(--text-muted);
}

.status-detail {
    margin-top: 4px;
    font-style: italic;
    color: #fbbf24;
}

.vm-error {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
    font-size: 12px;
    padding: 6px 20px;
    border-bottom: 1px solid var(--border);
    word-break: break-word;
}

/* Forms */
.form { padding: 20px; overflow: visible; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
    overflow: visible;
}

.form-group { display: flex; flex-direction: column; gap: 4px; position: relative; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text-light); }

.form-group input,
.form-group select {
    padding: 8px 12px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: var(--input-bg);
    color: var(--text);
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary), 0 0 8px var(--primary-glow);
}

.form-group input:disabled,
.form-group select:disabled {
    background: var(--surface-alt);
    color: var(--text-muted);
    border-color: var(--border);
}

.form-group small { font-size: 11px; color: var(--text-muted); }

/* Combobox */
.combobox {
    position: relative;
}

.combobox-input {
    width: 100%;
    padding: 8px 32px 8px 12px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: var(--input-bg);
    color: var(--text);
    transition: border-color 0.15s;
    cursor: pointer;
}

.combobox-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary), 0 0 8px var(--primary-glow);
    cursor: text;
}

.combobox-input:disabled {
    background: var(--surface-alt);
    color: var(--text-muted);
    cursor: not-allowed;
}

.combobox.loading .combobox-input {
    background: var(--surface-alt) linear-gradient(
        90deg,
        transparent 0%,
        var(--primary-glow) 50%,
        transparent 100%
    ) no-repeat;
    background-size: 30% 100%;
    animation: comboLoading 1.2s ease-in-out infinite;
}

@keyframes comboLoading {
    0% { background-position: -30% 0; }
    100% { background-position: 130% 0; }
}

.combobox.disabled .combobox-arrow { color: var(--text-muted); opacity: 0.5; }

.combobox-arrow {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--text-muted);
    pointer-events: none;
}

.combobox-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 150;
    background: var(--bg);
    border: 1px solid var(--primary);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(59, 130, 246, 0.3);
    max-height: 240px;
    overflow-y: auto;
}

.combobox.open .combobox-dropdown { display: block; }
.combobox.open .combobox-input {
    border-radius: var(--radius) var(--radius) 0 0;
}

.combobox-option {
    padding: 7px 12px;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}

.combobox-option:hover,
.combobox-option.highlighted {
    background: var(--primary-glow);
    color: #93bbfd;
}

.combobox-option.selected {
    background: var(--primary);
    color: white;
}

.combobox-empty {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
}

.password-match-hidden { visibility: hidden; }
.password-match-ok { color: var(--success) !important; font-weight: 600; }
.password-match-err { color: var(--danger) !important; font-weight: 600; }

.form-fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
    overflow: visible;
}

.form-fieldset legend {
    font-size: 14px;
    font-weight: 600;
    padding: 0 8px;
    color: var(--text);
}

.form-actions {
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

/* Size Details */
.size-details {
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
}

.size-details h4 { font-size: 13px; margin-bottom: 6px; color: #60a5fa; }

.size-specs {
    display: flex;
    gap: 20px;
    font-size: 13px;
    color: var(--text-light);
}

.size-specs span::before {
    font-weight: 600;
    margin-right: 4px;
}

/* VM Detail */
.vm-detail { padding: 20px; }

.detail-grid {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 8px 16px;
    font-size: 14px;
}

.detail-label { font-weight: 600; color: var(--text-muted); }
.detail-value { color: var(--text); word-break: break-all; }

.detail-actions {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

/* Resources Table */
.resources-section {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.resources-section h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
}

.resources-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.resources-table th {
    text-align: left;
    padding: 8px 12px;
    background: var(--bg);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.resources-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

.resources-table tr:hover td { background: var(--surface-hover); }

.resource-type {
    font-family: "Cascadia Code", "Consolas", monospace;
    font-size: 12px;
    color: var(--text-muted);
}

.no-resources {
    color: var(--text-muted);
    font-size: 13px;
    padding: 12px 0;
}

.rg-deleted-notice {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius);
    padding: 16px;
}

.rg-deleted-notice h4 { color: #fbbf24; }
.rg-deleted-notice p { font-size: 13px; color: #fbbf24; margin-top: 6px; opacity: 0.8; }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    max-width: 440px;
    width: 90%;
}

.modal-content h3 { margin-bottom: 12px; color: var(--text); }
.modal-content .warning { color: var(--danger); font-size: 13px; margin-top: 8px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* Toast */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    animation: slideIn 0.3s ease;
    max-width: 400px;
    border: 1px solid transparent;
}

.toast-success {
    background: rgba(34, 197, 94, 0.1);
    color: #4ade80;
    border-color: rgba(34, 197, 94, 0.3);
    border-left: 4px solid #22c55e;
}
.toast-error {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.3);
    border-left: 4px solid #ef4444;
}
.toast-info {
    background: rgba(59, 130, 246, 0.1);
    color: #60a5fa;
    border-color: rgba(59, 130, 246, 0.3);
    border-left: 4px solid #3b82f6;
}

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

/* Activity Log */
.log-filters {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.log-filter-row {
    display: flex;
    gap: 6px;
}

.log-filter-select {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    font-size: 12px;
    font-family: inherit;
    background: var(--input-bg);
    color: var(--text);
}

.log-filter-select:focus {
    outline: none;
    border-color: var(--primary);
}

.activity-log-list {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.log-entry {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.log-entry:last-child { border-bottom: none; }
.log-entry:hover { background: var(--surface-hover); }

.log-entry-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 2px;
}

.log-action-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.log-action-create { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
.log-action-create-ok { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.log-action-create-fail { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.log-action-delete { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.log-action-delete-ok { background: rgba(100, 116, 139, 0.15); color: var(--text-light); }
.log-action-delete-fail { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.log-action-external { background: rgba(239, 68, 68, 0.15); color: #f87171; }

.log-timestamp {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
}

.log-resource {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
}

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

.log-details {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
    word-break: break-word;
}

/* Grouped activity log */
.log-group {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

.log-group:last-child { border-bottom: none; }
.log-group:hover { background: var(--surface-hover); }

.log-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.log-group-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 2px;
}

/* Custom tooltip */
.log-group {
    position: relative;
}

.log-tooltip {
    display: none;
    position: fixed;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 8px 10px;
    z-index: 300;
    min-width: 180px;
    pointer-events: none;
}

.log-tooltip-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 3px 0;
}

.log-tooltip-row + .log-tooltip-row {
    border-top: 1px solid var(--border);
}

.log-tooltip-time {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Log detail modal */
.log-detail-modal-content {
    max-width: 520px !important;
    width: 90%;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

.log-detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.log-detail-header h3 { margin: 0; font-size: 16px; color: var(--text); }

.log-detail-close {
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.log-detail-timeline-wrap {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding-left: 20px;
}

.log-detail-timeline {
    position: relative;
    border-left: 2px solid var(--border);
    padding-left: 18px;
}

.log-detail-event {
    position: relative;
    padding: 0 0 18px 0;
}

.log-detail-event:last-child { padding-bottom: 4px; }

.log-detail-dot {
    position: absolute;
    left: -24px;
    top: 3px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--surface);
}

.dot-primary { background: var(--primary); }
.dot-success { background: #22c55e; }
.dot-warn    { background: #f59e0b; }
.dot-danger  { background: #ef4444; }

.log-detail-event-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}

.log-detail-event-body .log-user { margin-top: 2px; }
.log-detail-event-body .log-details { margin-top: 2px; }

.log-detail-time-full {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Responsive */
@media (max-width: 1024px) {
    .main-layout { grid-template-columns: 1fr; }
    .content-right {
        position: static;
        max-height: 400px;
    }
}

@media (max-width: 768px) {
    .form-row { grid-template-columns: 1fr; }
    .vm-card { grid-template-columns: 1fr; gap: 8px; }
    .header { padding: 0 12px; }
    .header h1 { font-size: 14px; }
    .main-content { padding: 0 12px; margin: 12px auto; }
}
