:root {
  /* ==========================================================================
     MATERIAL DESIGN 3 — SYSTEM TOKENS (Dark Tonal Palette)
     ========================================================================== */

  /* ── M3 Surface & Background Roles ── */
  --md-sys-color-background: #0E141B;
  --md-sys-color-on-background: #E1E8F0;
  --md-sys-color-surface: #0E141B;
  --md-sys-color-surface-dim: #0B1016;
  --md-sys-color-surface-bright: #333B46;
  --md-sys-color-surface-container-lowest: #090D12;
  --md-sys-color-surface-container-low: #161D26;
  --md-sys-color-surface-container: #1A222C;
  --md-sys-color-surface-container-high: #242D3A;
  --md-sys-color-surface-container-highest: #2F3948;
  --md-sys-color-on-surface: #E2E8F0;
  --md-sys-color-on-surface-variant: #94A3B8;

  /* ── M3 Outline Roles ── */
  --md-sys-color-outline: #64748B;
  --md-sys-color-outline-variant: #2A3647;

  /* ── M3 Primary Roles (Warm Amber Gold) ── */
  --md-sys-color-primary: #F5C438;
  --md-sys-color-on-primary: #261900;
  --md-sys-color-primary-container: #584400;
  --md-sys-color-on-primary-container: #FFE08B;

  /* ── M3 Secondary Roles (Slate Tonal) ── */
  --md-sys-color-secondary: #BCC7DC;
  --md-sys-color-on-secondary: #263141;
  --md-sys-color-secondary-container: #283548;
  --md-sys-color-on-secondary-container: #D8E3F8;

  /* ── M3 Tertiary Roles (Sky Cyan) ── */
  --md-sys-color-tertiary: #67D4FF;
  --md-sys-color-on-tertiary: #003547;
  --md-sys-color-tertiary-container: #004D65;
  --md-sys-color-on-tertiary-container: #BFE9FF;

  /* ── M3 Semantic Status Roles (Error / Success / Warning) ── */
  --md-sys-color-error: #F87171;
  --md-sys-color-on-error: #450A0A;
  --md-sys-color-error-container: #4C141B;
  --md-sys-color-on-error-container: #FECACA;

  --md-sys-color-success: #34D399;
  --md-sys-color-on-success: #022C22;
  --md-sys-color-success-container: #0F392B;
  --md-sys-color-on-success-container: #A7F3D0;

  --md-sys-color-warning: #FBBF24;
  --md-sys-color-on-warning: #3B2500;
  --md-sys-color-warning-container: #452B06;
  --md-sys-color-on-warning-container: #FDE68A;

  /* ── M3 Shape Scale ── */
  --md-sys-shape-corner-none: 0px;
  --md-sys-shape-corner-extra-small: 4px;
  --md-sys-shape-corner-small: 8px;
  --md-sys-shape-corner-medium: 12px;
  --md-sys-shape-corner-large: 16px;
  --md-sys-shape-corner-extra-large: 28px;
  --md-sys-shape-corner-full: 9999px;

  /* ── M3 Elevation (Tonal + Subtle Ambient Shadow) ── */
  --md-sys-elevation-level0: none;
  --md-sys-elevation-level1: 0 1px 3px rgba(0, 0, 0, 0.28), 0 1px 2px rgba(0, 0, 0, 0.18);
  --md-sys-elevation-level2: 0 4px 10px rgba(0, 0, 0, 0.32), 0 1px 3px rgba(0, 0, 0, 0.2);
  --md-sys-elevation-level3: 0 8px 20px rgba(0, 0, 0, 0.38), 0 2px 6px rgba(0, 0, 0, 0.22);
  --md-sys-elevation-level4: 0 14px 28px rgba(0, 0, 0, 0.44), 0 4px 10px rgba(0, 0, 0, 0.26);
  --md-sys-elevation-level5: 0 20px 40px rgba(0, 0, 0, 0.52), 0 6px 14px rgba(0, 0, 0, 0.3);

  /* ── M3 Motion & State Layers ── */
  --md-sys-motion-easing-standard: cubic-bezier(0.2, 0, 0, 1);
  --md-sys-motion-duration-short: 160ms;
  --md-sys-motion-duration-medium: 240ms;
  --md-sys-state-hover-opacity: 0.08;
  --md-sys-state-focus-opacity: 0.12;
  --md-sys-state-pressed-opacity: 0.12;

  /* ── Legacy Token Aliases (Mapped to M3 System Roles for 100% Compatibility) ── */
  --navy-dark: var(--md-sys-color-surface);
  --navy-medium: var(--md-sys-color-surface-container-low);
  --navy-light: var(--md-sys-color-surface-container-high);
  --navy-border: var(--md-sys-color-outline-variant);
  --navy-border-hover: var(--md-sys-color-outline);

  --accent-orange: var(--md-sys-color-primary);
  --accent-orange-hover: #FFD15C;
  --accent-cyan: var(--md-sys-color-tertiary);

  --text-light: var(--md-sys-color-on-surface);
  --text-gray: var(--md-sys-color-on-surface-variant);
  --text-muted: #64748B;

  --alert-red: var(--md-sys-color-error);
  --success-green: var(--md-sys-color-success);
  --warning-yellow: var(--md-sys-color-warning);

  --card-shadow: var(--md-sys-elevation-level1);
  --card-shadow-hover: var(--md-sys-elevation-level2);
}

