/* ════════════════════════════════════════════════════════════
   IoT Platform Dashboard — Styles
   ════════════════════════════════════════════════════════════ */

:root {
  --bg:        #0f1117;
  --bg-card:   #1a1d27;
  --bg-hover:  #222634;
  --border:    #2a2e3e;
  --text:      #e4e6ef;
  --text-dim:  #8b8fa3;
  --accent:    #f6821f;
  --accent-dim:#f6821f33;
  --green:     #22c55e;
  --red:       #ef4444;
  --yellow:    #fbbf24;
  --blue:      #3b82f6;
  --radius:    12px;
  --sidebar-w: 240px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Login ──────────────────────────────────────────────── */
.screen { min-height: 100vh; display: flex; }

#login-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #1a1d27 0%, #0f1117 100%);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  text-align: center;
  width: 400px;
  max-width: 90vw;
}

.logo {
  width: 64px; height: 64px;
  background: var(--accent);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 800; color: #000;
  margin: 0 auto 24px;
}

.login-card h1 { font-size: 24px; margin-bottom: 8px; }
.subtitle { color: var(--text-dim); font-size: 14px; margin-bottom: 32px; }

.login-card input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  margin-bottom: 16px;
}

.login-card input:focus { outline: none; border-color: var(--accent); }

.hint { color: var(--text-dim); font-size: 12px; margin-top: 16px; }

/* ── Buttons ────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
  transition: opacity .2s;
}
.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.btn-secondary:hover { background: var(--border); }

.btn-logout {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  width: 100%;
}
.btn-logout:hover { color: var(--red); border-color: var(--red); }

/* ── Layout ─────────────────────────────────────────────── */
#main-screen { display: flex; width: 100vw; height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.logo-sm {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: #000;
}

.sidebar-title { font-weight: 700; font-size: 16px; }

.sidebar nav { flex: 1; padding: 16px 12px; }

.nav-item {
  display: block;
  padding: 10px 16px;
  color: var(--text-dim);
  text-decoration: none;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 4px;
  transition: all .15s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }

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

.ws-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot.offline { background: var(--red); }

/* ── Content ────────────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.view { display: none; }
.view.active { display: block; }
.view h2 { margin-bottom: 24px; font-size: 22px; }
.view h3 { margin: 24px 0 16px; font-size: 16px; color: var(--text-dim); }

.view-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.view-header h2 { margin: 0; flex: 1; }

/* ── Stats ──────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.stat-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 4px;
}

.stat-label { color: var(--text-dim); font-size: 13px; }

/* ── Device Grid ────────────────────────────────────────── */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.device-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color .2s;
}
.device-card:hover { border-color: var(--accent); }

