/* ---------- design tokens ---------- */
:root {
    color-scheme: dark;
    --bg: #0b0d12;
    --bg-elevated: #12151c;
    --surface: #171b24;
    --surface-hover: #1d2230;
    --border: #262c3a;
    --border-strong: #343c4f;
    --text: #e8ebf2;
    --text-secondary: #9aa3b5;
    --text-muted: #6b7486;
    --primary: #7c83ff;
    --primary-hover: #6970f5;
    --primary-soft: rgba(124, 131, 255, 0.14);
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.12);
    --chart-1: #7c83ff;
    --chart-2: #f472b6;
    --chart-3: #38bdf8;
    --chart-4: #fbbf24;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
    :root {
        color-scheme: light;
        --bg: #f6f7fb;
        --bg-elevated: #ffffff;
        --surface: #ffffff;
        --surface-hover: #f1f3f9;
        --border: #e3e6ee;
        --border-strong: #cfd4e0;
        --text: #141824;
        --text-secondary: #555e72;
        --text-muted: #8a92a3;
        --primary: #5b5ff0;
        --primary-hover: #4a4ee0;
        --primary-soft: rgba(91, 95, 240, 0.1);
        --danger-soft: rgba(220, 38, 38, 0.08);
        --danger: #dc2626;
        --success: #059669;
        --warning: #d97706;
        --chart-1: #5b5ff0;
        --chart-2: #db2777;
        --chart-3: #0284c7;
        --chart-4: #d97706;
        --shadow: 0 1px 2px rgba(20, 24, 36, 0.06), 0 8px 24px rgba(20, 24, 36, 0.06);
    }
}

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

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -0.01em; }
a { color: var(--primary); }
img { display: block; max-width: 100%; }
.muted { color: var(--text-secondary); font-size: 0.9rem; }
[hidden] { display: none !important; }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    padding: 0 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-small { height: 30px; padding: 0 10px; font-size: 0.8rem; }
.btn-block { width: 100%; height: 44px; }

.btn-icon {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--surface-hover); color: var(--text); }
.btn-icon.delete:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- forms ---------- */
.input-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.input-group label, .input-group .label { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); }

input[type="text"], input[type="password"], input[type="url"], input[type="number"],
input[type="search"], textarea, select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
::placeholder { color: var(--text-muted); }

.error-message {
    display: none;
    padding: 10px 12px;
    margin-bottom: 16px;
    border-radius: var(--radius-sm);
    background: var(--danger-soft);
    color: var(--danger);
    font-size: 0.875rem;
}
.error-message.show { display: block; }

/* ---------- login ---------- */
.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(60rem 40rem at 10% -10%, rgba(124, 131, 255, 0.18), transparent 60%),
        radial-gradient(50rem 35rem at 110% 110%, rgba(244, 114, 182, 0.12), transparent 60%),
        var(--bg);
}
.login-card {
    width: 100%;
    max-width: 380px;
    padding: 36px 32px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
}
.logo { text-align: center; margin-bottom: 28px; }
.logo .logo-icon { font-size: 40px; margin-bottom: 8px; }
.logo h1 { font-size: 1.5rem; }

/* ---------- navbar ---------- */
.navbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 32px;
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}
.nav-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.nav-brand .logo-icon { font-size: 22px; }
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-link {
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.92rem;
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover { color: var(--text); background: var(--surface-hover); }
.nav-link.active { color: var(--primary); background: var(--primary-soft); }
.nav-user { display: flex; align-items: center; gap: 10px; }

/* ---------- layout ---------- */
.container { max-width: 1280px; margin: 0 auto; padding: 32px; }
.page { display: none; }
.page.active { display: block; animation: fade-in 0.2s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 28px;
}
.page-header h2 { font-size: 1.6rem; }
.header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search { width: 220px !important; height: 38px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }

.empty-state {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-secondary);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
}

/* ---------- categories ---------- */
.category-section { margin-bottom: 28px; }
.category-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.category-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px 6px 4px;
    border: none;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text);
    font: inherit;
    cursor: pointer;
}
.category-toggle:hover { background: var(--surface-hover); }
.category-toggle h3 { font-size: 1.05rem; font-weight: 600; }
.toggle-icon { color: var(--text-muted); transition: transform 0.2s; }
.category-section.collapsed .toggle-icon { transform: rotate(-90deg); }
.category-section.collapsed .category-content { display: none; }
.category-icon { font-size: 1.15rem; }
.category-count {
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--surface-hover);
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
}
.empty-category { padding: 4px 4px 0; }