:root[data-theme="light"], [data-theme="light"], body.theme-light {
  /* ==========================================================================
     MATERIAL DESIGN 3 — SYSTEM TOKENS (Light Tonal Palette)
     ========================================================================== */

  /* ── M3 Surface & Background Roles ── */
  --md-sys-color-background: #F8FAFC;
  --md-sys-color-on-background: #0F172A;
  --md-sys-color-surface: #FFFFFF;
  --md-sys-color-surface-dim: #F1F5F9;
  --md-sys-color-surface-bright: #FFFFFF;
  --md-sys-color-surface-container-lowest: #FFFFFF;
  --md-sys-color-surface-container-low: #F8FAFC;
  --md-sys-color-surface-container: #F1F5F9;
  --md-sys-color-surface-container-high: #E2E8F0;
  --md-sys-color-surface-container-highest: #CBD5E1;
  --md-sys-color-on-surface: #0F172A;
  --md-sys-color-on-surface-variant: #475569;

  /* ── M3 Outline Roles ── */
  --md-sys-color-outline: #94A3B8;
  --md-sys-color-outline-variant: #E2E8F0;

  /* ── M3 Primary Roles (Warm Amber Gold with high contrast) ── */
  --md-sys-color-primary: #D97706;
  --md-sys-color-on-primary: #FFFFFF;
  --md-sys-color-primary-container: #FEF3C7;
  --md-sys-color-on-primary-container: #78350F;

  /* ── M3 Secondary Roles (Slate Tonal) ── */
  --md-sys-color-secondary: #475569;
  --md-sys-color-on-secondary: #FFFFFF;
  --md-sys-color-secondary-container: #E2E8F0;
  --md-sys-color-on-secondary-container: #1E293B;

  /* ── M3 Tertiary Roles (Sky Cyan / Blue) ── */
  --md-sys-color-tertiary: #0284C7;
  --md-sys-color-on-tertiary: #FFFFFF;
  --md-sys-color-tertiary-container: #E0F2FE;
  --md-sys-color-on-tertiary-container: #0369A1;

  /* ── M3 Semantic Status Roles (Error / Success / Warning) ── */
  --md-sys-color-error: #DC2626;
  --md-sys-color-on-error: #FFFFFF;
  --md-sys-color-error-container: #FEE2E2;
  --md-sys-color-on-error-container: #991B1B;

  --md-sys-color-success: #16A34A;
  --md-sys-color-on-success: #FFFFFF;
  --md-sys-color-success-container: #DCFCE7;
  --md-sys-color-on-success-container: #166534;

  --md-sys-color-warning: #D97706;
  --md-sys-color-on-warning: #FFFFFF;
  --md-sys-color-warning-container: #FEF3C7;
  --md-sys-color-on-warning-container: #92400E;

  /* ── M3 Elevation for Light Theme ── */
  --md-sys-elevation-level1: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --md-sys-elevation-level2: 0 4px 10px rgba(15, 23, 42, 0.10), 0 1px 3px rgba(15, 23, 42, 0.05);
  --md-sys-elevation-level3: 0 8px 20px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.06);
  --md-sys-elevation-level4: 0 14px 28px rgba(15, 23, 42, 0.14), 0 4px 10px rgba(15, 23, 42, 0.08);
  --md-sys-elevation-level5: 0 20px 40px rgba(15, 23, 42, 0.18), 0 6px 14px rgba(15, 23, 42, 0.10);

  /* ── Legacy Token Aliases Mapped to M3 Light Roles ── */
  --navy-dark: var(--md-sys-color-surface);
  --navy-medium: var(--md-sys-color-surface-container);
  --navy-light: var(--md-sys-color-surface-container-high);
  --navy-border: var(--md-sys-color-outline-variant);
  --navy-border-hover: var(--md-sys-color-outline);

  --accent-orange: var(--md-sys-color-primary);
  --accent-orange-hover: #B45309;
  --accent-cyan: var(--md-sys-color-tertiary);

  --text-light: var(--md-sys-color-on-surface);
  --text-gray: var(--md-sys-color-on-surface-variant);
  --text-muted: #64748B;

  --alert-red: var(--md-sys-color-error);
  --success-green: var(--md-sys-color-success);
  --warning-yellow: var(--md-sys-color-warning);
}

