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

:root {
    --bg:        #0b1120;
    --surface:   #111827;
    --surface2:  #1a2535;
    --border:    #1f2f44;
    --border2:   #2a3f58;
    --text:      #e2e8f0;
    --muted:     #64748b;
    --blue:      #6366f1;
    --blue-d:    #4f46e5;
    --green:     #10b981;
    --amber:     #f59e0b;
    --red:       #ef4444;
    --radius:    14px;
}

html { font-size: 14px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}
code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
}

/* ── Login ── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 48px 40px;
    width: 100%;
    max-width: 360px;
    text-align: center;
}
.login-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px; height: 64px;
    border-radius: 16px;
    background: rgba(99,102,241,0.12);
    color: var(--blue);
    margin-bottom: 20px;
}
.login-card h1 { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.login-subtitle { color: var(--muted); font-size: 13px; margin-bottom: 32px; }

.form-input {
    width: 100%;
    padding: 11px 16px;
    background: var(--bg);
    border: 1px solid var(--border2);
    border-radius: 8px;
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: border-color .2s;
    margin-bottom: 12px;
    display: block;
}
.form-input:focus { border-color: var(--blue); }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 20px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; border: none; transition: all .15s; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-d); }
.btn-full { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; text-align: left; }
.alert-error { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.25); color: #fca5a5; }

/* ── Header ── */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 28px;
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky; top: 0; z-index: 100;
}
.header-brand { display: flex; align-items: center; gap: 12px; }
.header-icon { color: var(--blue); flex-shrink: 0; }
.header-title { font-size: 15px; font-weight: 700; }
.header-sub { font-size: 11px; color: var(--muted); }
.header-right { display: flex; align-items: center; gap: 12px; }

.refresh-pill {
    display: flex; align-items: center; gap: 7px;
    background: var(--surface2);
    border: 1px solid var(--border2);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 12px;
    color: var(--muted);
}
.refresh-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--green);
    animation: blink 2.5s ease-in-out infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

.btn-logout {
    font-size: 13px; font-weight: 500; color: var(--muted);
    text-decoration: none; padding: 5px 12px;
    border: 1px solid var(--border2); border-radius: 7px;
    transition: all .15s;
}
.btn-logout:hover { color: var(--text); border-color: var(--border2); background: var(--surface2); }

/* ── Main ── */
.main { padding: 28px 28px 60px; max-width: 1400px; margin: 0 auto; }

/* ── VM Grid ── */
.vm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}
.vm-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color .2s, box-shadow .2s;
}
.vm-card:hover { border-color: var(--border2); box-shadow: 0 4px 20px rgba(0,0,0,.3); }
.vm-card--offline { border-color: rgba(239,68,68,.3); }

