/* SensorMonitor theme — based on VRCarwash (Sneat) design tokens.
   Vanilla CSS reproduction of the brand: indigo primary, cyan info,
   gold accent, deep-navy login background, neon-glow logo, rounded cards. */

:root {
  /* Brand */
  --primary: #696CFF;
  --primary-darken: #5E61E6;
  --primary-light: #8789FF;
  --info: #03C3EC;
  --success: #71DD37;
  --warning: #FFAB00;
  --error: #FF3E1D;
  --gold: #F1BC39;

  /* Surfaces (dark theme — matches vrcarwash dark mode) */
  --bg: #232333;
  --surface: #2B2C40;
  --surface-2: #313246;
  --m-bg: #090C25;          /* deep-navy login backdrop */
  --border: rgba(230, 230, 241, 0.12);
  --text: #E6E6F1;
  --text-muted: #AAB3DE;
  --text-dim: #7983BB;

  /* Effects */
  --radius-card: 16px;
  --radius-input: 8px;
  --radius-btn: 8px;
  --shadow-card: 0 4px 18px rgba(0, 0, 0, 0.35);
  --neon: 0 0 18px rgba(3, 195, 236, 0.55), 0 0 4px rgba(3, 195, 236, 0.9);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Prompt', -apple-system, "Segoe UI", "Noto Sans Thai", Tahoma, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

/* ---------- App shell (sidebar + main, vrcarwash Sneat-style) ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}
.app-shell.collapsed { grid-template-columns: 72px 1fr; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 12;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.sidebar-brand .logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--m-bg);
  color: var(--info);
  font-size: 20px;
  border: 1.5px solid var(--gold);
  text-shadow: var(--neon);
  box-shadow: inset 0 0 8px rgba(3, 195, 236, 0.3);
  flex: none;
}
.sidebar-brand .brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.sidebar-brand h1 {
  font-size: 14px;
  margin: 0;
  letter-spacing: .5px;
  font-weight: 600;
  color: var(--info);
  text-shadow: 0 0 6px rgba(3, 195, 236, 0.45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-brand .brand-sub {
  color: var(--gold);
  font-size: 9px;
  letter-spacing: 2.5px;
  font-weight: 500;
  margin-top: 2px;
  text-shadow: 0 0 6px rgba(241, 188, 57, 0.5);
}
.sidebar-toggle {
  position: absolute;
  right: -12px;
  top: 24px;
  width: 24px; height: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  display: inline-flex; align-items: center; justify-content: center;
  z-index: 13;
}
.sidebar-toggle:hover { color: var(--info); border-color: var(--info); }
.app-shell.collapsed .sidebar-toggle { transform: rotate(180deg); }

.sidebar-nav { padding: 16px 10px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 400;
  transition: background-color .15s, color .15s;
  white-space: nowrap;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: linear-gradient(to right, rgba(105,108,255,.25), rgba(105,108,255,.08));
  color: var(--text);
  font-weight: 500;
  box-shadow: inset 3px 0 0 var(--primary);
}
.nav-icon {
  font-size: 18px;
  width: 24px;
  flex: none;
  text-align: center;
  color: var(--text-dim);
}
.nav-item.active .nav-icon { color: var(--primary); }

.app-shell.collapsed .brand-text,
.app-shell.collapsed .nav-label,
.app-shell.collapsed .sidebar-foot { display: none; }
.app-shell.collapsed .sidebar-brand { justify-content: center; }
.app-shell.collapsed .nav-item { justify-content: center; padding: 12px 0; }

.sidebar-foot {
  padding: 18px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
}
.sidebar-foot .vra-brand { font-size: 11px; }
.sidebar-foot .vra-chip { font-size: 12px; padding: 3px 7px; }
.sidebar-foot .vra-text { font-size: 11px; letter-spacing: 3px; }

/* ---------- Topbar in main area ---------- */
.app-main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.hamburger {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 18px;
  font-family: inherit;
}
.page-title {
  flex: 1;
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.brand { display: none; }                                /* old brand block hidden in shell layout */
.brand .logo, .brand h1, .brand-link { display: none; }
.status { display: flex; align-items: center; gap: 14px; }
.clock { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 14px; }
.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--text-muted); font-size: 13px;
}
.user-chip .logout-btn {
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: var(--radius-btn);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.user-chip .logout-btn:hover { color: var(--error); border-color: var(--error); }
.role-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-radius: 999px;
  border: 1px solid currentColor;
  vertical-align: middle;
}
.role-owner { color: var(--gold); background: rgba(241,188,57,.1); }
.role-admin { color: var(--info); background: rgba(3,195,236,.1); }
.role-staff { color: var(--text-muted); background: rgba(170,179,222,.1); }

