:root {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-base: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-heading: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", SFMono-Regular, Consolas, "Liberation Mono", monospace;

  --radius-xxl: 20px;
  --radius-xl: 16px;
  --radius-lg: 12px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --radius-xs: 4px;
  --radius-pill: 999px;

  --control-height-sm: 34px;
  --control-height-md: 40px;
  --control-height-lg: 44px;
  --control-gap: 10px;

  --transition-base: 0.2s ease;
  --transition-long: 0.35s ease;

  /* default (dark) palette to avoid FOUC before theme store boots */
  --bg-color: #10121c;
  --bg-gradient: radial-gradient(circle at 12% 5%, rgba(82, 115, 255, 0.18), transparent 52%), radial-gradient(circle at 80% 90%, rgba(42, 210, 164, 0.14), transparent 58%), #10121c;

  --surface-primary: rgba(22, 26, 40, 0.92);
  --surface-secondary: rgba(26, 30, 46, 0.9);
  --surface-muted: rgba(18, 22, 34, 0.78);
  --surface-border: rgba(84, 98, 140, 0.35);
  --surface-border-strong: rgba(118, 132, 176, 0.45);
  --surface-border-soft: rgba(76, 90, 132, 0.28);

  --shadow-lg: 0 30px 60px rgba(4, 8, 22, 0.58);
  --shadow-md: 0 18px 40px rgba(7, 12, 28, 0.52);
  --shadow-sm: 0 12px 24px rgba(8, 14, 30, 0.38);

  --text-primary: #f2f4ff;
  --text-secondary: rgba(214, 222, 252, 0.74);
  --text-muted: rgba(174, 186, 222, 0.58);
  --text-contrast: #05070f;

  --accent-primary: #2f7bff;
  --accent-primary-soft: rgba(64, 115, 255, 0.32);
  --accent-primary-strong: #63a1ff;
  --accent-glow: 0 0 0 6px rgba(64, 115, 255, 0.2);

  --chip-bg: rgba(38, 44, 60, 0.85);
  --chip-border: rgba(82, 96, 140, 0.36);
  --chip-text: var(--text-secondary);
  --chip-active-bg: linear-gradient(145deg, #2c6eff, #66a5ff);
  --chip-active-border: rgba(132, 174, 255, 0.7);
  --chip-active-text: var(--text-contrast);
  --chip-active-shadow: 0 12px 30px rgba(66, 123, 255, 0.32);

  --btn-primary-bg: linear-gradient(140deg, #3073ff, #63a0ff);
  --btn-primary-bg-hover: linear-gradient(140deg, #2b68eb, #6dafff);
  --btn-primary-text: var(--text-contrast);
  --btn-primary-shadow: 0 20px 36px rgba(66, 123, 255, 0.34);

  --btn-secondary-bg: rgba(30, 36, 52, 0.92);
  --btn-secondary-border: rgba(100, 118, 176, 0.42);
  --btn-secondary-text: var(--text-primary);
  --btn-secondary-hover: rgba(38, 44, 66, 0.96);

  --btn-danger-bg: rgba(255, 95, 122, 0.16);
  --btn-danger-border: rgba(255, 110, 148, 0.45);
  --btn-danger-text: #ff92aa;
  --btn-danger-hover: rgba(255, 95, 122, 0.23);

  --input-bg: rgba(20, 24, 38, 0.95);
  --input-border: rgba(76, 94, 150, 0.45);
  --input-hover: rgba(88, 110, 176, 0.55);
  --input-placeholder: rgba(152, 164, 210, 0.5);
  --input-focus: rgba(64, 115, 255, 0.9);
  --input-focus-ring: 0 0 0 4px rgba(64, 115, 255, 0.2);

  --badge-bg: rgba(86, 98, 148, 0.24);
  --badge-text: var(--text-secondary);
  --badge-online-bg: rgba(47, 216, 161, 0.18);
  --badge-online-text: #3ae3af;
  --badge-offline-bg: rgba(255, 102, 132, 0.2);
  --badge-offline-text: #ff8aa3;

  --toast-bg: rgba(26, 32, 46, 0.96);
  --toast-border: rgba(92, 112, 176, 0.32);

  --nav-bg: rgba(28, 34, 50, 0.92);
  --nav-border: rgba(88, 104, 156, 0.32);
  --nav-shadow: 0 20px 48px rgba(6, 10, 26, 0.55);
  --nav-pill-bg: rgba(38, 44, 60, 0.88);
  --nav-pill-border: rgba(90, 104, 150, 0.38);
  --nav-pill-text: var(--text-secondary);
  --nav-pill-active-bg: linear-gradient(145deg, #2c6eff, #66a5ff);
  --nav-pill-active-text: var(--text-contrast);
  --nav-pill-active-shadow: 0 14px 28px rgba(60, 118, 255, 0.3);
}

body.theme-dark {
  color-scheme: dark;
}

body.theme-silver {
  color-scheme: light;
  --bg-color: #e9ecf5;
  --bg-gradient: linear-gradient(180deg, #f4f7fd 0%, #e4e7f3 100%);
  --surface-primary: rgba(248, 249, 255, 0.95);
  --surface-secondary: rgba(252, 253, 255, 0.98);
  --surface-muted: rgba(238, 240, 250, 0.88);
  --surface-border: rgba(184, 194, 228, 0.6);
  --surface-border-strong: rgba(154, 164, 204, 0.72);
  --surface-border-soft: rgba(206, 212, 236, 0.5);
  --shadow-lg: 0 30px 48px rgba(150, 160, 205, 0.38);
  --shadow-md: 0 18px 38px rgba(150, 160, 210, 0.32);
  --shadow-sm: 0 12px 26px rgba(158, 168, 210, 0.28);
  --text-primary: #1e2433;
  --text-secondary: rgba(46, 56, 80, 0.78);
  --text-muted: rgba(72, 86, 116, 0.56);
  --text-contrast: #ffffff;
  --accent-primary: #2f7bff;
  --accent-primary-soft: rgba(64, 115, 255, 0.24);
  --accent-primary-strong: #205fe6;
  --accent-glow: 0 0 0 6px rgba(48, 98, 255, 0.18);
  --chip-bg: rgba(238, 240, 250, 0.94);
  --chip-border: rgba(190, 198, 230, 0.7);
  --chip-text: var(--text-secondary);
  --chip-active-bg: linear-gradient(145deg, #2f7bff, #61a0ff);
  --chip-active-border: rgba(118, 154, 255, 0.85);
  --chip-active-text: #ffffff;
  --chip-active-shadow: 0 18px 34px rgba(102, 140, 255, 0.3);
  --btn-primary-bg: linear-gradient(140deg, #2f7bff, #61a0ff);
  --btn-primary-bg-hover: linear-gradient(140deg, #2b6ce5, #6ba9ff);
  --btn-primary-text: #ffffff;
  --btn-primary-shadow: 0 20px 34px rgba(64, 115, 255, 0.28);
  --btn-secondary-bg: rgba(238, 240, 250, 0.95);
  --btn-secondary-border: rgba(194, 202, 232, 0.72);
  --btn-secondary-text: var(--text-primary);
  --btn-secondary-hover: rgba(246, 247, 254, 1);
  --btn-danger-bg: rgba(255, 120, 140, 0.18);
  --btn-danger-border: rgba(255, 126, 148, 0.3);
  --btn-danger-text: #d84a63;
  --btn-danger-hover: rgba(255, 120, 140, 0.24);
  --input-bg: rgba(252, 253, 255, 0.98);
  --input-border: rgba(190, 198, 232, 0.72);
  --input-hover: rgba(168, 178, 224, 0.7);
  --input-placeholder: rgba(122, 136, 174, 0.5);
  --input-focus: rgba(64, 115, 255, 0.9);
  --input-focus-ring: 0 0 0 4px rgba(64, 115, 255, 0.16);
  --badge-bg: rgba(188, 198, 230, 0.32);
  --badge-text: var(--text-secondary);
  --badge-online-bg: rgba(51, 195, 150, 0.2);
  --badge-online-text: #2a8d6a;
  --badge-offline-bg: rgba(236, 116, 140, 0.2);
  --badge-offline-text: #d35a74;
  --toast-bg: rgba(251, 252, 255, 0.96);
  --toast-border: rgba(190, 198, 228, 0.64);
  --nav-bg: rgba(247, 248, 255, 0.96);
  --nav-border: rgba(194, 202, 232, 0.68);
  --nav-shadow: 0 20px 40px rgba(154, 164, 206, 0.32);
  --nav-pill-bg: rgba(238, 240, 250, 0.94);
  --nav-pill-border: rgba(194, 202, 232, 0.72);
  --nav-pill-text: var(--text-secondary);
  --nav-pill-active-bg: linear-gradient(145deg, #2f7bff, #61a0ff);
  --nav-pill-active-text: #ffffff;
  --nav-pill-active-shadow: 0 16px 30px rgba(98, 140, 255, 0.28);
}

body.theme-light {
  color-scheme: light;
  --bg-color: #f7f8ff;
  --bg-gradient: linear-gradient(180deg, #ffffff 0%, #eff2ff 100%);
  --surface-primary: rgba(255, 255, 255, 0.98);
  --surface-secondary: rgba(255, 255, 255, 1);
  --surface-muted: rgba(246, 247, 255, 0.92);
  --surface-border: rgba(208, 214, 240, 0.64);
  --surface-border-strong: rgba(180, 188, 220, 0.74);
  --surface-border-soft: rgba(214, 220, 244, 0.55);
  --shadow-lg: 0 28px 48px rgba(190, 200, 240, 0.42);
  --shadow-md: 0 18px 38px rgba(188, 198, 240, 0.34);
  --shadow-sm: 0 12px 26px rgba(190, 198, 240, 0.28);
  --text-primary: #141722;
  --text-secondary: rgba(56, 66, 96, 0.78);
  --text-muted: rgba(84, 96, 126, 0.56);
  --text-contrast: #ffffff;
  --accent-primary: #2370ff;
  --accent-primary-soft: rgba(70, 120, 255, 0.26);
  --accent-primary-strong: #1e62e4;
  --accent-glow: 0 0 0 6px rgba(70, 120, 255, 0.18);
  --chip-bg: rgba(244, 246, 255, 0.96);
  --chip-border: rgba(206, 214, 240, 0.75);
  --chip-text: var(--text-secondary);
  --chip-active-bg: linear-gradient(145deg, #2370ff, #5b96ff);
  --chip-active-border: rgba(116, 150, 255, 0.86);
  --chip-active-text: #ffffff;
  --chip-active-shadow: 0 18px 32px rgba(90, 136, 255, 0.3);
  --btn-primary-bg: linear-gradient(140deg, #2370ff, #5a92ff);
  --btn-primary-bg-hover: linear-gradient(140deg, #2063e6, #659cff);
  --btn-primary-text: #ffffff;
  --btn-primary-shadow: 0 20px 34px rgba(80, 130, 255, 0.32);
  --btn-secondary-bg: rgba(244, 246, 255, 0.98);
  --btn-secondary-border: rgba(206, 214, 240, 0.75);
  --btn-secondary-text: var(--text-primary);
  --btn-secondary-hover: rgba(255, 255, 255, 1);
  --btn-danger-bg: rgba(255, 120, 140, 0.2);
  --btn-danger-border: rgba(255, 126, 148, 0.32);
  --btn-danger-text: #d8405d;
  --btn-danger-hover: rgba(255, 120, 140, 0.28);
  --input-bg: rgba(255, 255, 255, 0.98);
  --input-border: rgba(206, 214, 240, 0.75);
  --input-hover: rgba(184, 194, 232, 0.72);
  --input-placeholder: rgba(128, 138, 170, 0.52);
  --input-focus: rgba(70, 120, 255, 0.88);
  --input-focus-ring: 0 0 0 4px rgba(90, 132, 255, 0.2);
  --badge-bg: rgba(206, 214, 240, 0.32);
  --badge-text: var(--text-secondary);
  --badge-online-bg: rgba(64, 210, 160, 0.24);
  --badge-online-text: #2a9368;
  --badge-offline-bg: rgba(255, 126, 148, 0.24);
  --badge-offline-text: #d34864;
  --toast-bg: rgba(255, 255, 255, 0.96);
  --toast-border: rgba(206, 214, 240, 0.7);
  --nav-bg: rgba(248, 249, 255, 0.97);
  --nav-border: rgba(206, 214, 240, 0.78);
  --nav-shadow: 0 20px 42px rgba(190, 200, 240, 0.38);
  --nav-pill-bg: rgba(242, 244, 255, 0.96);
  --nav-pill-border: rgba(206, 214, 240, 0.78);
  --nav-pill-text: var(--text-secondary);
  --nav-pill-active-bg: linear-gradient(145deg, #2370ff, #5b96ff);
  --nav-pill-active-text: #ffffff;
  --nav-pill-active-shadow: 0 16px 30px rgba(90, 136, 255, 0.32);
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: var(--font-base);
  background: var(--bg-gradient);
  background-color: var(--bg-color);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background 0.4s var(--transition-long), color 0.3s var(--transition-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app {
  min-height: 100vh;
}

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

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font-family: inherit;
  border: none;
  outline: none;
  cursor: pointer;
  line-height: 1;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

input,
textarea,
select,
button {
  border-radius: var(--radius-sm);
  transition: all var(--transition-base);
}

input,
textarea,
select {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 15px;
}

input:hover,
textarea:hover,
select:hover {
  border-color: var(--input-hover);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--input-focus);
  box-shadow: var(--input-focus-ring);
}

input::placeholder,
textarea::placeholder {
  color: var(--input-placeholder);
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 42px;
}

select:focus {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
    linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
}

input[type="checkbox"] {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid var(--surface-border);
  background: var(--surface-muted);
  cursor: pointer;
  position: relative;
  transition: border-color var(--transition-base), background var(--transition-base), box-shadow var(--transition-base);
}

input[type="checkbox"]::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 4px;
  background: transparent;
  transition: background var(--transition-base);
}

input[type="checkbox"]:checked {
  border-color: var(--accent-primary);
  background: var(--accent-primary);
  box-shadow: var(--accent-glow);
}

input[type="checkbox"]:checked::after {
  background: var(--text-contrast);
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 48px 32px 64px;
}

.app-shell.guest {
  padding: 32px 16px;
}

.dashboard {
  width: min(1180px, 100%);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 24px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  padding: 18px 24px;
  border-radius: var(--radius-xl);
  background: var(--nav-bg);
  border: 1px solid var(--nav-border);
  box-shadow: var(--nav-shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  justify-self: center;
  text-align: center;
  line-height: 1.2;
}

.topbar-side {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--control-height-lg);
}

.topbar > .theme-switcher {
  justify-self: end;
}

.theme-switcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border-radius: var(--radius-xl);
  background: var(--nav-pill-bg);
  border: 1px solid var(--nav-pill-border);
}

.theme-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: var(--nav-pill-text);
  background: transparent;
  border: none;
  transition: background var(--transition-base), color var(--transition-base), box-shadow var(--transition-base);
}

.theme-pill:hover {
  color: var(--text-primary);
}

.theme-pill.active {
  background: var(--nav-pill-active-bg);
  color: var(--nav-pill-active-text);
  box-shadow: var(--nav-pill-active-shadow);
}

.theme-pill.cycle {
  min-width: 44px;
  width: auto;
  padding: 0 14px;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.08);
}

.dashboard-content {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}

.dashboard-content.device-content {
  grid-template-rows: auto 1fr;
}

.device-tabs,
.bottombar {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: var(--radius-xl);
  background: var(--nav-bg);
  border: 1px solid var(--nav-border);
  box-shadow: var(--nav-shadow);
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  min-height: var(--control-height-md);
  padding: 0 18px;
  background: var(--nav-pill-bg);
  border: 1px solid var(--nav-pill-border);
  color: var(--nav-pill-text);
  font-weight: 500;
  white-space: nowrap;
  transition: all var(--transition-base);
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--nav-pill-active-bg);
  color: var(--nav-pill-active-text);
  border-color: transparent;
  box-shadow: var(--nav-pill-active-shadow);
}

.schedule-layout,
.functions-layout {
  display: grid;
  gap: 24px;
}

.schedule-layout {
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
}

.panel {
  display: grid;
  gap: 20px;
  background: var(--surface-primary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-xl);
  padding: 28px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.panel-header > div:first-child {
  display: grid;
  gap: 2px;
}

.panel-header h2 {
  font-size: 20px;
  margin: 0;
}

.panel-header p {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.panel-group {
  display: grid;
  gap: 24px;
}

.panel-block {
  display: grid;
  gap: 16px;
  padding: 20px;
  border-radius: var(--radius-lg);
  background: var(--surface-secondary);
  border: 1px solid var(--surface-border-soft);
}

.panel-placeholder {
  padding: 18px;
  border-radius: var(--radius-lg);
  background: var(--surface-muted);
  border: 1px dashed var(--surface-border-strong);
  color: var(--text-secondary);
  text-align: center;
}

.panel-placeholder.warning {
  border-color: rgba(255, 209, 102, 0.45);
  background: rgba(255, 209, 102, 0.14);
  color: #ffcc75;
}

.panel-placeholder.error {
  border-color: rgba(255, 115, 140, 0.5);
  background: rgba(255, 115, 140, 0.16);
  color: #ff8ca3;
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.onboarding-card {
  display: grid;
  gap: 16px;
  padding: 20px;
  border-radius: var(--radius-lg);
  background: var(--surface-secondary);
  border: 1px solid var(--surface-border-soft);
  box-shadow: var(--shadow-sm);
}

.onboarding-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--text-secondary);
  font-size: 14px;
  display: grid;
  gap: 6px;
}

.onboarding-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--control-gap);
  align-items: center;
}

.group-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-start;
}

.group-toolbar > * {
  min-width: 0;
}

.group-chip-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--control-height-md);
  max-width: 100%;
}

.group-chip,
.group-chip.create {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  min-height: var(--control-height-md);
  padding: 0 16px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--chip-text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  max-width: min(100%, 320px);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all var(--transition-base);
}

.group-chip:hover {
  border-color: var(--accent-primary-soft);
  color: var(--text-primary);
}

.group-chip.active {
  background: var(--chip-active-bg);
  border-color: transparent;
  color: var(--chip-active-text);
  box-shadow: var(--chip-active-shadow);
}

.group-chip.create {
  background: rgba(48, 200, 160, 0.15);
  border-color: rgba(48, 200, 160, 0.35);
  color: var(--text-primary);
}

.group-chip-actions {
  display: inline-flex;
  gap: 6px;
  flex-shrink: 0;
}

.chip-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 0;
  line-height: 1;
  transition: color var(--transition-base), background var(--transition-base);
}

.chip-action:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--surface-border-soft);
}

.chip-action.danger:hover {
  color: #ff7f94;
}

.device-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.device-card {
  display: grid;
  gap: 18px;
  padding: 22px;
  border-radius: var(--radius-lg);
  background: var(--surface-secondary);
  border: 1px solid var(--surface-border-soft);
  box-shadow: var(--shadow-md);
}

.device-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.device-card__header > div {
  min-width: 0;
}

.device-card__header h3 {
  margin: 0 0 4px;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.device-card__chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-border);
  color: var(--chip-text);
  max-width: 100%;
}

.chip--group {
  background: rgba(80, 118, 255, 0.16);
  border-color: rgba(96, 138, 255, 0.36);
  color: var(--text-primary);
}

.device-card__groups {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.device-card__groupchips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.device-card__grouptoggles {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.device-card__editpanel .device-card__grouptoggles {
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 12px;
  background: var(--surface-muted);
}

.group-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 14px;
  min-width: 0;
}

.group-toggle span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.group-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid var(--surface-border);
  background: var(--surface-muted);
}

.group-toggle input[type="checkbox"]:checked {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  box-shadow: var(--accent-glow);
}

.group-toggle input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 4px;
  background: var(--text-contrast);
}

.device-card__footer {
  display: flex;
  gap: 12px;
  align-items: stretch;
  flex-wrap: wrap;
}

.device-card__footer > .primary,
.device-card__footer > .secondary {
  flex: 1 1 0;
}

.device-card__editpanel {
  display: grid;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--surface-border);
  min-width: 0;
}