.vm-card__header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}
.vm-name { font-weight: 700; font-size: 15px; }
.vm-fqdn { font-size: 11px; color: var(--muted); font-family: monospace; margin-top: 2px; }

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 700; letter-spacing: .02em;
    white-space: nowrap;
}
.badge__dot { width: 6px; height: 6px; border-radius: 50%; }
.badge--online  { background: rgba(16,185,129,.12); color: #34d399; }
.badge--online  .badge__dot { background: #34d399; }
.badge--offline { background: rgba(239,68,68,.12); color: #f87171; }
.badge--offline .badge__dot { background: #f87171; }
.badge--unknown { background: rgba(100,116,139,.12); color: var(--muted); }
.badge--unknown .badge__dot { background: var(--muted); }

.vm-card__body { padding: 16px 20px; }

/* IP row */
.ip-row {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
    padding-bottom: 14px; margin-bottom: 14px;
    border-bottom: 1px solid var(--border);
}
.label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 4px; }
.ip-val { font-family: monospace; font-size: 16px; font-weight: 700; }
.cf-area { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.cf-tag {
    font-size: 11px; font-weight: 700; padding: 3px 8px;
    border-radius: 6px; white-space: nowrap;
}
.cf-tag--ok   { background: rgba(16,185,129,.12); color: #34d399; }
.cf-tag--warn { background: rgba(245,158,11,.12);  color: #fbbf24; }
.cf-tag--none { background: rgba(100,116,139,.1);  color: var(--muted); }

.btn-sync {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 11px; font-weight: 600; color: var(--muted);
    background: var(--surface2); border: 1px solid var(--border2);
    border-radius: 6px; padding: 4px 9px; cursor: pointer;
    transition: all .15s;
}
.btn-sync:hover { color: var(--blue); border-color: var(--blue); }
.btn-sync:disabled { opacity: .5; cursor: not-allowed; }

/* Metrics */
.metrics { display: flex; flex-direction: column; gap: 9px; }
.metric { display: flex; align-items: center; gap: 10px; }
.metric__label { font-size: 11px; color: var(--muted); width: 28px; flex-shrink: 0; }
.metric__track { flex: 1; height: 5px; background: var(--surface2); border-radius: 3px; overflow: hidden; }
.metric__bar { height: 100%; border-radius: 3px; transition: width .5s ease; min-width: 2px; }
.bar--blue  { background: var(--blue); }
.bar--green { background: var(--green); }
.bar--amber { background: var(--amber); }
.bar--danger { background: var(--red) !important; }
.metric__val { font-size: 11px; font-family: monospace; width: 38px; text-align: right; color: var(--muted); }

.offline-msg {
    display: flex; align-items: center; gap: 8px;
    color: #f87171; font-size: 12px; padding: 8px 0;
}
.waiting-msg { color: var(--muted); font-size: 12px; padding: 8px 0; }

.vm-card__footer {
    padding: 10px 20px;
    border-top: 1px solid var(--border);
    background: rgba(0,0,0,.2);
    display: flex; align-items: center; justify-content: space-between;
}
.footer-uptime { font-size: 12px; font-weight: 600; color: var(--text); }
.footer-time { font-size: 11px; color: var(--muted); }

/* ── History section ── */
.history-section { margin-top: 8px; }
.section-title {
    display: flex; align-items: center; gap: 8px;
    font-size: 15px; font-weight: 700; margin-bottom: 16px;
    color: var(--text);
}
.section-title svg { color: var(--muted); }

.table-wrap {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    overflow-x: auto;
}
.hist-table {
    width: 100%; border-collapse: collapse;
    background: var(--surface);
}
.hist-table th {
    text-align: left; padding: 11px 16px;
    font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--muted); background: var(--surface2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.hist-table td {
    padding: 10px 16px; font-size: 13px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.hist-table tr:last-child td { border-bottom: none; }
.hist-table tr:hover td { background: var(--surface2); }
.hist-vm { font-weight: 600; font-size: 13px; }
.hist-fqdn { font-size: 10px; color: var(--muted); font-family: monospace; }
.tag-ok  { color: #34d399; font-size: 12px; font-weight: 600; }
.tag-err { color: #f87171; font-size: 12px; font-weight: 600; }
.tag-na  { color: var(--muted); font-size: 12px; }

.empty { text-align: center; padding: 40px; color: var(--muted); font-size: 13px; }

/* ── Toasts ── */
#toast-container {
    position: fixed; bottom: 24px; right: 24px;
    display: flex; flex-direction: column; gap: 10px;
    z-index: 999;
}
.toast {
    padding: 12px 18px; border-radius: 10px;
    font-size: 13px; font-weight: 500;
    opacity: 0; transform: translateY(8px);
    transition: all .25s;
    max-width: 320px;
    box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast--ok  { background: var(--green); color: #fff; }
.toast--err { background: var(--red);   color: #fff; }

/* ── Responsive ── */
@media (max-width: 640px) {
    .header { padding: 0 16px; }
    .main { padding: 16px 16px 40px; }
    .vm-grid { grid-template-columns: 1fr; }
    .header-sub { display: none; }
}