/* ── Light Theme Element Refinements ── */
[data-theme="light"] .card,
[data-theme="light"] .modal-card,
[data-theme="light"] .sidebar-card {
  background: #FFFFFF;
  border-color: #E2E8F0;
  box-shadow: var(--md-sys-elevation-level1);
}

[data-theme="light"] .device-card {
  background: #FFFFFF;
  border-color: #E2E8F0;
  box-shadow: var(--md-sys-elevation-level1);
}

[data-theme="light"] .device-card:hover {
  background: #F8FAFC;
  border-color: #CBD5E1;
}

[data-theme="light"] .device-card.selected {
  border-color: var(--md-sys-color-primary);
  background: #FEF3C7;
}

[data-theme="light"] .sidebar {
  background: #FFFFFF !important;
  border-left-color: #E2E8F0 !important;
}

[data-theme="light"] .sidebar-header {
  background: #FFFFFF;
  border-bottom-color: #E2E8F0;
}

[data-theme="light"] .sidebar-tabs {
  background: #F8FAFC;
  border-bottom-color: #E2E8F0;
}

[data-theme="light"] .sidebar-footer {
  background: #FFFFFF;
  border-top-color: #E2E8F0;
}

[data-theme="light"] .header-actions {
  background: #FFFFFF;
  border-color: #E2E8F0;
}

[data-theme="light"] input,
[data-theme="light"] select,
[data-theme="light"] textarea {
  background-color: #FFFFFF !important;
  color: #0F172A !important;
  border-color: #CBD5E1 !important;
}

[data-theme="light"] input:focus,
[data-theme="light"] select:focus,
[data-theme="light"] textarea:focus {
  border-color: var(--md-sys-color-primary) !important;
  box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.2) !important;
  background-color: #FFFFFF !important;
}

[data-theme="light"] .main-navigation {
  background: #F1F5F9;
  border-color: #E2E8F0;
}

[data-theme="light"] .main-nav-btn:hover {
  background: rgba(15, 23, 42, 0.06);
  color: #0F172A;
}

[data-theme="light"] .empty-state {
  background: #F8FAFC;
  border-color: #CBD5E1;
}

[data-theme="light"] .view-details-btn {
  background: #F1F5F9;
  color: #0F172A;
  border-color: #E2E8F0;
}

[data-theme="light"] .view-details-btn:hover {
  background: var(--md-sys-color-primary);
  color: #FFFFFF;
  border-color: var(--md-sys-color-primary);
}

* {
  box-sizing: border-box;
}

/* ==========================================================================
   BASE & TYPOGRAPHY (M3 Type Scale)
   ========================================================================== */

body {
  margin: 0;
  font-family: 'Inter', 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0.01em;
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-surface);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Accessible Focus Rings (M3 Focus Indicator) */
:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--md-sys-color-surface-dim);
}

::-webkit-scrollbar-thumb {
  background: var(--md-sys-color-surface-container-highest);
  border-radius: var(--md-sys-shape-corner-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--md-sys-color-outline);
}

.screen {
  min-height: 100vh;
  padding: 20px 28px;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   LOGIN SCREEN (M3 Elevated / Outlined Surface Card)
   ========================================================================== */

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 0%, rgba(245, 196, 56, 0.08) 0%, transparent 55%),
    var(--md-sys-color-background);
}

.card {
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 24px;
  box-shadow: var(--md-sys-elevation-level2);
}

.login-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
  border-radius: var(--md-sys-shape-corner-extra-large);
  background: var(--md-sys-color-surface-container);
  box-shadow: var(--md-sys-elevation-level3);
}

.brand-icon {
  font-size: 40px;
  margin-bottom: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 68px;
  height: 68px;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-radius: var(--md-sys-shape-corner-large);
  border: 1px solid rgba(255, 224, 139, 0.22);
}

.login-card h1 {
  margin-top: 0;
  margin-bottom: 6px;
  color: var(--md-sys-color-on-surface);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.subtitle {
  margin-top: 0;
  margin-bottom: 24px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 13.5px;
}

/* ==========================================================================
   FORMS & BUTTONS (M3 Outlined Fields & Tonal / Filled Buttons)
   ========================================================================== */

form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

label {
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: -4px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-small);
  padding: 10px 14px;
  background: var(--md-sys-color-surface-container-lowest);
  color: var(--md-sys-color-on-surface);
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              box-shadow var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

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

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

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 2px rgba(245, 196, 56, 0.2);
  background: var(--md-sys-color-surface);
}

