:root {
    --color-bg: #f4f6f9;
    --color-surface: #ffffff;
    --color-border: #e3e7ed;
    --color-text: #1f2530;
    --color-text-muted: #6b7280;
    --color-primary: #2952e3;
    --color-primary-dark: #1e3fb8;
    --color-primary-soft: #eef1fd;
    --color-success: #17a673;
    --color-success-soft: #e7f8f1;
    --color-danger: #e0393e;
    --color-danger-soft: #fdecec;
    --color-warning: #d99a1b;
    --radius: 10px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 16px rgba(16, 24, 40, 0.08);
    --sidebar-width: 250px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Login page ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(155deg, #101a3d 0%, #1c2f6b 45%, #2952e3 100%);
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 40px 36px;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
}

.login-brand .logo-mark {
    width: 38px;
    height: 38px;
    border-radius: 9px;
    background: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 16px;
}

.login-brand .brand-name {
    font-weight: 700;
    font-size: 17px;
    color: var(--color-text);
}

.login-brand .brand-name span {
    display: block;
    font-weight: 400;
    font-size: 11px;
    color: var(--color-text-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.form-group { margin-bottom: 18px; }

.form-group label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 14px;
    font-family: var(--font);
    background: #fbfcfe;
    transition: border-color .15s, box-shadow .15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
    background: white;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    transition: background .15s, opacity .15s;
}

.btn-primary { background: var(--color-primary); color: white; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-block { width: 100%; }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border); }
.btn-secondary:hover { background: #f0f2f6; }
.btn-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.btn-danger:hover { background: #f9d6d7; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }

.alert {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
}
.alert-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.alert-success { background: var(--color-success-soft); color: var(--color-success); }

.login-footnote {
    margin-top: 20px;
    font-size: 12px;
    color: var(--color-text-muted);
    text-align: center;
}

/* ---------- App shell ---------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: #12183a;
    color: #cfd6ee;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand .logo-mark {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

.sidebar-brand .brand-name {
    color: white;
    font-weight: 700;
    font-size: 14.5px;
    line-height: 1.2;
}
.sidebar-brand .brand-name span {
    display: block;
    font-weight: 400;
    font-size: 10.5px;
    color: #8b93bd;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.sidebar-nav { padding: 16px 12px; flex: 1; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: #c3cbe8;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 2px;
    transition: background .15s, color .15s;
}
.nav-item .nav-icon { width: 18px; text-align: center; opacity: 0.85; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: white; }
.nav-item.active { background: var(--color-primary); color: white; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 12.5px;
}
.sidebar-footer .user-line { color: #cfd6ee; margin-bottom: 8px; }
.sidebar-footer a { color: #9fa8d1; }

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 16px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; }
.topbar .topbar-sub { color: var(--color-text-muted); font-size: 12.5px; margin-top: 2px; }

.content { padding: 28px; flex: 1; }

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

/* ---------- Stat cards ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--color-text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-card .stat-value {
    font-size: 26px;
    font-weight: 700;
    margin-top: 6px;
}

.stat-card.up .stat-value { color: var(--color-success); }
.stat-card.down .stat-value { color: var(--color-danger); }

/* ---------- Cards / panels ---------- */
.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.panel-header h2 { font-size: 15px; margin: 0; font-weight: 700; }
.panel-body { padding: 20px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td {
    text-align: left;
    padding: 10px 12px;
    font-size: 13.5px;
    border-bottom: 1px solid var(--color-border);
}
th { color: var(--color-text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafbfd; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 600;
}
.badge-up { background: var(--color-success-soft); color: var(--color-success); }
.badge-down { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-unknown { background: #f0f1f5; color: var(--color-text-muted); }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.group-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 26px 0 10px;
}
.group-title-row:first-child { margin-top: 0; }
.group-title-row h3 { font-size: 14.5px; margin: 0; }
.group-meta { font-size: 12px; color: var(--color-text-muted); }

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

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15, 20, 40, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}
.modal-backdrop.active { display: flex; }

.modal {
    background: var(--color-surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 460px;
    box-shadow: var(--shadow-md);
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--color-border);
}
.modal-header h3 { margin: 0; font-size: 15px; }
.modal-close { cursor: pointer; color: var(--color-text-muted); font-size: 18px; background: none; border: none; }
.modal-body { padding: 20px; max-height: 70vh; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 8px; }

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

.text-muted { color: var(--color-text-muted); }
.mt-0 { margin-top: 0; }

.actions-cell { display: flex; gap: 8px; }

@media (max-width: 780px) {
    .sidebar { position: fixed; z-index: 50; height: 100vh; transform: translateX(-100%); transition: transform .2s; }
    .sidebar.open { transform: translateX(0); }
    .content { padding: 16px; }
    .topbar { padding: 14px 16px; }
}