/* Role-based UI gating: staff sees a read-only / control-only view. */
body[data-role="staff"] .admin-only,
body[data-role="staff"] .card-actions,
body[data-role="staff"] .detail-actions { display: none !important; }

/* ---------- Audit log page ---------- */
.audit-filter { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.audit-filter .audit-label { color: var(--text-muted); font-size: 13px; }
.audit-filter select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-input); padding: 6px 10px; font-size: 13px; font-family: inherit;
}
.audit-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 12px;
  overflow-x: auto;
}
.audit-table { font-size: 12px; }
.audit-table .audit-action { color: var(--info); }
.audit-table .audit-details code { color: var(--text-muted); word-break: break-all; }
.audit-table td { vertical-align: top; }

.badge {
  font-size: 12px;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.badge-on  { background: rgba(113,221,55,.12);  color: var(--success); border-color: rgba(113,221,55,.4); }
.badge-off { background: rgba(255,62,29,.12);   color: var(--error);   border-color: rgba(255,62,29,.4); }

/* ---------- layout ---------- */
main {
  padding: 26px 28px 40px;
  width: 100%;
  align-self: stretch;
  flex: 1;
}
section { margin-bottom: 32px; }
.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin: 0 0 14px;
  font-weight: 500;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 18px;
  box-shadow: var(--shadow-card);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.card-head .name { font-weight: 500; font-size: 15px; color: var(--text); }

.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-dim); display: inline-block; }
.dot.online  { background: var(--success); box-shadow: 0 0 10px var(--success); }
.dot.offline { background: var(--error);   box-shadow: 0 0 8px var(--error); }

.metric {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background-color .15s;
}
.metric:hover { background: rgba(105,108,255,.06); margin: 0 -10px; padding: 10px; border-radius: 8px; }
.metric .label { color: var(--text-muted); font-size: 13px; }
.metric .value {
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.metric .value.stale { color: var(--text-dim); opacity: 0.7; }
.metric .unit { color: var(--text-muted); font-size: 13px; margin-left: 4px; font-weight: 400; }

/* ---------- controls ---------- */
.control .row { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.switch { position: relative; width: 52px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; transition: .2s;
}
.slider::before {
  content: ""; position: absolute; height: 20px; width: 20px;
  left: 3px; top: 3px; background: var(--text-dim); border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: rgba(105,108,255,.3); border-color: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(24px); background: var(--primary); box-shadow: 0 0 10px var(--primary); }

.num-input {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-input); padding: 9px 11px; width: 100px; font-size: 15px;
  font-family: inherit;
}
.num-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(105,108,255,.2); }

.btn {
  background: linear-gradient(to right, var(--primary-darken), var(--primary));
  color: #fff; border: none; font-weight: 500;
  padding: 9px 16px; border-radius: var(--radius-btn);
  cursor: pointer; font-size: 14px; font-family: inherit;
  box-shadow: 0 4px 12px rgba(105,108,255,.35);
  transition: transform .1s, box-shadow .15s, filter .15s;
}
.btn:hover { filter: brightness(1.08); box-shadow: 0 6px 16px rgba(105,108,255,.5); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; filter: grayscale(.4); box-shadow: none; }

/* ---------- chart ---------- */
.chart-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px; }
.chart-controls { display: flex; gap: 12px; align-items: center; }
.chart-controls select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-input); padding: 8px 11px; font-size: 14px; font-family: inherit;
}
.range-btns { display: inline-flex; }
.range-btns button {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted);
  padding: 8px 13px; cursor: pointer; font-size: 13px; font-family: inherit;
}
.range-btns button:first-child { border-radius: var(--radius-btn) 0 0 var(--radius-btn); }
.range-btns button:last-child  { border-radius: 0 var(--radius-btn) var(--radius-btn) 0; }
.range-btns button.active {
  background: linear-gradient(to right, var(--primary-darken), var(--primary));
  color: #fff; border-color: var(--primary); font-weight: 500;
  box-shadow: 0 2px 8px rgba(105,108,255,.4);
}

