/* ── ThingsBoard-inspired Design Tokens ─────────────────────────────────── */
:root {
  --tb-bg:             #1c2134;
  --tb-surface:        #273142;
  --tb-surface-alt:    #2a3550;
  --tb-surface-hover:  #2e3a55;
  --tb-topbar:         #0d1b2e;
  --tb-sidebar:        #1a2744;
  --tb-sidebar-active: #305680;
  --tb-sidebar-hover:  rgba(255,255,255,0.06);
  --tb-primary:        #305680;
  --tb-primary-hover:  #3d6898;
  --tb-accent:         #00bcd4;
  --tb-success:        #4caf50;
  --tb-warning:        #ff9800;
  --tb-danger:         #f44336;
  --tb-danger-hover:   #d32f2f;
  --tb-text:           #ecf0f1;
  --tb-text-secondary: #90a4b4;
  --tb-text-muted:     #546e7a;
  --tb-border:         #2e3d4f;

  /* Widget accent colors by type */
  --wc-temp:     #2196f3;
  --wc-humidity: #00bcd4;
  --wc-switch:   #ff9800;
  --wc-number:   #9c27b0;
  --wc-text:     #4caf50;
  --wc-json:     #607d8b;
  --wc-current:  #ffc107;
  --wc-volt:     #ff5722;
  --wc-power:    #8bc34a;
  --wc-gps:      #009688;

  --topbar-height: 52px;
  --sidebar-width: 220px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --shadow-card: 0 2px 12px rgba(0,0,0,0.5);
  --shadow-top:  0 2px 8px rgba(0,0,0,0.6);

  /* Legacy aliases so existing JS still works */
  --color-bg-primary:    var(--tb-bg);
  --color-bg-secondary:  var(--tb-surface);
  --color-bg-tertiary:   var(--tb-surface-alt);
  --color-accent:        var(--tb-accent);
  --color-accent-hover:  #00a0b5;
  --color-success:       var(--tb-success);
  --color-danger:        var(--tb-danger);
  --color-danger-hover:  var(--tb-danger-hover);
  --color-text-primary:  var(--tb-text);
  --color-text-secondary:var(--tb-text-secondary);
  --color-text-muted:    var(--tb-text-muted);
  --color-border:        var(--tb-border);
}

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

body {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--tb-bg);
  color: var(--tb-text);
  min-height: 100vh;
  font-size: 14px;
}

