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

:root {
    --bg: #0f1117;
    --bg-card: #1a1d27;
    --bg-card-hover: #222633;
    --border: #2a2e3d;
    --text: #e4e6ed;
    --text-dim: #8b8fa3;
    --accent: #6c8cff;
    --accent-glow: rgba(108, 140, 255, 0.15);
    --green: #34d399;
    --red: #f87171;
    --yellow: #fbbf24;
    --orange: #fb923c;
    --radius: 10px;
    --sidebar-w: 200px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
}

/* ─── Sidebar ──────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 20px 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 15px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 16px;
}

.nav-menu {
    list-style: none;
    padding: 12px 8px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-dim);
    transition: all 0.15s;
    margin-bottom: 2px;
    font-size: 13px;
}

.nav-item:hover { background: var(--bg-card-hover); color: var(--text); }
.nav-item.active { background: var(--accent-glow); color: var(--accent); font-weight: 600; }

.logout-btn {
    margin: 0 8px;
    text-decoration: none;
    color: var(--text-dim);
}
.logout-btn:hover { color: var(--red); background: rgba(248,113,113,0.1); }

.lang-switcher {
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
}
.lang-btn {
    flex: 1;
    padding: 5px 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-dim);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}
.lang-btn:hover { border-color: var(--accent); color: var(--text); }
.lang-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ─── Content ──────────────────────────────────── */
.content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 28px 32px;
    max-width: 1100px;
}

.page { display: none; }
.page.active { display: block; }

h1 { font-size: 22px; font-weight: 700; margin-bottom: 20px; }
h2 { font-size: 16px; font-weight: 600; margin: 24px 0 12px; color: var(--text-dim); }
h3 { font-size: 14px; font-weight: 600; margin-bottom: 10px; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
.page-header h1 { margin-bottom: 0; }

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

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
}

.stat-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-detail { font-size: 11px; color: var(--text-dim); margin-top: 8px; }

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

.progress-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--accent);
    transition: width 0.5s ease;
}
.progress-fill.warn { background: var(--yellow); }
.progress-fill.danger { background: var(--red); }
.progress-fill.temp { background: var(--orange); }

/* ─── Info Row ─────────────────────────────────── */
.info-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 8px;
}

.info-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.info-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.info-value { font-size: 16px; font-weight: 600; }

/* ─── Sites Mini (Dashboard) ───────────────────── */
.sites-mini {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}

.site-mini-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.site-mini-info { display: flex; align-items: center; gap: 10px; }
.site-mini-name { font-weight: 600; font-size: 14px; }
.site-mini-type { font-size: 11px; color: var(--text-dim); }
.site-mini-actions { display: flex; align-items: center; gap: 8px; }

/* ─── Status Badge ─────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
}
.badge.running { background: rgba(52,211,153,0.12); color: var(--green); }
.badge.running::before { background: var(--green); }
.badge.stopped, .badge.inactive { background: rgba(139,143,163,0.12); color: var(--text-dim); }
.badge.stopped::before, .badge.inactive::before { background: var(--text-dim); }
.badge.failed { background: rgba(248,113,113,0.12); color: var(--red); }
.badge.failed::before { background: var(--red); }
.badge.static { background: rgba(108,140,255,0.12); color: var(--accent); }
.badge.static::before { background: var(--accent); }

/* ─── Sort Bar ─────────────────────────────────── */
.sort-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.sort-label {
    font-size: 12px;
    color: var(--text-dim);
    margin-right: 4px;
}
.sort-btn {
    padding: 4px 12px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.15s;
}
.sort-btn:hover {
    border-color: var(--accent);
    color: var(--text);
}
.sort-btn.active {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

/* ─── Sites List ───────────────────────────────── */
.sites-list { display: flex; flex-direction: column; gap: 12px; }

.site-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    transition: border-color 0.15s;
}
.site-card:hover { border-color: var(--accent); }

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

.site-card-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.site-card-title h3 { font-size: 16px; margin: 0; }

.site-card-meta {
    display: flex;
    gap: 20px;
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 12px;
}

