/* ═══════════════════════════════════════════════════════════
   COMPONENTS.CSS — Cards, Badges, Modals, Live Badge, Etc.
   ═══════════════════════════════════════════════════════════ */

/* ── Stat Cards ─────────────────────────────────────────── */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}
.stat-card.color-0::before { background: var(--accent); }
.stat-card.color-1::before { background: var(--yellow); }
.stat-card.color-2::before { background: var(--purple); }
.stat-card.color-3::before { background: var(--green); }
.stat-card.color-4::before { background: #f0883e; }
.stat-card.color-5::before { background: #f85149; }
.stat-card.color-6::before { background: #8b949e; }
.stat-card.color-7::before { background: #79c0ff; }
.stat-card.color-8::before { background: #d2a8ff; }

.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.5rem;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}
.stat-unit {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 0.2rem;
}

/* ── Device Cards (Overview Grid) ───────────────────────── */
.dev-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 1.25rem;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
  position: relative;
  overflow: hidden;
}
.dev-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.dev-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--purple));
}
.dev-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}
.dev-card-header h3 { font-size: 1rem; font-weight: 600; }
.dev-card-header .badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: rgba(88, 166, 255, 0.15);
  color: var(--accent);
}
.dev-card-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.dev-card-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.5rem;
}
.dev-stat {
  background: var(--surface2);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  text-align: center;
}
.dev-stat .ds-label {
  font-size: 0.6rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dev-stat .ds-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}
.dev-stat .ds-unit {
  font-size: 0.65rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 0.15rem;
}
.dev-card-footer {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dev-card-footer .last-seen { font-size: 0.7rem; color: var(--text-muted); }
.dev-card-footer .click-hint { font-size: 0.7rem; color: var(--accent); font-weight: 500; }

/* ── Settings Device Cards ──────────────────────────────── */
.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  overflow: hidden;
}
.device-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  cursor: pointer;
  gap: 0.75rem;
  flex-wrap: nowrap;
  user-select: none;
}
.device-header:hover { background: rgba(255, 255, 255, 0.02); }
.device-info { flex: 1; min-width: 0; }
.device-title { font-size: 1rem; font-weight: 600; }
.device-title .badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: rgba(88, 166, 255, 0.15);
  color: var(--accent);
  vertical-align: middle;
  margin-left: 0.4rem;
}
.device-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}
.device-actions { display: flex; gap: 0.4rem; flex-shrink: 0; margin-right: 0.5rem; }
.expand-icon {
  color: var(--text-muted);
  font-size: 1.1rem;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.expand-icon.open { transform: rotate(180deg); }

.mapping-section {
  display: none;
  border-top: 1px solid var(--border);
  padding: 1rem 1.25rem;
}
.mapping-section.open { display: block; }
.mapping-section h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.mapping-toolbar {
  margin-bottom: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

/* ── Memory Mapping Table & Inputs ──────────────────────── */
.mapping-table { border-collapse: collapse; }
.mapping-table th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.mapping-table td { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.mapping-table tr:last-child td { border-bottom: none; }
.mapping-table input {
  width: 100%;
  padding: 0.35rem 0.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
}
.mapping-table input:focus { outline: none; border-color: var(--accent); }

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.modal .actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}
.badge-admin { background: rgba(88, 166, 255, 0.15); color: var(--accent); }
.badge-user { background: rgba(139, 148, 158, 0.15); color: var(--text-muted); }
.badge-active { background: rgba(63, 185, 80, 0.15); color: var(--green); }
.badge-blocked { background: rgba(248, 81, 73, 0.12); color: var(--red); }

/* ── Live Badge / Clock Chip ────────────────────────────── */
.clock-chip {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
}
.live-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--green);
  background: rgba(63, 185, 80, 0.1);
  border: 1px solid rgba(63, 185, 80, 0.25);
  padding: 0.25rem 0.6rem;
  border-radius: 99px;
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.4s infinite;
}
.live-dot.off { background: var(--text-muted); animation: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ── Auto-tag ───────────────────────────────────────────── */
.auto-tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: rgba(63, 185, 80, 0.15);
  color: var(--green);
  border: 1px solid rgba(63, 185, 80, 0.3);
}