/* ============================================================
   SenseAI Dashboard — Dark Theme
   ============================================================ */

/* ---- Reset & Variables ---- */
:root {
  --bg:          #121212;
  --bg-surface:  #1a1a1a;
  --card:        #1e1e2e;
  --card-hover:  #252540;
  --border:      rgba(255,255,255,0.08);
  --text:        #e8e8e8;
  --text-secondary: #888;
  --text-muted:  #555;
  --accent:      #4CAF50;
  --accent-hover:#66BB6A;
  --danger:      #e74c3c;
  --warning:     #f39c12;
  --info:        #3b82f6;
  --purple:      #9C27B0;
  --radius:      12px;
  --radius-sm:   8px;
  --radius-lg:   16px;
  --shadow:      0 4px 24px rgba(0,0,0,0.3);
  --sidebar-w:   72px;
  --font:        'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
img { max-width: 100%; display: block; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }

/* ============================================================
   LAYOUT
   ============================================================ */

#app {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: rgba(18,18,30,0.97);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-brand {
  padding: 16px 0;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand img {
  width: 36px; height: 36px;
  margin: 0 auto;
  object-fit: contain;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 0;
  gap: 4px;
}

.sidebar-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  margin: 0 8px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.45);
  font-size: 10px;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  transition: all .2s ease;
  background: transparent;
  border: none;
}

.sidebar-link .icon { font-size: 22px; margin-bottom: 2px; }
.sidebar-link:hover { background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.85); }
.sidebar-link.active { background: linear-gradient(135deg, var(--accent), rgba(76,175,80,0.25)); color: #fff; }

.sidebar-divider { height: 1px; background: var(--border); margin: 8px 12px; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.sidebar-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #2E7D32);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: #fff;
}

.sidebar-username {
  font-size: 9px;
  color: rgba(255,255,255,0.6);
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-role {
  font-size: 8px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(76,175,80,0.2);
  color: var(--accent);
}

.sidebar-logout {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 4px; margin-top: 6px;
  border-radius: var(--radius-sm);
  background: rgba(239,68,68,0.15); color: #ef4444;
  font-size: 9px; cursor: pointer;
  border: none; width: 100%;
  transition: background .2s;
}
.sidebar-logout:hover { background: #ef4444; color: #fff; }
.sidebar-logout .icon { font-size: 14px; }

/* ---- Main content ---- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  overflow-y: auto;
}

#page-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 24px;
}

/* ============================================================
   LOGIN PAGE (no sidebar)
   ============================================================ */

body.login-page #app { display: block; }
body.login-page .sidebar { display: none; }
body.login-page .main-content { margin-left: 0; }

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #0a0a0a 100%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: rgba(10,10,10,0.85);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  padding: 44px 36px;
  box-shadow: 0 25px 80px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.12);
}

.login-card .logo-area {
  text-align: center;
  margin-bottom: 28px;
}

.login-card .logo-area img {
  max-width: 240px;
  margin: 0 auto 16px;
}

.login-card h2 {
  font-size: 26px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
}

.login-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 28px;
}

.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 14px;
  border: 1px solid #333;
  border-radius: var(--radius);
  background: #111;
  color: #fff;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.form-input:focus {
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.08);
}
.form-input::placeholder { color: #444; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all .2s ease;
}

.btn-primary {
  background: #fff;
  color: #000;
  width: 100%;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(255,255,255,0.15); }

.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover { border-color: var(--text); color: var(--text); }