.device-card__editpanel .button-ghost {
  justify-content: center;
  width: 100%;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--badge-bg);
  color: var(--badge-text);
  max-width: 100%;
}

.status-badge.online {
  background: var(--badge-online-bg);
  color: var(--badge-online-text);
}

.status-badge.offline {
  background: var(--badge-offline-bg);
  color: var(--badge-offline-text);
}

.primary,
.secondary,
.danger,
.button-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  border-radius: var(--radius-sm);
  padding: 0 16px;
  min-height: var(--control-height-lg);
  white-space: nowrap;
  transition: all var(--transition-base);
  position: relative;
}

.primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  box-shadow: var(--btn-primary-shadow);
}

.primary:hover {
  background: var(--btn-primary-bg-hover);
  transform: translateY(-1px);
}

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

.secondary:hover {
  background: var(--btn-secondary-hover);
}

.danger {
  background: var(--btn-danger-bg);
  border: 1px solid var(--btn-danger-border);
  color: var(--btn-danger-text);
}

.danger:hover {
  background: var(--btn-danger-hover);
}

.link {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-secondary);
  border-radius: 0;
  min-height: auto;
  font-weight: 500;
}

.link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

.button-ghost {
  background: transparent;
  border: 1px dashed var(--surface-border);
  color: var(--text-secondary);
  box-shadow: none;
}