/* M3 Filled Button (Default primary action in index.html) */
button {
  margin-top: 4px;
  border: 1px solid transparent;
  border-radius: var(--md-sys-shape-corner-full);
  padding: 10px 18px;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.01em;
  font-family: inherit;
  cursor: pointer;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              border-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              box-shadow var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
  box-shadow: none;
}

button:hover {
  background: var(--accent-orange-hover);
  box-shadow: var(--md-sys-elevation-level1);
}

button:active {
  box-shadow: none;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* M3 Filled Tonal Button */
button.secondary {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: none;
}

button.secondary:hover {
  background: var(--md-sys-color-surface-container-highest);
  border-color: var(--md-sys-color-outline);
  box-shadow: none;
}

button.google-btn {
  background: #FFFFFF;
  color: #1F1F1F;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: var(--md-sys-shape-corner-full);
  box-shadow: var(--md-sys-elevation-level1);
  border: 1px solid #DADCE0;
}

button.google-btn:hover {
  background: #F8FAFC;
  box-shadow: var(--md-sys-elevation-level2);
}

.error-msg {
  min-height: 18px;
  margin: 6px 0 0;
  color: var(--md-sys-color-error);
  font-size: 12.5px;
  text-align: center;
}

/* ==========================================================================
   TOP APP BAR & NAVIGATION TABS (M3 Top App Bar + Secondary Navigation)
   ========================================================================== */

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  flex-wrap: wrap;
  gap: 14px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-mobile-controls {
  display: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.header-btn {
  margin: 0 !important;
  padding: 8px 14px;
  font-size: 12.5px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--md-sys-shape-corner-full);
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--md-sys-color-on-surface);
}

/* M3 Segmented / Pill Navigation Bar */
.main-navigation {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  background: var(--md-sys-color-surface-container-low);
  padding: 6px;
  border-radius: var(--md-sys-shape-corner-large);
  border: 1px solid var(--md-sys-color-outline-variant);
  flex-wrap: wrap;
}

.main-nav-btn {
  flex: 1;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  border: 1px solid transparent;
  padding: 9px 14px;
  border-radius: var(--md-sys-shape-corner-medium);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              border-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
  box-shadow: none;
  margin: 0;
  min-width: 110px;
  text-align: center;
}

.main-nav-btn:hover {
  color: var(--md-sys-color-on-surface);
  background: rgba(226, 232, 240, 0.06);
  box-shadow: none;
}

.main-nav-btn.active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border-color: rgba(188, 199, 220, 0.22);
  font-weight: 700;
  box-shadow: none;
}

/* ==========================================================================
   DASHBOARD LAYOUT & DEVICE CARDS (M3 Filled / Outlined Cards)
   ========================================================================== */

.dashboard-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  position: relative;
}

.devices-section {
  flex: 1;
  width: 100%;
}

.devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

.empty-state {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 14px;
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 24px;
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-large);
  border: 1px dashed var(--md-sys-color-outline-variant);
}

.device-card {
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 18px;
  box-shadow: var(--md-sys-elevation-level1);
  transition: border-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
              box-shadow var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.device-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--md-sys-color-outline);
  opacity: 0.45;
  transition: background-color var(--md-sys-motion-duration-short), opacity var(--md-sys-motion-duration-short);
}

.device-card:hover {
  background: var(--md-sys-color-surface-container);
  border-color: var(--md-sys-color-outline);
  box-shadow: var(--md-sys-elevation-level2);
}

.device-card:hover::before {
  opacity: 1;
  background: var(--md-sys-color-primary);
}

.device-card.selected {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-surface-container);
  box-shadow: 0 0 0 1px var(--md-sys-color-primary), var(--md-sys-elevation-level2);
}

.device-card.selected::before {
  opacity: 1;
  background: var(--md-sys-color-primary);
}

.device-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

.device-title-group {
  flex: 1;
  min-width: 0;
}