.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-icon { padding: 8px; min-width: 36px; }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
}
.alert-error { background: rgba(231,76,60,0.12); color: #e74c3c; border: 1px solid rgba(231,76,60,0.25); }
.alert-success { background: rgba(46,204,113,0.12); color: #2ecc71; border: 1px solid rgba(46,204,113,0.25); }
.alert-warning { background: rgba(243,156,18,0.12); color: #f39c12; border: 1px solid rgba(243,156,18,0.25); }

/* ============================================================
   COMMON COMPONENTS
   ============================================================ */

/* ---- Cards ---- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: transform .2s, box-shadow .2s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card-flat { transform: none !important; box-shadow: none !important; }

/* ---- Stat cards ---- */
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.stat-card h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}
.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ---- Grids ---- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-5 { grid-template-columns: repeat(5, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

@media (max-width: 1100px) { .grid-4, .grid-5 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 800px)  { .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px)  { .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; } }

/* ---- Section headers ---- */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.section-header h2 {
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---- Status badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-online  { background: rgba(46,204,113,0.15); color: #2ecc71; }
.badge-warning { background: rgba(243,156,18,0.15); color: #f39c12; }
.badge-offline { background: rgba(231,76,60,0.15);  color: #e74c3c; }
.badge-neutral { background: rgba(107,114,128,0.15);color: #6b7280; }
.badge-accent  { background: rgba(156,39,176,0.15); color: #ce93d8; }

.badge .pulse {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.badge-online .pulse { animation: pulse 2s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .4; transform: scale(1.3); }
}

/* ---- Charts ---- */
.chart-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}
.chart-container h3 {
  font-size: 15px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chart-wrapper {
  position: relative;
  height: 280px;
}

/* ---- Tables ---- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.data-table tr:hover td { background: rgba(255,255,255,0.02); }

/* ---- Filters ---- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
  align-items: center;
}

.filter-bar select,
.filter-bar input {
  padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.filter-bar select:focus,
.filter-bar input:focus {
  border-color: var(--accent);
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: 10px 14px 10px 36px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.search-input:focus { border-color: var(--accent); }

/* ---- Loading / Error ---- */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--text-secondary);
  gap: 12px;
}

.loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

.error-state {
  text-align: center;
  padding: 48px;
  color: var(--text-secondary);
}
.error-state .error-icon { font-size: 40px; display: block; margin-bottom: 12px; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-state .icon { font-size: 64px; margin-bottom: 16px; opacity: .5; }
.empty-state h3 { font-size: 20px; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 14px; max-width: 400px; margin: 0 auto; }

/* ---- Category cards (landing) ---- */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.category-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 28px;
  text-align: center;
  transition: all .3s ease;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.category-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--card-accent);
  opacity: 0;
  transition: opacity .3s;
}
.category-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 16px 40px rgba(0,0,0,0.25);
  border-color: var(--card-accent);
}
.category-card:hover::before { opacity: 1; }

.category-card.sensors   { --card-accent: var(--accent); }
.category-card.playground { --card-accent: var(--purple); }

.category-icon {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  background: linear-gradient(135deg, var(--card-accent), transparent);
}

.category-card h2 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.category-card .description { font-size: 13px; color: var(--text-secondary); line-height: 1.5; margin-bottom: 16px; }

.category-card .stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 16px;
}
.category-card .stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--card-accent);
}
.category-card .stat-label {
  font-size: 10px;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.enter-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--card-accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s;
}
.enter-btn:hover { transform: scale(1.05); }

/* ---- Device cards (sensor list — legacy tile style, kept for reuse) ---- */
.device-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  cursor: pointer;
  transition: all .2s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.device-card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.device-card .device-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.device-card .device-name {
  font-size: 15px;
  font-weight: 700;
}
.device-card .device-type {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  background: rgba(76,175,80,0.15);
  color: var(--accent);
  text-transform: uppercase;
  font-weight: 600;
}

.device-card .device-location {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}

.device-card .device-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.device-card .metric {
  text-align: center;
  padding: 8px 4px;
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius-sm);
}
.device-card .metric .metric-value {
  font-size: 16px;
  font-weight: 700;
}
.device-card .metric .metric-label {
  font-size: 9px;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.device-card .device-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
}

/* ---- Sensor Table (list view) ---- */
.sensor-info-bar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 16px;
}
.info-bar-items {
  display: flex;
  gap: 24px;
  align-items: center;
  flex-wrap: wrap;
}
.info-bar-item {
  display: flex;
  align-items: center;
  gap: 8px;
}
.info-bar-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}
.info-bar-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.info-bar-item select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
}

.sensor-table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.sensor-table {
  width: 100%;
  border-collapse: collapse;
}
.sensor-table thead tr {
  background: linear-gradient(135deg, var(--accent), #2e7d32);
}
.sensor-table th {
  padding: 14px 12px;
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: center;
  white-space: nowrap;
}
.sensor-table th.col-device { text-align: left; }
.sensor-table td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
  text-align: center;
  vertical-align: middle;
}
.sensor-table td.col-device { text-align: left; }
.sensor-table td.col-seen { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }

.sensor-table .device-row:hover td {
  background: rgba(76,175,80,0.08);
}