.topbar .link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-height-md);
  padding: 0 12px;
  border-radius: var(--radius-md);
  background: var(--nav-pill-bg);
  border: 1px solid var(--nav-pill-border);
  color: var(--nav-pill-text);
  text-decoration: none;
  white-space: nowrap;
}

.topbar .link:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
  text-decoration: none;
}

.button-ghost.danger {
  border-color: var(--btn-danger-border);
  color: var(--btn-danger-text);
}

.button-ghost:hover {
  border-color: var(--btn-secondary-border);
  color: var(--text-primary);
}

.button-ghost.danger:hover {
  border-color: var(--btn-danger-border);
  color: var(--btn-danger-text);
  background: rgba(255, 95, 122, 0.08);
}

.icon-btn,
.icon-button {
  width: var(--control-height-md);
  height: var(--control-height-md);
  border-radius: 12px;
  background: var(--btn-secondary-bg);
  border: 1px solid var(--btn-secondary-border);
  color: var(--btn-secondary-text);
  padding: 0;
}

.icon-btn:hover,
.icon-button:hover {
  background: var(--btn-secondary-hover);
}

.toast {
  position: fixed;
  bottom: 32px;
  right: 32px;
  padding: 16px 22px;
  border-radius: var(--radius-lg);
  background: var(--toast-bg);
  border: 1px solid var(--toast-border);
  box-shadow: var(--shadow-lg);
  color: var(--text-primary);
  cursor: pointer;
  animation: toast-in 0.28s ease;
}

@keyframes toast-in {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.functions-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.mode-card {
  display: grid;
  gap: 16px;
  padding: 20px;
  border-radius: var(--radius-lg);
  background: var(--surface-secondary);
  border: 1px solid var(--surface-border-soft);
  box-shadow: var(--shadow-sm);
}

.mode-card.unsupported {
  opacity: 0.65;
  border-style: dashed;
}

.mode-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.mode-note {
  font-size: 13px;
  color: var(--text-muted);
}

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.mode-toggle input[type="checkbox"] {
  width: 40px;
  height: 20px;
  border-radius: 20px;
  border: 1px solid var(--surface-border);
  background: rgba(86, 98, 148, 0.35);
  position: relative;
}

.mode-toggle input[type="checkbox"]::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  top: 1.5px;
  left: 2px;
  background: var(--surface-primary);
  transition: transform var(--transition-base);
}

.mode-toggle input[type="checkbox"]:checked {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  box-shadow: var(--accent-glow);
}

.mode-toggle input[type="checkbox"]:checked::after {
  transform: translateX(18px);
  background: var(--text-contrast);
}

.mode-status {
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 189, 86, 0.18);
  color: #ffbe6d;
  font-size: 13px;
}

.mode-details {
  display: grid;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.mode-details .label {
  color: var(--text-muted);
}

.mode-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  background: rgba(120, 132, 190, 0.28);
  color: var(--text-secondary);
}

.mode-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 18, 0.7);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 100;
}

.modal-card {
  width: min(560px, 100%);
  background: var(--surface-primary);
  border-radius: var(--radius-xl);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 20px;
  padding: 24px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-body {
  display: grid;
  gap: 16px;
}

.info-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  border: 1px solid var(--surface-border-soft);
  font-size: 13px;
  color: var(--text-secondary);
}

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

.overview-status {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  width: 100%;
}

.device-sidebar-stack {
  display: grid;
  gap: 16px;
  align-content: start;
  min-width: 0;
}

.status-block {
  display: grid;
  gap: 6px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  border: 1px solid var(--surface-border-soft);
}

.status-block .label {
  font-size: 13px;
  color: var(--text-muted);
}

.control-row {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.control-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  border: 1px solid var(--surface-border-soft);
}

.sensor-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  border: 1px solid var(--surface-border-soft);
  width: 100%;
}

.sensor-panel h3 {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.sensor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.sensor-item {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-secondary);
  border: 1px solid var(--surface-border-soft);
}

.sensor-key {
  font-size: 12px;
  color: var(--text-muted);
}

.sensor-value {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-primary);
}

.range-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}

.ack-history {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  border: 1px solid var(--surface-border-soft);
}

.ack-history ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 12px;
}

.ack-history li {
  display: grid;
  grid-template-columns: 12px 90px 1fr;
  gap: 12px;
  align-items: center;
  font-size: 13px;
  color: var(--text-secondary);
}

.ack-history .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-primary);
}

.ack-history .dot.error {
  background: var(--badge-offline-text);
}

.ack-history .time {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.topology-panel {
  gap: 16px;
}

.topology-panel__head-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.topology-panel__head-badges .chip {
  max-width: 100%;
}

.topology-panel__block {
  gap: 14px;
}

.topology-ip-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
}

.topology-ip-card {
  display: grid;
  gap: 6px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-secondary);
  border: 1px solid var(--surface-border-soft);
  min-width: 0;
}

.topology-ip-card .label {
  font-size: 12px;
  color: var(--text-muted);
}

.topology-ip-value {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topology-role-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 6px;
  border-radius: var(--radius-lg);
  background: var(--nav-pill-bg);
  border: 1px solid var(--nav-pill-border);
}

.topology-role-switch .tab-btn {
  width: 100%;
  justify-content: center;
}

.topology-form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 0.7fr);
}

.topology-form-grid .field {
  min-width: 0;
}

.topology-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.topology-actions > button {
  min-width: 0;
}

.topology-note {
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-secondary);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface-muted) 80%, transparent);
  border: 1px solid var(--surface-border-soft);
}

.graph-layout,
.card {
  display: grid;
  gap: 18px;
  padding: 22px;
  border-radius: var(--radius-lg);
  background: var(--surface-secondary);
  border: 1px solid var(--surface-border-soft);
  box-shadow: var(--shadow-md);
}

.graph-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.control-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: var(--radius-lg);
  background: var(--nav-pill-bg);
  border: 1px solid var(--nav-pill-border);
}

.graph-canvas-shell {
  border-radius: var(--radius-lg);
  background: var(--surface-muted);
  border: 1px solid var(--surface-border-soft);
  padding: 16px;
  overflow: hidden;
}

.ptpanel {
  display: grid;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--surface-muted);
  border: 1px solid var(--surface-border-soft);
}

.mode-switch {
  display: inline-flex;
  gap: 10px;
  align-items: center;
}

.shared-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.shared-track {
  display: grid;
  gap: 10px;
}

.shared-chip {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-secondary);
  border: 1px solid var(--surface-border);
}

.shared-chip.active {
  border-color: var(--accent-primary);
  box-shadow: var(--accent-glow);
}

.shared-empty {
  padding: 18px;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  border: 1px dashed var(--surface-border-strong);
  color: var(--text-muted);
  text-align: center;
  font-size: 13px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.time-field input {
  font-family: var(--font-mono);
}

.hidden {
  display: none !important;
}

/* Auth layout */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 48px 16px;
  position: relative;
}

.auth-theme-switcher {
  position: absolute;
  top: 32px;
  right: 32px;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface-primary);
  border-radius: var(--radius-xl);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow-lg);
  padding: 36px;
  display: grid;
  gap: 20px;
}

.auth-title {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  text-align: center;
}

.auth-subtitle {
  margin: 4px 0 20px;
  text-align: center;
  color: var(--text-secondary);
}

.auth-tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
  background: var(--nav-pill-bg);
  border: 1px solid var(--nav-pill-border);
  border-radius: var(--radius-xl);
  padding: 6px;
  justify-self: stretch;
}

.auth-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-height-md);
  padding: 0 18px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--nav-pill-text);
  font-weight: 500;
  white-space: nowrap;
}

.auth-tab.active {
  background: var(--nav-pill-active-bg);
  color: var(--nav-pill-active-text);
  box-shadow: var(--nav-pill-active-shadow);
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-field {
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: var(--text-secondary);
}

.auth-message {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.auth-message.error {
  background: rgba(255, 120, 140, 0.18);
  color: #ff8ea4;
}

.auth-message.info {
  background: rgba(64, 210, 160, 0.18);
  color: #3ad6aa;
}

.auth-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--control-height-lg);
  border-radius: var(--radius-sm);
  padding: 0 18px;
  border: none;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  font-weight: 600;
  box-shadow: var(--btn-primary-shadow);
}

.auth-submit:hover:not(:disabled) {
  background: var(--btn-primary-bg-hover);
  transform: translateY(-1px);
}

.auth-switcher {
  display: flex;
  justify-content: center;
  min-height: var(--control-height-sm);
  align-items: center;
}

.auth-switcher .link {
  padding: 0;
  min-height: auto;
}