.device-name {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--md-sys-color-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-sub-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.device-id {
  margin: 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 11px;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.device-badges {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

/* M3 Assist / Status Chips */
.badge {
  border-radius: var(--md-sys-shape-corner-full);
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge.online {
  background: var(--md-sys-color-success-container);
  color: var(--md-sys-color-on-success-container);
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.badge.offline {
  background: rgba(148, 163, 184, 0.12);
  color: var(--md-sys-color-on-surface-variant);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.badge.alert {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  border: 1px solid rgba(248, 113, 113, 0.35);
}

.badge.version {
  background: rgba(103, 212, 255, 0.12);
  color: var(--md-sys-color-tertiary);
  border: 1px solid rgba(103, 212, 255, 0.28);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px;
  padding: 2px 7px;
}

.badge.outdated {
  background: var(--md-sys-color-warning-container);
  color: var(--md-sys-color-on-warning-container);
  border: 1px solid rgba(251, 191, 36, 0.35);
}

.last-seen {
  margin: 4px 0 12px 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 11.5px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.card-action-bar {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

.card-action-bar .action-btn {
  margin: 0;
  padding: 8px 12px;
  font-size: 12px;
  border-radius: var(--md-sys-shape-corner-small);
}

.view-details-btn {
  flex: 1;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: none;
}

.view-details-btn:hover {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-color: var(--md-sys-color-primary);
}

.quick-update-btn {
  background: var(--md-sys-color-warning-container);
  color: var(--md-sys-color-on-warning-container);
  border: 1px solid rgba(251, 191, 36, 0.35);
  box-shadow: none;
  white-space: nowrap;
}

.quick-update-btn:hover {
  background: var(--md-sys-color-warning);
  color: var(--md-sys-color-on-warning);
}

/* ═══════════════════════════════════════════════════════════════════════════
   DEVICES VIEW TOOLBAR & VIEW MODES (M3 Segmented Buttons & Layouts)
   ═══════════════════════════════════════════════════════════════════════════ */
.devices-view-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.devices-view-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.devices-view-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  letter-spacing: -0.01em;
}

.devices-view-selector {
  display: inline-flex;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-full);
  padding: 3px;
  gap: 2px;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.devices-view-selector::-webkit-scrollbar {
  display: none;
}

.view-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  background: transparent;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  cursor: pointer;
  transition: all var(--md-sys-motion-duration-short) ease;
  white-space: nowrap;
  box-shadow: none;
  margin: 0;
}

.view-btn:hover {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}

.view-btn.active {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--md-sys-elevation-level1);
}

.view-btn-icon {
  font-size: 13px;
  line-height: 1;
}

.device-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.expand-chevron {
  display: none;
  cursor: pointer;
  padding: 4px;
  user-select: none;
  font-size: 11px;
  color: var(--md-sys-color-on-surface-variant);
  transition: transform 0.25s ease, color 0.25s ease;
}

/* ── 1. MODE: Grid Large (default) ── */
#devices-container.view-grid-large {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
#devices-container.view-grid-large .device-card {
  padding: 18px;
}
#devices-container.view-grid-large .expand-chevron {
  display: none;
}

/* ── 2. MODE: Grid Small (compact cards) ── */
#devices-container.view-grid-small {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
#devices-container.view-grid-small .device-card {
  padding: 12px;
  border-radius: var(--md-sys-shape-corner-medium);
}
#devices-container.view-grid-small .device-name {
  font-size: 13.5px;
}
#devices-container.view-grid-small .device-sub-row {
  font-size: 10px;
  gap: 4px;
}
#devices-container.view-grid-small .badge {
  font-size: 9.5px;
  padding: 2px 6px;
}
#devices-container.view-grid-small .last-seen {
  font-size: 10px;
  margin: 2px 0 8px 0;
}
#devices-container.view-grid-small .card-action-bar {
  gap: 4px;
}
#devices-container.view-grid-small .card-action-bar .action-btn {
  padding: 5px 8px;
  font-size: 11px;
  height: 28px;
}
#devices-container.view-grid-small .expand-chevron {
  display: none;
}

/* ── 3. MODE: List (horizontal single-column rows) ── */
#devices-container.view-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#devices-container.view-list .device-card {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  gap: 16px;
  border-radius: var(--md-sys-shape-corner-medium);
}
#devices-container.view-list .device-header {
  margin-bottom: 0;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}
#devices-container.view-list .device-info-left {
  flex: 1;
  min-width: 0;
}
#devices-container.view-list .device-card-drawer {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0;
  flex-shrink: 0;
}
#devices-container.view-list .last-seen {
  margin: 0;
  white-space: nowrap;
}
#devices-container.view-list .card-action-bar {
  margin-top: 0;
}
#devices-container.view-list .expand-chevron {
  display: none;
}

/* ── 4. MODE: Details (expanded rich information) ── */
#devices-container.view-details {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 18px;
}
#devices-container.view-details .device-card {
  padding: 20px;
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline);
}
#devices-container.view-details .device-name {
  font-size: 17px;
}
#devices-container.view-details .last-seen {
  margin: 8px 0 14px 0;
  font-size: 12px;
  padding: 6px 10px;
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--md-sys-shape-corner-small);
}
#devices-container.view-details .expand-chevron {
  display: none;
}