a { color: var(--tb-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 20px; font-weight: 500; color: var(--tb-text); margin-bottom: 16px; }
h2 { font-size: 16px; font-weight: 500; color: var(--tb-text); margin-bottom: 12px; }
h3 { font-size: 15px; font-weight: 500; color: var(--tb-text); }

/* ── Top App Bar ─────────────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: var(--tb-topbar);
  box-shadow: var(--shadow-top);
  display: flex;
  align-items: center;
  padding: 0 16px 0 0;
  z-index: 200;
  gap: 0;
}

.topbar-hamburger {
  width: var(--sidebar-width);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  color: var(--tb-text);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

.topbar-logo {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--tb-accent), var(--tb-primary));
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  color: #fff;
  flex-shrink: 0;
}

.topbar-title { color: var(--tb-text); font-weight: 500; font-size: 15px; }

.topbar-breadcrumb {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--tb-text-secondary);
}

.topbar-breadcrumb .page-title {
  color: var(--tb-text);
  font-weight: 500;
  font-size: 15px;
}

.topbar-breadcrumb .sep { opacity: 0.4; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.topbar-btn {
  background: none;
  border: none;
  color: var(--tb-text-secondary);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background 0.15s, color 0.15s;
  padding: 0;
}

.topbar-btn:hover { background: rgba(255,255,255,0.08); color: var(--tb-text); }

.topbar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--tb-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  flex-shrink: 0;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: default;
  font-size: 13px;
}

.topbar-username {
  color: var(--tb-text-secondary);
  font-size: 13px;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
  padding-top: var(--topbar-height);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--tb-sidebar);
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  border-right: 1px solid rgba(0,0,0,0.2);
}

.sidebar-section-label {
  padding: 16px 16px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--tb-text-muted);
}

.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: var(--tb-text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 400;
  transition: all 0.15s;
  border-radius: 0;
  position: relative;
}

.sidebar-nav a:hover {
  background: var(--tb-sidebar-hover);
  color: var(--tb-text);
}

.sidebar-nav a.active {
  background: rgba(48, 86, 128, 0.4);
  color: var(--tb-accent);
}

.sidebar-nav a.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--tb-accent);
  border-radius: 0 2px 2px 0;
}

.nav-icon {
  font-size: 17px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
  opacity: 0.8;
}

.sidebar-nav a.active .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(0,0,0,0.2);
}

.sidebar-footer .user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--tb-text);
  margin-bottom: 2px;
}

.sidebar-footer .user-meta {
  font-size: 11px;
  color: var(--tb-text-muted);
  margin-bottom: 10px;
}

/* ── Main Content ───────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 20px 24px;
  min-height: calc(100vh - var(--topbar-height));
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--tb-border);
}

.page-header h1 { margin-bottom: 0; }

/* ── KPI Cards ──────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--tb-surface);
  border-radius: var(--radius-md);
  padding: 0;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.kpi-card-inner {
  padding: 18px 20px;
  flex: 1;
}

.kpi-card .kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--tb-text-secondary);
  margin-bottom: 10px;
}

.kpi-card .kpi-value {
  font-size: 30px;
  font-weight: 300;
  color: var(--tb-text);
  line-height: 1;
}

.kpi-card .kpi-sub {
  font-size: 11px;
  color: var(--tb-text-muted);
  margin-top: 6px;
}

.kpi-card-bar {
  height: 3px;
}
.kpi-card-bar.devices  { background: linear-gradient(90deg, var(--tb-primary), #4273a0); }
.kpi-card-bar.online   { background: linear-gradient(90deg, var(--tb-success), #66bb6a); }
.kpi-card-bar.rooms    { background: linear-gradient(90deg, var(--tb-warning), #ffa726); }
.kpi-card-bar.mqtt     { background: linear-gradient(90deg, var(--tb-accent), #26c6da); }

/* ── Panels / Sections ──────────────────────────────────────────────────── */
.panel {
  background: var(--tb-surface);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.panel-titlebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  height: 44px;
  background: var(--tb-surface-alt);
  border-bottom: 1px solid var(--tb-border);
  cursor: pointer;
  user-select: none;
}

.panel-titlebar h2 {
  margin-bottom: 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--tb-text-secondary);
}

.panel-toggle { color: var(--tb-text-muted); font-size: 16px; transition: transform 0.2s; }
.panel-toggle.collapsed { transform: rotate(-90deg); }

.panel-body { padding: 16px; }
.panel-body.collapsed { display: none; }

/* Legacy .panel-header / .panel-content aliases */
.panel-header { display: flex; justify-content: space-between; align-items: center; padding: 0 16px; height: 44px; background: var(--tb-surface-alt); border-bottom: 1px solid var(--tb-border); cursor: pointer; user-select: none; }
.panel-header h2 { margin-bottom: 0; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--tb-text-secondary); }
.panel-content { padding: 16px; }
.panel-content.collapsed { display: none; }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

/* ── Widget Cards (ThingsBoard-style) ───────────────────────────────────── */
.widget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.widget-card {
  background: var(--tb-surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s;
  position: relative;
}

.widget-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.6); }

.widget-accent {
  height: 3px;
  background: var(--wc-temp);
}
.widget-accent.temperature { background: var(--wc-temp); }
.widget-accent.humidity    { background: var(--wc-humidity); }
.widget-accent.switch      { background: var(--wc-switch); }
.widget-accent.number      { background: var(--wc-number); }
.widget-accent.text        { background: var(--wc-text); }
.widget-accent.json        { background: var(--wc-json); }
.widget-accent.current     { background: var(--wc-current); }
.widget-accent.volt        { background: var(--wc-volt); }
.widget-accent.power       { background: var(--wc-power); }
.widget-accent.gps         { background: var(--wc-gps); }