.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 18px;
  height: 360px;
  box-shadow: var(--shadow-card);
}

/* Multi-field chart: per-field toggle chips */
.field-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 12px 0 14px;
}
.field-chip {
  --chip-color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px; font-weight: 500;
  padding: 5px 12px; border-radius: 999px;
  cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background-color .15s, color .15s, border-color .15s;
}
.field-chip::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: var(--chip-color); opacity: 0.4;
}
.field-chip:hover { color: var(--text); }
.field-chip.active {
  background: rgba(255,255,255,0.04);
  border-color: var(--chip-color);
  color: var(--chip-color);
}
.field-chip.active::before { opacity: 1; box-shadow: 0 0 8px var(--chip-color); }
.empty { color: var(--text-muted); padding: 30px; text-align: center; }
.empty-mini { color: var(--text-dim); padding: 12px 0 4px; font-size: 13px; font-style: italic; text-align: center; }

/* ---------- Section headers with action buttons ---------- */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 0 14px;
}
.section-actions { display: flex; gap: 8px; }
.btn-sm { padding: 6px 12px; font-size: 13px; box-shadow: 0 2px 6px rgba(105,108,255,.3); }
.btn-ghost { background: var(--surface-2); color: var(--text); box-shadow: none; }
.btn-info { background: linear-gradient(to right, #0299b3, var(--info)); box-shadow: 0 4px 12px rgba(3,195,236,.35); }
.btn-info:hover { box-shadow: 0 6px 16px rgba(3,195,236,.5); }
.btn-danger { background: linear-gradient(to right, #c92e15, var(--error)); box-shadow: 0 4px 12px rgba(255,62,29,.35); }
.btn-danger:hover { box-shadow: 0 6px 16px rgba(255,62,29,.5); }

/* ---------- Device cards (list view) ---------- */
.brand-link { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.device-card { text-decoration: none; color: inherit; display: block; transition: transform .12s, box-shadow .15s; }
.device-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.45), 0 0 0 1px rgba(105,108,255,.25); }
.device-card .sub, .card-head .sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.device-card .more { color: var(--text-muted); font-size: 12px; padding-top: 8px; text-align: center; }
.metric-readonly { cursor: default; }
.metric-readonly:hover { background: transparent; margin: 0; padding: 10px 0; border-radius: 0; }

.gateway-card .kv { color: var(--text-muted); font-size: 13px; padding: 4px 0; word-break: break-all; }

.card-actions { display: flex; gap: 6px; }
.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text-muted);
  width: 28px; height: 28px; border-radius: 6px; cursor: pointer; font-size: 13px;
  display: inline-flex; align-items: center; justify-content: center; padding: 0; font-family: inherit;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn-danger:hover { color: var(--error); border-color: var(--error); }

/* ---------- Detail view ---------- */
.detail-header {
  display: grid; grid-template-columns: 1fr auto; align-items: end;
  gap: 12px; margin-bottom: 22px;
}
.back-link { grid-column: 1 / -1; color: var(--text-muted); text-decoration: none; font-size: 13px; margin-bottom: 4px; }
.back-link:hover { color: var(--info); }
.detail-title h2 { margin: 0; font-size: 22px; font-weight: 600; display: inline-flex; align-items: center; gap: 10px; }
.detail-title .sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.detail-actions { display: flex; gap: 8px; }

/* Panels (sections inside detail view) */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 18px; box-shadow: var(--shadow-card);
  margin-bottom: 22px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-title { margin: 0; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); font-weight: 500; }

.live-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}
.live-cell { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.live-cell .label { color: var(--text-muted); font-size: 13px; margin-bottom: 6px; }
.live-cell .value-wrap { display: flex; align-items: baseline; gap: 6px; }
.live-cell .value { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.live-cell .value.stale { color: var(--text-dim); opacity: .7; }
.live-cell .unit { color: var(--text-muted); font-size: 13px; }

/* ---------- Register Map table ---------- */
.reg-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.reg-table th, .reg-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--border); }
.reg-table th { color: var(--text-muted); font-weight: 500; text-transform: uppercase; font-size: 11px; letter-spacing: .5px; }
.reg-table tr:hover td { background: rgba(105,108,255,.05); }
.reg-table code { color: var(--info); font-family: 'JetBrains Mono', Menlo, monospace; font-size: 12px; }
.reg-table .test-val { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.reg-table .test-val.ok { color: var(--success); font-weight: 500; }
.reg-table .row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.reg-table .empty { background: transparent; }

/* ---------- Modal ---------- */
.modal-root[hidden] { display: none; }
.modal-root {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(9, 12, 37, 0.7); backdrop-filter: blur(4px); }
.modal {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 22px; width: min(560px, 100%);
  box-shadow: 0 20px 60px rgba(0,0,0,.6); max-height: 90vh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-form label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--text-muted); }