/* ── 5. MODE: Names Only ("solo nombre de persona y celular y solo al apretar baje") ── */
#devices-container.view-names-only {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#devices-container.view-names-only .device-card {
  cursor: pointer;
  padding: 12px 16px;
  border-radius: var(--md-sys-shape-corner-medium);
  transition: all var(--md-sys-motion-duration-short) ease;
}
#devices-container.view-names-only .device-card:hover {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-surface-container);
}
#devices-container.view-names-only .device-header {
  margin-bottom: 0;
  align-items: center;
}
#devices-container.view-names-only .expand-chevron {
  display: inline-block;
}
/* En estado colapsado (por defecto en solo nombre) */
#devices-container.view-names-only .device-card:not(.is-expanded) .device-header .status-badge,
#devices-container.view-names-only .device-card:not(.is-expanded) .device-id-sep,
#devices-container.view-names-only .device-card:not(.is-expanded) .device-id {
  display: none;
}
#devices-container.view-names-only .device-card .device-card-drawer {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.28s cubic-bezier(0.2, 0, 0, 1), opacity 0.22s ease, margin-top 0.22s ease;
  margin-top: 0;
}
/* En estado expandido ("al apretar baje") */
#devices-container.view-names-only .device-card.is-expanded {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-surface-container);
  box-shadow: var(--md-sys-elevation-level2);
}
#devices-container.view-names-only .device-card.is-expanded .expand-chevron {
  transform: rotate(180deg);
  color: var(--md-sys-color-primary);
}
#devices-container.view-names-only .device-card.is-expanded .device-card-drawer {
  max-height: 220px;
  opacity: 1;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--md-sys-color-outline-variant);
}
#devices-container.view-names-only .device-card.is-expanded .device-id-sep,
#devices-container.view-names-only .device-card.is-expanded .device-id {
  display: inline;
}
#devices-container.view-names-only .device-card.is-expanded .device-header .status-badge {
  display: inline-flex;
}

/* ==========================================================================
   SIDEBAR (M3 Side Sheet)
   ========================================================================== */

.sidebar {
  width: 580px;
  max-width: 92vw;
  background: var(--md-sys-color-surface-container-low);
  border-left: 1px solid var(--md-sys-color-outline-variant);
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  z-index: 100;
  display: flex;
  flex-direction: column;
  box-shadow: var(--md-sys-elevation-level5);
  transition: transform var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard),
              width var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

.sidebar.expanded {
  width: 92vw !important;
  max-width: 1400px !important;
}

.sidebar.expanded #panel-policies.active {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  align-items: start;
}

.sidebar.expanded #panel-policies.active .search-box {
  grid-column: 1 / -1;
}

.sidebar.expanded #panel-policies.active .sidebar-card {
  margin-bottom: 0 !important;
  height: 100%;
}

.sidebar.hidden {
  display: none !important;
}

.sidebar-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--md-sys-color-surface-container);
}

.sidebar-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
}

.sidebar-tabs {
  display: flex;
  background: var(--md-sys-color-surface-container);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  padding: 0 12px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  padding: 12px 8px;
  font-size: 12.5px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin: 0;
  box-shadow: none;
}

.tab-btn:hover {
  color: var(--md-sys-color-on-surface);
  background: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
  color: var(--md-sys-color-primary);
  border-bottom-color: var(--md-sys-color-primary);
}

.sidebar-content {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-card {
  background: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: 16px;
}

.sidebar-card h3 {
  margin: 0 0 8px 0;
  font-size: 13.5px;
  color: var(--md-sys-color-on-surface);
  font-weight: 700;
}

.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  padding: 7px 10px;
  border-radius: var(--md-sys-shape-corner-small);
  transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

.toggle-row:hover {
  background: rgba(226, 232, 240, 0.06);
}

.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--md-sys-color-primary);
  flex-shrink: 0;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 22px;
  cursor: pointer;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--md-sys-shape-corner-full);
  box-shadow: none;
  margin: 0;
  padding: 0;
}

.close-btn:hover {
  color: var(--md-sys-color-on-surface);
  background: rgba(226, 232, 240, 0.1);
}

/* ==========================================================================
   MODALS / DIALOGS (M3 Extra-Large 28px Surface Container High)
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 13, 18, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-extra-large);
  box-shadow: var(--md-sys-elevation-level4);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.modal-actions button {
  flex: 1;
}

/* ==========================================================================
   FILTER CHIPS & APPS (M3 8px Small Shape Filter Chips)
   ========================================================================== */

.apps-filters {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 6px 12px;
  border-radius: var(--md-sys-shape-corner-small);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface-variant);
  transition: all var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
  width: auto;
  box-shadow: none;
  margin: 0;
}

.filter-chip:hover {
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  border-color: var(--md-sys-color-outline);
}