.widget-header {
  padding: 8px 12px 8px 14px;
  background: var(--tb-surface-alt);
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 40px;
  border-bottom: 1px solid var(--tb-border);
}

.widget-title-wrap { min-width: 0; flex: 1; }

.widget-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--tb-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.widget-topic {
  font-size: 10px;
  color: var(--tb-text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.widget-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  margin-left: 8px;
}

.widget-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #455a64;
  flex-shrink: 0;
  margin-right: 4px;
}
.widget-status.active {
  background: var(--tb-success);
  box-shadow: 0 0 6px var(--tb-success);
}
.widget-status.offline { background: var(--tb-danger); box-shadow: 0 0 6px rgba(244,67,54,0.5); }

.widget-icon-btn {
  background: none;
  border: none;
  color: var(--tb-text-muted);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.15s;
  padding: 0;
}

.widget-icon-btn:hover { background: rgba(255,255,255,0.08); color: var(--tb-text); }
.widget-icon-btn.danger:hover { background: rgba(244,67,54,0.15); color: var(--tb-danger); }

.widget-body {
  padding: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Value widget */
.widget-value-display {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  text-align: center;
}

.widget-value {
  font-size: 44px;
  font-weight: 300;
  color: var(--tb-text);
  line-height: 1;
  letter-spacing: -1px;
}

.widget-unit {
  font-size: 18px;
  color: var(--tb-text-muted);
  margin-left: 4px;
  font-weight: 400;
  vertical-align: super;
  font-size: 14px;
}

.widget-footer {
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--tb-border);
  font-size: 11px;
  color: var(--tb-text-muted);
  background: rgba(0,0,0,0.1);
}

.widget-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.widget-type-badge.temperature { background: rgba(33,150,243,0.15);  color: var(--wc-temp); }
.widget-type-badge.humidity    { background: rgba(0,188,212,0.15);    color: var(--wc-humidity); }
.widget-type-badge.switch      { background: rgba(255,152,0,0.15);    color: var(--wc-switch); }
.widget-type-badge.number      { background: rgba(156,39,176,0.15);   color: var(--wc-number); }
.widget-type-badge.text        { background: rgba(76,175,80,0.15);    color: var(--wc-text); }
.widget-type-badge.json        { background: rgba(96,125,139,0.15);   color: var(--wc-json); }
.widget-type-badge.current     { background: rgba(255,193,7,0.15);    color: var(--wc-current); }
.widget-type-badge.volt        { background: rgba(255,87,34,0.15);    color: var(--wc-volt); }
.widget-type-badge.power       { background: rgba(139,195,74,0.15);   color: var(--wc-power); }
.widget-type-badge.gps         { background: rgba(0,150,136,0.15);    color: var(--wc-gps); }

/* Switch widget */
.switch-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  gap: 16px;
}

.tb-switch {
  position: relative;
  width: 56px;
  height: 28px;
  flex-shrink: 0;
}

.tb-switch input { display: none; }

.tb-switch-track {
  width: 100%;
  height: 100%;
  background: #455a64;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.25s;
  position: relative;
}

.tb-switch-track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  background: #b0bec5;
  border-radius: 50%;
  transition: transform 0.25s, background 0.25s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.tb-switch-track.on { background: rgba(255,152,0,0.3); }
.tb-switch-track.on::after { transform: translateX(28px); background: var(--wc-switch); }

.switch-state-label {
  font-size: 20px;
  font-weight: 500;
  min-width: 44px;
}
.switch-state-label.on  { color: var(--wc-switch); }
.switch-state-label.off { color: var(--tb-text-muted); }

/* Room sections */
.room-section { margin-bottom: 24px; }

.room-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding: 0 2px;
  cursor: pointer;
  user-select: none;
}