.modal-form label input, .modal-form label select {
  display: block; width: 100%; margin-top: 5px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-input); padding: 9px 11px; font-size: 14px; font-family: inherit;
}
.modal-form label input:focus, .modal-form label select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(105,108,255,.2);
}
.modal-form label.checkbox { display: flex; align-items: center; gap: 8px; color: var(--text); }
.modal-form label.checkbox input { display: inline-block; width: auto; margin: 0; }
.modal-form .row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-form .row-2 > label { margin: 0; }
.modal-form .hint { color: var(--text-muted); font-size: 12px; padding: 8px 12px; background: rgba(105,108,255,.08); border-radius: 6px; margin-bottom: 12px; }
.modal-form .hint code { color: var(--info); }
.modal-form .hint.warn { background: rgba(255,171,0,.1); color: var(--warning); }
.gateway-card .name-row, .broker-card .name-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 10px; font-size: 14px; z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); max-width: 90vw;
}
.toast[hidden] { display: none; }
.toast-success { border-color: rgba(113,221,55,.5); }
.toast-error   { border-color: rgba(255,62,29,.5); color: #ffb1a3; }
.toast-info    { border-color: rgba(3,195,236,.5); }

/* ---------- Profile cards ---------- */
.profile-card { display: flex; flex-direction: column; gap: 10px; }
.profile-card .name-row { display: flex; align-items: center; gap: 8px; }
.profile-card .name { color: var(--text); text-decoration: none; font-weight: 600; font-size: 15px; }
.profile-card .name:hover { color: var(--info); }
.profile-card .desc { color: var(--text-muted); font-size: 13px; line-height: 1.5; }
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; padding: 6px 0; }
.tag {
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px; font-size: 11px; font-weight: 500;
}
.tag-builtin { background: rgba(241,188,57,.13); color: var(--gold); border-color: rgba(241,188,57,.4); }
.profile-card .btn { align-self: flex-start; margin-top: 4px; }