.site-card-meta span { display: flex; align-items: center; gap: 4px; }

.site-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ─── Buttons ──────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card-hover);
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #5a7aee; }

.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); background: rgba(248,113,113,0.1); }

.btn-success { color: var(--green); }
.btn-success:hover { border-color: var(--green); background: rgba(52,211,153,0.1); }

.btn-sm { padding: 4px 10px; font-size: 11px; }

.btn-visit {
    color: var(--accent);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.btn-visit:hover { border-color: var(--accent); background: var(--accent-glow); }

.btn-diag { color: var(--yellow); }
.btn-diag:hover { border-color: var(--yellow); background: rgba(251,191,36,0.1); }

.btn-rebuild { color: #f97316; border-color: #f97316; }
.btn-rebuild:hover { background: rgba(249,115,22,0.15); }

/* ─── Card ─────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
}

/* ─── Pre / Logs ───────────────────────────────── */
pre {
    background: #12141c;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    font-size: 12px;
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    color: var(--text-dim);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 500px;
    overflow-y: auto;
    line-height: 1.6;
}

.log-output { min-height: 300px; }

select {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}
select:focus { outline: none; border-color: var(--accent); }

/* ─── Modal ────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-overlay.show { display: flex; }

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.modal-header h2 { font-size: 18px; margin: 0; }

.btn-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
}
.btn-close:hover { color: var(--text); }

.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.form-group input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
}
.form-group input:focus { outline: none; border-color: var(--accent); }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

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

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 13px;
    animation: slideIn 0.2s ease;
    max-width: 320px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--accent); }

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

/* ─── Diagnostics ─────────────────────────────── */
.diag-loading { text-align: center; color: var(--text-dim); padding: 30px 0; }

.diag-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 16px 0 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.diag-section-title:first-child { margin-top: 0; }

.diag-checks { display: flex; flex-direction: column; gap: 4px; }

.diag-check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 13px;
    background: var(--bg);
}
.diag-check-row.diag-ok .diag-icon { color: var(--green); }
.diag-check-row.diag-warn .diag-icon { color: var(--yellow); }
.diag-check-row.diag-error .diag-icon { color: var(--red); }

.diag-icon { font-size: 14px; width: 18px; text-align: center; flex-shrink: 0; }
.diag-label { flex: 1; }
.diag-value { font-weight: 600; font-family: 'Cascadia Code', 'Fira Code', monospace; font-size: 12px; }
.diag-detail { color: var(--text-dim); font-size: 11px; }

.diag-ok {
    color: var(--green);
    padding: 10px;
    text-align: center;
    font-size: 13px;
}

.diag-issues { display: flex; flex-direction: column; gap: 8px; }

.diag-issue {
    padding: 10px 12px;
    border-radius: 8px;
    border-left: 3px solid;
}
.diag-issue.diag-warn { border-color: var(--yellow); background: rgba(251,191,36,0.06); }
.diag-issue.diag-error { border-color: var(--red); background: rgba(248,113,113,0.06); }

.diag-issue-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}
.diag-issue-msg { flex: 1; font-weight: 500; }
.diag-issue-detail { color: var(--text-dim); font-size: 12px; font-family: monospace; }

.diag-log-sample {
    margin: 8px 0 4px;
    font-size: 11px;
    max-height: 120px;
    padding: 8px;
}

.diag-fix-btn { margin-top: 6px; }

.diag-procs { font-size: 12px; }
.diag-proc-header, .diag-proc-row {
    display: grid;
    grid-template-columns: 80px 1fr 80px;
    gap: 8px;
    padding: 5px 10px;
}
.diag-proc-header {
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    font-size: 11px;
    border-bottom: 1px solid var(--border);
}
.diag-proc-row { font-family: 'Cascadia Code', 'Fira Code', monospace; }
.diag-proc-row:nth-child(even) { background: var(--bg); border-radius: 4px; }

/* ─── Page Analysis ────────────────────────────── */
.diag-timing {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}
.diag-timing-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 12px;
    background: var(--bg);
    border-radius: 6px;
    font-size: 13px;
}
.diag-timing-highlight {
    color: var(--accent);
    font-weight: 600;
}

