:root {
    --bg: #f3f5f9;
    --panel: #ffffff;
    --panel-2: #eef1f7;
    --border: #dde3ee;
    --text: #1a2233;
    --text-dim: #64708a;
    --accent: #3b74e0;
    --accent-dim: rgba(59,116,224,.10);
    --ok: #188a53;
    --warn: #b3790a;
    --down: #d1373f;
    --sidebar-w: 232px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

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

.sidebar {
    flex: 0 0 var(--sidebar-w);
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, var(--panel), var(--bg) 220%);
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px 20px 22px;
    border-bottom: 1px solid var(--border);
}
.brand-logo { height: 84px; width: auto; display: block; }
.login-logo { height: 84px; width: auto; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; padding: 16px 12px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--text-dim);
    text-decoration: none;
    font-weight: 500;
    font-size: 13.5px;
    border-left: 3px solid transparent;
    transition: background .15s, color .15s, border-color .15s;
}
.nav-item svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--text); border-left-color: var(--accent); }

.nav-submenu {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 2px 0 8px 34px;
    padding-left: 12px;
    border-left: 1px solid var(--border);
}
.nav-subitem {
    padding: 6px 10px;
    border-radius: 6px;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 12.5px;
    transition: background .15s, color .15s;
}
.nav-subitem:hover { background: var(--panel-2); color: var(--text); }
.nav-subitem.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; }

.nav-subgroup { display: flex; flex-direction: column; }
.nav-subsubmenu {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin: 1px 0 4px 14px;
    padding-left: 10px;
    border-left: 1px dashed var(--border);
}
.nav-subsubitem {
    padding: 4px 10px;
    border-radius: 5px;
    color: var(--text-dim);
    opacity: .8;
    text-decoration: none;
    font-size: 11.5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    transition: background .15s, color .15s, opacity .15s;
}
.nav-subsubitem:hover { background: var(--panel-2); color: var(--text); opacity: 1; }

.sidebar-footer {
    margin-top: auto;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-dim);
}
.sidebar-footer a { color: var(--accent); text-decoration: none; font-weight: 500; }
.sidebar-footer a:hover { text-decoration: underline; }

.app-main { flex: 1; min-width: 0; }

.container { max-width: 1200px; margin: 0 auto; padding: 32px; }

h1 { font-size: 21px; margin: 0 0 20px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 24px 0 12px; color: var(--text-dim); }

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 1px 3px rgba(20,30,60,.06);
}

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

.device-card {
    display: block; text-decoration: none; color: var(--text);
    transition: border-color .15s, transform .15s, box-shadow .15s;
}
.device-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 20px rgba(20,30,60,.10); }
.device-card .name { font-weight: 600; margin-bottom: 4px; }
.device-card .ip { color: var(--text-dim); font-size: 12px; }
.device-card .badges { margin-top: 10px; display: flex; gap: 8px; font-size: 12px; }

.badge { padding: 3px 10px; border-radius: 999px; font-weight: 600; }
.badge.up { background: rgba(47,191,113,.15); color: var(--ok); }
.badge.down { background: rgba(239,75,86,.15); color: var(--down); }
.badge.unknown { background: rgba(147,160,189,.15); color: var(--text-dim); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--text-dim); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .04em; }
tr:hover td { background: rgba(0,0,0,.025); }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.up { background: var(--ok); }
.status-dot.down { background: var(--down); }
.status-dot.unknown { background: var(--text-dim); }

.tabs { display: flex; gap: 8px; margin-bottom: 22px; }
.tabs a {
    padding: 9px 18px; border-radius: 8px; text-decoration: none; color: var(--text-dim);
    background: var(--panel); border: 1px solid var(--border); font-weight: 500;
    transition: border-color .15s, color .15s;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); background: var(--accent-dim); border-color: var(--accent); }

