:root {
    --bg: #0b0f14;
    --panel: #121820;
    --panel-2: #18202a;
    --line: #232d39;
    --text: #e6edf3;
    --muted: #8b98a7;
    --accent: #2ee6a0;
    --accent-ink: #04140d;
    --blue: #5ab0ff;
    --amber: #f5b84b;
    --red: #ff6b6b;
    --grey: #66717e;
    --radius: 14px;
    --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 10px 30px rgba(0,0,0,.25);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    background: radial-gradient(1200px 600px at 80% -10%, rgba(46,230,160,.06), transparent 60%), var(--bg);
    color: var(--text);
    font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.pos { color: var(--accent); }
.neg { color: var(--red); }
.warn { color: var(--amber); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; gap: 18px;
    padding: 18px 14px; background: rgba(10,14,19,.85); border-right: 1px solid var(--line);
    backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); padding: 4px 8px; }
.brand:hover { text-decoration: none; }
.brand img { border-radius: 9px; }
.brand span { display: flex; flex-direction: column; font-weight: 700; line-height: 1.15; }
.brand small { font-weight: 500; color: var(--muted); font-size: 11px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
    display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
    color: var(--muted); font-weight: 550;
}
.sidebar nav a svg { width: 18px; height: 18px; fill: currentColor; opacity: .9; }
.sidebar nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.sidebar nav a.active { background: rgba(46,230,160,.1); color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 6px 0; border-top: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: 8px; min-width: 0; }
.me span:last-child { display: flex; flex-direction: column; font-weight: 600; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me small { color: var(--muted); font-weight: 500; }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 800; flex: none; }