.filter-chip.active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  border-color: var(--md-sys-color-secondary);
  font-weight: 700;
}

.apps-update-item {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  padding: 10px 14px !important;
  background-color: var(--md-sys-color-surface-container-low) !important;
  border-radius: var(--md-sys-shape-corner-medium) !important;
  border: 1px solid var(--md-sys-color-outline-variant) !important;
  gap: 10px !important;
}

.apps-update-btn {
  width: auto !important;
  min-width: 84px !important;
  flex-shrink: 0 !important;
  white-space: nowrap !important;
  padding: 6px 12px !important;
  font-size: 11.5px !important;
  font-weight: 700 !important;
  border-radius: var(--md-sys-shape-corner-full) !important;
  border: none !important;
  cursor: pointer !important;
}

/* ==========================================================================
   SIDEBAR APP LIST ITEMS
   ========================================================================== */

.app-item {
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: 10px 12px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color var(--md-sys-motion-duration-short), background-color var(--md-sys-motion-duration-short);
}

.app-item:hover {
  border-color: var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-container);
}

.app-main-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 8px;
}

.app-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.app-meta {
  flex: 1;
  min-width: 0;
}

.app-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-pkg {
  margin: 2px 0 0 0;
  font-size: 10.5px;
  color: var(--md-sys-color-on-surface-variant);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-toggles {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.app-toggle-btn {
  width: auto !important;
  padding: 4px 9px !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  border-radius: var(--md-sys-shape-corner-small) !important;
  border: 1px solid var(--md-sys-color-outline-variant) !important;
  background: var(--md-sys-color-surface-container-high) !important;
  color: var(--md-sys-color-on-surface) !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  box-shadow: none !important;
  transition: all var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard) !important;
  height: 28px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin: 0 !important;
}

.app-toggle-btn:hover {
  background: var(--md-sys-color-surface-container-highest) !important;
  border-color: var(--md-sys-color-outline) !important;
}

/* Estado activo Bloquear (Rojo M3) */
.app-toggle-btn.active-block {
  background: var(--md-sys-color-error-container) !important;
  border-color: var(--md-sys-color-error) !important;
  color: var(--md-sys-color-on-error-container) !important;
}

.app-toggle-btn.active-block:hover {
  background: #691B24 !important;
}

/* Estado activo Suspender (Ámbar M3) */
.app-toggle-btn.active-suspend {
  background: var(--md-sys-color-warning-container) !important;
  border-color: var(--md-sys-color-warning) !important;
  color: var(--md-sys-color-on-warning-container) !important;
}

.app-toggle-btn.active-suspend:hover {
  background: #5E3B08 !important;
}

/* Estado activo Bloquear Web (Índigo/Terciario M3) */
.app-toggle-btn.active-webview {
  background: var(--md-sys-color-tertiary-container) !important;
  border-color: var(--md-sys-color-tertiary) !important;
  color: var(--md-sys-color-on-tertiary-container) !important;
}

.app-toggle-btn.active-webview:hover {
  background: #006685 !important;
}

.app-toggle-btn.gear-btn {
  padding: 4px 6px !important;
  font-size: 11px !important;
  min-width: 28px !important;
}

/* ==========================================================================
   RESPONSIVE BREAKPOINTS (Compact / Medium / Expanded Window Size Classes)
   ========================================================================== */

@media (max-width: 768px) {
  .screen {
    padding: 12px 14px;
  }

  .dashboard-layout {
    gap: 0;
  }

  .sidebar {
    width: 100% !important;
    max-width: 100vw;
    border-left: none;
  }

  .sidebar.expanded {
    width: 100% !important;
  }

  #sidebar-expand-btn {
    display: none;
  }

  #devices-container, #groups-list, #archived-list, #presets-list, #store-apps-list,
  #master-profiles-list, #app-requests-list, #whitelist-apps-list, #qr-pending-list, #iab-audit-list {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  #devices-container.view-list .device-card {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  #devices-container.view-list .device-card-drawer {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  #devices-container.view-list .last-seen {
    white-space: normal;
  }
}

