/* GhostESP Dashboard shell — persistent header + sidebar + workspace.
   Load this stylesheet LAST so it wins the layout fights with the
   console/mirror/files/crash CSS that was written for the old tab layout. */

/* Dim the animated dot terrain like the hardware page does: a fixed scrim
   that paints above the canvas (later in the DOM, same z-index) but below
   the dashboard content (z-index 1). */
.dash-scrim {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.62);
}

.dash-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Nav is in normal flow on this page (serial.css makes it relative),
   so NO top padding — the header sits flush under it. Sticky top: 0
   takes over when the nav scrolls away. */
.dash-shell.serial-page {
  padding-top: 0;
}

/* The v2.1 announcement bar floats above the fixed nav and reads as an
   empty strip above the dashboard title bar — hide it on this page. */
body:has(.dash-shell) .announce-bar {
  display: none !important;
}

/* ---- Header ---- */
.dash-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #050505;
  border-bottom: 1px solid var(--border, var(--serial-border));
  padding: 0.65rem 1rem 0.65rem 1.25rem;
}

.dash-header-inner {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  max-width: none;
  margin: 0;
  flex-wrap: wrap;
}

.dash-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.dash-title-icon {
  font-size: 1.5rem;
  color: var(--primary-color, #00ff80);
  line-height: 1;
}

.dash-title-name {
  font-weight: 600;
  font-size: 1.02rem;
  display: block;
  line-height: 1.2;
  color: var(--text-primary, var(--serial-text));
}

.dash-title-sub {
  font-size: 0.66rem;
  color: var(--text-dim, var(--serial-secondary));
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
}

.dash-device {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-dim, var(--serial-secondary));
  margin-left: auto;
}

.dash-device-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #555;
  flex-shrink: 0;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.dash-device-dot.connected {
  background: #00ff80;
  box-shadow: 0 0 8px rgba(0, 255, 128, 0.6);
}

.dash-device-sub {
  opacity: 0.7;
}

.dash-chipinfo {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.22rem 0.7rem;
  border: 1px solid rgba(0, 255, 128, 0.3);
  border-radius: 999px;
  background: rgba(0, 255, 128, 0.07);
  color: #00ff80;
  font-size: 0.72rem;
  white-space: nowrap;
  cursor: help;
}

.dash-chipinfo.visible {
  display: inline-flex;
}

.dash-header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.dash-baud {
  max-width: 150px;
  background: transparent;
  font-size: 0.8rem;
  padding: 0.5rem 0.6rem;
}

/* ---- Body grid ---- */
.dash-body {
  display: grid;
  grid-template-columns: 220px 1fr;
  flex: 1;
  align-items: stretch;
}/* ---- Sidebar ---- */
.dash-nav {
  border-right: 1px solid var(--border, var(--serial-border));
  background: rgba(0, 0, 0, 0.35);
  padding: 1.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.dash-nav-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.dash-nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.7rem 0.85rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text-dim, var(--serial-secondary));
  font-family: var(--font-sans, var(--serial-font-sans));
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  flex: 0 0 auto;
  transition: all 0.18s ease;
}

.dash-nav-item i {
  font-size: 1.05rem;
  line-height: 1;
}

.dash-nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary, var(--serial-text));
}

.dash-nav-item.active {
  background: rgba(0, 255, 128, 0.1);
  border-color: rgba(0, 255, 128, 0.35);
  color: #00ff80;
}

.dash-nav-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  border-top: 1px solid var(--border, var(--serial-border));
  padding-top: 0.75rem;
}

/* Device info card in the sidebar */
.dash-device-card {
  border: 1px solid var(--border, var(--serial-border));
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.35);
  padding: 0.75rem 0.8rem;
  opacity: 0.55;
  transition: opacity 0.25s ease, border-color 0.25s ease;
}

.dash-device-card.has-device {
  opacity: 1;
  border-color: rgba(0, 255, 128, 0.3);
}

.dash-device-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim, var(--serial-secondary));
}

.dash-device-card-head i {
  color: #00ff80;
}

.dash-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border, var(--serial-border));
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim, var(--serial-secondary));
  cursor: pointer;
  transition: all 0.15s ease;
}

.dash-icon-btn:hover {
  color: #00ff80;
  border-color: rgba(0, 255, 128, 0.4);
}

.dash-icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.dash-spinning {
  display: inline-block;
  animation: dash-spin 0.8s linear infinite;
}

@keyframes dash-spin {
  to { transform: rotate(360deg); }
}

.dash-device-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.dash-device-card-empty {
  margin: 0;
  color: var(--text-dim, var(--serial-secondary));
  font-size: 0.75rem;
  line-height: 1.4;
}

.dash-device-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.76rem;
  line-height: 1.35;
}

