*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #242836;
    --border: #2e3348;
    --text: #e2e4eb;
    --text2: #8b90a5;
    --accent: #4f8ff7;
    --green: #34d399;
    --red: #f87171;
    --orange: #fbbf24;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ─── Layout ─────────────────────────────── */

.shell {
    display: flex;
    min-height: 100vh;
}

nav {
    width: 230px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 24px 0;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

nav .logo {
    padding: 0 24px 24px;
    font-size: 17px;
    font-weight: 700;
    color: var(--accent);
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}

nav .logo small {
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: var(--text2);
    margin-top: 3px;
    letter-spacing: 0.3px;
}

nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 24px;
    color: var(--text2);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.15s;
    cursor: pointer;
}

nav a i, nav a svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

nav a:hover, nav a.active {
    color: var(--text);
    background: var(--surface2);
}

nav a.active { border-left: 3px solid var(--accent); padding-left: 21px; }

/* ─── Content Area ───────────────────────── */

.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 12px 32px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.top-bar-left { flex: 1; }

.top-bar-auth {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
}

.top-bar-auth a {
    color: var(--text2);
    text-decoration: none;
    transition: color 0.15s;
}

.top-bar-auth a:hover {
    color: var(--text);
}

.top-bar-username {
    font-weight: 600;
    color: var(--accent);
    font-size: 13px;
}

main {
    flex: 1;
    padding: 28px 36px;
    max-width: 1200px;
    overflow-x: hidden;
}

h1 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 24px;
}

/* ─── Cards ──────────────────────────────── */

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
}

.card .label { font-size: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }
.card .value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.card .value.green { color: var(--green); }
.card .value.red { color: var(--red); }
.card .value.accent { color: var(--accent); }

/* ─── Table ──────────────────────────────── */

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    text-align: left;
    padding: 12px 14px;
    color: var(--text2);
    font-weight: 500;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

thead th:hover { color: var(--text); }
thead th .sort-arrow { margin-left: 4px; font-size: 10px; }

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

tbody tr:hover { background: var(--surface2); }

td {
    padding: 12px 14px;
    vertical-align: middle;
}

.dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}

.dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.off { background: var(--red); }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}

.badge.client { background: rgba(79,143,247,0.15); color: var(--accent); }
.badge.sc { background: rgba(251,191,36,0.15); color: var(--orange); }
.badge.ic { background: rgba(52,211,153,0.15); color: var(--green); }

/* ─── Buttons ────────────────────────────── */

.btn {
    padding: 8px 18px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn:hover { background: var(--border); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { opacity: 0.9; }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: rgba(248,113,113,0.1); }
.btn.sm { padding: 5px 12px; font-size: 12px; }

/* Probe spinner */
.probe-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: probe-spin 0.6s linear infinite;
    vertical-align: middle;
}
.btn.sm .probe-spinner {
    width: 12px;
    height: 12px;
    border-width: 2px;
    border-color: rgba(100,100,100,0.3);
    border-top-color: var(--accent);
}
@keyframes probe-spin {
    to { transform: rotate(360deg); }
}

.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar .spacer { flex: 1; }

.search-input {
    padding: 8px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    width: 260px;
}

.search-input::placeholder { color: var(--text2); }

/* ─── Modal ──────────────────────────────── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px;
    width: 90%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal h2 {
    font-size: 18px;
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text2);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 9px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
}

.form-group textarea { min-height: 120px; resize: vertical; font-family: monospace; font-size: 12px; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.checkbox-row input[type=checkbox] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

/* ─── Chart ──────────────────────────────── */

.chart-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.chart-container h3 {
    font-size: 14px;
    color: var(--text2);
    margin-bottom: 14px;
}

canvas { width: 100% !important; height: 200px !important; }

/* ─── Station Detail ─────────────────────── */

.detail-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.detail-header .back {
    color: var(--text2);
    cursor: pointer;
    font-size: 20px;
    text-decoration: none;
}

.detail-header .back:hover { color: var(--text); }

.detail-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.meta-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
}

.meta-item .label { font-size: 11px; color: var(--text2); text-transform: uppercase; }
.meta-item .val { font-size: 18px; font-weight: 600; margin-top: 4px; }

/* ─── XRay ───────────────────────────────── */

.xray-pre {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    font-size: 12px;
    color: var(--text);
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ─── Toast ──────────────────────────────── */

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 22px;
    border-radius: var(--radius);
    font-size: 13px;
    z-index: 200;
    animation: slideIn 0.3s;
}

.toast.success { background: var(--green); color: #000; }
.toast.error { background: var(--red); color: #fff; }

@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } }

/* ─── Import Results ─────────────────────── */

.import-results {
    margin-top: 14px;
    padding: 14px;
    border-radius: var(--radius);
    background: var(--surface2);
    font-size: 13px;
}

.import-results .ok { color: var(--green); }
.import-results .err { color: var(--red); font-family: monospace; font-size: 11px; }

/* ─── Sparkline (inline SVG) ─────────────── */

.sparkline { vertical-align: middle; }

/* ─── Auth Pages ─────────────────────────── */

.auth-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 36px;
    width: 100%;
    max-width: 400px;
}

.auth-card h1 {
    font-size: 20px;
    margin-bottom: 24px;
    text-align: center;
}

.auth-card .btn.full {
    width: 100%;
    justify-content: center;
    padding: 10px;
    font-size: 14px;
    margin-top: 8px;
}

.auth-error {
    background: rgba(248,113,113,0.1);
    border: 1px solid var(--red);
    color: var(--red);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 14px;
}

.auth-link {
    text-align: center;
    font-size: 13px;
    color: var(--text2);
    margin-top: 20px;
}

.auth-link a {
    color: var(--accent);
    text-decoration: none;
}

.auth-link a:hover {
    text-decoration: underline;
}

.auth-notice {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    color: var(--text2);
    font-size: 14px;
}

.auth-notice a {
    color: var(--accent);
    text-decoration: none;
}

/* ─── Player Bar ─────────────────────────── */

#player-bar {
    animation: slideUp 0.3s ease;
}

#player-bar span:first-child {
    font-size: 22px;
    line-height: 1;
}

#player-bar #player-flag img {
    width: 24px;
    height: 18px;
    border-radius: 2px;
    object-fit: cover;
}

#player-bar #player-name {
    color: var(--text);
    font-size: 14px;
}

#player-bar .btn.sm {
    padding: 6px 14px;
}

@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ─── Responsive ─────────────────────────── */

@media (max-width: 768px) {
    nav { display: none; }
    .top-bar { padding: 10px 16px; }
    main { padding: 20px 16px; }
    .form-row { grid-template-columns: 1fr; }
    .cards { grid-template-columns: 1fr 1fr; }
    #player-bar { padding: 10px 12px; }
    #player-bar #player-name { font-size: 13px; }
    #player-bar .btn.sm { padding: 5px 10px; font-size: 11px; }
}