.ip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.ip-cell {
    padding: 8px; border-radius: 6px; font-size: 12px; border: 1px solid var(--border);
    background: var(--panel-2); cursor: default; transition: border-color .15s;
}
.ip-cell.used { border-color: var(--warn); background: rgba(179,121,10,.08); }
.ip-cell.free { border-color: var(--ok); background: rgba(24,138,83,.06); }
.ip-cell.undocumented { border-color: #8a5cf5; background: rgba(138,92,245,.08); }
.ip-cell:hover { border-color: var(--accent); }
.ip-cell .addr { font-weight: 600; display: block; }
.ip-cell .meta { color: var(--text-dim); font-size: 11px; display: block; margin-top: 2px; }

.summary-bar { display: flex; gap: 24px; }
.summary-bar .stat { color: var(--text-dim); font-size: 13px; }
.summary-bar .stat b { color: var(--text); font-size: 20px; display: block; }

.usage-row { display: flex; align-items: stretch; gap: 24px; margin-bottom: 18px; flex-wrap: wrap; }
.usage-card {
    flex: 1 1 320px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    padding: 16px 20px 20px; min-width: 0;
}
.usage-card h3 { margin: 0 0 14px; font-size: 13px; font-weight: 600; color: var(--text-dim); padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.usage-chart-wrap { position: relative; width: 100%; height: 260px; }
.usage-chart-wrap canvas { width: 100% !important; height: 100% !important; }

.threshold-row { margin-bottom: 16px; }
.threshold-bar {
    display: flex; height: 30px; border-radius: 6px; overflow: hidden;
    background: var(--panel-2); border: 1px solid var(--border);
}
.threshold-bar .seg {
    height: 100%; display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 11px; font-weight: 700; white-space: nowrap;
    transition: width .3s;
}
.threshold-legend { display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--text-dim); }
.threshold-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

.subnet-calc { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.subnet-calc .form-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.subnet-calc .form-row input[type="text"] { width: 110px; min-width: 0; }
.subnet-calc .form-row button { padding: 8px 12px; border-radius: 6px; border: none; background: var(--accent); color: #fff; font-weight: 600; font-size: 12.5px; white-space: nowrap; cursor: pointer; transition: filter .15s; }
.subnet-calc .form-row button:hover { filter: brightness(1.1); }
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.calc-field { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.calc-field.full { grid-column: 1 / -1; }
.calc-field label { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); margin-bottom: 3px; }
.calc-field .val { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; font-weight: 600; }

.login-wrap {
    display: flex; align-items: center; justify-content: center; min-height: 100vh;
    background: radial-gradient(600px circle at 50% 30%, rgba(76,141,255,.08), transparent 70%);
}
.login-card { width: 340px; padding: 32px; border-radius: 14px; box-shadow: 0 16px 48px rgba(20,30,60,.12); }
.login-card h1 { text-align: center; margin-bottom: 24px; }
.login-card input {
    width: 100%; padding: 11px 12px; margin-bottom: 12px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--bg); color: var(--text);
    transition: border-color .15s;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button {
    width: 100%; padding: 11px; border-radius: 8px; border: none;
    background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
    transition: filter .15s;
}
.login-card button:hover { filter: brightness(1.1); }
.error { color: var(--down); margin-bottom: 12px; font-size: 13px; }

.notice { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; border: 1px solid; }
.notice.ok { background: rgba(47,191,113,.12); color: var(--ok); border-color: rgba(47,191,113,.3); }
.notice.error { background: rgba(239,75,86,.12); color: var(--down); border-color: rgba(239,75,86,.3); }

.device-form .form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.device-form input, .device-form select {
    padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: 13px;
}
.device-form input[name="name"] { flex: 1 1 160px; }
.device-form input[name="ip"] { flex: 0 1 140px; }
.device-form input[name="snmp_community"] { flex: 1 1 160px; }
.device-form input[name="snmp_port"] { width: 80px; }
.device-form button {
    padding: 8px 16px; border-radius: 6px; border: none;
    background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}

.subnet-block { margin-bottom: 32px; scroll-margin-top: 24px; }
.subnet-title { display: flex; justify-content: space-between; align-items: baseline; }
.subnet-title .desc { color: var(--text-dim); font-size: 12px; }

canvas { max-width: 100%; }
.chart-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 20px; }
.range-select a { color: var(--text-dim); text-decoration: none; margin-right: 12px; font-size: 12px; }
.range-select a.active { color: var(--accent); font-weight: 600; }

.rrd-summary { margin-top: 16px; width: auto; }
.rrd-summary th { font-weight: 600; color: var(--text-dim); padding: 4px 14px 4px 0; border: none; }
.rrd-summary td { padding: 3px 14px 3px 0; border: none; font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.rrd-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