@media (max-width: 600px) {
  .screen {
    padding: 8px 10px;
  }

  .devices-view-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .devices-view-info {
    justify-content: space-between;
  }

  .devices-view-selector {
    width: 100%;
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 2px;
  }

  .view-btn {
    padding: 5px 8px;
    font-size: 11px;
    flex: 1 0 auto;
    justify-content: center;
  }

  .app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    position: relative;
    padding: 4px 0;
  }

  .header-brand h1 {
    font-size: 15px;
    margin: 0;
    line-height: 1.2;
  }

  .header-mobile-controls {
    display: flex;
    gap: 6px;
    align-items: center;
  }

  .header-icon-btn {
    background: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-on-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-small);
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    cursor: pointer;
    padding: 0;
    box-shadow: none;
  }

  .header-icon-btn:hover {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
  }

  .header-actions {
    display: none;
    position: absolute;
    top: 40px;
    right: 0;
    background: var(--md-sys-color-surface-container-high);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-large);
    padding: 8px;
    flex-direction: column;
    gap: 4px;
    z-index: 300;
    box-shadow: var(--md-sys-elevation-level4);
    min-width: 220px;
  }

  .header-actions.menu-open {
    display: flex !important;
  }

  .header-actions .header-btn {
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    font-size: 12px;
    border-radius: var(--md-sys-shape-corner-small);
    justify-content: flex-start;
    margin: 0 !important;
  }

  .main-navigation {
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap !important;
    gap: 4px;
    padding: 4px !important;
    margin-bottom: 10px !important;
    border-radius: var(--md-sys-shape-corner-medium) !important;
    background: var(--md-sys-color-surface-container-low);
    border: 1px solid var(--md-sys-color-outline-variant);
    scrollbar-width: none;
  }

  .main-navigation::-webkit-scrollbar {
    display: none;
  }

  .main-nav-btn {
    flex: 0 0 auto !important;
    font-size: 11.5px !important;
    padding: 5px 10px !important;
    border-radius: var(--md-sys-shape-corner-small) !important;
    height: 30px;
    line-height: 1;
    margin: 0;
    min-width: auto;
  }

  #devices-container, #groups-list, #archived-list, #presets-list, #store-apps-list,
  #master-profiles-list, #app-requests-list, #whitelist-apps-list, #qr-pending-list, #iab-audit-list {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }

  .device-card {
    padding: 10px 12px;
    margin-bottom: 6px;
    border-radius: var(--md-sys-shape-corner-medium);
    background: var(--md-sys-color-surface-container-low);
    border: 1px solid var(--md-sys-color-outline-variant);
  }

  .device-header {
    margin-bottom: 4px;
    gap: 4px;
  }

  .device-name {
    font-size: 13.5px;
  }

  .device-sub-row {
    font-size: 10px;
    margin-top: 2px;
    gap: 4px;
  }

  .device-id {
    font-size: 9.5px;
  }

  .badge {
    font-size: 9.5px;
    padding: 2px 7px;
  }

  .last-seen {
    font-size: 10px;
    margin: 2px 0 6px 0;
  }

  .card-action-bar {
    margin-top: 4px;
    gap: 6px;
  }

  .view-details-btn {
    padding: 6px 10px;
    font-size: 11px;
    height: 30px;
    border-radius: var(--md-sys-shape-corner-small);
  }

  .quick-update-btn {
    padding: 6px 10px;
    font-size: 11px;
    height: 30px;
    min-width: 75px;
    border-radius: var(--md-sys-shape-corner-small);
  }

  .sidebar {
    width: 100% !important;
    max-width: 100vw;
    border-left: none;
    box-shadow: none;
  }

  .sidebar-header {
    padding: 10px 12px;
  }

  .sidebar-header h2 {
    font-size: 14.5px;
  }

  .sidebar-tabs {
    padding: 0 4px;
  }

  .tab-btn {
    font-size: 11px;
    padding: 8px 4px;
  }

  .sidebar-content {
    padding: 8px;
    gap: 8px;
  }

  .sidebar-card {
    padding: 10px 12px;
    margin-bottom: 6px;
    border-radius: var(--md-sys-shape-corner-small) !important;
  }

  .sidebar-card h3 {
    font-size: 12.5px;
    margin-bottom: 6px;
  }

  .toggle-row {
    font-size: 11.5px;
    min-height: 34px;
  }

  .modal-overlay {
    padding: 8px;
  }

  .modal-card {
    padding: 16px;
    max-width: 100%;
    border-radius: var(--md-sys-shape-corner-large);
  }

  .login-card {
    padding: 16px;
    max-width: 100%;
  }
}

@media (max-width: 320px) {
  body {
    font-size: 10.5px;
  }

  .screen {
    padding: 4px 6px;
  }

  .header-brand h1 {
    font-size: 12px;
  }

  .devices-view-title {
    font-size: 11.5px;
  }

  .view-btn {
    padding: 3px 5px;
    font-size: 9.5px;
    gap: 2px;
  }

  .view-btn-label {
    font-size: 9px;
  }

  .main-nav-btn {
    font-size: 10px !important;
    padding: 3px 6px !important;
  }

  .device-card {
    padding: 8px;
  }

  .device-name {
    font-size: 12px;
  }

  .card-action-bar .action-btn {
    font-size: 10px;
    height: 26px;
    padding: 3px 6px;
  }
}