.auth-loader {
  text-align: center;
  color: var(--text-secondary);
  min-height: var(--control-height-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Minimalist refinement pass */
body.theme-light,
body.theme-silver {
  --bg-gradient: linear-gradient(180deg, #f4f6fa 0%, #eef2f7 100%);
  --surface-primary: rgba(255, 255, 255, 0.96);
  --surface-secondary: rgba(255, 255, 255, 0.98);
  --surface-muted: rgba(245, 247, 251, 0.98);
  --surface-border: rgba(207, 214, 227, 0.9);
  --surface-border-soft: rgba(220, 225, 236, 0.9);
  --surface-border-strong: rgba(196, 204, 219, 0.95);
  --shadow-lg: 0 12px 30px rgba(17, 24, 39, 0.06);
  --shadow-md: 0 6px 18px rgba(17, 24, 39, 0.05);
  --shadow-sm: 0 2px 8px rgba(17, 24, 39, 0.04);
  --nav-shadow: none;
  --nav-pill-active-shadow: none;
  --chip-active-shadow: none;
  --btn-primary-shadow: none;
  --accent-glow: 0 0 0 3px rgba(35, 112, 255, 0.14);
  --nav-bg: rgba(255, 255, 255, 0.92);
  --nav-pill-bg: rgba(247, 249, 253, 1);
  --nav-pill-border: rgba(217, 223, 234, 1);
  --nav-pill-active-bg: #2b6fff;
  --nav-pill-active-text: #ffffff;
  --btn-primary-bg: #2b6fff;
  --btn-primary-bg-hover: #245fdd;
  --btn-secondary-bg: rgba(255, 255, 255, 1);
  --btn-secondary-hover: rgba(249, 250, 253, 1);
  --btn-secondary-border: rgba(215, 222, 234, 1);
  --chip-bg: rgba(247, 249, 253, 1);
  --chip-border: rgba(217, 223, 234, 1);
  --chip-active-bg: rgba(43, 111, 255, 0.1);
  --chip-active-border: rgba(43, 111, 255, 0.22);
  --chip-active-text: #214fb3;
  --badge-bg: rgba(239, 242, 248, 1);
  --toast-bg: rgba(255, 255, 255, 0.96);
  --toast-border: rgba(216, 223, 235, 0.95);
}

body.theme-dark {
  --nav-shadow: none;
  --nav-pill-active-shadow: none;
  --chip-active-shadow: none;
  --btn-primary-shadow: none;
}

.app-shell {
  padding: 24px 20px 28px;
}

.dashboard {
  width: min(1040px, 100%);
  grid-template-rows: auto auto auto;
  gap: 16px;
  align-content: start;
}

.dashboard-content {
  gap: 16px;
  align-items: start;
  align-content: start;
}

.dashboard-content > * {
  min-width: 0;
}

.topbar {
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.topbar h1 {
  justify-self: start;
  text-align: left;
  font-size: 18px;
  font-weight: 600;
}

.topbar-side {
  min-height: var(--control-height-md);
  gap: 8px;
}

.theme-switcher {
  gap: 4px;
  padding: 3px;
  border-radius: 12px;
}

.theme-pill {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-size: 12px;
}

.theme-pill.cycle {
  min-width: 30px;
  padding: 0 10px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--nav-pill-border);
}

.device-tabs,
.bottombar {
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  box-shadow: none;
}

.device-tabs,
.bottombar {
  display: flex;
  flex-wrap: wrap;
}

.bottombar {
  width: min(100%, 720px);
  justify-self: center;
}

.tab-btn {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-tabs .tab-btn,
.bottombar .tab-btn {
  flex: 1 1 150px;
}

.panel {
  gap: 12px;
  padding: 16px;
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  align-content: start;
  align-items: start;
}

.graph-layout,
.card {
  gap: 12px;
  padding: 16px;
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  align-content: start;
  align-items: start;
}

.panel-header {
  width: 100%;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.panel-header > * {
  min-width: 0;
}

.panel-header > div:first-child {
  flex: 1 1 240px;
}

.panel-header > :last-child:not(:first-child) {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  max-width: 100%;
}

.panel-header h2 {
  font-size: 18px;
  line-height: 1.25;
}

.panel-header p {
  margin-top: 2px;
  font-size: 13px;
  max-width: 560px;
}

.onboarding-card,
.mode-card,
.panel-block,
.ptpanel {
  border-radius: 14px;
  box-shadow: none;
}

.graph-canvas-shell {
  padding: 10px;
  border-radius: 12px;
}

.control-group {
  padding: 4px;
  border-radius: 12px;
}

.group-toolbar {
  gap: 8px;
  align-items: flex-start;
}

.schedule-layout > *,
.functions-layout > * {
  min-width: 0;
}

.group-chip-wrapper {
  gap: 4px;
  max-width: 100%;
}

.group-chip,
.group-chip.create {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  max-width: min(100%, 320px);
}

.group-chip.active {
  background: var(--chip-active-bg);
  border-color: var(--chip-active-border);
  color: var(--chip-active-text);
}

.group-chip.create {
  background: rgba(44, 182, 125, 0.08);
  border-color: rgba(44, 182, 125, 0.22);
  color: #21785b;
}

.chip-action {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  font-size: 13px;
}

.form-row > * {
  min-width: 0;
}

.form-row > input,
.form-row > select,
.form-row > textarea {
  flex: 1 1 220px;
}

.form-row > button {
  flex: 0 0 auto;
}

.dashboard-help,
.panel-help {
  border: 1px solid var(--surface-border);
  border-radius: 14px;
  background: var(--surface-primary);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.dashboard-help summary,
.panel-help summary {
  cursor: pointer;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--surface-secondary) 80%, transparent);
}

.dashboard-help[open] summary,
.panel-help[open] summary {
  border-bottom: 1px solid var(--surface-border);
}

.dashboard-help-grid,
.panel-help-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
}

.dashboard-help-item,
.panel-help-item {
  min-width: 0;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--surface-border);
  background: var(--surface-secondary);
}

.dashboard-help-item strong,
.panel-help-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-primary);
}

.dashboard-help-item p,
.panel-help-item p {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-secondary);
}

.dashboard-help-item code,
.panel-help-item code {
  font-size: 11px;
}

.panel-block h3,
.panel-block h4 {
  margin: 0;
  line-height: 1.25;
}

.panel-block .muted {
  margin: 0;
}

.onboarding-card ul li {
  overflow-wrap: anywhere;
}

.onboarding-actions > * {
  min-width: 0;
}

.onboarding-actions > .primary {
  flex: 1 1 220px;
}

.add-device-panel {
  width: 100%;
  min-width: 0;
}

.add-device-panel > * {
  min-width: 0;
}

.add-device-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}

.add-device-grid > * {
  min-width: 0;
}

.add-device-panel .panel-block {
  min-width: 0;
  align-content: start;
}

.add-device-panel .panel-block > * {
  min-width: 0;
}

.add-device-panel .muted {
  overflow-wrap: anywhere;
}

.add-device-warning {
  display: grid;
  gap: 10px;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--warning-border, rgba(245, 158, 11, 0.35));
  background: var(--warning-bg, rgba(245, 158, 11, 0.08));
}

.add-device-warning p {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-secondary);
}

.add-device-warning code {
  font-size: 11px;
}

.add-device-warning .secondary {
  justify-self: start;
  min-height: 34px;
  padding-inline: 12px;
}

.add-device-row {
  align-items: stretch;
}

.add-device-row > input {
  min-width: 0;
}

.add-device-panel textarea,
.add-device-qr-input {
  width: 100%;
  min-width: 0;
  resize: vertical;
}

.add-device-qr-input {
  min-height: 96px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.claim-code-input {
  font-family: var(--font-mono);
}

.onboarding-card h4 {
  margin: 0;
  line-height: 1.25;
}

.onboarding-meta {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.onboarding-meta-row {
  display: grid;
  grid-template-columns: minmax(0, 110px) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface-primary);
  border: 1px solid var(--surface-border);
}

.onboarding-meta-key {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.3;
}

.onboarding-meta-value {
  display: block;
  min-width: 0;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-primary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.onboarding-actions {
  justify-content: space-between;
}

.onboarding-actions > .link {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--surface-border);
  background: var(--surface-primary);
  color: var(--text-secondary);
  text-decoration: none;
}

.onboarding-actions > .link:hover {
  text-decoration: none;
  color: var(--text-primary);
  background: var(--surface-muted);
}

.device-grid {
  gap: 12px;
  align-items: start;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.device-list-panel {
  gap: 14px;
}

.device-list-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--surface-border);
  background: color-mix(in srgb, var(--surface-secondary) 65%, transparent);
}

.device-list-section {
  display: grid;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--surface-border);
  background: color-mix(in srgb, var(--surface-secondary) 58%, transparent);
}

.device-list-section__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 0;
}

.device-list-section__head > * {
  min-width: 0;
}

.device-list-section__head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-primary);
}

.device-list-section__head p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.device-card {
  gap: 12px;
  padding: 14px;
  border-radius: 14px;
  box-shadow: none;
  align-content: start;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface-secondary) 72%, transparent), transparent 44%),
    var(--surface-primary);
}

.device-card__header h3 {
  font-size: 16px;
  line-height: 1.25;
}

.device-card__header {
  padding-bottom: 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--surface-border) 70%, transparent);
}

.device-filters {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--surface-border);
  background: color-mix(in srgb, var(--surface-secondary) 65%, transparent);
}

.device-filters__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.device-filters__label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.device-filters__stats {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chip.chip--muted {
  background: color-mix(in srgb, var(--surface-primary) 70%, transparent);
  border-color: var(--surface-border-soft);
  color: var(--text-muted);
}

.chip.chip--stat {
  min-height: 22px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
}

.chip.chip--stat-online {
  border-color: color-mix(in srgb, var(--badge-online-text) 22%, var(--surface-border-soft));
  color: color-mix(in srgb, var(--badge-online-text) 72%, var(--text-muted));
  background: color-mix(in srgb, var(--badge-online-bg) 45%, transparent);
}

.device-card__groups {
  gap: 8px;
}

.device-card__groupchips {
  gap: 6px;
}

.device-card__chips {
  padding-top: 2px;
  padding-bottom: 2px;
}

.device-card__section {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.device-card__section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.device-card__section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.device-card__section-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  border: 1px solid var(--surface-border-soft);
  background: color-mix(in srgb, var(--surface-secondary) 80%, transparent);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
}

.device-card__section-note {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.device-card__groups {
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--surface-border-soft);
  background: color-mix(in srgb, var(--surface-secondary) 70%, transparent);
}

.device-card__footer {
  gap: 8px;
  margin-top: 2px;
  padding-top: 10px;
  border-top: 1px solid color-mix(in srgb, var(--surface-border) 80%, transparent);
  align-items: center;
}

.device-card__footer > .primary,
.device-card__footer > .secondary {
  flex: 1 1 220px;
}

.device-card__footer > .secondary {
  flex: 0 0 160px;
}

.status-badge,
.chip {
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
}

.chip--group {
  border-style: solid;
}

.device-card__groupchips .chip {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-card__editpanel {
  gap: 10px;
  padding: 10px;
  border-top: none;
  border: 1px solid rgba(255, 99, 132, 0.12);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-secondary) 72%, transparent);
}

.device-card__note {
  margin: 0;
}

.device-card__grouptoggles {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 0;
  border: none;
  background: transparent;
}

.group-toggle {
  min-height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--surface-border-soft);
  background: color-mix(in srgb, var(--surface-primary) 70%, transparent);
}

.group-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.group-toggle span {
  font-size: 13px;
}

.device-card__dangerzone {
  display: flex;
  justify-content: flex-end;
}

.device-card__dangerzone .button-ghost {
  width: auto;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 10px;
}

.primary,
.secondary,
.danger,
.button-ghost {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: none;
}

.primary:hover,
.auth-submit:hover:not(:disabled) {
  transform: none;
}

.secondary,
.button-ghost {
  background-image: none;
}

.group-toolbar {
  padding: 2px;
  border-radius: 12px;
  align-items: center;
}