.device-card .name { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.device-card .type { color: var(--text-dim); font-size: 12px; margin-bottom: 12px; }
.device-card .state {
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: monospace;
  color: var(--green);
  word-break: break-all;
}

/* ── Tables ─────────────────────────────────────────────── */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  text-align: left;
  padding: 12px 16px;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ── Status Badges ──────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
}
.badge.online  { background: #22c55e22; color: var(--green); }
.badge.offline { background: #ef444422; color: var(--red); }
.badge.pending { background: #fbbf2422; color: var(--yellow); }
.badge.delivered { background: #3b82f622; color: var(--blue); }
.badge.executed { background: #22c55e22; color: var(--green); }
.badge.failed  { background: #ef444422; color: var(--red); }
.badge.warning { background: #fbbf2422; color: var(--yellow); }
.badge.critical { background: #ef444422; color: var(--red); }
.badge.info { background: #3b82f622; color: var(--blue); }

/* ── Modal ──────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 440px;
  max-width: 90vw;
}

.modal-card h3 { margin-bottom: 24px; }
.modal-card label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  margin-top: 16px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.modal-card input, .modal-card select, .modal-card textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.modal-card textarea { resize: vertical; }
.modal-card input:focus, .modal-card select:focus, .modal-card textarea:focus {
  outline: none; border-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 28px;
}

/* ── Select ─────────────────────────────────────────────── */
select {
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

/* ── Live Feed ──────────────────────────────────────────── */
.live-feed {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.feed-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  animation: fadeIn .3s ease;
}
.feed-item:hover { background: var(--bg-hover); }
.feed-item .ts { color: var(--text-dim); font-family: monospace; font-size: 12px; white-space: nowrap; }
.feed-item .dev { color: var(--accent); font-weight: 600; }
.feed-item .data { color: var(--green); font-family: monospace; }

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

/* ── Chart ──────────────────────────────────────────────── */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  height: 400px;
  position: relative;
}

/* ── API Key Cell ───────────────────────────────────────── */
.api-key-cell {
  font-family: monospace;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.api-key-cell:hover { color: var(--accent); }

/* ── Filter Label ───────────────────────────────────────── */
.filter-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.filter-label input { cursor: pointer; }

/* ── Alert Feed Item ────────────────────────────────────── */
.feed-item.alert-feed {
  border-left: 3px solid var(--yellow);
}

/* ── Telemetry Stats ────────────────────────────────────── */
#telemetry-stats-grid .stat-card {
  padding: 16px 20px;
}
#telemetry-stats-grid .stat-value {
  font-size: 14px;
}

/* ── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Tag Chips ─────────────────────────────────────────── */
.tag-chip {
  display: inline-block;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 4px;
  margin-bottom: 2px;
}
.tags-cell { max-width: 180px; }

/* ── Actions Cell ──────────────────────────────────────── */
.actions-cell {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* ── URL Cell ──────────────────────────────────────────── */
.url-cell {
  font-family: monospace;
  font-size: 12px;
  color: var(--text-dim);
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Section Hint ──────────────────────────────────────── */
.section-hint {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* ── Field Hint ────────────────────────────────────────── */
.field-hint {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 4px;
  margin-bottom: 8px;
}

/* ── Compare Controls ──────────────────────────────────── */
.compare-controls {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.compare-field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.compare-field input, .compare-field select {
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  width: 100%;
  max-width: 400px;
}

/* ── Checkbox Group ────────────────────────────────────── */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.checkbox-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  padding: 6px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.checkbox-item:hover { border-color: var(--accent); }
.checkbox-item input { cursor: pointer; }

/* ── Template Bar ──────────────────────────────────────── */
.template-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  flex-wrap: wrap;
}
.template-label {
  color: var(--text-dim);
  font-size: 13px;
  white-space: nowrap;
}
.template-btn {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid transparent;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.template-btn:hover {
  background: var(--accent);
  color: #000;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Shadow Panels ─────────────────────────────────────── */
.shadow-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.shadow-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.shadow-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.shadow-panel-header h3 {
  margin: 0;
  font-size: 15px;
  color: var(--text);
}
.shadow-state {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: monospace;
  font-size: 13px;
  color: var(--green);
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 120px;
  max-height: 400px;
  overflow-y: auto;
}

/* ── Theme Button ──────────────────────────────────────── */
.btn-theme {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  width: 100%;
  margin-bottom: 12px;
}
.btn-theme:hover { color: var(--accent); border-color: var(--accent); }

/* ── Import Textarea ───────────────────────────────────── */
#import-textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: monospace;
  resize: vertical;
}
#import-textarea:focus { outline: none; border-color: var(--accent); }

/* ── Light Theme ───────────────────────────────────────── */
body.light-theme {
  --bg:        #f5f6fa;
  --bg-card:   #ffffff;
  --bg-hover:  #e8eaf0;
  --border:    #d8dae6;
  --text:      #1a1d27;
  --text-dim:  #6b7280;
  --accent:    #ea6c0a;
  --accent-dim:#ea6c0a18;
}
body.light-theme .login-card input,
body.light-theme .modal-card input,
body.light-theme .modal-card select,
body.light-name .modal-card textarea {
  background: var(--bg-hover);
}
body.light-theme .badge.online  { background: #22c55e18; }
body.light-theme .badge.offline { background: #ef444418; }
body.light-theme .shadow-state { color: #16a34a; }
body.light-theme .feed-item .data { color: #16a34a; }

/* ── Auth Tabs ─────────────────────────────────────────── */
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 12px 8px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all .15s;
}
.auth-tab:hover { color: var(--text); }
.auth-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.auth-panel input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
}
.auth-panel input:focus { outline: none; border-color: var(--accent); }
.auth-link {
  color: var(--accent);
  text-decoration: none;
}
.auth-link:hover { text-decoration: underline; }

/* ── Current User Info ─────────────────────────────────── */
.current-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  margin-bottom: 8px;
}
.user-avatar {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #000;
  flex-shrink: 0;
}
.user-name {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
