:root {
  --bg: #121212;
  --side: #1c1c1c;
  --side2: #242424;
  --line: #333;
  --text: #eaeaea;
  --muted: #9a9a9a;
  --orange: #f39c12;
  --orange2: #e67e22;
  --green: #2ecc71;
  --yellow: #f1c40f;
  --red: #e74c3c;
  --gray: #7f8c8d;
  --panel: #1a1a1a;
  --shadow: 0 8px 28px rgba(0,0,0,.45);
  --font: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: #0d0d0d;
  overflow: hidden;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }

/* LOGIN */
.view-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(800px 400px at 50% 0%, rgba(243,156,18,.18), transparent), #111;
}
.login-box {
  width: min(380px, 92vw);
  background: var(--side);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.75rem 1.4rem 1.5rem;
  box-shadow: var(--shadow);
}
.login-brand {
  font-weight: 800;
  letter-spacing: .18em;
  color: var(--orange);
  font-size: 1.6rem;
}
.login-sub { color: var(--muted); margin: .35rem 0 1.25rem; font-size: .9rem; }
.login-box label { display: grid; gap: .3rem; margin-bottom: .8rem; color: var(--muted); font-size: .82rem; }
.login-box input {
  background: #111;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .7rem .75rem;
}
.login-box input:focus { outline: 1px solid var(--orange); border-color: var(--orange); }
.btn-orange {
  width: 100%;
  border: 0;
  border-radius: 4px;
  padding: .8rem;
  background: linear-gradient(180deg, var(--orange), var(--orange2));
  color: #1a1200;
  font-weight: 700;
  cursor: pointer;
}
.err { color: var(--red); margin: 0 0 .7rem; font-size: .88rem; }

/* SHELL */
.shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: 1fr auto;
}

.sidebar {
  grid-row: 1 / span 2;
  background: var(--side);
  border-right: 1px solid #000;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: #151515;
  border-bottom: 1px solid #000;
}
.side-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: .85rem .4rem;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  font-weight: 600;
  font-size: .88rem;
}
.side-tab.is-active {
  color: var(--orange);
  border-bottom-color: var(--orange);
  background: #1a1a1a;
}

.side-toolbar {
  display: flex;
  gap: .4rem;
  align-items: center;
  padding: .55rem .55rem;
  border-bottom: 1px solid #111;
  background: var(--side2);
}
.search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: .4rem;
  background: #111;
  border: 1px solid #333;
  border-radius: 3px;
  padding: .35rem .5rem;
  color: var(--muted);
}
.search-wrap input {
  border: 0;
  outline: 0;
  background: transparent;
  width: 100%;
  color: var(--text);
  font-size: .88rem;
}
.tool-btn {
  width: 34px;
  height: 34px;
  border: 1px solid #333;
  background: #181818;
  border-radius: 3px;
  cursor: pointer;
}
.tool-btn-orange {
  background: var(--orange);
  border-color: var(--orange2);
  color: #1a1200;
  font-weight: 700;
}

