:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #08101f;
  color: #e8eef9;
  --bg: #08101f;
  --panel: #0e1829;
  --panel-2: #111e32;
  --border: #263650;
  --muted: #91a0b8;
  --accent: #4f8cff;
  --accent-2: #73a7ff;
  --danger: #ff6577;
  --success: #54d49a;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 20% 0%, #12213a 0, var(--bg) 36%); }
button, input, select { font: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { color: var(--muted); text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; }
.brand-mark { width: 52px; height: 52px; border-radius: 16px; display:grid; place-items:center; font-weight:800; font-size:1.4rem; background:linear-gradient(145deg,#4f8cff,#6f61ff); box-shadow:0 12px 35px #244eaa55; }
.brand-mark.small { width:38px; height:38px; border-radius:12px; font-size:1rem; }
.brand-row,.sidebar-brand,.section-head,.topbar,.modal-head,.modal-actions,.actions,.topbar-meta { display:flex; align-items:center; }
.brand-row,.sidebar-brand { gap:14px; }
.login-shell { min-height:100vh; display:grid; place-items:center; padding:24px; }
.login-card { width:min(430px,100%); background:#0c1728e8; border:1px solid var(--border); border-radius:24px; padding:30px; box-shadow:0 30px 90px #0008; backdrop-filter:blur(12px); }
.login-card h1 { margin:.15rem 0 0; }
.stack { display:grid; gap:16px; margin-top:28px; }
label { display:grid; gap:7px; color:#cbd6e8; font-size:.9rem; }
input,select { width:100%; border:1px solid var(--border); border-radius:11px; background:#091321; color:#eef5ff; padding:11px 12px; outline:none; }
input:focus,select:focus { border-color:var(--accent); box-shadow:0 0 0 3px #4f8cff22; }
.button { border:1px solid transparent; border-radius:11px; padding:10px 15px; cursor:pointer; color:#eef5ff; background:#18263b; }
.button.primary { background:linear-gradient(135deg,#397df5,#5b6cf7); }
.button.ghost { border-color:var(--border); background:transparent; }
.button.compact { padding:7px 10px; }
.button.danger { background:#4a1c29; color:#ffd8df; }
.button:disabled { opacity:.45; cursor:not-allowed; }
.form-error { min-height:20px; color:#ff94a1; font-size:.88rem; }
.app-shell { min-height:100vh; display:grid; grid-template-columns:250px 1fr; }
.sidebar { position:sticky; top:0; height:100vh; display:flex; flex-direction:column; padding:20px 16px; border-right:1px solid var(--border); background:#091322e8; backdrop-filter:blur(10px); }
.sidebar-brand { padding:4px 8px 22px; }
.sidebar nav { display:grid; gap:6px; }
.nav-item { text-align:left; border:0; border-radius:11px; padding:11px 12px; color:#b8c5d9; background:transparent; cursor:pointer; }
.nav-item:hover,.nav-item.active { color:white; background:#18263b; }
.sidebar-footer { margin-top:auto; border-top:1px solid var(--border); padding-top:16px; display:grid; gap:12px; }
.user-chip { display:grid; gap:2px; }
.user-chip span { color:var(--muted); font-size:.82rem; }
.content { min-width:0; padding:26px 30px 50px; }
.topbar { justify-content:space-between; gap:20px; margin-bottom:28px; }
.topbar h2 { margin:.25rem 0 0; font-size:1.7rem; }
.topbar-meta { gap:8px; flex-wrap:wrap; justify-content:flex-end; }
.badge { border:1px solid #31568f; background:#173560; color:#dceaff; border-radius:999px; padding:6px 10px; font-size:.8rem; }
.badge.subtle { border-color:var(--border); background:#111e32; color:#aebbd0; }
.page { display:none; }
.page.active { display:block; }
.metric-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:16px; margin-bottom:18px; }
.metric-card,.card,.table-card,.role-card { background:linear-gradient(180deg,#101d30,#0d1727); border:1px solid var(--border); border-radius:17px; }
.metric-card { padding:20px; display:grid; gap:7px; }
.metric-card span,.metric-card small { color:var(--muted); }
.metric-card strong { font-size:1.65rem; }
.card { padding:20px; }
.card h3 { margin-top:0; }
.section-head { justify-content:space-between; gap:18px; margin-bottom:16px; }
.section-head h3 { margin:0 0 4px; }
.section-head p { margin:0; color:var(--muted); }
.table-card { overflow:hidden; }
table { width:100%; border-collapse:collapse; }
th,td { padding:13px 15px; border-bottom:1px solid #1d2b40; text-align:left; vertical-align:middle; }
th { color:#91a0b8; font-size:.78rem; text-transform:uppercase; letter-spacing:.06em; font-weight:600; }
tbody tr:last-child td { border-bottom:0; }
.entity { display:grid; gap:3px; }
.entity small { color:var(--muted); }
.status { display:inline-flex; border-radius:999px; padding:4px 8px; font-size:.75rem; border:1px solid var(--border); }
.status.active { color:#9bf2c6; border-color:#267454; background:#123b2d; }
.status.disabled { color:#c2cad8; }
.actions { gap:7px; justify-content:flex-end; flex-wrap:wrap; }
.icon-button,.link-button { cursor:pointer; border:0; background:transparent; color:#aebbd0; }
.icon-button { font-size:1.5rem; }
.link-button:hover { color:white; }
.link-button.danger { color:#ff8998; }
.empty-state { padding:28px; text-align:center; color:var(--muted); }

.dashboard-metrics { grid-template-columns:repeat(4,minmax(0,1fr)); }
.dashboard-head { margin-top:22px; }
.dashboard-refresh { display:flex; align-items:center; gap:10px; }
.dashboard-master-list { display:grid; gap:16px; }
.dashboard-master-card {
  background:linear-gradient(180deg,#101d30,#0d1727);
  border:1px solid var(--border);
  border-radius:17px;
  overflow:hidden;
}
.dashboard-master-head {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  padding:16px 18px;
  border-bottom:1px solid #1d2b40;
}
.sensor-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(320px,1fr)); gap:12px; padding:14px; }
.sensor-card { border:1px solid #263a58; border-radius:14px; background:#0a1525; padding:15px; display:grid; gap:14px; }
.sensor-card.no-current { border-style:dashed; }
.sensor-card-head { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; }
.measurement-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(120px,1fr)); gap:9px; }
.measurement { border:1px solid #21334e; border-radius:10px; background:#101d30; padding:10px; display:grid; gap:4px; }
.measurement span { color:var(--muted); font-size:.75rem; }
.measurement strong { font-size:1.05rem; font-variant-numeric:tabular-nums; }
.sensor-card-foot { display:flex; justify-content:space-between; gap:12px; flex-wrap:wrap; color:var(--muted); font-size:.75rem; }
.sensor-no-data,.dashboard-no-channels { padding:8px 2px; }

.history-layout { display:grid; grid-template-columns:260px minmax(0,1fr); gap:16px; align-items:start; }
.history-sidebar {
  position:sticky; top:24px; display:grid; gap:14px; padding:16px;
  background:linear-gradient(180deg,#101d30,#0d1727); border:1px solid var(--border); border-radius:17px;
}
.history-channel-meta { border-top:1px solid var(--border); padding-top:14px; display:grid; gap:12px; }
.history-channel-meta dl { margin:0; display:grid; gap:7px; }
.history-channel-meta dl div { display:flex; justify-content:space-between; gap:12px; }
.history-channel-meta dt { color:var(--muted); }
.history-channel-meta dd { margin:0; text-align:right; }
.history-main { min-width:0; display:grid; gap:14px; }
.history-chart-card { min-height:360px; }
.history-chart { min-height:280px; display:grid; place-items:center; overflow:hidden; }
.history-chart svg { width:100%; min-width:520px; height:auto; }
.chart-axis { stroke:#52657f; stroke-width:1; }
.chart-grid { stroke:#243650; stroke-width:1; stroke-dasharray:5 6; }
.chart-line { fill:none; stroke:var(--accent-2); stroke-width:2.5; stroke-linejoin:round; stroke-linecap:round; vector-effect:non-scaling-stroke; }
.chart-label { fill:#91a0b8; font-size:13px; font-family:inherit; }
.history-no-chart { min-height:240px; display:grid; place-items:center; }
.history-table-card { max-height:460px; overflow:auto; }
.history-table-card thead { position:sticky; top:0; background:#111e32; z-index:1; }
.event-filter-card {
  display:grid;
  grid-template-columns:minmax(160px,220px) minmax(220px,1fr) auto;
  gap:12px;
  align-items:end;
  margin-bottom:16px;
}
.event-dialog-body { padding:22px; display:grid; gap:18px; }
.event-dialog-meta dl {
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:10px;
  margin:0;
}
.event-dialog-meta dl div {
  border:1px solid #21334e;
  border-radius:10px;
  padding:10px;
  background:#101d30;
}
.event-dialog-meta dt { color:var(--muted); font-size:.75rem; }
.event-dialog-meta dd { margin:4px 0 0; overflow-wrap:anywhere; }
.event-json {
  margin:0;
  max-height:420px;
  overflow:auto;
  border:1px solid var(--border);
  border-radius:12px;
  background:#08111f;
  padding:14px;
  white-space:pre-wrap;
  overflow-wrap:anywhere;
  color:#cdd8e8;
  font-size:.8rem;
}
.task-filter-card {
  display:flex;
  align-items:end;
  gap:14px;
  margin-bottom:16px;
}
.task-filter-card > label:first-child { min-width:190px; }
.task-mine-filter {
  display:flex;
  align-items:center;
  gap:8px;
  padding:10px 0;
}
.task-mine-filter input { width:auto; }
.task-priority {
  display:inline-flex;
  border:1px solid var(--border);
  border-radius:999px;
  padding:4px 8px;
  font-size:.75rem;
}
.task-priority-low { color:#b6c1d2; }
.task-priority-normal { color:#cfe0ff; border-color:#365986; }
.task-priority-high { color:#ffd995; border-color:#7d5a2d; background:#332614; }
.task-priority-critical { color:#ffb2bc; border-color:#8c3949; background:#3b1d26; }
.status.progress { color:#a9d4ff; border-color:#32659c; background:#153251; }
textarea {
  width:100%;
  resize:vertical;
  border:1px solid var(--border);
  border-radius:11px;
  background:#091321;
  color:#eef5ff;
  padding:11px 12px;
  outline:none;
  font:inherit;
}
textarea:focus { border-color:var(--accent); box-shadow:0 0 0 3px #4f8cff22; }
.task-detail-shell { padding:22px; display:grid; gap:18px; }
.task-detail-meta dl {
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:10px;
  margin:0;
}
.task-detail-meta dl div {
  border:1px solid #21334e;
  border-radius:10px;
  padding:10px;
  background:#101d30;
}
.task-detail-meta dt { color:var(--muted); font-size:.75rem; }
.task-detail-meta dd { margin:4px 0 0; overflow-wrap:anywhere; }
.task-description {
  white-space:pre-wrap;
  overflow-wrap:anywhere;
  border:1px solid var(--border);
  border-radius:12px;
  background:#0a1525;
  padding:14px;
}
.task-detail-actions { display:flex; justify-content:flex-end; gap:9px; }
.compact-head { margin-bottom:8px; }
.task-comments { display:grid; gap:8px; max-height:280px; overflow:auto; }
.task-comment {
  border:1px solid #21334e;
  border-radius:10px;
  background:#101d30;
  padding:10px 12px;
  display:grid;
  gap:6px;
}
.task-comment-head { display:flex; justify-content:space-between; gap:12px; }
.task-comment-head span { color:var(--muted); font-size:.75rem; }
.task-comment-form { display:grid; grid-template-columns:1fr auto; gap:9px; margin-top:10px; align-items:end; }
.role-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(280px,1fr)); gap:14px; }
.role-card { padding:18px; display:grid; gap:14px; }
.role-card h4 { margin:0; }
.permission-list { display:flex; flex-wrap:wrap; gap:6px; }
.permission-chip { font-size:.72rem; color:#bdc9da; padding:4px 7px; border-radius:7px; background:#17253a; border:1px solid #243753; }
.modal { width:min(620px,calc(100vw - 28px)); border:1px solid var(--border); border-radius:20px; background:#0d1727; color:#eef5ff; padding:0; box-shadow:0 30px 90px #000b; }
.modal.wide { width:min(760px,calc(100vw - 28px)); }
.modal::backdrop { background:#030711b8; backdrop-filter:blur(4px); }
.modal form { padding:22px; display:grid; gap:18px; }
.modal-head { justify-content:space-between; }
.modal-head h3 { margin:.2rem 0 0; }
.modal-actions { justify-content:flex-end; gap:9px; }
.form-grid { display:grid; grid-template-columns:1fr 1fr; gap:14px; }
.form-grid .full { grid-column:1/-1; }
.field-label { display:block; color:#cbd6e8; font-size:.9rem; margin-bottom:8px; }
.permission-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; max-height:310px; overflow:auto; border:1px solid var(--border); border-radius:12px; padding:12px; }
.permission-option { display:flex; align-items:center; gap:8px; color:#cbd6e8; }
.permission-option input { width:auto; }
.toast { position:fixed; right:20px; bottom:20px; max-width:420px; background:#18283f; border:1px solid #35527e; padding:11px 14px; border-radius:12px; opacity:0; transform:translateY(12px); pointer-events:none; transition:.18s; z-index:20; }
.toast.show { opacity:1; transform:none; }
.toast.error { border-color:#8f3949; background:#401c27; }
@media (max-width:800px) {
  .app-shell { grid-template-columns:1fr; }
  .sidebar { position:static; height:auto; border-right:0; border-bottom:1px solid var(--border); }
  .sidebar nav { grid-template-columns:repeat(auto-fit,minmax(92px,1fr)); }
  .sidebar-footer { grid-template-columns:1fr auto; align-items:center; }
  .content { padding:20px 14px 40px; }
  .metric-grid,.dashboard-metrics { grid-template-columns:1fr; }
  .dashboard-head,.dashboard-master-head { align-items:flex-start; flex-direction:column; }
  .sensor-grid { grid-template-columns:1fr; }
  .event-filter-card { grid-template-columns:1fr; }
  .event-dialog-meta dl { grid-template-columns:1fr; }
  .task-filter-card { align-items:stretch; flex-direction:column; }
  .task-filter-card > label:first-child { min-width:0; }
  .task-detail-meta dl { grid-template-columns:1fr; }
  .task-comment-form { grid-template-columns:1fr; }
  .history-layout { grid-template-columns:1fr; }
  .history-sidebar { position:static; }
  .history-chart { overflow:auto; justify-content:start; }
  .topbar { align-items:flex-start; flex-direction:column; }
  .form-grid,.permission-grid { grid-template-columns:1fr; }
  .table-card { overflow:auto; }
}


/* --------------------------------------------------------------------------
   Client Panel parity layer.
   Layout, density and visual language follow the legacy 0.7.51 test panel.
   -------------------------------------------------------------------------- */
:root {
  --legacy-bg: #03111f;
  --legacy-bg2: #041a2e;
  --legacy-panel: rgba(8, 28, 50, .82);
  --legacy-panel2: rgba(11, 35, 61, .78);
  --legacy-text: #f4f8ff;
  --legacy-muted: #9fb4cd;
  --legacy-border: rgba(116, 180, 235, .18);
  --legacy-accent: #159bff;
  --legacy-accent-soft: #6dc7ff;
  --legacy-good: #6ee7b7;
  --legacy-bad: #ff6b81;
  --legacy-warn: #e8c078;
  --legacy-gold: #b98237;
  --legacy-shadow: 0 24px 70px rgba(0, 8, 20, .36), inset 0 1px 0 rgba(255,255,255,.05);
}

body {
  background:
    radial-gradient(circle at 50% 0%, rgba(21,155,255,.16), transparent 34%),
    linear-gradient(180deg, #020b16 0%, var(--legacy-bg) 45%, var(--legacy-bg2) 100%);
  color: var(--legacy-text);
  font-family: Manrope, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 18%, rgba(21,155,255,.12), transparent 20%),
    radial-gradient(circle at 85% 14%, rgba(185,130,55,.08), transparent 24%);
  z-index: 0;
}
body > * { position: relative; z-index: 1; }
h1,h2,h3,h4,strong,b { color: var(--legacy-text); }
p,.muted,.small,label { color: var(--legacy-muted); }

.button,
button {
  border-radius: 12px;
}
.button.primary {
  color: #fff8ea;
  border-color: rgba(232,192,120,.55);
  background:
    linear-gradient(180deg, rgba(255,255,255,.14), rgba(255,255,255,0) 42%),
    linear-gradient(135deg, #e0b46a 0%, #b98237 42%, #7a4f22 100%);
  box-shadow: 0 10px 28px rgba(185,130,55,.28), inset 0 1px 0 rgba(255,255,255,.22);
  font-weight: 800;
}
.button.primary:hover {
  border-color: rgba(232,192,120,.82);
  box-shadow: 0 14px 32px rgba(185,130,55,.34), 0 0 0 3px rgba(232,192,120,.08);
}
.button.ghost,
.profile-button,
.logout-button,
.subtab,
.device-tab {
  color: #d8eaff;
  background: rgba(255,255,255,.045);
  border: 1px solid rgba(116,180,235,.24);
  box-shadow: none;
}
.button.ghost:hover,
.profile-button:hover,
.logout-button:hover,
.subtab:hover,
.device-tab:hover {
  border-color: rgba(92,178,255,.45);
  box-shadow: 0 0 0 3px rgba(21,155,255,.1);
}
.button.danger,.link-button.danger {
  color: #ffabb8;
}

input,select,textarea {
  border-radius: 12px;
  border: 1px solid rgba(116,180,235,.20);
  background: rgba(255,255,255,.045);
  color: var(--legacy-text);
}
input:focus,select:focus,textarea:focus {
  border-color: rgba(92,178,255,.48);
  box-shadow: 0 0 0 3px rgba(21,155,255,.08);
}
select option { background: #0b233d; color: var(--legacy-text); }

/* Login copied structurally from the test panel. */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
}
.login-view.hidden { display: none !important; }
.login-shell {
  width: min(1180px, 100%);
  min-height: 620px;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(380px, .8fr);
  gap: 28px;
  align-items: stretch;
}
.login-hero,
.login-form-card {
  border: 1px solid var(--legacy-border);
  border-radius: 28px;
  box-shadow: var(--legacy-shadow);
  background:
    radial-gradient(circle at 50% 0%, rgba(21,155,255,.14), transparent 46%),
    linear-gradient(180deg, rgba(8,28,50,.76), rgba(5,20,36,.92));
}
.login-hero {
  padding: 58px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login-logo-text,
.brand-logo-text {
  font-weight: 900;
  letter-spacing: -.04em;
  color: #fff;
}
.login-logo-text { font-size: 42px; margin-bottom: 28px; }
.brand-logo-text { font-size: 27px; }
.login-logo-text span,
.brand-logo-text span { color: var(--legacy-accent-soft); }
.login-badge,
.login-form-kicker {
  width: fit-content;
  text-transform: uppercase;
  letter-spacing: .15em;
  font-size: 11px;
  font-weight: 800;
  color: var(--legacy-accent-soft);
}
.login-hero h1 {
  margin: 18px 0 12px;
  max-width: 640px;
  font-size: clamp(36px, 5vw, 64px);
  line-height: .98;
}
.login-hero > p {
  max-width: 670px;
  color: #bdd0e6;
  font-size: 17px;
  line-height: 1.65;
}
.login-feature-grid {
  display: grid;
  grid-template-columns: repeat(3,1fr);
  gap: 12px;
  margin-top: 36px;
}
.login-feature-grid > div {
  padding: 18px;
  border: 1px solid rgba(116,180,235,.18);
  border-radius: 18px;
  background: rgba(255,255,255,.025);
  display: grid;
  gap: 4px;
}
.login-feature-grid b { font-size: 22px; }
.login-feature-grid span { color: var(--legacy-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.login-form-card {
  padding: 42px;
  align-self: center;
}
.login-form-head h2 { font-size: 30px; margin: 8px 0 8px; }
.login-form-head p { margin-bottom: 26px; }
.login-form { display: grid; gap: 15px; }
.login-form .forgot { justify-self: center; color: var(--legacy-muted); font-size: 13px; }
.login-hint { text-align: center; margin: 18px 0 0; }

/* Application shell. */
.app-shell {
  grid-template-columns: 290px 1fr;
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 16px;
  background: rgba(2,11,22,.86);
  backdrop-filter: blur(18px);
  border-right: 1px solid rgba(116,180,235,.14);
  box-shadow: 0 24px 70px rgba(0,8,20,.28);
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
  padding: 14px;
  border: 1px solid rgba(116,180,235,.14);
  border-radius: 20px;
  background: radial-gradient(circle at 50% 0%, rgba(21,155,255,.08), transparent 54%), rgba(255,255,255,.02);
}
.brand-copy { min-width: 0; }
.brand-copy strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand-subtitle {
  margin-top: 4px;
  color: var(--legacy-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .13em;
}
.nav-menu { display: grid; gap: 8px; }
.nav-item {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 8px;
  text-align: left;
  color: rgba(244,248,255,.78);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 12px 14px;
}
.nav-item.active,.nav-item:hover {
  color: white;
  background: linear-gradient(90deg, rgba(21,155,255,.14), rgba(255,255,255,.03));
  border-color: rgba(116,180,235,.22);
}
.nav-icon {
  width: 24px;
  text-align: center;
  color: var(--legacy-accent-soft);
  font-size: 18px;
}
.collapse-btn {
  position: absolute;
  right: -12px;
  bottom: 24px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  color: #d8eaff;
  background: rgba(11,35,61,.96);
  border: 1px solid rgba(116,180,235,.24);
}
.sidebar-footer {
  margin-top: auto;
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 20px;
  border-top: 1px solid rgba(116,180,235,.12);
  padding-top: 13px;
}
.user-chip { display: grid; gap: 3px; }
.user-chip span { color: var(--legacy-muted); font-size: 12px; }

.content-shell { min-width: 0; }
.content {
  padding: 24px 26px 60px;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 26px;
  background: rgba(2,11,22,.82);
  border-bottom: 1px solid rgba(116,180,235,.14);
  backdrop-filter: blur(18px);
}
.topbar-left { display:flex; align-items:center; gap:12px; min-width:0; }
.topbar-left h1 { margin:0 0 5px; font-size:30px; }
.topbar-left p { margin:0; color:var(--legacy-muted); }
.topbar-actions { display:flex; align-items:center; gap:10px; }
.master-selector-wrap { display:flex; align-items:center; gap:8px; }
.topbar-master-label { color:var(--legacy-muted); font-size:12px; }
.topbar-actions select { min-width:220px; }
.topbar-badge,.topbar-host {
  border:1px solid rgba(116,180,235,.18);
  border-radius:999px;
  padding:7px 10px;
  color:#d9ecff;
  background:rgba(255,255,255,.035);
  font-size:11px;
}
.topbar-host { color:var(--legacy-muted); }
.profile-button,.logout-button {
  padding:9px 12px;
  border-radius:11px;
}
.mobile-menu { display:none; }

/* Use the test-panel panel/table language for every already-working module. */
.metric-card,.card,.table-card,.role-card,.dashboard-master-card {
  background:
    radial-gradient(circle at 50% 0%, rgba(21,155,255,.12), transparent 44%),
    linear-gradient(180deg, rgba(8,28,50,.72), rgba(5,20,36,.88));
  border:1px solid rgba(116,180,235,.18);
  border-radius:20px;
  box-shadow:var(--legacy-shadow);
}
.section-head { margin:18px 0 16px; }
.section-head h2,.section-head h3 { margin-bottom:6px; }
.table-card { overflow:auto; }
table { min-width:780px; }
th {
  color:#e5f2ff;
  background:rgba(11,35,61,.88);
  font-weight:800;
}
tr:nth-child(even) td { background:rgba(255,255,255,.018); }
tr:hover td { background:rgba(21,155,255,.04); }
.subtabs,.device-tabs {
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin:10px 0 14px;
}
.subtab.active,.device-tab.active {
  border-color:var(--legacy-accent);
  background:rgba(21,155,255,.16);
  color:white;
}
.settings-subtabs { margin-top:0; }

/* Devices: structure follows 0.7.51. */
.device-tabs-row {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  margin-bottom:14px;
}
.device-offline-filter {
  display:flex;
  align-items:center;
  gap:8px;
  color:var(--legacy-muted);
}
.device-offline-filter input { width:auto; }
.device-summary {
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(160px,1fr));
  gap:12px;
  margin-bottom:16px;
}
.device-summary-card {
  padding:14px 16px;
  border:1px solid rgba(116,180,235,.16);
  border-radius:16px;
  background:rgba(11,35,61,.52);
}
.device-summary-card span { display:block; color:var(--legacy-muted); font-size:12px; }
.device-summary-card strong { display:block; margin-top:5px; font-size:24px; }
.device-cards {
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:14px;
}
.device-card {
  position:relative;
  min-height:300px;
  padding:16px;
  border-radius:16px;
  background:linear-gradient(160deg, rgba(49,120,172,.92), rgba(20,79,135,.72));
  border:1px solid rgba(84,184,234,.35);
  box-shadow:var(--legacy-shadow);
  overflow:hidden;
}
.device-card::after {
  content:"";
  position:absolute;
  right:-34px;
  top:-34px;
  width:120px;
  height:120px;
  border-radius:50%;
  background:radial-gradient(circle,rgba(21,155,255,.14),rgba(21,155,255,.04) 58%,transparent 70%);
}
.device-head {
  position:relative;
  z-index:1;
  display:flex;
  justify-content:space-between;
  gap:10px;
  margin-bottom:12px;
}
.device-title { min-width:0; }
.device-title strong {
  display:block;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.device-title small {
  display:block;
  margin-top:4px;
  color:#c6def2;
}
.device-kind {
  position:relative;
  z-index:1;
  width:fit-content;
  margin-bottom:10px;
  padding:4px 8px;
  border-radius:999px;
  background:rgba(255,255,255,.08);
  border:1px solid rgba(255,255,255,.12);
  color:#e8f6ff;
  font-size:10px;
  font-weight:800;
  text-transform:uppercase;
  letter-spacing:.06em;
}
.device-kv {
  position:relative;
  z-index:1;
  display:grid;
  grid-template-columns:94px minmax(0,1fr);
  gap:6px 8px;
  font-size:12px;
  color:#cce7f9;
}
.device-kv b { color:white; overflow-wrap:anywhere; }
.device-values {
  position:relative;
  z-index:1;
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:8px;
  margin-top:12px;
}
.device-value {
  padding:8px;
  border-radius:10px;
  background:rgba(2,18,46,.25);
  border:1px solid rgba(255,255,255,.10);
}
.device-value span { display:block; color:#c6def2; font-size:10px; }
.device-value strong { display:block; margin-top:3px; font-size:14px; }
.device-card-actions {
  position:relative;
  z-index:1;
  display:flex;
  gap:7px;
  margin-top:14px;
  padding-top:10px;
  border-top:1px dashed rgba(255,255,255,.16);
}
.device-card-actions button { min-height:32px; padding:6px 8px; font-size:11px; }

/* Responsive behavior follows the legacy sidebar/mobile model. */
@media (max-width: 1280px) {
  .device-cards { grid-template-columns:repeat(3,minmax(0,1fr)); }
  .topbar-badge,.topbar-host { display:none; }
}
@media (max-width: 1050px) {
  .device-cards { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .topbar-actions select { min-width:160px; }
}
@media (max-width: 800px) {
  .app-shell { grid-template-columns:1fr; }
  .sidebar {
    position:fixed;
    left:-310px;
    width:290px;
    transition:left .2s ease;
  }
  .sidebar.mobile-open { left:0; }
  .mobile-menu { display:inline-flex; }
  .content { padding:18px 14px 40px; }
  .topbar { padding:14px; align-items:flex-start; }
  .topbar-actions { flex-wrap:wrap; justify-content:flex-end; }
  .master-selector-wrap { display:none !important; }
  .device-cards { grid-template-columns:1fr; }
  .login-shell { grid-template-columns:1fr; min-height:0; }
  .login-hero { padding:34px; }
  .login-form-card { padding:30px; }
}
@media (max-width: 560px) {
  .login-view { padding:14px; }
  .login-hero { display:none; }
  .device-tabs-row { align-items:stretch; flex-direction:column; }
  .device-tabs { overflow-x:auto; flex-wrap:nowrap; }
}

body.sidebar-collapsed .app-shell { grid-template-columns: 88px 1fr; }
body.sidebar-collapsed .sidebar { width: 88px; }
body.sidebar-collapsed .brand-copy,
body.sidebar-collapsed .nav-item b,
body.sidebar-collapsed .user-chip,
body.sidebar-collapsed .brand-logo-text span { display:none; }
body.sidebar-collapsed .brand { justify-content:center; padding-inline:8px; }
body.sidebar-collapsed .brand-logo-text { font-size:20px; letter-spacing:0; }
body.sidebar-collapsed .nav-item { grid-template-columns:1fr; justify-items:center; padding-inline:8px; }
body.sidebar-collapsed .nav-icon { width:auto; }
body.sidebar-collapsed .collapse-btn { transform:rotate(180deg); }


/* Legacy Notifications / Service parity surfaces. */
.status.alarm {
  color:#ffb2bc;
  border-color:#8c3949;
  background:#3b1d26;
}
.status.progress {
  color:#a9d4ff;
  border-color:#32659c;
  background:#153251;
}
.service-nav { opacity:.88; }
.automation-form-panel { margin-bottom:16px; }
.automation-form-grid { grid-template-columns:repeat(4,minmax(150px,1fr)); }
.automation-conditions-block {
  margin:16px 0 6px;
  padding:14px;
  border:1px solid rgba(116,180,235,.18);
  border-radius:14px;
  background:rgba(255,255,255,.025);
}
.automation-conditions-head {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:10px;
}
.automation-conditions-head > div { display:grid; gap:4px; }
.automation-conditions-head small { color:var(--legacy-muted); }
.automation-conditions-list { display:grid; gap:10px; }
.automation-condition-row {
  display:grid;
  grid-template-columns:minmax(150px,.9fr) minmax(210px,1.2fr) minmax(120px,.7fr) minmax(120px,.7fr) auto;
  align-items:end;
  gap:10px;
  padding:10px;
  border:1px solid rgba(116,180,235,.18);
  border-radius:12px;
  background:rgba(255,255,255,.025);
}
.automation-remove-condition {
  width:42px;
  height:42px;
  align-self:end;
  border:1px solid rgba(255,107,129,.28);
  border-radius:10px;
  color:#ffabb8;
  background:rgba(255,107,129,.06);
}
.automation-channel-row {
  display:flex;
  flex-wrap:wrap;
  gap:18px;
  margin:14px 0;
}
.automation-channel-row label {
  display:flex;
  align-items:center;
  gap:7px;
}
.automation-channel-row input { width:auto; }
.automation-bell { color:var(--legacy-accent-soft); }
.automation-events-head { margin-top:24px; }

.service-master-state {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  margin-bottom:16px;
}
.service-master-state > div { display:grid; gap:4px; }
.service-command-grid {
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(280px,1fr));
  gap:14px;
  align-items:start;
}
.service-card { display:grid; gap:12px; }
.service-card h3 { margin:0 0 4px; }
.service-card label { display:grid; gap:6px; }
.service-inline-fields {
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px;
}
.button-row.wrap { flex-wrap:wrap; }
.service-history-head { margin-top:24px; }
.service-response {
  display:block;
  max-width:520px;
  white-space:normal;
  overflow-wrap:anywhere;
  font-size:.72rem;
  color:#c9d8ea;
  background:rgba(1,9,28,.6);
  border:1px solid rgba(116,180,235,.12);
  border-radius:8px;
  padding:6px 8px;
}

@media (max-width:1050px) {
  .automation-form-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .automation-condition-row { grid-template-columns:1fr 1fr; }
  .automation-remove-condition { justify-self:end; }
}
@media (max-width:680px) {
  .automation-form-grid,
  .automation-condition-row,
  .service-inline-fields { grid-template-columns:1fr; }
  .automation-conditions-head,
  .service-master-state { align-items:stretch; flex-direction:column; }
  .automation-remove-condition { justify-self:stretch; width:100%; }
}