.diag-subsection-title {
    font-size: 13px;
    color: var(--text-dim);
    margin: 10px 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.diag-asset-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}
.diag-asset-tag {
    display: inline-block;
    padding: 3px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 12px;
    color: var(--text-dim);
}

.diag-asset-table-wrap {
    overflow-x: auto;
    max-height: 250px;
    overflow-y: auto;
    margin-bottom: 12px;
}
.diag-asset-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.diag-asset-table th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    text-align: left;
    padding: 6px 8px;
    color: var(--text-dim);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    border-bottom: 1px solid var(--border);
}
.diag-asset-table td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.diag-asset-table tr:hover td {
    background: var(--bg);
}
.diag-asset-url {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 11px;
}
.diag-asset-table .diag-warn { color: var(--yellow); }
.diag-asset-table .diag-error { color: var(--red); }

/* ─── File Manager ─────────────────────────────── */
.fm-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
.fm-breadcrumb {
    font-size: 13px;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
}
.fm-bc-item {
    cursor: pointer;
    color: var(--accent);
    padding: 2px 4px;
    border-radius: 4px;
}
.fm-bc-item:hover { background: var(--accent-glow); }
.fm-bc-sep { color: var(--text-dim); margin: 0 2px; }
.fm-toolbar-actions { display: flex; gap: 6px; }
.fm-upload-btn { cursor: pointer; }

.fm-dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    margin-bottom: 12px;
    transition: all 0.15s;
}
.fm-dropzone:hover, .fm-dropzone.fm-dragover {
    border-color: var(--accent);
    background: var(--accent-glow);
    color: var(--accent);
}

.fm-table-wrap {
    overflow-x: auto;
    max-height: 350px;
    overflow-y: auto;
}
.fm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.fm-table th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    text-align: left;
    padding: 8px 10px;
    color: var(--text-dim);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}
.fm-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.fm-table tr:hover td { background: var(--bg); }
.fm-clickable {
    cursor: pointer;
    color: var(--accent);
}
.fm-clickable:hover { text-decoration: underline; }
.fm-empty {
    text-align: center;
    color: var(--text-dim);
    padding: 20px !important;
}

/* ─── Visitors ─────────────────────────────────── */
.visitor-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.visitor-table th, .visitor-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}
.visitor-table th {
    color: var(--text-dim);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
}
.visitor-table-scroll { overflow-x: auto; }
.visitor-time { font-size: 12px; color: var(--text-dim); }
.visitor-path { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.visitor-threat-row { background: rgba(248,113,113,0.06); }
.visitor-blocked-row { opacity: 0.5; }
.visitor-threat-text { color: var(--red); }
.visitor-top-list { font-size: 13px; line-height: 1.9; }
.text-dim { color: var(--text-dim); }

.blocked-form {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.blocked-form input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 12px;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
}
.blocked-form input:focus { outline: none; border-color: var(--accent); }

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

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px 36px;
    width: 100%;
    max-width: 380px;
}

.login-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    margin-bottom: 32px;
}

.login-error {
    background: rgba(248,113,113,0.1);
    border: 1px solid var(--red);
    border-radius: 8px;
    color: var(--red);
    font-size: 13px;
    padding: 10px 14px;
    margin-bottom: 18px;
    text-align: center;
}

.login-field {
    margin-bottom: 18px;
}
.login-field label {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.login-field input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s;
}
.login-field input:focus {
    outline: none;
    border-color: var(--accent);
}

.login-btn {
    width: 100%;
    padding: 11px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
    margin-top: 6px;
}
.login-btn:hover { background: #5a7aee; }

/* ─── Responsive ───────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar .logo span, .nav-item span { display: none; }
    .logo { padding: 0 14px 20px; justify-content: center; }
    .nav-item { justify-content: center; padding: 10px; }
    .content { margin-left: 60px; padding: 20px 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .info-row { grid-template-columns: repeat(2, 1fr); }
}