.side-panel {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.group-head {
  padding: .55rem .75rem;
  font-size: .78rem;
  color: var(--muted);
  background: #171717;
  border-bottom: 1px solid #101010;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.empty-side { padding: 1.2rem; color: var(--muted); font-size: .9rem; }

.device-list { display: flex; flex-direction: column; }
.device-row {
  display: grid;
  grid-template-columns: 22px 36px 1fr auto;
  gap: .55rem;
  align-items: center;
  padding: .55rem .65rem;
  border-bottom: 1px solid #151515;
  cursor: pointer;
}
.device-row:hover { background: #222; }
.device-row.is-selected { background: #2a2114; box-shadow: inset 3px 0 0 var(--orange); }
.device-row input { accent-color: var(--orange); width: 15px; height: 15px; }
.device-ico {
  width: 34px;
  height: 34px;
  border-radius: 4px;
  background: var(--orange);
  color: #1a1200;
  display: grid;
  place-items: center;
}
.device-ico svg { display: block; }
.device-main { min-width: 0; }
.device-name {
  font-size: .92rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.device-sub {
  margin-top: .12rem;
  font-size: .72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.device-right {
  text-align: right;
  display: grid;
  gap: .25rem;
  justify-items: end;
}
.device-speed { font-size: .78rem; color: #ccc; }
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gray);
  box-shadow: 0 0 0 2px rgba(0,0,0,.35);
}
.dot.online-move { background: var(--green); }
.dot.online-idle { background: var(--yellow); }
.dot.online-stop { background: var(--red); }
.dot.offline { background: var(--gray); }

/* MAP */
.map-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #dfe8d8;
}
#map { position: absolute; inset: 0; z-index: 1; }
.map-topbar {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 5;
  display: flex;
  gap: .6rem;
  align-items: center;
  background: rgba(20,20,20,.88);
  border: 1px solid #333;
  border-radius: 4px;
  padding: .35rem .65rem;
  color: #ddd;
  font-size: .8rem;
}
.map-brand { color: var(--orange); font-weight: 800; letter-spacing: .08em; }
.map-zoom {
  position: absolute;
  right: 10px;
  top: 48px;
  z-index: 5;
  display: grid;
  gap: 2px;
}
.map-zoom button {
  width: 34px;
  height: 34px;
  border: 1px solid #333;
  background: rgba(20,20,20,.9);
  color: #fff;
  cursor: pointer;
  font-size: 1.1rem;
}

.leaflet-control-attribution { font-size: 10px !important; }

.marker-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.45);
}
.marker-dot.move { background: var(--green); }
.marker-dot.idle { background: var(--yellow); }
.marker-dot.stop { background: var(--red); }
.marker-dot.off { background: var(--gray); }

/* DETAIL FOOTER */
.detail {
  grid-column: 2;
  position: relative;
  display: grid;
  grid-template-columns: 1.3fr 1.1fr 1fr;
  gap: 0;
  background: var(--panel);
  border-top: 2px solid #000;
  min-height: 168px;
  max-height: 220px;
  z-index: 6;
  box-shadow: 0 -8px 24px rgba(0,0,0,.35);
}
.detail-col {
  padding: .75rem .9rem;
  border-right: 1px solid #2a2a2a;
  overflow: auto;
}
.detail-col:last-of-type { border-right: 0; }
.detail-title-row {
  display: flex;
  align-items: center;
  gap: .65rem;
  margin-bottom: .45rem;
}
.detail-title-row strong { font-size: 1.05rem; }
.status-tag {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .78rem;
  color: #ccc;
}
.status-tag i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--gray);
  display: inline-block;
}
.status-tag.is-move i { background: var(--green); }
.status-tag.is-idle i { background: var(--yellow); }
.status-tag.is-stop i { background: var(--red); }
.status-tag.is-off i { background: var(--gray); }

.detail-label {
  color: var(--orange);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .35rem;
}
.detail-addr { font-size: .86rem; line-height: 1.35; color: #ddd; }
.detail-meta { margin-top: .45rem; font-size: .75rem; color: var(--muted); }

.cmd-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #222;
  border: 1px solid #333;
  border-radius: 3px;
  padding: .55rem .65rem;
  margin-bottom: .35rem;
  cursor: pointer;
  text-align: left;
}
.cmd-row:hover { border-color: var(--orange); color: #fff; }
.cmd-row i { color: var(--orange); font-style: normal; font-weight: 700; }
.cmd-msg { margin: .35rem 0 0; font-size: .78rem; color: var(--green); }
.cmd-msg.is-err { color: var(--red); }

.sensors {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .4rem;
}
.sensor {
  background: #222;
  border: 1px solid #333;
  border-radius: 4px;
  padding: .45rem .25rem;
  text-align: center;
}
.sensor.is-on { border-color: rgba(46,204,113,.55); }
.sensor.is-warn { border-color: rgba(241,196,15,.55); }
.sensor-ico {
  width: 28px;
  height: 28px;
  margin: 0 auto .25rem;
  border-radius: 50%;
  background: #333;
  display: grid;
  place-items: center;
  color: #bbb;
  font-size: .85rem;
}
.sensor.is-on .sensor-ico { background: rgba(46,204,113,.2); color: var(--green); }
.sensor.is-warn .sensor-ico { background: rgba(241,196,15,.18); color: var(--yellow); }
.sensor-name { font-size: .62rem; color: var(--muted); letter-spacing: .03em; }
.sensor-val { margin-top: .15rem; font-size: .72rem; font-weight: 700; }

.detail-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 0;
  background: transparent;
  color: #888;
  font-size: 1.3rem;
  cursor: pointer;
}