/* ---------- cards ---------- */
.card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.card:hover { border-color: var(--border-strong); transform: translateY(-2px); box-shadow: var(--shadow); }
.card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card-icon {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--surface-hover);
    font-size: 26px;
}
.card-image { width: 48px; height: 48px; object-fit: cover; border-radius: 12px; }
.card-actions { display: flex; align-items: center; gap: 2px; opacity: 0.7; transition: opacity 0.15s; }
.card:hover .card-actions, .card:focus-within .card-actions { opacity: 1; }
.card-body { flex: 1; min-width: 0; }
.card-title { font-size: 1.02rem; font-weight: 600; }
.card-subtitle { color: var(--text-muted); font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-description {
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 0.88rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.card-link {
    align-self: flex-start;
    font-size: 0.86rem;
    font-weight: 600;
    text-decoration: none;
}
.card-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); } /* whole card clickable */
.card-actions, .card-link { position: relative; z-index: 1; }
.card-link:hover { text-decoration: underline; }

/* ---------- servers ---------- */
.server-card.is-offline { opacity: 0.75; }
.stats-grid { display: grid; gap: 12px; }
.stat-row { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 5px; }
.stat .stat-label { color: var(--text-secondary); }
.stat .stat-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-bar { height: 6px; border-radius: 999px; background: var(--surface-hover); overflow: hidden; }
.stat-fill { height: 100%; width: 0; border-radius: inherit; background: var(--primary); transition: width 0.5s ease; }
.stat-fill.warning { background: var(--warning); }
.stat-fill.danger { background: var(--danger); }

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.status-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-badge.online { color: var(--success); background: color-mix(in srgb, var(--success) 14%, transparent); }
.status-badge.offline { color: var(--danger); background: var(--danger-soft); }

/* ---------- speed test ---------- */
.speedtest-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { padding: 18px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.stat-card .stat-label { color: var(--text-secondary); font-size: 0.82rem; font-weight: 500; }
.stat-card .stat-value { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; }
.stat-card .stat-unit { color: var(--text-muted); font-size: 0.8rem; }
.chart-container {
    position: relative;
    height: 420px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* ---------- dialogs ---------- */
.modal {
    width: min(500px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    padding: 24px;
    margin: auto;
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.45);
}
.modal[open] { animation: pop-in 0.18s ease; }
.modal::backdrop { background: rgba(5, 7, 12, 0.6); backdrop-filter: blur(3px); }
@keyframes pop-in { from { opacity: 0; transform: scale(0.97); } }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-size: 1.2rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.image-picker { display: flex; gap: 14px; align-items: stretch; }
.file-upload-area {
    flex: 0 0 112px;
    height: 112px;
    padding: 0;
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.15s, background 0.15s;
}
.file-upload-area:hover { border-color: var(--primary); background: var(--primary-soft); }
.file-upload-area.busy { opacity: 0.6; cursor: progress; }
.image-preview { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; width: 100%; height: 100%; }
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.upload-icon { font-size: 1.4rem; }
.image-picker-side { flex: 1; display: flex; flex-direction: column; gap: 6px; justify-content: center; }
.image-picker-side label { font-size: 0.82rem; color: var(--text-muted); font-weight: 500; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
    padding: 11px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-left: 3px solid var(--primary);
    box-shadow: var(--shadow);
    font-size: 0.9rem;
    animation: pop-in 0.18s ease;
    transition: opacity 0.4s, transform 0.4s;
}
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast.hide { opacity: 0; transform: translateY(6px); }

/* ---------- mobile ---------- */
@media (max-width: 768px) {
    .navbar { flex-wrap: wrap; gap: 8px 16px; padding: 10px 16px; }
    .nav-links { order: 3; flex-basis: 100%; overflow-x: auto; }
    .nav-user { margin-left: auto; }
    .nav-user #username { display: none; }
    .container { padding: 20px 16px; }
    .page-header h2 { font-size: 1.35rem; }
    .header-actions { width: 100%; }
    .search { flex: 1; width: auto !important; }
    .grid { grid-template-columns: 1fr; }
    .card-actions { opacity: 1; }
    .chart-container { height: 320px; padding: 12px; }
    .stat-card .stat-value { font-size: 1.5rem; }
}