.group-toolbar > .group-chip:first-child {
  margin-right: 2px;
}

.topbar .link {
  min-height: 34px;
  border-radius: 10px;
  padding: 0 10px;
}

.icon-btn,
.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 10px;
}

.toast {
  padding: 12px 14px;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
}

.graph-controls {
  gap: 8px;
}

.sensor-panel {
  gap: 10px;
  padding: 12px;
  border-radius: 10px;
}

.sensor-item {
  padding: 8px 10px;
  border-radius: 10px;
}

.sensor-value {
  font-size: 13px;
}

.profile-panel .panel-block {
  width: 100%;
}

.profile-panel .panel-block > * {
  min-width: 0;
}

.profile-panel .danger {
  width: 100%;
  justify-content: center;
}

.overview-status > * {
  min-width: 0;
}

.status-block {
  min-width: 0;
}

.status-block > span:not(.label) {
  min-width: 0;
  overflow-wrap: anywhere;
}

.control-row > * {
  min-width: 0;
}

.control-card > input[type="range"] {
  width: 100%;
  min-width: 0;
}

.sensor-item {
  min-width: 0;
}

.sensor-value {
  overflow-wrap: anywhere;
}

.ack-history h3 {
  margin: 0;
  line-height: 1.25;
}

.ack-history li {
  min-width: 0;
}

.ack-history .message {
  min-width: 0;
  overflow-wrap: anywhere;
}

.ack-history .time {
  overflow-wrap: anywhere;
}

.shared-chip {
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
}

.shared-chip.active {
  box-shadow: none;
  background: var(--surface-primary);
}

.graph-layout {
  width: 100%;
  min-width: 0;
}

.graph-layout > * {
  min-width: 0;
}

.graph-controls > * {
  min-width: 0;
}

.graph-controls .control-group {
  flex: 1 1 280px;
  min-width: 0;
  max-width: 100%;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.graph-controls .control-group .badge {
  max-width: min(100%, 320px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.graph-controls .status-indicator {
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
}

.graph-canvas-shell canvas {
  display: block;
  width: 100% !important;
  max-width: 100%;
}

.graph-layout .shared-actions {
  width: 100%;
  align-items: flex-start;
}

.graph-layout .shared-actions > * {
  min-width: 0;
}

.graph-layout .shared-actions .mode-switch {
  flex: 0 0 auto;
}

.graph-layout .shared-actions .time-field {
  flex: 0 1 150px;
  min-width: 132px;
}

.graph-layout .shared-actions .shared-track {
  flex: 1 1 100%;
  width: 100%;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.graph-layout .shared-track .shared-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.graph-layout .shared-track .shared-empty {
  width: 100%;
}

.graph-layout .channel-slider-panel {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  gap: 12px;
  align-items: flex-start;
  justify-content: flex-start;
}

.graph-layout .advanced-row {
  width: 100%;
  justify-content: space-between;
}

.functions-panel {
  width: 100%;
  min-width: 0;
}

.functions-panel > * {
  min-width: 0;
}

/* Final layout pass for functions cards and nav tabs (desktop-first). */
.functions-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-items: stretch;
}

.mode-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  min-height: 100%;
  padding: 16px;
}

.mode-card-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 12px;
  align-items: start;
}

.mode-card-header > .mode-toggle,
.mode-card-header > .mode-status {
  justify-self: end;
  align-self: start;
}

.mode-details {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--surface-border-soft);
  background: color-mix(in srgb, var(--surface-secondary) 70%, transparent);
}

.mode-details li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 6px 12px;
}

.mode-details .label {
  line-height: 1.35;
}

.mode-details .value {
  text-align: right;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}

.mode-badges {
  min-height: 28px;
  align-items: center;
}

.mode-card-actions {
  margin-top: auto;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.mode-card-main-action {
  width: 100%;
  justify-content: center;
}

.mode-card-subactions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.mode-card-subaction {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--btn-secondary-border);
  background: var(--btn-secondary-bg);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 600;
  line-height: 1;
}

.mode-card-subaction:hover:not(:disabled) {
  background: var(--btn-secondary-hover);
  color: var(--text-primary);
}

.mode-card-subaction.danger {
  color: #c94f63;
  border-color: rgba(201, 79, 99, 0.24);
  background: rgba(201, 79, 99, 0.08);
}

.mode-card-subaction.danger:hover:not(:disabled) {
  background: rgba(201, 79, 99, 0.14);
  color: #b53d52;
}

@media (min-width: 1320px) {
  .functions-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 920px) {
  .functions-grid {
    grid-template-columns: 1fr;
  }

  .mode-card-header {
    grid-template-columns: 1fr;
  }

  .mode-card-header > .mode-toggle,
  .mode-card-header > .mode-status {
    justify-self: start;
  }

  .mode-details li {
    grid-template-columns: 1fr;
  }

  .mode-details .value {
    text-align: left;
  }
}

@media (min-width: 900px) {
  .device-tabs,
  .bottombar {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 6px;
  }

  .device-tabs .tab-btn,
  .bottombar .tab-btn {
    width: 100%;
    justify-content: center;
    flex: initial;
  }

  .topbar {
    align-items: center;
  }

  .topbar h1 {
    justify-self: center;
    text-align: center;
  }

  .topbar-side {
    min-width: 112px;
  }
}

.functions-grid {
  align-items: stretch;
}

.functions-grid > * {
  min-width: 0;
}

.mode-card {
  min-width: 0;
  align-content: start;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface-secondary) 68%, transparent), transparent 42%),
    var(--surface-primary);
}

.mode-card::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: color-mix(in srgb, var(--accent-primary) 55%, transparent);
  opacity: 0.9;
}

.mode-card[data-mode="acclimation"]::before {
  background: rgba(78, 163, 255, 0.95);
}

.mode-card[data-mode="clouds"]::before {
  background: rgba(138, 167, 255, 0.95);
}

.mode-card[data-mode="thunder"]::before {
  background: rgba(255, 196, 86, 0.95);
}

.mode-card[data-mode="lunar"]::before {
  background: rgba(123, 183, 255, 0.95);
}

.mode-card.unsupported::before {
  opacity: 0.35;
}

.mode-card-header {
  flex-wrap: wrap;
}

.mode-card-header > div:first-child {
  flex: 1 1 220px;
  min-width: 0;
}

.mode-card-header h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.mode-card-header p {
  margin: 4px 0 0;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.mode-card-header > div:first-child > p:not(.mode-note) {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mode-toggle {
  flex: 0 1 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0;
  border: none;
  background: transparent;
  max-width: 100%;
}

.mode-toggle input[type="checkbox"] {
  width: 40px;
  height: 20px;
  min-width: 40px;
  border-radius: 20px;
  border: 1px solid var(--surface-border);
  background: rgba(86, 98, 148, 0.35);
  position: relative;
  padding: 8px 0;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  cursor: pointer;
  transition: background var(--transition-base), border-color var(--transition-base);
}

.mode-toggle input[type="checkbox"]::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  top: 1.5px;
  left: 2px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 1px 3px rgba(17, 24, 39, 0.18);
  transition: transform var(--transition-base), background var(--transition-base);
}

.mode-toggle input[type="checkbox"]:checked {
  background: var(--accent-primary);
  border-color: color-mix(in srgb, var(--accent-primary) 70%, #ffffff 30%);
}

.mode-toggle input[type="checkbox"]:checked::after {
  transform: translateX(18px);
}

.mode-toggle input[type="checkbox"]:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-primary) 22%, transparent);
}

.mode-toggle input[type="checkbox"]:disabled {
  opacity: 0.65;
  cursor: default;
}

.mode-status {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  max-width: 100%;
  border: 1px solid rgba(255, 190, 109, 0.24);
  background: rgba(255, 190, 109, 0.12);
  color: #ffbe6d;
  overflow-wrap: anywhere;
}

.mode-details li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 12px;
}

.mode-details li + li {
  border-top: 1px dashed color-mix(in srgb, var(--surface-border) 70%, transparent);
  padding-top: 8px;
}

.mode-details .value {
  color: var(--text-primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.mode-card-actions > * {
  min-width: 0;
}

.mode-card-actions > .secondary {
  flex: 1 1 220px;
}

.mode-card-main-action {
  min-height: 38px;
}

.mode-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 30px;
}

.mode-card-meta > * {
  min-width: 0;
}

.mode-card-meta .mode-badges {
  flex: 1 1 180px;
}

.mode-card-meta .mode-card-subactions {
  margin-left: auto;
  justify-content: flex-end;
}

.mode-card-subactions {
  gap: 6px;
}

.mode-card-subaction {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 9px;
  font-size: 12px;
}

.mode-badges .badge {
  border: 1px solid color-mix(in srgb, var(--surface-border) 75%, transparent);
  background: color-mix(in srgb, var(--badge-bg) 70%, transparent);
  color: var(--text-secondary);
}

@media (max-width: 920px) {
  .mode-card-meta .mode-badges,
  .mode-card-meta .mode-card-subactions {
    flex: 1 1 100%;
    margin-left: 0;
    justify-content: flex-start;
  }
}

.dashboard-help summary,
.panel-help summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dashboard-help summary::-webkit-details-marker,
.panel-help summary::-webkit-details-marker {
  display: none;
}

.dashboard-help summary::after,
.panel-help summary::after {
  content: "▾";
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--text-muted);
  transform: rotate(-90deg);
  transition: transform var(--transition-base);
}

.dashboard-help[open] summary::after,
.panel-help[open] summary::after {
  transform: rotate(0deg);
}

@media (min-width: 900px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  }

  .topbar h1 {
    grid-column: 2;
  }

  .topbar-side {
    justify-self: start;
    min-width: 132px;
  }

  .topbar > .theme-switcher {
    justify-self: end;
  }

  .device-tabs,
  .bottombar {
    align-items: stretch;
  }

  .device-tabs .tab-btn,
  .bottombar .tab-btn {
    min-height: 38px;
  }
}

.modal-backdrop {
  place-items: start center;
  overflow: auto;
}

.modal-card {
  max-height: min(86vh, 920px);
  overflow: hidden;
}

.modal-body {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  overflow: auto;
  padding-right: 2px;
}

.modal-body > * {
  min-width: 0;
}

.modal-body > label {
  display: grid;
  gap: 6px;
}

.modal-body > label > span {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.3;
}

.modal-body > label > input,
.modal-body > label > select {
  width: 100%;
  min-width: 0;
}

.modal-body > .info-line,
.modal-body > .modal-actions {
  grid-column: 1 / -1;
}

.info-line {
  flex-wrap: wrap;
  align-items: flex-start;
}