@media (max-width: 960px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: 42vh 1fr auto;
  }
  .sidebar {
    grid-row: 1;
    border-right: 0;
    border-bottom: 1px solid #000;
  }
  .map-wrap { grid-row: 2; }
  .detail {
    grid-column: 1;
    grid-template-columns: 1fr;
    max-height: 40vh;
  }
  .sensors { grid-template-columns: repeat(4, 1fr); }
}

/* side tabs 4 cols */
.side-tabs { grid-template-columns: repeat(4, 1fr); }
.side-tab { font-size: .78rem; padding: .75rem .2rem; }

.mini-btn {
  margin-left: auto;
  border: 1px solid #444;
  background: #2a2a2a;
  color: var(--orange);
  border-radius: 3px;
  padding: .2rem .55rem;
  font-size: .75rem;
  font-weight: 700;
  cursor: pointer;
}
.mini-btn:hover { border-color: var(--orange); }

.row-actions { display: flex; gap: .25rem; }
.row-action {
  border: 1px solid #333;
  background: #1f1f1f;
  color: #bbb;
  border-radius: 3px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: .85rem;
  line-height: 1;
}
.row-action:hover { color: var(--orange); border-color: var(--orange); }

.user-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: .55rem;
  align-items: center;
  padding: .55rem .65rem;
  border-bottom: 1px solid #151515;
  cursor: pointer;
}
.user-row:hover { background: #222; }
.user-ico {
  width: 34px; height: 34px; border-radius: 4px;
  background: #333; color: var(--orange);
  display: grid; place-items: center; font-weight: 800; font-size: .8rem;
}

/* MODAL */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.62);
  display: grid; place-items: center;
  padding: 1rem;
}
.modal-card {
  width: min(520px, 100%);
  max-height: min(90vh, 720px);
  overflow: auto;
  background: #1c1c1c;
  border: 1px solid #333;
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.modal-card-wide { width: min(640px, 100%); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1rem;
  border-bottom: 1px solid #2a2a2a;
  background: #171717;
}
.modal-head strong { color: var(--orange); }
.modal-x {
  border: 0; background: transparent; color: #888;
  font-size: 1.4rem; cursor: pointer; line-height: 1;
}
.modal-tabs {
  display: flex; gap: 0; border-bottom: 1px solid #222; background: #151515;
}
.modal-tab {
  border: 0; background: transparent; color: var(--muted);
  padding: .7rem 1rem; cursor: pointer; font-weight: 600;
  border-bottom: 3px solid transparent; font-size: .88rem;
}
.modal-tab.is-active { color: var(--orange); border-bottom-color: var(--orange); }
.modal-body { padding: 1rem; display: grid; gap: .75rem; }
.modal-body label { display: grid; gap: .3rem; font-size: .8rem; color: var(--muted); }
.modal-body label em { font-style: normal; color: #666; font-size: .75rem; }
.modal-body input, .modal-body select, .modal-body textarea {
  background: #111; border: 1px solid #333; border-radius: 4px;
  padding: .65rem .7rem; color: var(--text); font: inherit;
}
.modal-body input:focus, .modal-body select:focus, .modal-body textarea:focus {
  outline: 1px solid var(--orange); border-color: var(--orange);
}
.check-row {
  display: flex !important; align-items: center; gap: .55rem;
  flex-direction: row !important; color: var(--text) !important;
}
.check-row input { width: auto; }
.hint { margin: 0; color: var(--muted); font-size: .82rem; }
.check-list {
  display: grid; gap: .35rem; max-height: 240px; overflow: auto;
  border: 1px solid #2a2a2a; border-radius: 4px; padding: .5rem; background: #141414;
}
.check-list label {
  display: flex !important; flex-direction: row !important;
  align-items: center; gap: .5rem; color: #ddd !important; font-size: .85rem !important;
}
.modal-err { margin: 0; color: var(--red); font-size: .85rem; }
.modal-actions {
  display: flex; align-items: center; gap: .5rem; margin-top: .25rem;
}
.modal-actions .spacer { flex: 1; }
.btn-ghost {
  border: 1px solid #444; background: #222; color: #ddd;
  border-radius: 4px; padding: .65rem .9rem; cursor: pointer; font-weight: 600;
}
.btn-ghost:hover { border-color: #666; }
#btn-device-delete, #btn-user-delete { color: var(--red); border-color: #633; }

/* map admin button */
.map-admin-btn {
  border: 1px solid var(--orange);
  background: rgba(243,156,18,.15);
  color: var(--orange);
  border-radius: 3px;
  padding: .2rem .55rem;
  font-size: .75rem;
  font-weight: 800;
  cursor: pointer;
  letter-spacing: .04em;
}
.map-admin-btn:hover { background: var(--orange); color: #1a1200; }

/* ADMIN SHELL */
.admin-shell {
  min-height: 100vh;
  background: #101010;
  color: var(--text);
  display: flex;
  flex-direction: column;
}
.admin-top {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .65rem 1rem;
  background: #1a1a1a;
  border-bottom: 1px solid #000;
  position: sticky;
  top: 0;
  z-index: 20;
}
.admin-brand { display: flex; align-items: center; gap: .55rem; }
.admin-logo {
  color: var(--orange);
  font-weight: 900;
  letter-spacing: .14em;
}
.admin-badge {
  background: var(--orange);
  color: #1a1200;
  font-size: .68rem;
  font-weight: 800;
  padding: .15rem .4rem;
  border-radius: 3px;
}
.admin-nav { display: flex; flex-wrap: wrap; gap: .15rem; flex: 1; }
.admin-nav-item {
  border: 0;
  background: transparent;
  color: #aaa;
  padding: .55rem .75rem;
  cursor: pointer;
  font-weight: 700;
  font-size: .88rem;
  border-bottom: 3px solid transparent;
}
.admin-nav-item.is-active,
.admin-nav-item:hover {
  color: var(--orange);
  border-bottom-color: var(--orange);
}
.admin-top-right {
  display: flex;
  align-items: center;
  gap: .55rem;
}
.admin-user-label { color: var(--muted); font-size: .8rem; }

.admin-toolbar {
  display: flex;
  gap: .75rem;
  align-items: center;
  padding: .75rem 1rem;
  background: #151515;
  border-bottom: 1px solid #222;
}
.admin-toolbar input {
  flex: 1;
  background: #111;
  border: 1px solid #333;
  border-radius: 4px;
  padding: .65rem .75rem;
  color: var(--text);
}
.admin-toolbar-actions { display: flex; gap: .4rem; }

.admin-content { padding: 1rem; flex: 1; }
.admin-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .75rem;
}
.admin-panel-head h2 { margin: 0; font-size: 1.15rem; }
.admin-filters { display: flex; gap: .35rem; }
.chip {
  border: 1px solid #333;
  background: #1c1c1c;
  color: #bbb;
  border-radius: 999px;
  padding: .3rem .7rem;
  font-size: .78rem;
  cursor: pointer;
  font-weight: 700;
}
.chip.is-active { border-color: var(--orange); color: var(--orange); }

.admin-table-wrap {
  overflow: auto;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  background: #171717;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
.admin-table th {
  text-align: left;
  padding: .7rem .75rem;
  background: #1f1f1f;
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid #2a2a2a;
  white-space: nowrap;
}
.admin-table td {
  padding: .7rem .75rem;
  border-bottom: 1px solid #222;
  vertical-align: middle;
}
.admin-table tr:hover td { background: #1d1d1d; }
.empty-td { text-align: center; color: var(--muted); padding: 2rem !important; }
.td-actions { text-align: right; white-space: nowrap; }
.td-actions .admin-btn { margin-left: .25rem; }

.label {
  display: inline-block;
  padding: .15rem .45rem;
  border-radius: 3px;
  font-size: .7rem;
  font-weight: 800;
  text-transform: uppercase;
}
.label-ok { background: rgba(46,204,113,.18); color: var(--green); }
.label-warn { background: rgba(241,196,15,.18); color: var(--yellow); }
.label-bad { background: rgba(231,76,60,.18); color: var(--red); }
.tag {
  display: inline-block;
  font-size: .68rem;
  color: var(--orange);
  border: 1px solid rgba(243,156,18,.4);
  border-radius: 3px;
  padding: 0 .3rem;
}
.status-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--gray);
}
.status-dot.on { background: var(--green); }
.status-dot.off { background: var(--red); }

.admin-btn {
  border: 1px solid #444;
  background: #222;
  color: #eee;
  border-radius: 4px;
  padding: .4rem .7rem;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
}
.admin-btn.primary {
  background: linear-gradient(180deg, var(--orange), var(--orange2));
  border-color: var(--orange2);
  color: #1a1200;
}
.admin-btn.ghost { background: transparent; }
.admin-btn:hover { border-color: var(--orange); }

.server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .75rem;
}
.server-card {
  background: #171717;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: .9rem;
}
.server-k { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }
.server-v { margin-top: .35rem; font-weight: 700; font-size: 1rem; }
.admin-note { color: var(--muted); font-size: .85rem; margin-top: 1rem; max-width: 720px; }

@media (max-width: 900px) {
  .admin-top { flex-wrap: wrap; }
  .admin-toolbar { flex-direction: column; align-items: stretch; }
}

.admin-split {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1rem;
  align-items: start;
}
@media (max-width: 980px) {
  .admin-split { grid-template-columns: 1fr; }
}
.admin-side-form, .admin-settings-form {
  background: #171717;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  padding: 1rem;
  display: grid;
  gap: .65rem;
}
.admin-side-form h3, .admin-settings-form h3 { margin: 0; font-size: 1rem; color: var(--orange); }
.admin-side-form label, .admin-settings-form label {
  display: grid; gap: .25rem; font-size: .78rem; color: var(--muted);
}
.admin-side-form input, .admin-side-form select, .admin-side-form textarea,
.admin-settings-form input, .admin-settings-form select {
  background: #111; border: 1px solid #333; border-radius: 4px;
  padding: .55rem .65rem; color: var(--text); font: inherit;
}
.admin-hr { border: 0; border-top: 1px solid #2a2a2a; margin: .4rem 0; width: 100%; }
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .75rem;
}
.icons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: .65rem;
}
.icon-card {
  display: flex; gap: .65rem; align-items: center;
  background: #171717; border: 1px solid #2a2a2a; border-radius: 6px; padding: .7rem;
}
.icon-badge, .icon-pick span {
  width: 40px; height: 40px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--ic, #f39c12); color: #1a1200; font-weight: 900;
}
.icon-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: .5rem;
}
.icon-pick {
  border: 1px solid #333;
  background: #1a1a1a;
  border-radius: 6px;
  padding: .55rem .35rem;
  cursor: pointer;
  color: #ddd;
  display: grid;
  justify-items: center;
  gap: .3rem;
}
.icon-pick small { font-size: .68rem; color: var(--muted); }
.icon-pick.is-on { border-color: var(--orange); box-shadow: inset 0 0 0 1px var(--orange); }
.admin-table code { font-size: .75rem; color: #cfcfcf; }
