:root {
  --bg: #0f1419;
  --bg2: #171d26;
  --bg3: #1f2733;
  --line: #2a3441;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #3ba7ff;
  --green: #35c76a;
  --red: #ff5d5d;
  --amber: #ffb020;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; }

.brand { font-weight: 700; font-size: 18px; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }

/* ---- Login ---- */
.login-screen { height: 100%; display: flex; align-items: center; justify-content: center; }
.login-box {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  padding: 32px; width: 320px; display: flex; flex-direction: column; gap: 14px;
}
.login-box .subtitle { color: var(--muted); margin: -6px 0 6px; font-size: 13px; }
.login-box input, .modal input, .modal textarea {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 8px;
  padding: 11px 12px; color: var(--text); font-size: 14px; width: 100%;
}
.login-box button, .modal button.primary {
  background: var(--accent); color: #04121f; border: none; border-radius: 8px;
  padding: 11px; font-weight: 700; font-size: 14px;
}
.error { color: var(--red); font-size: 13px; min-height: 16px; }

/* ---- Topbar ---- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; background: var(--bg2); border-bottom: 1px solid var(--line);
}
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.btn-ghost { background: transparent; color: var(--muted); border: none; padding: 8px 10px; }
.btn-secondary:hover { border-color: var(--accent); }

/* ---- Layout ---- */
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 300px; background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.sidebar-head { padding: 12px 16px; color: var(--muted); border-bottom: 1px solid var(--line); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.device-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.device-item { padding: 13px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.device-item:hover { background: var(--bg3); }
.device-item.active { background: var(--bg3); border-left: 3px solid var(--accent); padding-left: 13px; }
.device-item .name { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.device-item .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.offline { background: #55606e; }
.badge { background: var(--amber); color: #1a1200; border-radius: 10px; padding: 1px 7px; font-size: 11px; font-weight: 700; margin-left: 6px; }

/* ---- Main / mapa ---- */
.main { flex: 1; position: relative; min-width: 0; display: flex; flex-direction: column; }
#map { flex: 1; background: #0a0e13; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--bg2); color: var(--text); }

/* ---- Painel de detalhe ---- */
.detail {
  position: absolute; top: 14px; right: 14px; width: 340px; max-height: calc(100% - 28px);
  overflow-y: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px; box-shadow: 0 8px 30px rgba(0,0,0,.4); z-index: 500;
}
.detail h2 { margin: 0 0 2px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.detail .sub { color: var(--muted); font-size: 12px; margin-bottom: 14px; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 4px 10px; font-size: 13px; margin-bottom: 14px; }
.kv .k { color: var(--muted); }
.kv .v { word-break: break-word; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.actions button { border: 1px solid var(--line); background: var(--bg3); color: var(--text); border-radius: 8px; padding: 10px; font-weight: 600; font-size: 13px; }
.actions button:hover { border-color: var(--accent); }
.actions button.danger:hover { border-color: var(--red); color: var(--red); }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 16px 0 8px; }
.log { font-size: 12px; color: var(--muted); }
.log-item { padding: 6px 0; border-bottom: 1px solid var(--line); }
.log-item .t { color: var(--text); }
.cmd-status { display: inline-block; padding: 1px 6px; border-radius: 6px; font-size: 11px; font-weight: 700; }
.cmd-status.queued { background: #3a3320; color: var(--amber); }
.cmd-status.sent { background: #22344a; color: var(--accent); }
.cmd-status.done { background: #16341f; color: var(--green); }
.cmd-status.failed { background: #3a1e1e; color: var(--red); }
.detail-close { position: absolute; top: 12px; right: 12px; }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-box { background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: 420px; max-width: 92vw; position: relative; }
.modal-box h3 { margin: 0 0 14px; }
.modal-box label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.modal-x { position: absolute; top: 12px; right: 12px; }
.modal .row { display: flex; gap: 8px; margin-top: 16px; }
.modal .row button { flex: 1; }
.code {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 8px; padding: 10px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px;
  word-break: break-all; margin-top: 6px;
}
.muted { color: var(--muted); }
@media (max-width: 720px) {
  .sidebar { width: 100%; position: absolute; z-index: 600; height: 100%; }
  .detail { width: calc(100% - 28px); }
}