.device-cell-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.device-icon-circle {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent), #2e7d32);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 4px 8px rgba(76,175,80,0.3);
  flex-shrink: 0;
}
.device-serial {
  font-weight: 700;
  font-size: 14px;
}
.device-mac {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

.cell-icon { font-size: 14px; opacity: 0.7; margin-right: 4px; }
.cell-value { font-weight: 700; font-size: 14px; }
.cell-unit { font-size: 11px; color: var(--text-secondary); margin-left: 2px; }
.temp-color { color: #ef4444; }
.hum-color { color: #3b82f6; }

.battery-indicator {
  width: 32px;
  height: 12px;
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.15);
  display: inline-block;
  vertical-align: middle;
  margin-right: 6px;
}
.battery-level {
  height: 100%;
  background: linear-gradient(90deg, #ef4444, #f59e0b, #4CAF50);
  border-radius: 5px;
  transition: width 0.5s ease;
}
.battery-percent { font-size: 12px; color: var(--text-secondary); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.status-pill.online { background: rgba(76,175,80,0.15); color: #4CAF50; }
.status-pill.warning { background: rgba(243,156,18,0.15); color: #f39c12; }
.status-pill.offline { background: rgba(239,68,68,0.15); color: #ef4444; }

.status-dot-sm {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot-sm.online { background: #4CAF50; animation: pulse-dot 2s infinite; }
.status-dot-sm.warning { background: #f39c12; }
.status-dot-sm.offline { background: #ef4444; }
@keyframes pulse-dot { 0%,100%{opacity:1} 50%{opacity:.5} }

.table-error { text-align: center; padding: 40px; color: #ef4444; }

/* Date filter */
.sensor-date-filter {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
}
.sensor-date-filter h3 {
  margin: 0 0 16px 0;
  font-size: 16px;
  color: var(--text);
}
.date-filter-controls {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.date-input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.date-input-group label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}
.date-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  min-width: 150px;
}
.date-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(76,175,80,0.2);
}

/* Stat card enhancements for sensors page */
.stat-card .stat-icon { font-size: 28px; margin-bottom: 6px; line-height: 1; }

/* CSS-based stat icons (avoid emoji encoding issues) */
.stat-icon.temp-icon::before  { content: "T"; font-weight: 800; color: #e74c3c; }
.stat-icon.hum-icon::before   { content: "H"; font-weight: 800; color: #3498db; }
.stat-icon.net-icon::before   { content: "N"; font-weight: 800; color: #2ecc71; }
.stat-icon.bat-icon::before   { content: "B"; font-weight: 800; color: #f39c12; }

/* Device icon circles */
.icon-sensor::before { content: "S"; font-weight: 700; font-size: 14px; }
.icon-ruler::before  { content: "R"; font-weight: 700; font-size: 14px; }

/* Sensei chat widget */
.sensei-widget { background: var(--card); border-radius: var(--radius); padding: 20px; border: 1px solid var(--border); }
.sensei-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.sensei-avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; }
.sensei-chat-area { max-height: 300px; overflow-y: auto; margin-bottom: 12px; display: flex; flex-direction: column; gap: 8px; }
.sensei-msg { padding: 10px 14px; border-radius: 12px; font-size: 13px; line-height: 1.5; max-width: 85%; word-wrap: break-word; }
.sensei-msg.user { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.sensei-msg.bot { background: rgba(255,255,255,0.06); color: var(--text); align-self: flex-start; border-bottom-left-radius: 4px; }
.sensei-input-area { display: flex; gap: 8px; }
.sensei-input-area .form-input { flex: 1; }
.typing-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--text-secondary); margin: 0 2px; animation: typingBounce 1.2s infinite ease-in-out; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce { 0%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-6px); } }

/* Grid helpers */
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 768px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .sensor-table th:nth-child(n+3), .sensor-table td:nth-child(n+3) {
    display: none;
  }
  .sensor-table th.col-status, .sensor-table td.col-status { display: table-cell; }
}

/* ---- Progress bar ---- */
.progress-bar {
  height: 8px;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .5s ease;
}
.progress-fill.excellent { background: #2ecc71; }
.progress-fill.good      { background: #4ecdc4; }
.progress-fill.warning   { background: #f39c12; }
.progress-fill.critical  { background: #e74c3c; }

/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all .2s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- Back button ---- */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all .2s;
}
.back-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- Tooltip ---- */
.tooltip { position: relative; }
.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%; left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: #333;
  color: #fff;
  font-size: 11px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.tooltip:hover::after { opacity: 1; }

/* ---- Mobile ---- */
.mobile-toggle {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 200;
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  background: rgba(18,18,30,0.95);
  border: 1px solid var(--border);
  color: #fff;
  font-size: 20px;
  align-items: center; justify-content: center;
  cursor: pointer;
}

@media (max-width: 768px) {
  .mobile-toggle { display: flex; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  #page-content { padding: 16px; }
  .category-grid { grid-template-columns: 1fr; }
}

/* ---- Quick info bar (landing) ---- */
.quick-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.info-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.info-card .icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  background: rgba(76,175,80,0.15);
  flex-shrink: 0;
}
.info-card h4 {
  font-size: 10px;
  color: var(--text-secondary);
  margin-bottom: 2px;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 500;
}
.info-card .value {
  font-size: 16px;
  font-weight: 700;
}

/* ---- Space cards (playground) ---- */
.space-card {
  background: var(--card);
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  padding: 22px;
  cursor: pointer;
  transition: all .2s;
}
.space-card:hover {
  border-color: var(--purple);
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0,0,0,0.15);
}
.space-card .name { font-size: 17px; font-weight: 700; }
.space-card .description { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

.new-space-card {
  background: var(--card);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  transition: all .2s;
}
.new-space-card:hover { border-color: var(--purple); background: rgba(156,39,176,0.05); }
.new-space-card .icon { font-size: 40px; margin-bottom: 12px; opacity: .5; }
.new-space-card .text { font-size: 14px; font-weight: 600; color: var(--text-secondary); }

/* ---- Alerts summary ---- */
.alerts-summary {
  display: flex;
  gap: 8px;
  align-items: center;
}
.alert-count {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
}
.alert-count.critical { background: rgba(231,76,60,0.15); color: #e74c3c; }
.alert-count.warning  { background: rgba(243,156,18,0.15); color: #f39c12; }
.alert-count.info     { background: rgba(59,130,246,0.15); color: #3b82f6; }

/* ---- Page footer ---- */
.page-footer {
  margin-top: 40px;
  padding: 20px 0;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}
.page-footer .copyright { margin-bottom: 2px; }
.page-footer .build { font-size: 11px; opacity: .6; }

/* ---- Alerts badge ---- */
.alerts-summary {
  display: flex;
  gap: 12px;
}
.alerts-summary .alert-count {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.alerts-summary .critical { background: rgba(231,76,60,0.15); color: #e74c3c; }
.alerts-summary .warning  { background: rgba(243,156,18,0.15); color: #f39c12; }
.alerts-summary .info     { background: rgba(59,130,246,0.15); color: #3b82f6; }

/* ---- Footer ---- */
.page-footer {
  text-align: center;
  padding: 32px;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}
.page-footer .copyright { font-size: 12px; color: var(--text-muted); }
.page-footer .build { font-size: 10px; color: var(--text-muted); margin-top: 4px; }

/* ============================================================
   NEW — Sensors page enhancements
   ============================================================ */

/* Distance star + event badge */
.distance-star { font-size: 14px; vertical-align: middle; margin-left: 2px; }
.event-badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 10px;
  background: rgba(255,152,0,0.15); color: #FF9800;
  margin-left: 4px; vertical-align: middle;
}

.dist-color { color: #a78bfa; }

/* Event log table */
.event-closer  { color: #2ecc71; font-weight: 700; }
.event-farther { color: #e74c3c; font-weight: 700; }
.event-type-badge {
  display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 11px; font-weight: 600;
}
.event-type-badge.event-closer  { background: rgba(46,204,113,0.15); color: #2ecc71; }
.event-type-badge.event-farther { background: rgba(231,76,60,0.15); color: #e74c3c; }

/* Device cell info */
.device-cell-info { display: flex; align-items: center; gap: 10px; }
.device-icon-circle {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(76,175,80,0.15); display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.device-icon-circle.offline { background: rgba(136,136,136,0.15); opacity: .6; }
.device-serial { font-weight: 600; font-size: 13px; }
.device-mac { font-size: 11px; color: var(--text-muted); font-family: monospace; }

/* Last value timestamp */
.last-value-relative { font-weight: 600; font-size: 13px; }
.last-value-abs { font-size: 11px; color: var(--text-muted); }

/* Battery indicator in table */
.battery-indicator {
  width: 48px; height: 8px; background: rgba(255,255,255,0.08);
  border-radius: 4px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 6px;
}
.battery-level { height: 100%; border-radius: 4px; transition: width .3s; }
.battery-percent { font-size: 12px; color: var(--text-secondary); }

/* Info bar */
.sensor-info-bar {
  background: var(--card); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px;
}
.info-bar-items { display: flex; gap: 24px; flex-wrap: wrap; align-items: center; }
.info-bar-item { display: flex; align-items: center; gap: 6px; }
.info-bar-label { font-size: 12px; color: var(--text-secondary); }
.info-bar-value { font-size: 13px; font-weight: 600; }

/* Date filter */
.sensor-date-filter {
  background: var(--card); border-radius: var(--radius); padding: 16px 20px;
}
.sensor-date-filter h3 { font-size: 14px; margin-bottom: 10px; }
.date-filter-controls { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.date-input-group { display: flex; flex-direction: column; gap: 4px; }
.date-input-group label { font-size: 11px; color: var(--text-secondary); }
.date-input {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); padding: 6px 10px; font-size: 13px;
}

/* Sensor table improvements */
.col-dist { min-width: 100px; }

/* Small table variant */
.small-table { font-size: 13px; }
.small-table th { font-size: 11px; }
.small-table td { padding: 8px 10px; }

/* Search input */
.search-input {
  width: 100%; padding: 10px 14px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 14px; outline: none;
  transition: border-color .2s;
}
.search-input:focus { border-color: var(--accent); }

/* ============================================================
   NEW — Spaces page
   ============================================================ */

.page-subtitle { color: var(--text-secondary); margin-bottom: 20px; font-size: 14px; }

.spaces-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.spaces-empty {
  background: var(--card); border: 2px dashed var(--border); border-radius: var(--radius-lg);
  padding: 40px; text-align: center; cursor: pointer; transition: border-color .2s;
}
.spaces-empty:hover { border-color: var(--purple); }
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: .5; }

.space-card-header {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.space-card-header h3 { font-size: 16px; font-weight: 700; flex: 1; }
.space-card-icon { font-size: 24px; }
.space-card-actions { display: flex; gap: 4px; }
.space-card-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; min-height: 36px; }
.space-card-meta { display: flex; gap: 16px; font-size: 12px; color: var(--text-secondary); }
.space-card-footer {
  display: flex; justify-content: space-between; align-items: center; margin-top: 16px;
  padding-top: 12px; border-top: 1px solid var(--border);
}

.btn-icon {
  background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px;
  border-radius: 6px; transition: background .15s;
}
.btn-icon:hover { background: rgba(255,255,255,0.08); }

/* Stats mini */
.stat-card.mini { padding: 14px 16px; }
.stat-card.mini .stat-value { font-size: 24px; }
.stat-card.mini h4 { font-size: 11px; margin-top: 4px; }

/* ============================================================
   NEW — Modal
   ============================================================ */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-content {
  background: var(--bg-surface); border-radius: var(--radius-lg); width: 100%;
  max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--text-secondary); font-size: 24px;
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: rgba(255,255,255,0.08); }
.modal-body { padding: 24px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 24px; border-top: 1px solid var(--border); }

/* Form controls */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 8px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 14px; outline: none;
  font-family: var(--font);
}
.form-control:focus { border-color: var(--accent); }
textarea.form-control { resize: vertical; }

/* Checkbox label */
.cb-label { display: block; padding: 4px 0; cursor: pointer; font-size: 13px; }
.cb-label input { margin-right: 8px; accent-color: var(--accent); }

/* Device checklist scroll */
.device-checklist { max-height: 180px; overflow-y: auto; padding: 8px 0; }
.var-checklist { display: flex; flex-wrap: wrap; gap: 8px 20px; }

/* ============================================================
   NEW — Space Detail Layout
   ============================================================ */

.space-detail-layout { display: flex; gap: 24px; min-height: 70vh; }

.space-sidebar {
  width: 280px; flex-shrink: 0; background: var(--card); border-radius: var(--radius-lg);
  padding: 24px; position: sticky; top: 24px; max-height: calc(100vh - 48px); overflow-y: auto;
}
.space-sidebar h2 { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.space-sidebar-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 20px; }

.sidebar-section { margin-bottom: 20px; }
.sidebar-section h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-secondary); margin-bottom: 8px; }

.device-list-sidebar { list-style: none; }
.device-list-sidebar li { padding: 4px 0; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.device-list-sidebar a:hover { color: var(--accent); }

.var-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.var-tag {
  background: rgba(156,39,176,0.12); color: var(--purple); padding: 3px 10px;
  border-radius: 12px; font-size: 11px; font-weight: 600;
}

.collab-list { list-style: none; }
.collab-list li { padding: 3px 0; font-size: 13px; }

/* Sensei widget in sidebar */
.sensei-widget {
  background: rgba(156,39,176,0.08); border-radius: var(--radius); padding: 16px;
  text-align: center; margin-top: 16px;
}
.sensei-avatar-sidebar { width: 64px; height: 64px; object-fit: contain; margin: 0 auto 8px; }
.sensei-widget-text h4 { font-size: 14px; margin-bottom: 2px; }
.sensei-widget-text p { font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; }

.space-main { flex: 1; min-width: 0; }

/* Chart controls */
.chart-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chart-controls { display: flex; gap: 8px; }
.chart-controls select {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); padding: 4px 8px; font-size: 12px;
}

/* ============================================================
   NEW — Inference Model Cards
   ============================================================ */

.inference-grid { gap: 16px; }

.model-card {
  background: var(--card); border-radius: var(--radius); padding: 16px; position: relative;
  transition: transform .15s;
}
.model-card:hover { transform: translateY(-2px); }
.model-card-header { padding-left: 12px; margin-bottom: 8px; }
.model-card-header h4 { font-size: 15px; font-weight: 700; }
.model-full-name { font-size: 11px; color: var(--text-secondary); }
.model-desc { font-size: 12px; color: var(--text-secondary); margin-bottom: 12px; }

.model-accuracy { display: flex; align-items: center; gap: 8px; }
.accuracy-bar { flex: 1; height: 6px; background: rgba(255,255,255,0.08); border-radius: 3px; overflow: hidden; }
.accuracy-fill { height: 100%; border-radius: 3px; }
.accuracy-pct { font-size: 13px; font-weight: 700; min-width: 44px; text-align: right; }

.mockup-badge {
  position: absolute; top: 8px; right: 8px; font-size: 10px; font-weight: 600;
  background: rgba(255,255,255,0.06); color: var(--text-muted); padding: 2px 8px;
  border-radius: 6px; text-transform: uppercase; letter-spacing: .5px;
}

/* Correlation matrix */
.corr-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.corr-table th { padding: 6px 8px; font-weight: 600; color: var(--text-secondary); font-size: 11px; }
.corr-table td { padding: 6px 8px; border-radius: 4px; font-weight: 600; }

/* Anomaly mockup */
.anomaly-mockup { display: flex; gap: 24px; flex-wrap: wrap; padding: 16px 0; }
.anomaly-stat { display: flex; align-items: center; gap: 10px; }
.anomaly-count { font-size: 28px; font-weight: 800; }

/* Simulation mockup */
.simulation-mockup { background: var(--card); border-radius: var(--radius); padding: 20px; }
.form-range { width: 100%; accent-color: var(--accent); }
.sim-val { display: block; text-align: center; font-weight: 600; font-size: 13px; margin-top: 4px; }
.sim-result-card { background: rgba(76,175,80,0.08); border-radius: var(--radius); padding: 16px; }

/* ============================================================
   NEW — Sensei Chat Modal
   ============================================================ */

.sensei-chat-container {
  background: var(--bg-surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 600px; height: 70vh; max-height: 700px;
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}

.sensei-chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.sensei-chat-header h3 { font-size: 16px; margin: 0; }
.sensei-chat-header p { font-size: 12px; margin: 0; }
.sensei-chat-header .modal-close { margin-left: auto; }
.sensei-chat-icon { width: 40px; height: 40px; object-fit: contain; }

.sensei-chat-messages {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 16px;
}

.chat-msg { display: flex; gap: 10px; max-width: 85%; }
.chat-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg.sensei { align-self: flex-start; }

.chat-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: contain; flex-shrink: 0; }

.chat-bubble {
  padding: 10px 14px; border-radius: 14px; font-size: 13px; line-height: 1.5;
}
.chat-msg.user .chat-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.sensei .chat-bubble { background: var(--card); border-bottom-left-radius: 4px; }

/* Typing indicator */
.chat-bubble.typing { display: flex; gap: 5px; align-items: center; padding: 14px 18px; }
.chat-bubble.typing .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted);
  animation: typingDot 1.4s infinite ease-in-out;
}
.chat-bubble.typing .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-bubble.typing .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

.sensei-chat-input {
  display: flex; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--border);
}
.sensei-chat-input .form-control { flex: 1; }

/* ============================================================
   Space Detail responsive
   ============================================================ */
@media (max-width: 900px) {
  .space-detail-layout { flex-direction: column; }
  .space-sidebar { width: 100%; position: static; max-height: none; }
}
