/* ═══════════════════════════════════════════
   TrainControl — Layout
   ═══════════════════════════════════════════ */

/* ── Toolbar ── */
.toolbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: rgba(17,17,17,0.85);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.toolbar-actions { display: flex; gap: 6px; align-items: center; }
.toolbar-logo { height: 30px; object-fit: contain; }

[data-theme="light"] .toolbar { background: rgba(242,242,247,0.88); }

/* ── Bottom nav (mobile only) ── */
.bnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  display: flex; justify-content: center; gap: 3px;
  padding: 7px 14px calc(env(safe-area-inset-bottom, 8px) + 7px);
  background: rgba(17,17,17,0.9);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid rgba(255,255,255,0.05);
}
.nav-i {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 5px 18px; border: none; cursor: pointer;
  background: transparent; color: var(--text3);
  font: 600 10px/1 'DM Sans', sans-serif;
  border-radius: var(--r-sm); transition: all 0.18s var(--ease);
}
.nav-i.on { color: var(--blue); }
.nav-i .ni { font-size: 19px; }

[data-theme="light"] .bnav { background: rgba(242,242,247,0.9); }

/* ── Mobile card list ── */
.cards {
  display: flex; flex-direction: column; gap: 18px;
  padding: 16px; max-width: 780px; margin: 0 auto;
}

/* ═══════════════════════════════════════════
   DESKTOP LAYOUT (≥1024px) — Sidebar + Grid
   ═══════════════════════════════════════════ */
.desktop-layout {
  display: none;
  position: relative;
  z-index: 1;
}

@media (min-width: 1024px) {
  .desktop-layout {
    display: flex;
    height: calc(100vh - 54px);
    height: calc(100dvh - 54px);
    overflow: hidden;
  }
  .mobile-layout { display: none !important; }
  .bnav { display: none !important; }
}

/* ── Sidebar ── */
.sidebar {
  width: 110px;
  flex-shrink: 0;
  border-right: 1px solid var(--glass-border);
  background: var(--bg2);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  padding: 8px 0;
  scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

.sidebar-section {
  padding: 6px 8px 2px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text3);
}

.sidebar-add {
  display: flex; align-items: center; justify-content: center;
  width: calc(100% - 16px); margin: 4px 8px;
  padding: 10px; border: 2px dashed var(--glass-border-focus);
  border-radius: var(--r-sm); cursor: pointer;
  color: var(--text2); font-size: 20px; font-weight: 400;
  background: transparent;
  transition: all 0.18s var(--ease);
}
.sidebar-add:hover { border-color: var(--blue); color: var(--blue); }

/* ── Sidebar thumbnail (draggable) ── */
.sb-thumb {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 6px; margin: 2px 6px;
  border-radius: var(--r-sm);
  cursor: grab; user-select: none;
  transition: all 0.18s var(--ease);
  position: relative;
  text-decoration: none; color: inherit;
}
.sb-thumb:hover { background: var(--glass-bg-hover); }
.sb-thumb:active { cursor: grabbing; transform: scale(0.95); }
.sb-thumb.dragging { opacity: 0.4; }
.sb-thumb.in-grid { opacity: 0.35; }

.sb-thumb__img {
  width: 56px; height: 56px; border-radius: 10px;
  overflow: hidden; display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--blue), var(--blue-dk));
  position: relative;
}
.sb-thumb__img.grp { background: linear-gradient(135deg, var(--violet), var(--violet-dk)); }
.sb-thumb__img img { width: 100%; height: 100%; object-fit: cover; }

.sb-thumb__status {
  position: absolute; top: -2px; right: -2px;
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--bg2);
}
.sb-thumb__status.on { background: var(--green); }
.sb-thumb__status.off { background: #555; }
[data-theme="light"] .sb-thumb__status.off { background: #bbb; }
[data-theme="light"] .sb-thumb__status { border-color: var(--bg2); }

.sb-thumb__name {
  margin-top: 4px; font-size: 10px; font-weight: 600;
  text-align: center; line-height: 1.2;
  max-width: 100%; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.sb-thumb__sub {
  font-size: 8px; color: var(--text3);
  display: flex; align-items: center; gap: 2px;
}

/* ── Grid board ── */
.grid-board {
  flex: 1; overflow-y: auto; padding: 16px;
  display: grid; gap: 16px;
  align-content: start;
  grid-template-columns: 1fr;
}

@media (min-width: 1024px) and (max-width: 1279px) {
  .grid-board { grid-template-columns: 1fr; }
}
@media (min-width: 1280px) and (max-width: 1599px) {
  .grid-board { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1600px) and (max-width: 1919px) {
  .grid-board { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1920px) {
  .grid-board { grid-template-columns: 1fr 1fr 1fr; }
}

/* ── Grid slot (empty) ── */
.grid-slot {
  min-height: 320px;
  border: 2px dashed var(--glass-border);
  border-radius: var(--r-lg);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 8px;
  color: var(--text3); font-size: 13px; font-weight: 500;
  transition: all 0.2s var(--ease);
}
.grid-slot.drag-over {
  border-color: var(--blue);
  background: rgba(68,89,143,0.08);
  color: var(--blue);
}
.grid-slot .slot-icon { font-size: 28px; opacity: 0.3; }
.grid-slot .slot-text { font-size: 12px; }

/* ── Grid slot (filled) ── */
.grid-slot-filled {
  position: relative;
}
.grid-slot-close {
  position: absolute; top: 8px; right: 8px; z-index: 5;
  width: 28px; height: 28px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--glass-bg); backdrop-filter: blur(8px);
  color: var(--text2); font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s var(--ease);
}
.grid-slot-close:hover { background: var(--red); color: #fff; }

/* ── Responsive mobile ── */
@media (max-width: 1023px) {
  .desktop-layout { display: none !important; }
  .mobile-layout { display: block !important; }

  .cards { padding: 10px; gap: 12px; }
  .loco-ctrl { flex-direction: column; align-items: stretch; }
  .spd-wrap { flex-direction: row; width: 100%; gap: 10px; }
  .spd-track { width: 100%; height: 54px; }
  .spd-fill { left: 0 !important; right: auto !important; top: 0; bottom: 0; height: 100% !important; border-radius: var(--r-lg); }
  .spd-val { bottom: auto; top: 50%; right: 10px; left: auto; transform: translateY(-50%); font-size: 15px; }
  .spd-stop { width: 54px; height: 54px; }
  .loco-right { width: 100%; }
  .modal { max-width: 100%; max-height: min(93vh,93dvh); border-radius: var(--r-lg) var(--r-lg) 0 0; margin-top: auto; }
  .overlay { align-items: flex-end; padding: 0; }
}

/* ── Grid drag handle ── */
.grid-slot-drag {
  position: absolute; top: 8px; right: 42px; z-index: 5;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--glass-bg); backdrop-filter: blur(8px);
  color: var(--text2); font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  cursor: grab; user-select: none;
  transition: all 0.15s var(--ease);
}
.grid-slot-drag:hover { background: var(--blue); color: #fff; }
.grid-slot-drag:active { cursor: grabbing; }