.main { min-width: 0; padding: 20px 28px 48px; display: flex; flex-direction: column; gap: 18px; }
.topbar { display: flex; align-items: center; gap: 14px; min-height: 48px; }
.topbar > div:nth-child(2) { flex: 1; min-width: 0; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.topbar-actions form { margin: 0; }
.crumbs { font-size: 12px; color: var(--muted); display: flex; gap: 6px; }
.crumbs a { color: var(--muted); }
.menu-toggle { display: none; }

/* ---------- controls ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
    background: var(--panel-2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
    transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: #33404f; text-decoration: none; background: #1d2632; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #4cf0b2; border-color: #4cf0b2; }
.btn-danger { background: transparent; border-color: rgba(255,107,107,.45); color: var(--red); }
.btn-danger:hover { background: rgba(255,107,107,.1); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.icon-btn { background: none; border: 0; color: var(--text); padding: 6px; cursor: pointer; }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

input, select, textarea {
    width: 100%; height: 38px; padding: 0 12px; border-radius: 10px;
    border: 1px solid var(--line); background: #0e141b; color: var(--text); font: inherit;
}
input:focus, select:focus { outline: 2px solid rgba(46,230,160,.35); border-color: var(--accent); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
input[readonly], select:disabled { opacity: .6; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 12.5px; color: #c4ced9; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; grid-column: 1 / -1; }

/* ---------- cards & layout ---------- */
.card {
    background: linear-gradient(180deg, rgba(255,255,255,.015), transparent), var(--panel);
    border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 12px; min-width: 0;
}
.card-flush { padding: 0; overflow: hidden; gap: 0; }
.card-flush > .card-head { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi > span { color: var(--muted); font-size: 12px; font-weight: 600; }
.kpi strong { font-size: 26px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; transition: color .4s; }
.kpi strong.bump { color: var(--accent); }
.kpi small { color: var(--muted); }
.kpi-online { border-color: rgba(46,230,160,.35); background: linear-gradient(180deg, rgba(46,230,160,.08), transparent), var(--panel); }
.kpi-online strong { color: var(--accent); }
.big-number { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }

.props { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; margin: 0; }
.props dt { color: var(--muted); }
.props dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 18px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; background: rgba(255,255,255,.015); }
.table th.num, .table td.num { text-align: right; }
.table tbody tr:hover { background: rgba(255,255,255,.02); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.empty { text-align: center; color: var(--muted); padding: 28px; }
.table form { margin: 0; }
.card-flush { overflow-x: auto; }
.details { max-width: 420px; overflow-wrap: anywhere; color: var(--muted); }

.filters { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px; }
.filters input[type=search] { flex: 1 1 260px; width: auto; }
.filters select { width: auto; min-width: 150px; }

/* ---------- badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px;
    font-size: 11.5px; font-weight: 650; text-transform: capitalize; white-space: nowrap;
    background: rgba(139,152,167,.14); color: #c3ccd6;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge-online, .badge-active, .badge-delivered, .badge-paid, .badge-completed, .badge-approved { background: rgba(46,230,160,.12); color: var(--accent); }
.badge-idle, .badge-leased, .badge-pending, .badge-sending, .badge-queued { background: rgba(245,184,75,.12); color: var(--amber); }
.badge-sent, .badge-shared, .badge-dedicated { background: rgba(90,176,255,.12); color: var(--blue); }
.badge-offline { background: rgba(102,113,126,.18); color: #9aa5b1; }
.badge-revoked, .badge-suspended, .badge-failed, .badge-rejected, .badge-canceled, .badge-disabled { background: rgba(255,107,107,.12); color: var(--red); }

.battery { display: inline-block; vertical-align: middle; width: 26px; height: 11px; border: 1.5px solid #6b7785; border-radius: 3px; padding: 1px; position: relative; margin-right: 4px; }
.battery::after { content: ""; position: absolute; right: -4px; top: 3px; width: 2px; height: 4px; background: #6b7785; border-radius: 0 1px 1px 0; }
.battery i { display: block; height: 100%; background: var(--accent); border-radius: 1px; }
.battery.mid i { background: var(--amber); }
.battery.low i { background: var(--red); }

/* ---------- alerts ---------- */
.alert { padding: 12px 16px; border-radius: 12px; border: 1px solid; }
.alert ul { margin: 6px 0 0 18px; padding: 0; }
.alert-success { background: rgba(46,230,160,.08); border-color: rgba(46,230,160,.35); color: #b6f5dc; }
.alert-error { background: rgba(255,107,107,.08); border-color: rgba(255,107,107,.4); color: #ffc9c9; }
.alert-info { background: rgba(90,176,255,.08); border-color: rgba(90,176,255,.35); color: #cfe6ff; }

/* ---------- forms ---------- */
.form { max-width: 860px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 6px; }
.checklist { max-height: 230px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; }
.checklist label { flex-direction: row; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; font-weight: 500; cursor: pointer; }
.checklist label:hover { background: var(--panel-2); }
.checklist label.hidden { display: none; }
.list-search { height: 32px; }

/* ---------- circuits ---------- */
.circuit-card { color: var(--text); transition: border-color .15s, transform .15s; }
.circuit-card:hover { text-decoration: none; border-color: rgba(46,230,160,.4); transform: translateY(-2px); }
.circuit-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.circuit-stats div, .map-stats div { display: flex; flex-direction: column; }
.circuit-stats strong, .map-stats strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.circuit-stats span, .map-stats span { color: var(--muted); font-size: 11.5px; }

/* ---------- pager ---------- */
.pagination { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0; justify-content: center; }
.pagination a { display: grid; place-items: center; min-width: 34px; height: 34px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.pagination .active a { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- live ---------- */
.live-dot { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 0 rgba(46,230,160,.6); animation: ping 1.8s infinite; }
.live-dot.stale { color: var(--amber); }
.live-dot.down { color: var(--red); }
.live-dot.down::before, .live-dot.stale::before { animation: none; }

.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 360px; overflow: auto; }
.feed li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 6px; border-radius: 8px; font-size: 13px; }
.feed li.new { animation: flash 1.6s ease-out; }
.feed .t { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }

/* ---------- maps ---------- */
.map { background: #0d1319; }
.map-compact { height: 380px; }
.map-full { height: calc(100vh - 150px); min-height: 480px; }
.map-mini { height: 220px; }
.map-picker { height: 360px; border-radius: 12px; border: 1px solid var(--line); }
.map-caption { margin: 0; padding: 10px 14px; }
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; }
.map-card { position: relative; }
.map-legend { position: absolute; left: 12px; bottom: 12px; z-index: 500; display: flex; flex-wrap: wrap; gap: 10px; padding: 8px 12px; border-radius: 10px; background: rgba(11,15,20,.85); border: 1px solid var(--line); font-size: 12px; }
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-online { background: var(--accent); } .dot-idle { background: var(--amber); } .dot-offline { background: var(--grey); }
.dot-revoked { background: var(--red); } .dot-approx { border: 1.5px dashed #c3ccd6; }
.map-side { max-height: calc(100vh - 110px); overflow: auto; gap: 6px; }
.map-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.map-filters { display: flex; gap: 8px; margin-top: 8px; }
.device-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.device-list li { display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; align-items: center; padding: 8px; border-radius: 8px; cursor: pointer; }
.device-list li:hover { background: var(--panel-2); }
.device-list .meta { color: var(--muted); font-size: 11.5px; }

.leaflet-container { background: #0d1319; font: inherit; }
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9) saturate(.35); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 12px 14px; min-width: 210px; }
.leaflet-popup-content a { color: var(--accent); }
.leaflet-control-attribution { background: rgba(11,15,20,.7) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-bar a { background: var(--panel); color: var(--text); border-bottom-color: var(--line); }
.popup h4 { margin: 0 0 6px; font-size: 14px; }
.popup dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 8px 0; font-size: 12.5px; }
.popup dt { color: var(--muted); }
.popup dd { margin: 0; }

.relay-marker { position: relative; width: 18px; height: 18px; }
.relay-marker .core { position: absolute; inset: 3px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px rgba(11,15,20,.9), 0 0 12px var(--c); }
.relay-marker .ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--c); opacity: 0; }
.relay-marker.online .ring { animation: pulse 2s ease-out infinite; }
.relay-marker.approx .core { background: transparent; border: 2px dashed var(--c); box-shadow: 0 0 0 1px rgba(11,15,20,.9); }
.relay-marker.ping .ring { animation: pulse .9s ease-out 3; opacity: 1; }
.relay-marker.online { --c: var(--accent); }
.relay-marker.idle { --c: var(--amber); }
.relay-marker.offline { --c: var(--grey); }
.relay-marker.revoked, .relay-marker.suspended { --c: var(--red); }

@keyframes pulse { 0% { transform: scale(.6); opacity: .9; } 100% { transform: scale(2.8); opacity: 0; } }
@keyframes ping { 0% { box-shadow: 0 0 0 0 rgba(46,230,160,.6); } 100% { box-shadow: 0 0 0 10px rgba(46,230,160,0); } }
@keyframes flash { 0% { background: rgba(46,230,160,.18); } 100% { background: transparent; } }

/* ---------- auth ---------- */
.auth-page { display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; padding: 32px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); text-align: center; }
.auth-card img { margin: 0 auto; border-radius: 14px; }
.auth-card label { text-align: left; }
.auth-card p { margin: -8px 0 6px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .map-layout, .grid-2-1 { grid-template-columns: 1fr; }
    .map-side { max-height: none; }
}
@media (max-width: 820px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; z-index: 1000; left: 0; width: 250px; transform: translateX(-100%); transition: transform .2s; }
    .sidebar.open { transform: none; box-shadow: 20px 0 60px rgba(0,0,0,.5); }
    .menu-toggle { display: inline-flex; }
    .main { padding: 14px 14px 40px; }
    .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
    .topbar { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- customers ---------- */
.kpi-link { color: var(--text); transition: border-color .15s; }
.kpi-link:hover { text-decoration: none; border-color: rgba(46,230,160,.4); }
.badge-new { background: rgba(90,176,255,.15); color: var(--blue); margin-left: 6px; }
textarea { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: #0e141b; color: var(--text); font: inherit; resize: vertical; min-height: 90px; }
textarea:focus { outline: 2px solid rgba(46,230,160,.35); border-color: var(--accent); }
.message-form { display: flex; flex-direction: column; gap: 10px; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; align-self: flex-start; }
.segmented label { flex-direction: row; align-items: center; gap: 6px; padding: 7px 14px; cursor: pointer; font-weight: 600; }
.segmented label:has(input:checked) { background: rgba(46,230,160,.12); color: var(--accent); }
.segmented label.disabled { opacity: .45; cursor: not-allowed; }
.segmented input { width: auto; height: auto; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.inline-select { width: auto; }
[hidden] { display: none !important; }