.info-line > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.modal-actions {
  flex-wrap: wrap;
}

.modal-actions > * {
  min-width: 0;
}

.auth-page {
  padding: 28px 14px;
}

.auth-card {
  width: min(420px, 100%);
  padding: 22px;
  gap: 14px;
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
}

.auth-title {
  font-size: 22px;
}

.auth-subtitle {
  margin: 0 0 8px;
  font-size: 13px;
}

.auth-tabs {
  gap: 6px;
  padding: 4px;
}

.auth-tab {
  min-height: 36px;
  border-radius: 10px;
  font-size: 13px;
}

.auth-submit {
  min-height: 40px;
  border-radius: 10px;
  box-shadow: none;
}

.flow-monitor-panel {
  gap: 16px;
}

.flow-monitor-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.flow-monitor-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 16px;
  min-height: 420px;
}

.flow-column {
  display: grid;
  gap: 10px;
  align-content: start;
  min-width: 0;
}

.flow-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
}

.flow-filter-bar > .flow-input {
  flex: 1 1 150px;
  min-width: 0;
}

.flow-filter-bar > .flow-select {
  flex-basis: 130px;
}

.flow-filter-btn {
  flex: 0 0 auto;
  min-height: 38px;
}

.flow-filter-actions {
  display: inline-flex;
  gap: 8px;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: stretch;
}

.flow-help-panel {
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  background: var(--surface-secondary);
  overflow: hidden;
}

.flow-help-panel summary {
  cursor: pointer;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--surface-primary) 70%, transparent);
}

.flow-help-panel[open] summary {
  border-bottom: 1px solid var(--surface-border);
}

.flow-help-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
}

.flow-help-item {
  background: var(--surface-primary);
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  padding: 10px;
  min-width: 0;
}

.flow-help-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-primary);
}

.flow-help-item p {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-secondary);
}

.flow-help-item code {
  font-size: 11px;
}

.flow-input {
  min-height: 38px;
  border-radius: 10px;
  border: 1px solid var(--surface-border);
  background: var(--surface-secondary);
  color: var(--text-primary);
  padding: 0 10px;
  font-size: 13px;
}

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

.flow-select {
  padding-right: 28px;
}

.flow-column-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.flow-column-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 0;
}

.flow-muted {
  color: var(--text-muted);
  font-size: 12px;
}

.flow-event-list {
  display: grid;
  gap: 8px;
  max-height: 560px;
  overflow: auto;
  padding-right: 4px;
}

.flow-list-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.flow-error-inline {
  color: #b4233c;
}

.flow-event-item {
  display: grid;
  gap: 8px;
  text-align: left;
  background: var(--surface-secondary);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  padding: 10px 12px;
  transition: border-color var(--transition-base), background-color var(--transition-base), box-shadow var(--transition-base);
}

.flow-event-item:hover {
  border-color: var(--accent-primary);
}

.flow-event-item.active {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-primary) 35%, transparent);
  background: color-mix(in srgb, var(--surface-secondary) 80%, var(--accent-primary) 20%);
}

.flow-event-main {
  display: grid;
  gap: 4px;
}

.flow-time {
  font-size: 12px;
  color: var(--text-muted);
}

.flow-stage {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-word;
}

.flow-event-meta,
.flow-step-context {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-start;
  min-width: 0;
}

.flow-step-context > * {
  min-width: 0;
}

.flow-event-meta {
  min-width: 0;
}

.flow-event-meta .flow-chip,
.flow-step-context .flow-chip {
  max-width: 100%;
}

.flow-event-meta .flow-chip {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flow-step-context .flow-chip.mono {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.3;
  align-items: flex-start;
}

.flow-chip {
  min-width: 0;
}

.flow-json-block pre {
  white-space: pre-wrap;
  word-break: break-word;
}

.flow-trace-step {
  min-width: 0;
}

.flow-trace-step > * {
  min-width: 0;
}

.flow-event-item {
  min-width: 0;
}

.flow-event-item > * {
  min-width: 0;
}

.flow-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid var(--surface-border);
  background: var(--surface-primary);
  color: var(--text-secondary);
}

.flow-badge.direction {
  color: var(--text-primary);
}

.flow-badge.status-received {
  background: color-mix(in srgb, var(--surface-primary) 70%, #ffe08a 30%);
}

.flow-badge.status-parsed,
.flow-badge.status-processed {
  background: color-mix(in srgb, var(--surface-primary) 70%, #9fd4ff 30%);
}

.flow-badge.status-stored,
.flow-badge.status-forwarded,
.flow-badge.status-accepted {
  background: color-mix(in srgb, var(--surface-primary) 70%, #9ce3bf 30%);
}

.flow-badge.status-error {
  background: color-mix(in srgb, var(--surface-primary) 65%, #ffb7c2 35%);
}

.flow-badge.status-skipped {
  background: color-mix(in srgb, var(--surface-primary) 70%, #d5d9e5 30%);
}

.flow-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--surface-primary);
  border: 1px solid var(--surface-border);
}

.flow-chip.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.flow-trace-column {
  border-left: 1px solid color-mix(in srgb, var(--surface-border) 80%, transparent);
  padding-left: 12px;
}

.flow-trace-head {
  align-items: flex-start;
}

.flow-trace-id {
  max-width: 100%;
  word-break: break-all;
}

.flow-trace-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
  max-height: 560px;
  overflow: auto;
  padding-right: 4px;
}

.flow-trace-step {
  display: grid;
  gap: 8px;
  background: var(--surface-secondary);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  padding: 12px;
}

.flow-step-head {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.flow-step-stage {
  font-weight: 700;
  color: var(--text-primary);
  word-break: break-word;
}

.flow-json-block {
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  background: var(--surface-primary);
  overflow: hidden;
}

.flow-json-block summary {
  cursor: pointer;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.flow-json-block pre {
  margin: 0;
  padding: 10px;
  max-height: 220px;
  overflow: auto;
  font-size: 11px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--surface-secondary) 70%, transparent);
  border-top: 1px solid var(--surface-border);
}

@media (max-width: 1180px) {
  .schedule-layout {
    grid-template-columns: 1fr;
  }

  .flow-monitor-layout {
    grid-template-columns: 1fr;
  }

  .flow-filter-bar {
    align-items: stretch;
  }

  .flow-help-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-help-grid {
    grid-template-columns: 1fr;
  }

  .panel-help-grid {
    grid-template-columns: 1fr;
  }

  .flow-trace-column {
    border-left: 0;
    border-top: 1px solid color-mix(in srgb, var(--surface-border) 80%, transparent);
    padding-left: 0;
    padding-top: 12px;
  }
}

@media (max-width: 960px) {
  .app-shell {
    padding: 18px 12px 28px;
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .topbar h1 {
    justify-self: stretch;
    text-align: left;
    order: 0;
  }

  .topbar-side {
    order: -1;
  }

  .topbar > .theme-switcher {
    justify-self: start;
  }

  .device-card__footer {
    flex-direction: column;
    align-items: stretch;
  }

  .device-card__footer > .secondary {
    flex: 1 1 auto;
  }

  .device-card__grouptoggles {
    grid-template-columns: 1fr;
  }

  .device-card__dangerzone {
    justify-content: stretch;
  }

  .device-card__dangerzone .button-ghost {
    width: 100%;
  }

  .device-filters__stats {
    justify-content: flex-start;
  }

  .device-list-summary,
  .device-list-section {
    padding: 10px;
  }

  .device-list-section__head h3 {
    font-size: 13px;
  }

  .functions-grid {
    grid-template-columns: 1fr;
  }

  .modal-body {
    grid-template-columns: 1fr;
  }

  .topology-form-grid {
    grid-template-columns: 1fr;
  }

  .topology-panel__head-badges {
    justify-content: flex-start;
  }

  .topology-ip-row {
    grid-template-columns: 1fr;
  }

  .add-device-grid {
    grid-template-columns: 1fr;
  }

  .auth-theme-switcher {
    top: 20px;
    right: 20px;
  }
}

@media (max-width: 640px) {
  .dashboard {
    gap: 12px;
  }

  .panel,
  .card,
  .graph-layout {
    padding: 12px;
  }

  .form-row {
    flex-direction: column;
  }

  .graph-controls {
    align-items: stretch;
  }

  .graph-controls .control-group {
    flex: 1 1 100%;
  }

  .onboarding-meta-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .flow-filter-actions {
    flex: 1 1 100%;
  }

  .flow-filter-actions > .flow-filter-btn {
    flex: 1 1 120px;
  }

  .graph-layout .shared-actions .time-field {
    flex-basis: 100%;
  }

  .graph-layout .advanced-row {
    justify-content: flex-start;
  }

  .graph-layout .zoom-controls {
    flex-wrap: wrap;
  }

  .graph-layout .zoom-controls button {
    width: 36px;
    height: 36px;
  }

  .mode-card-actions > .secondary {
    flex-basis: 100%;
  }

  .mode-card-actions > .link {
    min-height: 34px;
    padding: 0 8px;
    border-radius: 8px;
  }

  .ack-history li {
    grid-template-columns: 12px 1fr;
    align-items: start;
  }

  .ack-history .time {
    grid-column: 2;
  }

  .ack-history .message {
    grid-column: 1 / -1;
    padding-left: 24px;
  }

  .modal-card {
    width: min(560px, 100%);
    padding: 16px;
    gap: 14px;
  }

  .modal-body {
    gap: 12px;
  }

  .modal-actions > .secondary,
  .modal-actions > .primary {
    flex: 1 1 140px;
  }

  .device-grid {
    grid-template-columns: 1fr;
  }

  .toast {
    left: 16px;
    right: 16px;
    bottom: 24px;
  }

  .auth-card {
    padding: 16px;
  }
}

/* Dashboard visual polish: stronger structure for topbar and navigation sections */
.topbar {
  grid-template-columns: minmax(0, 1fr) minmax(0, 2.4fr) minmax(0, 1fr);
  align-items: center;
}

.topbar-side {
  justify-self: start;
  display: inline-flex;
  align-items: center;
}

.topbar-actions {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.topbar-actions > .theme-switcher {
  margin-left: auto;
}

.topbar-title {
  min-width: 0;
  display: grid;
  gap: 2px;
  justify-items: center;
  text-align: center;
  padding-inline: 8px;
}

.topbar-title__meta {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.topbar .topbar-title h1 {
  margin: 0;
  justify-self: center;
  text-align: center;
  line-height: 1.2;
}

.topbar-title__subtitle {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-muted);
  max-width: 560px;
}

.dashboard-nav-panel {
  width: 100%;
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--surface-border);
  background: color-mix(in srgb, var(--surface-secondary) 62%, transparent);
}

.dashboard-nav-panel--device {
  margin-bottom: 2px;
}

.dashboard-nav-panel--bottom {
  width: min(100%, 760px);
  justify-self: center;
  position: sticky;
  bottom: 14px;
  z-index: 8;
  box-shadow: var(--shadow-sm);
}

.dashboard-nav-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.dashboard-nav-panel__head > * {
  min-width: 0;
}

.dashboard-nav-panel__head h3 {
  margin: 0;
  font-size: 12px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.dashboard-nav-panel__head p {
  margin: 3px 0 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-muted);
  max-width: 560px;
}

.dashboard-nav-panel__head--compact p {
  display: none;
}

.dashboard-nav-panel .device-tabs,
.dashboard-nav-panel .bottombar {
  width: 100%;
  margin: 0;
  justify-self: stretch;
  border: 1px solid color-mix(in srgb, var(--surface-border) 92%, transparent);
  background: color-mix(in srgb, var(--surface-primary) 70%, transparent);
}

.dashboard-nav-panel .tab-btn {
  min-height: 38px;
}

.dashboard-nav-panel .bottombar .tab-btn {
  font-weight: 700;
}

.dashboard-content.device-content {
  gap: 12px;
}

.device-list-panel > .panel-header {
  padding-bottom: 10px;
  border-bottom: 1px solid color-mix(in srgb, var(--surface-border) 80%, transparent);
}

.device-list-panel .panel-help {
  margin-top: -2px;
}

.device-filters .group-toolbar {
  padding: 4px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--surface-border-soft) 92%, transparent);
  background: color-mix(in srgb, var(--surface-primary) 48%, transparent);
}

.device-list-section__head {
  padding-bottom: 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--surface-border-soft) 88%, transparent);
}