.dash-device-row-label {
  color: var(--text-dim, var(--serial-secondary));
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.dash-device-row-value {
  color: var(--text-primary, var(--serial-text));
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dash-nav-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.85rem;
  color: var(--text-dim, var(--serial-secondary));
  text-decoration: none;
  font-size: 0.82rem;
  border-radius: 8px;
  transition: all 0.15s ease;
}

.dash-nav-link:hover {
  color: var(--text-primary, var(--serial-text));
  background: rgba(255, 255, 255, 0.04);
}

/* ---- Workspace ---- */
.dash-content {
  padding: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Connected console view stretches to fill the workspace */
.console-main {
  flex: 1;
  min-height: 0;
}

#tab-console.active {
  flex: 1;
  min-height: 0;
}

#tab-console .console {
  flex: 1;
  min-height: 240px;
  max-height: calc(100vh - 270px);
  border: none;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.55);
}

/* ---- Terminal controls, redone as a cohesive bottom bar ---- */
.controls-container {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.65rem 0.9rem 0.8rem;
  background: rgba(8, 8, 8, 0.92);
  border-top: 1px solid var(--border, var(--serial-border));
}

.controls-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.quick-commands {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  background: transparent;
  border: none;
  padding: 0;
}

.quick-label {
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim, var(--serial-text-dim));
  opacity: 0.8;
  margin-right: 0.15rem;
}

.quick-cmd {
  border-radius: 999px;
  padding: 0.28rem 0.75rem;
  font-size: 0.75rem;
  color: var(--text-dim, var(--serial-text-dim));
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.09);
  transition: all 0.15s ease;
}

.quick-cmd:hover {
  color: #00ff80;
  border-color: rgba(0, 255, 128, 0.4);
  background: rgba(0, 255, 128, 0.06);
}

.control-panel {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
  background: transparent;
  border: none;
  padding: 0;
}

.control-panel .btn {
  flex: 0 0 auto;
  width: auto;
  padding: 0.45rem 0.95rem;
  font-size: 0.8rem;
}

.input-group {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 0.35rem 0.35rem 0.35rem 0.9rem;
}

.serial-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--serial-text, var(--text));
  padding: 0.5rem 0;
  font-family: var(--font-mono, var(--serial-font-mono));
  font-size: 0.85rem;
  outline: none;
}

.serial-input::placeholder {
  color: var(--text-dim, var(--serial-text-dim));
  opacity: 0.5;
}

.input-group:focus-within {
  border-color: rgba(0, 255, 128, 0.35);
}

.input-group .btn-send {
  flex-shrink: 0;
  width: auto;
  border-radius: 8px;
  padding: 0.5rem 0.95rem;
  background: rgba(0, 255, 128, 0.12);
  border: 1px solid rgba(0, 255, 128, 0.3);
  color: #00ff80;
}

.input-group .btn-send:hover:not(:disabled) {
  background: rgba(0, 255, 128, 0.22);
  border-color: rgba(0, 255, 128, 0.5);
  color: #00ff80;
}

/* The store view fills the workspace even while disconnected */
#tab-store {
  min-height: 70vh;
}

#tab-store.active {
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.5rem 3rem;
}

#tab-store .store-grid {
  align-content: start;
}

/* Store controls span the full workspace (no centered gutters) */
#tab-store .store-tabs {
  margin-bottom: 0.75rem;
  max-width: none;
}

#tab-store .store-toolbar {
  margin-bottom: 0.9rem;
  max-width: none;
  grid-template-columns: 1fr 220px;
}

#tab-store .store-security-notice {
  max-width: none;
}

#tab-store .store-list-meta {
  margin-bottom: 0.75rem;
}

#tab-store .store-chip-filter {
  max-width: none;
  margin-top: -0.25rem;
}

/* Reworked security notice — slim, quiet, icon-led */
#tab-store .store-security-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  border: 1px solid rgba(255, 200, 87, 0.22);
  border-radius: 999px;
  color: rgba(255, 236, 188, 0.75);
  background: rgba(255, 200, 87, 0.05);
  font-size: 0.78rem;
  text-align: center;
}

#tab-store .store-security-notice::before {
  content: '\F33D';
  font-family: 'bootstrap-icons';
  color: rgba(255, 200, 87, 0.8);
  font-size: 0.85rem;
  line-height: 1;
}

/* Welcome card — centered, compact, no double margins */
.welcome-card {
  max-width: 560px;
  margin: 2.25rem auto;
  padding: 2.75rem 2rem;
  gap: 1.1rem;
  background: rgba(5, 5, 5, 0.9);
}

.welcome-card h1 {
  font-size: 1.9rem;
  margin: 0;
  line-height: 1.15;
  color: var(--text-primary, var(--serial-text));
}

.welcome-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin: 0.25rem 0 0.5rem;
}

/* Mirror stage — the display wrapper fills the available space so the
   auto-fit canvas has room to scale with no black bars. */