.profile-banner {
  background: linear-gradient(135deg, rgba(3,195,236,.15), rgba(105,108,255,.15));
  border: 1px solid rgba(3,195,236,.3);
  border-radius: 10px; padding: 14px; margin-bottom: 16px;
}
.profile-banner-title { font-weight: 600; color: var(--info); font-size: 15px; }
.profile-banner-sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ---------- Plan banner (trial / expired) ---------- */
.plan-banner {
  margin: 0 28px 18px;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  border: 1px solid;
}
.plan-banner-trial    { background: rgba(105,108,255,.12); border-color: rgba(105,108,255,.4); color: #BAB9FF; }
.plan-banner-trial b  { color: var(--info); }
.plan-banner-expired  { background: rgba(255,62,29,.12); border-color: rgba(255,62,29,.4); color: #FF8B72; }
.plan-banner-expired b { color: var(--error); }
.plan-banner-warn     { background: rgba(255,171,0,.12); border-color: rgba(255,171,0,.45); color: #FFCB7A; }
.plan-banner-warn b   { color: var(--warning, #FFAB00); }
.plan-banner-warn a   { color: #FFCB7A; text-decoration: underline; font-weight: 600; }
.plan-warn { color: #FFCB7A; }
@media (max-width: 900px) {
  .plan-banner { margin: 12px 16px; }
}

/* ---------- KPI tiles (Dashboard summary) ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 26px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 18px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: linear-gradient(180deg, var(--primary), var(--info));
}
.kpi-label {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin-bottom: 8px;
}
.kpi-value {
  font-size: 32px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
  margin-bottom: 6px;
  font-variant-numeric: tabular-nums;
}
.kpi-hint { color: var(--text-dim); font-size: 12px; }

/* ---------- MQTT credentials modal ---------- */
.cred-banner {
  background: linear-gradient(135deg, rgba(241,188,57,.18), rgba(105,108,255,.12));
  border: 1px solid rgba(241,188,57,.4);
  border-radius: 10px; padding: 14px 16px; margin-bottom: 16px;
}
.cred-banner-title { font-weight: 600; color: var(--gold); font-size: 15px; }
.cred-banner-sub { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.cred-line { display: flex; gap: 6px; margin-top: 5px; }
.cred-line input {
  flex: 1; background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-input); padding: 9px 11px; font-size: 14px; font-family: 'JetBrains Mono', Menlo, monospace;
}
.copy-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted);
  border-radius: var(--radius-input); padding: 6px 10px; cursor: pointer; font-size: 14px;
  font-family: inherit;
}
.copy-btn:hover { background: rgba(105,108,255,.15); color: var(--info); border-color: var(--info); }
.cred-actions { display: flex; justify-content: center; margin-top: 16px; }
.cred-warn {
  background: rgba(255,171,0,.1); border: 1px solid rgba(255,171,0,.4);
  color: var(--warning); padding: 12px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 14px;
}
.cred-warn b { color: var(--warning); }

/* ============================================================ */
/*  VR AUTOMATION brand mark                                     */
/* ============================================================ */
.vra-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
.vra-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #090C25 0%, #1a2040 100%);
  border: 1.5px solid var(--gold);
  color: var(--gold);
  font-family: 'Prompt', system-ui;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.5px;
  padding: 4px 9px;
  border-radius: 6px;
  text-shadow: 0 0 8px rgba(241, 188, 57, 0.7);
  box-shadow:
    0 0 12px rgba(241, 188, 57, 0.3),
    inset 0 0 6px rgba(241, 188, 57, 0.15);
  position: relative;
  overflow: hidden;
}
.vra-chip::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 40%, rgba(241,188,57,.18) 50%, transparent 60%);
  animation: vra-shimmer 6s ease-in-out infinite;
  pointer-events: none;
}
@keyframes vra-shimmer {
  0%, 100% { transform: translateX(-100%); }
  50%      { transform: translateX(100%); }
}
.vra-text {
  font-family: 'Prompt', system-ui;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 4px;
  color: var(--gold);
  text-shadow: 0 0 8px rgba(241, 188, 57, 0.5);
}
.vra-tag {
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  margin-left: 8px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
}

/* Topbar brand: add subtitle under SENSOR MONITOR */
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-sub {
  color: var(--gold);
  font-size: 10px;
  letter-spacing: 3px;
  font-weight: 500;
  margin-top: 2px;
  text-shadow: 0 0 6px rgba(241, 188, 57, 0.5);
}

/* Login page: large brand mark above the title */
.login-illu .vra-brand {
  position: absolute;
  top: 28px;
  left: 0; right: 0;
  justify-content: center;
}

/* Footer */
.page-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px 0 16px;
  margin-top: 20px;
  border-top: 1px solid var(--border);
}
.page-footer .vra-brand { gap: 12px; }

/* ============================================================ */
/* ====================== LOGIN PAGE =========================== */
/* ============================================================ */
.login-page {
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  display: flex;
  flex-direction: row;
  overflow: hidden;
  border-radius: var(--radius-card);
  background: var(--m-bg);
  width: min(80vw, 980px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(241, 188, 57, 0.08);
}
.login-illu {
  flex: 0 0 56%;
  background: radial-gradient(ellipse at center, rgba(105,108,255,.18) 0%, transparent 60%), var(--m-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  position: relative;
}
.login-illu::after {
  content: "";
  position: absolute; inset: 12px;
  border: 1px solid rgba(241, 188, 57, 0.12);
  border-radius: 12px;
  pointer-events: none;
}
.illu-glow {
  font-size: 140px;
  color: var(--info);
  text-shadow:
    0 0 14px rgba(3, 195, 236, 0.7),
    0 0 28px rgba(3, 195, 236, 0.45),
    0 0 60px rgba(3, 195, 236, 0.25);
  animation: pulse 3.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.25); }
}
.illu-title {
  position: absolute;
  bottom: 36px;
  left: 0; right: 0;
  text-align: center;
  color: var(--info);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-shadow: 0 0 10px rgba(3,195,236,.5);
}
.illu-subtitle {
  position: absolute;
  bottom: 14px;
  left: 0; right: 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.login-form {
  flex: 1 1 44%;
  background: var(--m-bg);
  padding: 48px 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login-form h2 {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
}
.login-form .subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

.field { margin-bottom: 18px; }
.field label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}
.field input {
  width: 100%;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.14);
  color: var(--text);
  border-radius: var(--radius-input);
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(105,108,255,.22);
}
.password-wrap { position: relative; }
.password-wrap input { padding-right: 42px; }
.password-wrap .toggle {
  position: absolute;
  right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 16px; padding: 4px;
}
.password-wrap .toggle:hover { color: var(--text); }

.login-btn {
  width: 100%;
  padding: 13px;
  font-size: 15px;
  font-weight: 500;
  margin-top: 8px;
  background: linear-gradient(to right, var(--primary-darken), var(--primary));
  color: #fff;
  border: none;
  border-radius: var(--radius-btn);
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(105,108,255,.45);
  font-family: inherit;
  transition: transform .1s, box-shadow .15s, filter .15s;
}
.login-btn:hover { filter: brightness(1.08); box-shadow: 0 8px 28px rgba(105,108,255,.6); }
.login-btn:active { transform: translateY(1px); }
.login-btn:disabled { opacity: .6; cursor: default; }

.login-error {
  background: rgba(255,62,29,.1);
  border: 1px solid rgba(255,62,29,.35);
  color: var(--error);
  border-radius: var(--radius-input);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.login-error.visible { display: block; }

/* Mobile: drawer-style sidebar */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 260px; transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .app-shell.drawer-open .sidebar { transform: translateX(0); }
  .sidebar-toggle { display: none; }
  .hamburger { display: inline-flex; }
}

/* Mobile: stack the login card */
@media (max-width: 760px) {
  .login-card { flex-direction: column; width: 100%; }
  .login-illu { flex: 0 0 auto; padding: 36px 24px 24px; }
  .illu-glow { font-size: 90px; }
  .illu-title { position: static; margin-top: 16px; }
  .illu-subtitle { display: none; }
  .login-form { padding: 28px 24px 36px; }
  .login-illu::after { display: none; }
}

/* ====== Upgrade modal (Thai PLG soft 402) ====== */
.upgrade-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.upgrade-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
}
.upgrade-modal {
  position: relative; z-index: 1;
  background: #fff; border-radius: 16px;
  max-width: 560px; width: 100%;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  max-height: 90vh; overflow-y: auto;
}
.upgrade-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.upgrade-emoji { font-size: 28px; }
.upgrade-head h3 { flex: 1; margin: 0; font-size: 20px; color: #1e293b; }
.upgrade-close { background: transparent; border: 0; font-size: 18px; cursor: pointer; color: #64748b; }
.upgrade-msg { color: #475569; font-size: 14px; margin: 8px 0 18px; line-height: 1.55; }
.upgrade-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.upgrade-card {
  border: 1.5px solid #e2e8f0; border-radius: 12px;
  padding: 14px 16px; background: #f8fafc;
}
.upgrade-card-title { font-weight: 700; color: #0f172a; margin-bottom: 8px; font-size: 15px; }
.upgrade-card ul { margin: 0; padding-left: 18px; color: #475569; font-size: 13px; line-height: 1.7; }
.upgrade-pro { border-color: #6366f1; background: linear-gradient(180deg, #eef2ff, #fff); }
.upgrade-pro .upgrade-card-title { color: #4338ca; }
.upgrade-ent { border-color: #d4af37; background: linear-gradient(180deg, #fef9e7, #fff); }
.upgrade-ent .upgrade-card-title { color: #8a6d10; }
.upgrade-payment {
  border-top: 1px dashed #cbd5e1; padding-top: 14px; margin-bottom: 14px;
}
.upgrade-payment-loading { text-align: center; color: #64748b; font-size: 13px; padding: 14px; }
.upgrade-payment-grid {
  display: grid; grid-template-columns: 140px 1fr; gap: 16px; align-items: center;
}
.upgrade-qr {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 8px; border: 1px solid #e2e8f0; border-radius: 10px;
  background: #fff;
}
.upgrade-qr-img {
  width: 124px; height: 124px; object-fit: contain;
  background: #fff; border-radius: 6px;
}
.upgrade-qr-empty { background: #f8fafc; }
.upgrade-qr-placeholder { font-size: 56px; line-height: 1; padding: 24px 0 16px; }
.upgrade-qr-cap { font-size: 11px; color: #64748b; text-align: center; }
.upgrade-link { color: #4338ca; text-decoration: none; font-size: 13px; font-weight: 600; }
.upgrade-link:hover { text-decoration: underline; }
.upgrade-contact {
  display: flex; flex-direction: column; gap: 10px;
}
.upgrade-contact-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #334155; }
.upgrade-label { width: 92px; color: #64748b; font-size: 12px; text-transform: uppercase; }
.btn-line {
  background: #06c755; color: #fff; padding: 6px 14px; border-radius: 8px;
  text-decoration: none; font-weight: 600; font-size: 13px;
}
.btn-line:hover { background: #05a648; }
.upgrade-self {
  padding: 12px; background: #fffbeb; border: 1px dashed #f59e0b; border-radius: 10px;
  margin-bottom: 14px; text-align: center;
}
.upgrade-self-trial { font-weight: 600; }
.upgrade-foot { text-align: right; }

@media (max-width: 560px) {
  .upgrade-grid { grid-template-columns: 1fr; }
  .upgrade-payment-grid { grid-template-columns: 1fr; text-align: center; }
  .upgrade-contact-row { justify-content: center; flex-wrap: wrap; }
  .upgrade-modal { padding: 20px; }
}

/* ====== Settings page (PLG control center) ====== */
.settings-card { margin-bottom: 18px; }
.settings-body { padding: 18px 20px; }
.settings-section-title {
  font-size: 13px; text-transform: uppercase;
  color: rgba(255,255,255,.6); letter-spacing: .5px;
  margin: 18px 0 10px; font-weight: 600;
}
.plan-summary {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px; background: rgba(105,108,255,.08);
  border: 1px solid rgba(105,108,255,.25); border-radius: 10px;
  margin-bottom: 14px;
}
.plan-summary-name { font-size: 22px; font-weight: 700; color: var(--info); }
.plan-summary-sub { font-size: 12px; color: rgba(255,255,255,.55); margin-top: 2px; }
.usage-grid { display: grid; gap: 14px; margin-bottom: 16px; }
.usage-item { display: flex; flex-direction: column; gap: 6px; }
.usage-label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; color: rgba(255,255,255,.85);
}
.usage-label b { color: #fff; }
.usage-bar {
  width: 100%; height: 10px;
  background: rgba(255,255,255,.08);
  border-radius: 99px; overflow: hidden;
}
.usage-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--info), #06b6d4);
  border-radius: 99px;
  transition: width .3s ease;
}
.usage-fill-warn { background: linear-gradient(90deg, #f59e0b, #f97316); }
.usage-fill-full { background: linear-gradient(90deg, var(--error), #dc2626); }
.usage-warn { font-size: 12px; color: #FFCB7A; margin-top: 2px; }
.settings-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0;
  border-bottom: 1px dashed rgba(255,255,255,.08);
  font-size: 14px; color: rgba(255,255,255,.85);
}
.settings-row:last-child { border-bottom: 0; }
.settings-row b { color: #fff; }
.settings-form { display: flex; flex-direction: column; gap: 12px; }
.settings-form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; color: rgba(255,255,255,.7);
}
.settings-form input, .settings-form select {
  padding: 10px 12px; border-radius: 8px;
  background: rgba(255,255,255,.05); color: #fff;
  border: 1px solid rgba(255,255,255,.12);
  font-size: 14px; font-family: inherit;
}
.settings-form input:focus { outline: 2px solid var(--info); outline-offset: -1px; }
.settings-actions { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