.room-header-line {
  flex: 1;
  height: 1px;
  background: var(--tb-border);
}
.room-header-line:first-child { display: none; }

.room-header-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--tb-text-secondary);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-toggle-icon { font-size: 10px; color: var(--tb-text-muted); transition: transform 0.2s; }
.room-devices.collapsed { display: none; }

.room-remove-btn {
  background: none;
  border: none;
  color: var(--tb-text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.room-remove-btn:hover { color: var(--tb-danger); background: rgba(244,67,54,0.1); }

/* Messages Panel */
.msg-list {
  max-height: 260px;
  overflow-y: auto;
}

.msg-item {
  padding: 8px 12px;
  border-bottom: 1px solid var(--tb-border);
  font-size: 12px;
}
.msg-item:last-child { border-bottom: none; }

.msg-topic {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 3px;
}
.msg-topic-name { color: var(--tb-accent); font-size: 11px; font-weight: 500; }
.msg-time { color: var(--tb-text-muted); font-size: 10px; }
.msg-payload { color: var(--tb-text-secondary); word-break: break-all; }

/* Connection status banner */
.conn-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-weight: 500;
}
.conn-status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.conn-status.connected    { background: rgba(76,175,80,0.12);  color: #81c784; }
.conn-status.connected .conn-status-dot { background: var(--tb-success); box-shadow: 0 0 5px var(--tb-success); }
.conn-status.disconnected { background: rgba(244,67,54,0.1); color: #ef9a9a; }
.conn-status.disconnected .conn-status-dot { background: var(--tb-danger); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
button {
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--tb-primary);
  color: #fff;
  font-weight: 500;
  cursor: pointer;
  font-size: 13px;
  letter-spacing: 0.3px;
  transition: background 0.15s;
}

button:hover { background: var(--tb-primary-hover); }
button:disabled { background: var(--tb-surface-alt); color: var(--tb-text-muted); cursor: not-allowed; }

button.accent { background: var(--tb-accent); color: #fff; }
button.accent:hover { background: #00a0b5; }

button.secondary { background: transparent; color: var(--tb-text-secondary); border: 1px solid var(--tb-border); }
button.secondary:hover { background: var(--tb-sidebar-hover); color: var(--tb-text); }

button.danger { background: var(--tb-danger); color: #fff; }
button.danger:hover { background: var(--tb-danger-hover); }

.btn-sm, button.sm { padding: 5px 12px; font-size: 12px; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--tb-text-secondary);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
}

input, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--tb-border);
  border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.25);
  color: var(--tb-text);
  font-size: 13px;
  transition: border-color 0.15s;
  outline: none;
}

/* Options don't inherit the select's bg/color — set them explicitly */
select option {
  background: #273142;
  color: #e0e6f0;
}
select option:disabled { color: #667; }

input:focus, select:focus { border-color: var(--tb-accent); }

input::placeholder { color: var(--tb-text-muted); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--tb-text-muted);
  border-bottom: 1px solid var(--tb-border);
}

td {
  padding: 11px 14px;
  border-bottom: 1px solid rgba(46,61,79,0.5);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--tb-text-secondary); }
th.sortable::after { content: ' \2195'; opacity: 0.4; }
th.sortable.asc::after  { content: ' \2191'; opacity: 0.9; }
th.sortable.desc::after { content: ' \2193'; opacity: 0.9; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge.admin { background: rgba(0,188,212,0.15); color: var(--tb-accent); }
.badge.user  { background: rgba(255,255,255,0.07); color: var(--tb-text-secondary); }

.limit-badge {
  font-size: 11px;
  color: var(--tb-text-muted);
  background: var(--tb-surface-alt);
  padding: 2px 7px;
  border-radius: 10px;
}

/* ── Modals ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--tb-surface);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7);
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  background: var(--tb-surface-alt);
  border-bottom: 1px solid var(--tb-border);
}

.modal-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--tb-text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal-body { padding: 20px; }

/* legacy .modal h3 */
.modal h3 { font-size: 14px; font-weight: 600; color: var(--tb-text); margin-bottom: 16px; text-transform: uppercase; letter-spacing: 0.5px; }

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

.confirm-modal .confirm-msg { font-size: 13px; color: var(--tb-text-secondary); margin-bottom: 6px; }
.confirm-modal .target, .confirm-modal .device-label { font-size: 14px; font-weight: 600; color: var(--tb-text); margin-bottom: 16px; }

/* ── Error / Empty ───────────────────────────────────────────────────────── */
.error-msg {
  display: none;
  background: rgba(244,67,54,0.12);
  color: #ef9a9a;
  border: 1px solid rgba(244,67,54,0.25);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
}
.error-msg.visible { display: block; }

.empty {
  text-align: center;
  color: var(--tb-text-muted);
  padding: 40px 20px;
  font-size: 13px;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: 360px;
  animation: toastIn 0.25s ease-out, toastOut 0.25s ease-in forwards;
  animation-delay: 0s, 2.75s;
}

.toast::before { font-size: 16px; }
.toast.success { background: #1b5e20; border-left: 4px solid var(--tb-success); }
.toast.success::before { content: '✓'; color: var(--tb-success); }
.toast.error   { background: #7f0000; border-left: 4px solid var(--tb-danger); }
.toast.error::before { content: '✕'; color: #ef9a9a; }
.toast.info    { background: #0d2137; border-left: 4px solid var(--tb-accent); }
.toast.info::before { content: 'ℹ'; color: var(--tb-accent); }

@keyframes toastIn  { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* ── Skeletons ───────────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--tb-surface-alt) 25%, var(--tb-surface-hover) 50%, var(--tb-surface-alt) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
.skeleton-card { height: 160px; margin-bottom: 14px; }
.skeleton-row  { height: 44px; margin-bottom: 6px; }

@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Search ──────────────────────────────────────────────────────────────── */
.search-input {
  padding: 7px 12px;
  border: 1px solid var(--tb-border);
  border-radius: var(--radius-sm);
  background: rgba(0,0,0,0.2);
  color: var(--tb-text);
  font-size: 13px;
  width: 220px;
}
.search-input:focus { outline: none; border-color: var(--tb-accent); }
.search-input::placeholder { color: var(--tb-text-muted); }

/* ── Login ───────────────────────────────────────────────────────────────── */
.login-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top left, #0d2137 0%, var(--tb-bg) 60%);
}

.login-card {
  background: var(--tb-surface);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 10px;
}

.login-logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--tb-accent), var(--tb-primary));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
}

.login-logo-text {
  font-size: 20px;
  font-weight: 500;
  color: var(--tb-text);
  letter-spacing: -0.3px;
}

.subtitle {
  text-align: center;
  color: var(--tb-text-muted);
  font-size: 12px;
  margin-bottom: 28px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.login-card button {
  width: 100%;
  padding: 11px;
  font-size: 14px;
  margin-top: 4px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ── User detail panel (admin) ───────────────────────────────────────────── */

/* Stats row */
.ud-stats { display: flex; gap: 12px; margin-bottom: 20px; }
.ud-stat {
  flex: 1; background: var(--tb-surface-alt);
  border-radius: var(--radius-md); padding: 12px 14px;
  border: 1px solid var(--tb-border);
}
.ud-stat-value { font-size: 24px; font-weight: 300; line-height: 1.1; }
.ud-stat-of    { font-size: 13px; color: var(--tb-text-muted); font-weight: 400; }
.ud-stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--tb-text-muted); margin-top: 4px; }
.ud-stat-bar   { height: 3px; background: rgba(255,255,255,.08); border-radius: 2px; margin-top: 8px; overflow: hidden; }
.ud-stat-fill  { height: 100%; border-radius: 2px; transition: width .4s; }

/* Section label */
.ud-section-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--tb-text-muted);
  margin-bottom: 8px; margin-top: 4px;
}