#tab-mirror.active {
  display: flex;
  flex: 1;
  min-height: 0;
  padding: 1.25rem 1.5rem;
}

#tab-mirror .mirror-root {
  flex: 1;
  min-height: 0;
}

/* ---- IRDB view ---- */
#tab-irdb.active {
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.5rem 3rem;
  min-height: 70vh;
}

#tab-irdb .irdb-root {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
}

#tab-irdb .irdb-tab-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.25rem;
  margin: 0 0 1.25rem;
}

#tab-irdb .irdb-tab-header h1 {
  margin: 0;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary, var(--serial-text));
}

#tab-irdb .irdb-tab-header h1 i { color: #00ff80; font-size: 1.2rem; }

#tab-irdb .header-description {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-dim, var(--serial-secondary));
}

#tab-irdb .irdb-main {
  width: 100%;
  padding: 1.25rem;
}

#tab-irdb .search-section { margin-bottom: 1rem; }

#tab-irdb .search-bar { max-width: none; }

/* Store-consistent controls: capped, compact, no infinite-width dropdowns */
#tab-irdb .search-bar input {
  width: 100%;
  min-width: 0;
  padding: 0.7rem 1rem;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid var(--border, var(--serial-border));
  border-radius: 10px;
  color: var(--text-primary, var(--serial-text));
  font-family: var(--font-mono);
  font-size: 0.85rem;
  outline: none;
}

#tab-irdb .search-bar input::placeholder { color: rgba(255, 255, 255, 0.3); }

#tab-irdb .search-bar input:focus {
  border-color: rgba(255, 255, 255, 0.42);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

#tab-irdb .filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-width: 760px;
}

#tab-irdb .filters select {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 300px;
  padding: 0.6rem 1.9rem 0.6rem 0.85rem;
  background-color: rgba(0, 0, 0, 0.72);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  background-size: 0.85em;
  border: 1px solid var(--border, var(--serial-border));
  border-radius: 10px;
  color: var(--text-primary, var(--serial-text));
  font-family: var(--font-mono);
  font-size: 0.8rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
}

#tab-irdb .filters select:nth-child(3) { max-width: 130px; }

#tab-irdb .filters select:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.42);
}

#tab-irdb .stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  justify-content: center;
  padding: 0.55rem 1rem;
}

#tab-irdb .results { margin: 1.25rem 0; }

#tab-irdb .result-item { padding: 1rem 1.1rem; }

#tab-irdb .button-group { display: flex; gap: 0.5rem; }

#tab-irdb .download-button,
#tab-irdb .send-button { padding: 0.55rem 0.85rem; font-size: 0.8rem; }

#tab-irdb .irdb-footer {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--text-dim, var(--serial-secondary));
}

#tab-irdb .irdb-footer a { color: var(--text-primary, var(--serial-text)); }

@media (max-width: 700px) {
  #tab-irdb.active { padding: 1rem 0.75rem 2.5rem; }
  #tab-irdb .filters { flex-direction: column; max-width: none; }
  #tab-irdb .filters select { max-width: none; width: 100%; }
  #tab-irdb .stats { justify-content: flex-start; }
}

/* ---- Other views ---- */
#tab-files.active,
#tab-crash.active {
  padding: 1.25rem 1.5rem;
}

/* Mobile: sidebar becomes a top rail */
@media (max-width: 900px) {
  .dash-body {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .dash-nav {
    position: static;
    flex-direction: row;
    justify-content: flex-start;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border, var(--serial-border));
    padding: 0.5rem 0.75rem;
    gap: 0.4rem;
  }

  .dash-nav-list {
    flex-direction: row;
    gap: 0.4rem;
  }

  .dash-nav-item {
    flex: 0 0 auto;
    padding: 0.55rem 0.85rem;
    white-space: nowrap;
  }

  .dash-nav-item span {
    display: inline;
  }

  .dash-nav-foot,
  .dash-device-card {
    display: none;
  }

  .dash-content {
    padding: 0;
  }

  .dash-header-inner {
    gap: 0.5rem;
  }

  .dash-device {
    order: 3;
    width: 100%;
  }

  #tab-store.active {
    padding: 1rem 0.75rem 2.5rem;
  }

  #tab-store .store-toolbar {
    grid-template-columns: 1fr;
  }

  #tab-store .store-tab {
    padding: 0.55rem 0.9rem;
    font-size: 0.85rem;
  }

  #tab-mirror.active,
  #tab-files.active,
  #tab-crash.active {
    padding: 1rem 0.75rem;
  }

  .welcome-card {
    margin: 1.25rem auto;
  }
}

@media (max-width: 560px) {
  .dash-header-actions {
    order: 2;
    width: 100%;
  }

  .dash-header-actions .btn {
    flex: 1;
  }
}