.device-list-section__head p {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.device-card__chips {
  gap: 6px;
}

.device-card__footer > .secondary {
  min-width: 150px;
}

@media (max-width: 960px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .topbar-side,
  .topbar-actions {
    justify-self: stretch;
  }

  .topbar-actions {
    order: 1;
  }

  .topbar-actions > .theme-switcher {
    margin-left: 0;
  }

  .topbar-title {
    justify-items: start;
    text-align: left;
    order: 0;
    padding-inline: 0;
  }

  .topbar .topbar-title h1 {
    justify-self: start;
    text-align: left;
  }

  .topbar-title__subtitle {
    max-width: 100%;
  }

  .dashboard-nav-panel {
    padding: 10px;
  }

  .dashboard-nav-panel--bottom {
    width: 100%;
    bottom: 10px;
  }

  .dashboard-nav-panel__head p {
    max-width: 100%;
  }
}

@media (max-width: 640px) {
  .topbar-title__subtitle,
  .dashboard-nav-panel__head p {
    display: none;
  }

  .dashboard-nav-panel__head {
    align-items: center;
  }

  .dashboard-nav-panel {
    gap: 6px;
    padding: 8px;
  }

  .dashboard-nav-panel .tab-btn {
    min-height: 36px;
  }
}

/* Theme switcher and navigation polish */
.topbar-actions > .theme-switcher {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--surface-border) 92%, transparent);
  background: color-mix(in srgb, var(--surface-primary) 78%, transparent);
}

.topbar-actions .theme-pill {
  width: auto;
  min-width: 0;
  height: 32px;
  padding: 0 10px 0 8px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.topbar-actions .theme-pill:hover {
  background: color-mix(in srgb, var(--surface-secondary) 80%, transparent);
  border-color: color-mix(in srgb, var(--surface-border-soft) 94%, transparent);
  transform: translateY(-1px);
}

.topbar-actions .theme-pill.active {
  background: color-mix(in srgb, var(--accent-primary-soft) 34%, var(--surface-secondary));
  border-color: color-mix(in srgb, var(--accent-primary) 32%, var(--surface-border));
  color: var(--text-primary);
  box-shadow: none;
}

.topbar-actions .theme-pill:focus-visible {
  outline: none;
  box-shadow: var(--accent-glow);
}

.theme-pill__swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  flex: 0 0 auto;
}

.theme-pill--light .theme-pill__swatch {
  background: linear-gradient(180deg, #ffffff, #e9eefc);
  border-color: rgba(194, 204, 236, 0.95);
}

.theme-pill--silver .theme-pill__swatch {
  background: linear-gradient(180deg, #e8ebf4, #bcc5df);
  border-color: rgba(161, 171, 205, 0.9);
}

.theme-pill--dark .theme-pill__swatch {
  background: linear-gradient(180deg, #1b2031, #090c15);
  border-color: rgba(112, 124, 170, 0.62);
}

.theme-pill__text {
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.topbar-actions .theme-pill.cycle {
  padding-inline: 8px 10px;
  border-color: color-mix(in srgb, var(--surface-border-soft) 92%, transparent);
  background: color-mix(in srgb, var(--surface-secondary) 72%, transparent);
}

.topbar-actions .theme-pill.cycle > [aria-hidden="true"] {
  font-size: 13px;
  line-height: 1;
}

.topbar-actions .theme-pill.cycle .theme-pill__text {
  color: var(--text-muted);
}

.dashboard-nav-panel__head-badges {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.dashboard-nav-panel .tab-btn {
  position: relative;
  border-width: 1px;
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);
}

.dashboard-nav-panel .tab-btn:hover {
  background: color-mix(in srgb, var(--surface-secondary) 78%, transparent);
  border-color: color-mix(in srgb, var(--surface-border-soft) 94%, transparent);
  color: var(--text-primary);
}

.dashboard-nav-panel .tab-btn:focus-visible {
  outline: none;
  box-shadow: var(--accent-glow);
}

.dashboard-nav-panel .tab-btn.active {
  background: color-mix(in srgb, var(--accent-primary-soft) 34%, var(--surface-secondary));
  border-color: color-mix(in srgb, var(--accent-primary) 32%, var(--surface-border));
  color: var(--text-primary);
}

.dashboard-nav-panel .tab-btn.active::before {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  top: 5px;
  height: 2px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-primary) 90%, #ffffff 10%);
}

.topbar .link {
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 0 10px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.topbar .link:hover {
  border-color: color-mix(in srgb, var(--surface-border-soft) 94%, transparent);
  background: color-mix(in srgb, var(--surface-secondary) 78%, transparent);
}

.topbar .link:focus-visible {
  outline: none;
  box-shadow: var(--accent-glow);
}

.dashboard-help,
.panel-help {
  border-radius: 14px;
}

.dashboard-help summary,
.panel-help summary {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.dashboard-help[open] summary,
.panel-help[open] summary {
  border-bottom-color: color-mix(in srgb, var(--surface-border-soft) 84%, transparent);
}

@media (max-width: 960px) {
  .topbar-actions > .theme-switcher {
    width: 100%;
    justify-content: flex-start;
  }

  .dashboard-nav-panel__head-badges {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  .topbar-actions .theme-pill {
    padding-inline: 8px;
  }

  .topbar-actions .theme-pill .theme-pill__text:not(.theme-pill__text--cycle) {
    display: none;
  }

  .topbar-actions .theme-pill__text--cycle {
    display: none;
  }

  .topbar-actions .theme-pill.cycle {
    padding-inline: 8px;
    min-width: 32px;
    justify-content: center;
  }

  .dashboard-nav-panel__head-badges {
    width: 100%;
  }
}

/* Auth page compact variant for updated ThemeSwitcher */
.auth-theme-switcher.theme-switcher {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--surface-border) 90%, transparent);
  background: color-mix(in srgb, var(--surface-primary) 74%, transparent);
  box-shadow: var(--shadow-sm);
}

.auth-theme-switcher .theme-pill {
  width: 30px;
  height: 30px;
  min-width: 30px;
  padding: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.auth-theme-switcher .theme-pill__text {
  display: none;
}

.auth-theme-switcher .theme-pill__swatch {
  width: 12px;
  height: 12px;
}

.auth-theme-switcher .theme-pill.cycle {
  min-width: 30px;
  width: 30px;
}

/* Device list view modes (cards / list) */
.device-list-section__controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.device-list-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 2px 0 0;
  border: 0;
  background: transparent;
}

.device-list-tools__left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1 1 520px;
  min-width: 0;
}

.device-list-tools__left > .device-list-section__controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1 1 420px;
  min-width: 0;
  justify-content: flex-start;
}

.device-list-tool {
  display: grid;
  gap: 0;
  min-width: 0;
}

.device-list-tool--search {
  flex: 1 1 240px;
}

.device-list-tool--sort {
  flex: 0 1 170px;
}

.device-list-tool__label {
  display: none;
}

.device-list-search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 2px 4px 2px 10px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--surface-border-soft) 94%, transparent);
  background: color-mix(in srgb, var(--surface-secondary) 74%, transparent);
}

.device-list-search:focus-within {
  border-color: color-mix(in srgb, var(--input-focus) 80%, var(--surface-border));
  box-shadow: var(--input-focus-ring);
}

.device-list-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  line-height: 1.2;
}

.device-list-search input::placeholder {
  color: var(--input-placeholder);
}

.device-list-search__clear {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.device-list-search__clear:hover {
  background: color-mix(in srgb, var(--surface-primary) 70%, transparent);
  border-color: color-mix(in srgb, var(--surface-border-soft) 94%, transparent);
  color: var(--text-primary);
}

.device-list-tool select {
  min-height: 32px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--surface-border-soft) 94%, transparent);
  background: color-mix(in srgb, var(--surface-secondary) 74%, transparent);
  color: var(--text-primary);
  padding: 0 30px 0 10px;
  font: inherit;
  font-size: 12px;
}

.device-list-tool select:focus-visible {
  outline: none;
  border-color: color-mix(in srgb, var(--input-focus) 80%, var(--surface-border));
  box-shadow: var(--input-focus-ring);
}

.device-list-quickfilters {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.device-list-quickfilters__btn {
  min-height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--surface-border-soft) 92%, transparent);
  background: color-mix(in srgb, var(--surface-secondary) 74%, transparent);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.device-list-quickfilters__btn:hover {
  color: var(--text-primary);
  border-color: color-mix(in srgb, var(--surface-border) 92%, transparent);
  background: color-mix(in srgb, var(--surface-primary) 64%, transparent);
}

.device-list-quickfilters__btn.active {
  color: var(--text-primary);
  border-color: color-mix(in srgb, var(--accent-primary) 28%, var(--surface-border));
  background: color-mix(in srgb, var(--accent-primary-soft) 28%, var(--surface-secondary));
}