/* Rooms */
.ud-rooms { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.ud-room-chip {
  background: rgba(255,152,0,.12); color: #ffb300;
  border: 1px solid rgba(255,152,0,.25);
  padding: 3px 10px; border-radius: 12px; font-size: 12px;
}

/* Device grid */
.ud-device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.ud-device-card {
  background: var(--tb-surface-alt);
  border: 1px solid var(--tb-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  transition: border-color .15s, box-shadow .15s;
}
.ud-device-card:hover {
  border-color: rgba(255,255,255,.15);
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}

/* Colored left accent bar — reuse widget type colors */
.ud-device-accent {
  width: 4px; flex-shrink: 0;
  background: var(--tb-border);
}
.ud-device-accent.temperature { background: var(--wc-temp); }
.ud-device-accent.humidity    { background: var(--wc-humidity); }
.ud-device-accent.switch      { background: var(--wc-switch); }
.ud-device-accent.number      { background: var(--wc-number); }
.ud-device-accent.text        { background: var(--wc-text); }
.ud-device-accent.json        { background: var(--wc-json); }
.ud-device-accent.current     { background: var(--wc-current); }
.ud-device-accent.volt        { background: var(--wc-volt); }
.ud-device-accent.power       { background: var(--wc-power); }
.ud-device-accent.gps         { background: var(--wc-gps); }

.ud-device-body   { padding: 10px 12px; flex: 1; min-width: 0; }
.ud-device-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.ud-device-name   { font-size: 13px; font-weight: 500; color: var(--tb-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ud-device-room   { font-size: 11px; color: var(--tb-text-muted); margin-top: 6px; }

/* Topic rows */
.topic-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.topic-row .topic { color: var(--tb-text-muted); font-size: 11px; font-family: monospace; word-break: break-all; flex: 1; min-width: 0; }
.topic-label { font-size: 10px; color: var(--tb-text-muted); opacity: .6; flex-shrink: 0; }

.topic-badge {
  font-size: 9px; font-weight: 700; letter-spacing: .6px;
  padding: 2px 5px; border-radius: 3px; flex-shrink: 0;
}
.topic-badge.sub { background: rgba(0,168,255,.15); color: #00a8ff; border: 1px solid rgba(0,168,255,.3); }
.topic-badge.pub { background: rgba(255,160,0,.15);  color: #ffa000; border: 1px solid rgba(255,160,0,.3); }

/* ── Actions ─────────────────────────────────────────────────────────────── */
.actions { display: flex; gap: 6px; align-items: center; }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2e3d4f; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3d5068; }

/* ── Chart panel ─────────────────────────────────────────────────────────── */
.chart-panel {
  padding: 10px 14px 12px;
  border-top: 1px solid var(--tb-border);
  background: var(--tb-bg);
}
.chart-waiting {
  font-size: 12px;
  color: var(--tb-text-muted);
  text-align: center;
  padding: 14px 0;
}
.chart-gps-note {
  font-size: 12px;
  color: var(--tb-text-muted);
  padding: 8px 0;
}
.chart-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin-top: 8px;
}
.chart-stat {
  background: var(--tb-surface);
  border-radius: var(--radius-sm);
  padding: 5px 6px;
  text-align: center;
}
.chart-stat-v {
  font-size: 13px;
  font-weight: 600;
  color: var(--tb-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart-stat-l {
  font-size: 9px;
  color: var(--tb-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}
.widget-icon-btn.chart-active { color: var(--tb-accent); }

/* ── Chart hover tooltip ─────────────────────────────────────────────────── */
#chart-tooltip {
  display: none;
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  background: var(--tb-surface);
  border: 1px solid var(--tb-border);
  border-radius: var(--radius-md);
  padding: 7px 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  min-width: 90px;
}
#chart-tt-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--tb-text);
  white-space: nowrap;
}
#chart-tt-time {
  font-size: 11px;
  color: var(--tb-text-muted);
  margin-top: 2px;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 14px; }
  .topbar-hamburger { width: auto; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
