:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --surface-muted: #eef3f8;
    --border: #dbe4ee;
    --text: #172033;
    --muted: #67768a;
    --primary: #315f9f;
    --primary-soft: #e8f0fb;
    --success: #198754;
    --warning: #b7791f;
    --danger: #c2413a;
    --info: #2563eb;
    --shadow: 0 12px 30px rgba(20, 35, 60, .07);
    --radius: 8px;
    --sidebar: #111827;
    --sidebar-text: #d7dee9;
    --sidebar-muted: #9ca3af;
    --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
button, .btn {
    border: 0;
    border-radius: 8px;
    padding: 10px 13px;
    background: var(--primary);
    color: white;
    font-weight: 700;
    font-size: 13px;
    box-shadow: 0 8px 18px rgba(49, 95, 159, .16);
    cursor: pointer;
}
button.secondary, .btn.secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: none;
}

.app { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar {
    background: linear-gradient(180deg, var(--sidebar), #0b1220);
    color: var(--sidebar-text);
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 16px; }
.logo { width: 42px; height: 42px; border-radius: 8px; background: linear-gradient(135deg, #315f9f, #87b4e8); display: grid; place-items: center; color: white; font-weight: 800; }
.brand small { display: block; color: var(--sidebar-muted); margin-top: 2px; }
.nav-section { margin: 20px 0 8px; color: var(--sidebar-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 0 10px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; margin: 2px 0; color: var(--sidebar-text); font-size: 14px; }
.nav a:hover, .nav a.active { background: rgba(255, 255, 255, .09); }
.nav .dot { width: 8px; height: 8px; border-radius: 999px; background: #6b7280; flex: 0 0 auto; }
.nav a.active .dot { background: #8ec5ff; }

.main { padding: 24px 30px 42px; min-width: 0; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; gap: 18px; }
.topbar-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.breadcrumb { color: var(--muted); font-size: 14px; margin-bottom: 6px; }
h1 { font-size: 30px; line-height: 1.12; margin: 0; }
.page-subtitle { color: var(--muted); margin: 8px 0 0; max-width: 840px; }
.search { display: flex; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 10px 14px; min-width: 320px; color: var(--muted); }
.userbox { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 8px 12px; }
.userbox small { color: var(--muted); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; }
.mobile-menu { display: none; }

.grid { display: grid; gap: 18px; }
.grid.kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; }
.grid.two { grid-template-columns: 1.4fr .9fr; }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mt { margin-top: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.card h2 { font-size: 18px; margin: 0 0 14px; }
.kpi-card { padding: 18px; }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { font-size: 31px; font-weight: 800; margin: 8px 0 4px; }
.kpi-foot { font-size: 13px; color: var(--muted); }
.good { color: var(--success); }
.warn { color: var(--warning); }
.bad { color: var(--danger); }
.blue { color: var(--info); }
.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 650; background: var(--surface-muted); color: var(--muted); white-space: nowrap; }
.badge.ok { background: #e8f7ee; color: var(--success); }
.badge.warn { background: #fff4de; color: var(--warning); }
.badge.bad { background: #fdebea; color: var(--danger); }
.badge.blue { background: #e8f0fb; color: var(--primary); }
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 14px; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); }
th, td { padding: 13px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-soft); }
tr:last-child td { border-bottom: 0; }
.mini-list { display: grid; gap: 12px; }
.list-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 13px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-soft); }
.list-title { font-weight: 750; }
.list-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.timeline { display: grid; gap: 13px; }
.timeline-item { display: grid; grid-template-columns: 12px 1fr; gap: 11px; }
.timeline-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--primary); margin-top: 5px; }
.panel-row { display: grid; grid-template-columns: 160px 1fr; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.panel-row:last-child { border-bottom: 0; }
.field { min-height: 42px; border: 1px solid var(--border); border-radius: 8px; background: white; padding: 10px 12px; display: flex; align-items: center; color: var(--muted); }
.progress { height: 10px; background: var(--surface-muted); border-radius: 999px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.stat-bar { display: grid; gap: 8px; }
.stat-row { display: grid; grid-template-columns: 140px 1fr 48px; gap: 10px; align-items: center; font-size: 13px; }
.footer-note { margin-top: 18px; color: var(--muted); font-size: 12px; }
.toolbar-surface { margin-bottom: 18px; box-shadow: none; }
.filter-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; align-items: center; }
.filter-form input, .filter-form select { height: 42px; border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; background: white; color: var(--text); font: inherit; min-width: 0; }

.map-canvas {
    height: 520px;
    border-radius: 8px;
    background: radial-gradient(circle at 25% 30%, rgba(49,95,159,.15), transparent 22%),
        radial-gradient(circle at 70% 65%, rgba(25,135,84,.13), transparent 25%),
        linear-gradient(135deg, #f7fbff, #eef4fb);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}
.node { position: absolute; background: white; border: 1px solid var(--border); box-shadow: 0 12px 24px rgba(20,35,60,.10); border-radius: 8px; padding: 12px 14px; min-width: 120px; }
.node strong { display: block; font-size: 13px; }
.node span { font-size: 12px; color: var(--muted); }
.node small { display: block; margin-top: 4px; font-size: 11px; color: var(--primary); }
.container-node { min-width: 170px; min-height: 72px; background: rgba(255,255,255,.72); border: 1px dashed var(--primary); }
.map-edge { position: relative; display: inline-flex; margin: 4px; border-radius: 999px; padding: 4px 8px; font-size: 11px; color: var(--primary); background: var(--primary-soft); z-index: 1; }
.node.n1 { left: 8%; top: 42%; }
.node.n2 { left: 28%; top: 25%; }
.node.n3 { left: 47%; top: 44%; }
.node.n4 { left: 68%; top: 22%; }
.node.n5 { left: 72%; top: 64%; }
.node.n6 { left: 30%; top: 70%; }
.line { position: absolute; height: 2px; background: rgba(49,95,159,.25); transform-origin: left center; }
.line.l1 { left: 19%; top: 47%; width: 170px; transform: rotate(-22deg); }
.line.l2 { left: 39%; top: 33%; width: 160px; transform: rotate(28deg); }
.line.l3 { left: 57%; top: 48%; width: 145px; transform: rotate(-28deg); }
.line.l4 { left: 57%; top: 52%; width: 165px; transform: rotate(22deg); }
.line.l5 { left: 39%; top: 74%; width: 130px; transform: rotate(-24deg); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 420px); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 26px; }
.login-brand { border-bottom: 0; margin-bottom: 18px; padding: 0; }
.login-form { display: grid; gap: 10px; margin-top: 20px; }
.login-form label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.login-form input { height: 44px; border: 1px solid var(--border); border-radius: 8px; padding: 0 12px; font: inherit; }
.alert { border-radius: 8px; padding: 12px; margin-top: 16px; background: #fdebea; color: var(--danger); }
.flash { border-radius: 8px; padding: 12px 14px; margin: 0 0 18px; border: 1px solid var(--border); background: var(--surface); font-weight: 650; }
.flash.success { background: #e8f7ee; color: var(--success); border-color: #bfe8cf; }
.flash.error { background: #fdebea; color: var(--danger); border-color: #f3c5c1; }
.user-create-form { display: grid; grid-template-columns: minmax(180px, 1.2fr) minmax(220px, 1.4fr) 140px minmax(260px, 1.5fr) auto; gap: 10px; align-items: center; }
.user-create-form input, .user-create-form select, .profile-form input, .user-admin-row input, .user-admin-row select {
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0 10px;
    background: white;
    color: var(--text);
    font: inherit;
    min-width: 0;
}
.role-checks { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; font-size: 12px; color: var(--muted); }
.role-checks label { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.users-grid { display: grid; gap: 12px; }
.user-admin-row { border: 1px solid var(--border); border-radius: 8px; background: var(--surface-soft); padding: 12px; display: grid; gap: 10px; }
.user-admin-row form { display: grid; grid-template-columns: minmax(260px, 1.5fr) minmax(240px, 1.1fr) 130px auto; gap: 10px; align-items: center; }
.user-admin-main { display: grid; grid-template-columns: 42px 1fr; gap: 10px; align-items: center; min-width: 0; }
.user-row-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.user-row-actions form { display: block; }
.profile-form { display: grid; gap: 10px; }
.profile-form label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

@media (max-width: 1100px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { display: none; position: fixed; z-index: 20; width: 280px; }
    body.sidebar-open .sidebar { display: block; }
    .mobile-menu { display: inline-flex; margin-right: 8px; }
    .grid.kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid.two { grid-template-columns: 1fr; }
    .search { min-width: 0; }
    .user-create-form, .user-admin-row form { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .main { padding: 18px; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .topbar-actions { justify-content: flex-start; }
    .grid.kpi, .grid.three { grid-template-columns: 1fr; }
    .panel-row { grid-template-columns: 1fr; }
    .stat-row { grid-template-columns: 1fr; }
    .filter-form { grid-template-columns: 1fr; }
}
