/* ══════════════════════════════════════════════════════════════════════════════
 * sm-iot-panel — Design System
 * Same dark theme as sm-panel. IoT-specific additions.
 * ══════════════════════════════════════════════════════════════════════════════ */

/* ── Foundational ────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg:        #0a0b0f;
  --surface:   #12141a;
  --surface-2: #181a22;
  --border:    #1e2028;
  --border-2:  #2a2d38;
  --text:      #e4e4e7;
  --text-muted:#71717a;
  --accent:    #6366f1;
  --accent-2:  #818cf8;
  --green:     #22c55e;
  --red:       #ef4444;
  --yellow:    #f59e0b;
  --cyan:      #06b6d4;
  --radius:    12px;
  --radius-sm: 8px;
  --radius-xs: 4px;
  --shadow:    0 4px 24px rgba(0,0,0,.4);
  --transition: 200ms cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}

/* ── App Shell ──────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  padding: 2rem 2.5rem;
  overflow-y: auto;
  max-width: 1400px;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: 240px;
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.nav-brand {
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  border-bottom: 1px solid var(--border);
}

.nav-logo {
  font-size: 1.5rem;
  color: var(--accent);
  filter: drop-shadow(0 0 6px rgba(99,102,241,.4));
}

.nav-title {
  font-weight: 700;
  font-size: 1rem;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav-sections { flex: 1; padding: .75rem 0; }

.nav-section-label {
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  padding: .5rem 1.5rem;
  display: block;
}

.nav-links {
  list-style: none;
  padding: 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .85rem;
  font-weight: 500;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}

.nav-link:hover {
  color: var(--text);
  background: rgba(99,102,241,.06);
  border-left-color: rgba(99,102,241,.3);
}

.nav-link[aria-current="page"],
.nav-link.active {
  color: var(--accent-2);
  background: rgba(99,102,241,.1);
  border-left-color: var(--accent);
}

.nav-icon { font-size: 1rem; }

.nav-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

.nav-status {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .75rem;
  color: var(--text-muted);
}

/* ── Page header ────────────────────────────────────────────────────────── */
.page-header {
  margin-bottom: 1.75rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.page-subtitle {
  font-size: .85rem;
  color: var(--text-muted);
  margin-left: .5rem;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.back-link {
  font-size: .8rem;
  color: var(--accent-2);
  text-decoration: none;
  margin-right: auto;
}
.back-link:hover { text-decoration: underline; }

/* ── Glass Card ─────────────────────────────────────────────────────────── */
.glass-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.card-header h2 {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.card-body { padding: 1.25rem; }

/* ── Stats Grid ─────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  position: relative;
  overflow: hidden;
  transition: all var(--transition);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--cyan));
  opacity: .6;
}

.stat-card:hover {
  border-color: var(--border-2);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  margin-bottom: .25rem;
}

.stat-label {
  font-size: .75rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.stat-icon {
  position: absolute;
  top: 1rem; right: 1rem;
  font-size: 1.5rem;
  color: var(--accent);
  opacity: .15;
}

.stats-loading, .stats-error { padding: 2rem; color: var(--text-muted); text-align: center; }

/* ── Data Tables ────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}

.data-table thead th {
  padding: .6rem 1rem;
  text-align: left;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-2);
}

.data-table tbody td {
  padding: .55rem 1rem;
  border-bottom: 1px solid var(--border);
}

.data-table tbody tr {
  transition: background var(--transition);
}

.data-table tbody tr:hover {
  background: rgba(99,102,241,.04);
}

.clickable-row { cursor: pointer; }

.device-link {
  color: var(--accent-2);
  text-decoration: none;
  font-weight: 600;
}
.device-link:hover { text-decoration: underline; }

.cell-device { font-weight: 500; color: var(--accent-2); }
.cell-readings code {
  font-family: 'JetBrains Mono', monospace;
  font-size: .75rem;
  background: rgba(99,102,241,.08);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  color: var(--text);
  word-break: break-all;
}
.cell-time { color: var(--text-muted); font-size: .75rem; white-space: nowrap; }
.cell-location { color: var(--text-muted); }

.table-loading, .table-error, .table-empty {
  padding: 2.5rem;
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
}

.table-footer {
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  font-size: .75rem;
  color: var(--text-muted);
}

/* ── Toolbar ────────────────────────────────────────────────────────────── */
.toolbar {
  margin-bottom: 1rem;
  display: flex;
  gap: .75rem;
}

.search-input {
  flex: 1;
  max-width: 400px;
  padding: .55rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .85rem;
  outline: none;
  transition: border-color var(--transition);
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: .7rem;
  font-weight: 600;
}

.badge-type {
  background: rgba(99,102,241,.15);
  color: var(--accent-2);
  border: 1px solid rgba(99,102,241,.2);
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn-accent-sm {
  padding: .4rem .9rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}
.btn-accent-sm:hover { background: var(--accent-2); }

.btn-outline-sm {
  padding: .35rem .7rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  font-size: .75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-outline-sm:hover {
  color: var(--text);
  border-color: var(--accent);
}

.btn-outline-sm.btn-danger:hover {
  border-color: var(--red);
  color: var(--red);
}

.btn-ghost { background: none; border: none; cursor: pointer; }
.btn-sm { font-size: .8rem; padding: .3rem .6rem; color: var(--text-muted); }

/* ── Detail Grid ────────────────────────────────────────────────────────── */
.detail-grid { display: flex; flex-direction: column; gap: .5rem; }

.detail-row {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  padding: .4rem 0;
  border-bottom: 1px solid var(--border);
}
.detail-row:last-child { border-bottom: none; }

.detail-label {
  width: 100px;
  flex-shrink: 0;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
}
.detail-value { font-size: .85rem; }
.mono { font-family: 'JetBrains Mono', monospace; font-size: .8rem; }

/* ── Status Dot ─────────────────────────────────────────────────────────── */
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
  transition: all var(--transition);
}

.status-dot.connected {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 6px var(--green); }
  50% { opacity: .6; box-shadow: 0 0 12px var(--green); }
}

/* ── Live Feed ──────────────────────────────────────────────────────────── */
.live-indicator {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .75rem;
  color: var(--text-muted);
}
.live-indicator.connected { color: var(--green); }

.event-counter {
  font-size: .75rem;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

.live-card { overflow: hidden; }

.live-feed {
  max-height: 70vh;
  overflow-y: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: .78rem;
}

.live-empty {
  padding: 3rem;
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  font-family: 'Inter', sans-serif;
}

.live-rows { display: flex; flex-direction: column; }

.live-row {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  padding: 4px 1rem;
  border-left: 3px solid var(--accent);
  border-bottom: 1px solid var(--border);
  animation: slideIn 200ms ease-out;
}

.live-row:hover { background: rgba(99,102,241,.04); }

.live-ts {
  flex-shrink: 0;
  font-size: .68rem;
  color: var(--text-muted);
}

.live-device {
  flex-shrink: 0;
  min-width: 120px;
  font-weight: 600;
}

.live-metric {
  color: var(--green);
  min-width: 100px;
}

.live-value { font-weight: 500; }
.live-unit { color: var(--text-muted); font-size: .7rem; margin-left: 2px; }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Device Map ─────────────────────────────────────────────────────────── */
.map-container { position: relative; }

.map-loading, .map-error {
  padding: 3rem;
  text-align: center;
  color: var(--text-muted);
}

.map-stats {
  padding: 1rem 1.25rem;
  display: flex;
  gap: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.map-stat {
  font-size: .75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  padding: 1.25rem;
}

.map-location {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  border-left-width: 3px;
  transition: all var(--transition);
}

.map-location:hover {
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.map-location-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem 1rem;
  font-size: .8rem;
  font-weight: 600;
}

.map-location-icon { font-size: 1rem; }
.map-location-name { flex: 1; }
.map-location-count {
  font-size: .7rem;
  color: var(--text-muted);
  background: rgba(255,255,255,.06);
  padding: 1px 8px;
  border-radius: 9999px;
}

.map-devices {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: .5rem;
}

.map-device-node {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .45rem .75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
}

.map-device-node:hover {
  transform: translateX(2px);
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

.map-device-name { font-size: .8rem; font-weight: 500; }
.map-device-type { font-size: .7rem; font-weight: 600; }

.map-detail-panel {
  margin-top: 1.25rem;
  animation: slideIn 200ms ease-out;
}

.map-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.map-detail-header h3 { font-size: 1rem; font-weight: 600; }

/* ── 404 ────────────────────────────────────────────────────────────────── */
.not-found {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 1rem;
  text-align: center;
}

.not-found h1 {
  font-size: 4rem;
  font-weight: 800;
  color: var(--accent);
  opacity: .3;
}

.not-found p { color: var(--text-muted); }

/* ── Loading shimmer ────────────────────────────────────────────────────── */
.loading {
  color: var(--text-muted);
  font-style: italic;
}

.error {
  color: var(--red);
  font-size: .85rem;
}

/* ── Scrollbars ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