.device-list-quickfilters__btn:focus-visible {
  outline: none;
  box-shadow: var(--accent-glow);
}

.device-list-quickfilters__count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--surface-border-soft) 92%, transparent);
  background: color-mix(in srgb, var(--surface-primary) 66%, transparent);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.device-list-quickfilters__btn.active .device-list-quickfilters__count {
  color: var(--text-primary);
  border-color: color-mix(in srgb, var(--accent-primary) 18%, var(--surface-border-soft));
  background: color-mix(in srgb, var(--surface-secondary) 82%, transparent);
}

.device-list-section__controls-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--surface-border-soft) 94%, transparent);
  background: color-mix(in srgb, var(--surface-primary) 54%, transparent);
}

.view-toggle__btn {
  min-height: 28px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.view-toggle__btn:hover {
  color: var(--text-primary);
  background: color-mix(in srgb, var(--surface-secondary) 82%, transparent);
  border-color: color-mix(in srgb, var(--surface-border-soft) 94%, transparent);
}

.view-toggle__btn.active {
  color: var(--text-primary);
  background: color-mix(in srgb, var(--accent-primary-soft) 30%, var(--surface-secondary));
  border-color: color-mix(in srgb, var(--accent-primary) 30%, var(--surface-border));
}

.view-toggle__btn:focus-visible {
  outline: none;
  box-shadow: var(--accent-glow);
}

.device-card__main {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.device-grid--list {
  grid-template-columns: 1fr;
  gap: 10px;
}

.device-card--list {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  column-gap: 12px;
  row-gap: 10px;
  padding: 12px;
}

.device-card--list .device-card__main {
  gap: 10px;
}

.device-card--list .device-card__header {
  padding-bottom: 6px;
  margin-bottom: 0;
}

.device-card--list .device-card__header h3 {
  font-size: 15px;
}

.device-card--list .device-card__header p {
  font-size: 12px;
}

.device-card--list .device-card__groups {
  padding: 8px;
  gap: 6px;
}

.device-card--list .device-card__groupchips {
  gap: 4px;
}

.device-card--list .device-card__groupchips .chip {
  min-height: 22px;
  padding: 0 8px;
  font-size: 11px;
}

.device-card--list .device-card__footer {
  width: 170px;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border-top: none;
  align-self: start;
}

.device-card--list .device-card__footer > .primary,
.device-card--list .device-card__footer > .secondary {
  width: 100%;
  min-width: 0;
  flex: 1 1 auto;
}

.device-card--list .device-card__editpanel {
  grid-column: 1 / -1;
}

@media (max-width: 960px) {
  .device-list-section__controls {
    justify-content: flex-start;
    width: 100%;
  }

  .device-list-tools {
    align-items: stretch;
    padding-top: 6px;
  }

  .device-list-tools__left {
    flex: 1 1 100%;
    align-items: stretch;
  }

  .device-list-tools__left > .device-list-section__controls {
    flex: 1 1 100%;
    align-items: stretch;
  }

  .device-list-tool--search {
    flex: 1 1 100%;
  }

  .device-list-tool--sort {
    flex: 1 1 220px;
  }

  .device-list-section__controls--view {
    justify-content: flex-start;
  }

  .device-card--list {
    grid-template-columns: 1fr;
  }

  .device-card--list .device-card__footer {
    width: 100%;
    grid-template-columns: 1fr 1fr;
    align-self: stretch;
  }
}

@media (max-width: 640px) {
  .device-list-section__head {
    gap: 8px;
  }

  .device-list-section__controls {
    width: 100%;
  }

  .device-list-tools {
    padding-top: 6px;
    gap: 8px;
  }

  .device-list-quickfilters {
    width: 100%;
  }

  .device-list-quickfilters__btn {
    flex: 1 1 110px;
    justify-content: center;
  }

  .view-toggle {
    width: 100%;
  }

  .view-toggle__btn {
    flex: 1 1 0;
    justify-content: center;
    display: inline-flex;
    align-items: center;
  }

  .device-card--list .device-card__footer {
    grid-template-columns: 1fr;
  }
}

/* Device list row compaction + stronger text contrast (light themes) */
.device-card--list .device-card__main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

.device-card--list .device-card__header {
  flex: 1 1 100%;
}

.device-card--list .device-card__chips {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 0;
  flex: 0 1 auto;
}

.device-card--list .device-card__chips--list-inline {
  flex: 1 1 auto;
  min-width: 0;
  gap: 6px;
}

.device-card--list .device-card__chips--list-inline .chip {
  max-width: 100%;
}

.device-card--list .device-card__chips--list-inline .muted.small {
  margin-left: 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.device-card--list .device-card__groups {
  flex: 1 1 260px;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: transparent;
}

.device-card--list .device-card__groups .device-card__section-head {
  display: none;
}

.device-card--list .device-card__groupchips {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.device-card--list .device-card__groupchips .muted.small {
  font-size: 12px;
}

body.theme-light,
body.theme-silver {
  --text-secondary: rgba(24, 31, 46, 0.96);
  --text-muted: rgba(44, 53, 75, 0.84);
  --input-placeholder: rgba(86, 98, 128, 0.82);
  --badge-text: rgba(28, 36, 52, 0.9);
  --chip-text: rgba(28, 36, 52, 0.92);
}

body.theme-light .panel-header p,
body.theme-light .topbar-title__subtitle,
body.theme-light .dashboard-nav-panel__head p,
body.theme-light .device-list-section__head p,
body.theme-light .panel-help-item p,
body.theme-light .dashboard-help-item p,
body.theme-silver .panel-header p,
body.theme-silver .topbar-title__subtitle,
body.theme-silver .dashboard-nav-panel__head p,
body.theme-silver .device-list-section__head p,
body.theme-silver .panel-help-item p,
body.theme-silver .dashboard-help-item p {
  color: color-mix(in srgb, var(--text-secondary) 88%, var(--text-primary));
}

body.theme-light .muted,
body.theme-silver .muted {
  color: color-mix(in srgb, var(--text-muted) 92%, var(--text-primary));
}

body.theme-light .topbar-title__meta,
body.theme-silver .topbar-title__meta,
body.theme-light .device-list-section__meta,
body.theme-silver .device-list-section__meta,
body.theme-light .device-list-tool__label,
body.theme-silver .device-list-tool__label {
  color: color-mix(in srgb, var(--text-secondary) 84%, var(--text-primary));
  font-weight: 700;
}

body.theme-light .device-list-search input::placeholder,
body.theme-silver .device-list-search input::placeholder {
  color: var(--input-placeholder);
  opacity: 1;
}

body.theme-light .chip.chip--muted,
body.theme-silver .chip.chip--muted {
  color: color-mix(in srgb, var(--text-muted) 88%, var(--text-primary));
}

body.theme-light .device-card__header p.muted,
body.theme-silver .device-card__header p.muted {
  color: color-mix(in srgb, var(--text-secondary) 80%, var(--text-primary));
}

@media (max-width: 960px) {
  .device-card--list .device-card__main {
    gap: 8px;
  }

  .device-card--list .device-card__groups {
    flex: 1 1 100%;
  }
}

/* Device edit panel polish (list mode) */
.device-card--list .device-card__editpanel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px 12px;
}

.device-card--list .device-card__editpanel > .device-card__section-head,
.device-card--list .device-card__editpanel > .device-card__note {
  grid-column: 1 / -1;
}

.device-card--list .device-card__grouptoggles {
  grid-column: 1 / 2;
  grid-template-columns: 1fr;
  align-content: start;
  gap: 8px;
  min-width: 0;
}

.device-card--list .device-card__dangerzone {
  grid-column: 2 / 3;
  align-self: end;
  justify-content: flex-end;
}

.device-card--list .device-card__dangerzone .button-ghost {
  min-width: 148px;
  white-space: nowrap;
}

.device-card--list .device-card__footer {
  grid-column: 1 / -1;
  width: 100%;
  grid-template-columns: minmax(0, 1fr) minmax(0, 180px);
  align-self: stretch;
}

.group-toggle {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--surface-border-soft);
  background: color-mix(in srgb, var(--surface-primary) 72%, transparent);
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    border-color var(--transition-base),
    background-color var(--transition-base),
    box-shadow var(--transition-base);
}

.group-toggle:hover {
  border-color: color-mix(in srgb, var(--accent-primary) 24%, var(--surface-border));
  background: color-mix(in srgb, var(--surface-primary) 84%, transparent);
}

.group-toggle:has(input[type="checkbox"]:checked) {
  border-color: color-mix(in srgb, var(--accent-primary) 34%, var(--surface-border));
  background: color-mix(in srgb, var(--accent-primary-soft) 14%, var(--surface-primary));
}

.group-toggle input[type="checkbox"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  margin: 0;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--surface-border) 90%, transparent);
  background: color-mix(in srgb, var(--surface-primary) 94%, var(--surface-muted));
  position: relative;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  transition:
    border-color var(--transition-base),
    background-color var(--transition-base),
    box-shadow var(--transition-base);
}

.group-toggle input[type="checkbox"]::after {
  content: "";
  width: 8px;
  height: 4px;
  border: 2px solid var(--text-contrast);
  border-top: 0;
  border-right: 0;
  transform: translateY(-1px) rotate(-45deg) scale(0);
  transform-origin: center;
  transition: transform var(--transition-base);
}

.group-toggle input[type="checkbox"]:checked {
  border-color: color-mix(in srgb, var(--accent-primary) 92%, black 4%);
  background: var(--accent-primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-primary-soft) 45%, transparent);
}

.group-toggle input[type="checkbox"]:checked::after {
  transform: translateY(-1px) rotate(-45deg) scale(1);
}

.group-toggle input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--surface-primary) 92%, transparent),
    0 0 0 5px color-mix(in srgb, var(--accent-primary-soft) 70%, transparent);
}

.group-toggle input[type="checkbox"]:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.group-toggle input[type="checkbox"]:disabled + span {
  opacity: 0.75;
}

.group-toggle span {
  font-size: 13px;
  font-weight: 600;
  color: inherit;
  line-height: 1.2;
}

@media (max-width: 960px) {
  .device-card--list .device-card__editpanel {
    grid-template-columns: 1fr;
  }

  .device-card--list .device-card__grouptoggles,
  .device-card--list .device-card__dangerzone {
    grid-column: 1 / -1;
  }

  .device-card--list .device-card__dangerzone {
    justify-content: flex-start;
  }

  .device-card--list .device-card__dangerzone .button-ghost {
    min-width: 0;
  }

  .device-card--list .device-card__footer {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .device-card--list .device-card__footer {
    grid-template-columns: 1fr;
  }
}
