:root,
[data-theme="dark"] {
    --bg-primary: #0b1220;
    --bg-secondary: #121a2b;
    --bg-card: #182235;
    --bg-card-hover: #1e2b42;
    --bg-elevated: #1a2740;
    --accent: #0d9488;
    --accent-light: #2dd4bf;
    --accent-soft: rgba(13, 148, 136, 0.14);
    --accent-glow: rgba(13, 148, 136, 0.22);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --text-primary: #eef2ff;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #243044;
    --border-strong: #334155;
    --gradient-1: linear-gradient(135deg, #0d9488 0%, #0891b2 100%);
    --gradient-2: linear-gradient(160deg, #0b1220 0%, #152238 55%, #0f1a2e 100%);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
    --shadow-soft: 0 4px 16px rgba(0, 0, 0, 0.18);
    --radius: 14px;
    --radius-sm: 10px;
    --font: 'Figtree', 'Segoe UI', sans-serif;
    --font-display: 'Sora', 'Figtree', sans-serif;
    --chart-grid: rgba(148, 163, 184, 0.18);
    --chart-label: #94a3b8;
}

[data-theme="light"] {
    --bg-primary: #f3f6f9;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --bg-elevated: #eef3f7;
    --accent: #0f766e;
    --accent-light: #0d9488;
    --accent-soft: rgba(15, 118, 110, 0.1);
    --accent-glow: rgba(15, 118, 110, 0.16);
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --gradient-1: linear-gradient(135deg, #0f766e 0%, #0369a1 100%);
    --gradient-2: linear-gradient(160deg, #eef5f7 0%, #f8fafc 50%, #e8f0f4 100%);
    --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
    --shadow-soft: 0 4px 14px rgba(15, 23, 42, 0.06);
    --chart-grid: rgba(100, 116, 139, 0.2);
    --chart-label: #64748b;
}

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

body {
    font-family: var(--font);
    background: var(--bg-primary);
    background-image: var(--gradient-2);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    transition: background-color 0.25s ease, color 0.25s ease;
}

a {
    color: var(--accent-light);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Layout */
.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 24px;
}

/* Header */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: var(--gradient-1);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.85rem;
}

.logo span {
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-links {
    display: flex;
    gap: 24px;
    align-items: center;
}

.nav-links a {
    color: var(--text-secondary);
    font-weight: 500;
    transition: color 0.2s;
    text-decoration: none;
}

.nav-links a:hover {
    color: var(--accent-light);
    text-decoration: none;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--gradient-1);
    color: white;
    box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--accent-glow);
    text-decoration: none;
    color: white;
}

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

.btn-secondary:hover {
    background: var(--bg-card-hover);
    text-decoration: none;
    color: var(--text-primary);
}

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

.btn-warning {
    background: #d97706;
    color: white;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.8rem;
}

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

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gradient-1);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 2.2rem;
    font-weight: 700;
    margin-top: 8px;
}

.stat-icon {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 2.5rem;
    opacity: 0.15;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

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

/* Tables */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

tr:hover td {
    background: var(--bg-card-hover);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-success { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.2); color: var(--warning); }
.badge-danger { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.badge-info { background: rgba(59, 130, 246, 0.2); color: var(--accent-light); }
.badge-muted { background: rgba(100, 116, 139, 0.2); color: var(--text-muted); }

/* Status indicators */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.status-online { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-offline { background: var(--text-muted); }
.status-alerta { background: var(--danger); box-shadow: 0 0 8px var(--danger); animation: pulse 1.5s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Login */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gradient-2);
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 40px;
}

.login-card .logo {
    justify-content: center;
    margin-bottom: 32px;
}

.login-card h2 {
    text-align: center;
    margin-bottom: 8px;
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

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

.modal-overlay.confirm-modal {
    z-index: 700;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(3px);
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 90%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal.modal-lg {
    max-width: 720px;
}

.confirm-modal .confirm-dialog {
    max-width: 420px;
    text-align: center;
    padding: 28px 32px 24px;
}
.confirm-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    line-height: 1;
    width: 56px;
    height: 56px;
    margin-left: auto;
    margin-right: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(13, 148, 136, 0.18);
    color: var(--accent, #0d9488);
    font-weight: 700;
}
.confirm-icon.warning {
    background: rgba(245, 158, 11, 0.18);
    color: #f59e0b;
}
.confirm-icon.danger {
    background: rgba(239, 68, 68, 0.18);
    color: #ef4444;
}
.confirm-dialog h2 {
    font-size: 1.15rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}
.confirm-dialog p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 24px;
    white-space: pre-line;
}
.agent-update-msg {
    white-space: pre-line;
    min-height: 3.2em;
}
.agent-update-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent, #0d9488);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}
.agent-update-dialog .confirm-actions {
    margin-top: 4px;
}
.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.confirm-actions .btn {
    min-width: 110px;
    padding: 10px 20px;
}
.confirm-modal.active .confirm-dialog {
    animation: confirmPop 0.12s ease-out;
}
@keyframes confirmPop {
    from { transform: scale(0.96); opacity: 0.5; }
    to { transform: scale(1); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

/* Alerts list */
.alert-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    background: var(--bg-secondary);
    border-left: 3px solid var(--warning);
}

.alert-item.critico {
    border-left-color: var(--danger);
}

.alert-item .alert-time {
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Machine cards */
.machines-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.machine-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: transform 0.2s, border-color 0.2s;
}

.machine-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

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

.machine-name {
    font-weight: 600;
    font-size: 1.05rem;
}

.metric-bars {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.metric-bar label {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.bar-track {
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.bar-cpu { background: var(--gradient-1); }
.bar-ram { background: linear-gradient(90deg, #10b981, #34d399); }

.bar-fill.warning { background: var(--warning) !important; }
.bar-fill.danger { background: var(--danger) !important; }

/* Chart container */
.chart-container {
    position: relative;
    height: 200px;
    margin-top: 16px;
}

/* Keys display */
.keys-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 420px;
    overflow-y: auto;
}

.key-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    font-family: 'Consolas', monospace;
    font-size: 0.85rem;
    gap: 12px;
    flex-wrap: wrap;
}

.key-item-full {
    align-items: flex-start;
}

.key-main {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.key-code {
    word-break: break-all;
}

.key-pc {
    font-family: inherit;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.key-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

/* Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    color: white;
    font-weight: 500;
    animation: slideIn 0.3s ease;
    box-shadow: var(--shadow);
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: #d97706; }
.toast-info { background: var(--accent); }

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

/* Hero landing */
.hero {
    padding: 80px 0;
    text-align: center;
}

.hero h1 {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 16px;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    font-size: 1.2rem;
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto 40px;
}

.hero-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.features {
    padding: 60px 0;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
}

.feature-card {
    padding: 32px;
    text-align: center;
}

.feature-icon {
    font-size: 2.5rem;
    margin-bottom: 16px;
}

.feature-card h3 {
    margin-bottom: 8px;
}

.feature-card p {
    color: var(--text-secondary);
}

/* Dashboard layout */
.dashboard {
    padding: 32px 0;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.section-title {
    font-size: 1.5rem;
    font-weight: 700;
}

.hidden { display: none !important; }

.copy-btn {
    background: none;
    border: none;
    color: var(--accent-light);
    cursor: pointer;
    font-size: 0.85rem;
}

.copy-btn:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
    .form-row { grid-template-columns: 1fr; }
    .hero h1 { font-size: 2rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .dashboard-header { flex-direction: column; gap: 16px; align-items: flex-start; }
}

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

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

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

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}
