/* LC Panel Web Control Panel Stylesheet - Monochrome Redesign */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --header-height: 48px;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* Status Colors (Semantic) */
  --success: #10b981;
  --success-subtle: rgba(16, 185, 129, 0.15);

  --warning: #f59e0b;
  --warning-subtle: rgba(245, 158, 11, 0.15);

  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-subtle: rgba(239, 68, 68, 0.15);

  /* Fallback Light Theme (R=G=B Greys) */
  --bg-base: #ffffff;
  --bg-surface: #f5f5f5;
  --bg-elevated: #ebebeb;
  --bg-hover: #e0e0e0;
  --bg-active: #d4d4d4;
  --border-color: #e0e0e0;
  --border-subtle: #ebebeb;

  --text-main: #0a0a0a;
  --text-dim: #525252;
  --text-muted: #737373;

  --primary: #0a0a0a;
  --primary-hover: #262626;
  --primary-subtle: #ebebeb;
  --primary-contrast: #ffffff;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
}

:root[data-theme="light"] {
  --bg-base: #ffffff;
  --bg-surface: #f5f5f5;
  --bg-elevated: #ebebeb;
  --bg-hover: #e0e0e0;
  --bg-active: #d4d4d4;
  --border-color: #e0e0e0;
  --border-subtle: #ebebeb;

  --text-main: #0a0a0a;
  --text-dim: #525252;
  --text-muted: #737373;

  --primary: #0a0a0a;
  --primary-hover: #262626;
  --primary-subtle: #ebebeb;
  --primary-contrast: #ffffff;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
}

:root[data-theme="dark"] {
  --bg-base: #000000;
  --bg-surface: #0a0a0a;
  --bg-elevated: #171717;
  --bg-hover: #262626;
  --bg-active: #333333;
  --border-color: #262626;
  --border-subtle: #171717;

  --text-main: #fafafa;
  --text-dim: #a3a3a3;
  --text-muted: #737373;

  --primary: #fafafa;
  --primary-hover: #e5e5e5;
  --primary-subtle: #262626;
  --primary-contrast: #000000;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.6), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.7), 0 4px 6px -4px rgba(0, 0, 0, 0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-base: #000000;
    --bg-surface: #0a0a0a;
    --bg-elevated: #171717;
    --bg-hover: #262626;
    --bg-active: #333333;
    --border-color: #262626;
    --border-subtle: #171717;

    --text-main: #fafafa;
    --text-dim: #a3a3a3;
    --text-muted: #737373;

    --primary: #fafafa;
    --primary-hover: #e5e5e5;
    --primary-subtle: #262626;
    --primary-contrast: #000000;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.6), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.7), 0 4px 6px -4px rgba(0, 0, 0, 0.6);
  }
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-base);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Typography & Links */
a {
  color: var(--text-main);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
a:hover {
  color: var(--text-dim);
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-main);
  font-weight: 600;
  line-height: 1.25;
}

/* App Layout: fixed left sidebar + content column */
.app-container {
  display: flex;
  flex-direction: row;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Sidebar */
.app-sidebar {
  --sidebar-width: 240px;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  height: 100%;
  flex-shrink: 0;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  z-index: 30;
  transition: width 0.15s ease, transform 0.2s ease;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  height: var(--header-height);
  min-height: var(--header-height);
  box-sizing: border-box;
  padding: 0 0.75rem 0 1rem;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.sidebar-top .brand {
  min-width: 0;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
}

/* Scrolls independently of the content area */
.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.75rem 0.5rem;
  scrollbar-width: thin;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.sidebar-nav .nav-link {
  display: flex;
  width: 100%;
  white-space: nowrap;
}

.sidebar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-nav-row {
  display: flex;
  align-items: center;
  gap: 0.125rem;
}
.sidebar-nav-row .nav-link {
  flex: 1;
  min-width: 0;
}

.sidebar-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  flex-shrink: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
}
.sidebar-icon-btn:hover {
  background-color: var(--bg-elevated);
  color: var(--text-main);
}

.sidebar-chevron {
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.sidebar-group-toggle[aria-expanded="true"] .sidebar-chevron,
.sidebar-machine.expanded > .sidebar-machine-btn .sidebar-chevron {
  transform: rotate(90deg);
}

/* Machine tree under 'Machines' */
.sidebar-machines,
.sidebar-actions {
  list-style: none;
}
.sidebar-machines {
  margin: 0.125rem 0 0.375rem 0.75rem;
  padding-left: 0.375rem;
  border-left: 1px solid var(--border-color);
}
.sidebar-actions {
  margin: 0.125rem 0 0.25rem 1.1rem;
  padding-left: 0.375rem;
  border-left: 1px solid var(--border-subtle);
}

.sidebar-empty {
  padding: 0.35rem 0.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.sidebar-machine-btn,
.sidebar-action {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  padding: 0.3rem 0.5rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}
.sidebar-machine-btn:hover,
.sidebar-action:hover:not(:disabled) {
  background-color: var(--bg-elevated);
  color: var(--text-main);
}
.sidebar-machine.active > .sidebar-machine-btn,
.sidebar-machine.has-open > .sidebar-machine-btn {
  color: var(--text-main);
}
.sidebar-machine.active > .sidebar-machine-btn {
  font-weight: 600;
}
.sidebar-action.open {
  color: var(--text-main);
}
.sidebar-action.active {
  background-color: var(--bg-hover);
  color: var(--text-main);
  font-weight: 600;
}
.sidebar-action:disabled {
  color: var(--text-muted);
  opacity: 0.55;
  cursor: not-allowed;
}

.sidebar-action-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.sidebar-machine-name,
.sidebar-action-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sidebar-dot.online {
  background-color: var(--success);
}
.sidebar-dot.offline {
  background-color: transparent;
  border: 1px solid var(--text-muted);
}

/* Marks a machine / action with an open tab */
.sidebar-open-mark {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--text-main);
  flex-shrink: 0;
}

.sidebar-bottom {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.sidebar-bottom .sidebar-account {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-bottom .sidebar-account svg {
  flex-shrink: 0;
}

.sidebar-bottom .sidebar-logout {
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

.sidebar-bottom .sidebar-logout svg {
  flex-shrink: 0;
}

.sidebar-bottom .sidebar-logout .sidebar-label,
.sidebar-collapsed .app-sidebar .sidebar-bottom .sidebar-logout .sidebar-label {
  display: none !important;
}

.sidebar-nav .badge-count {
  margin-left: auto;
}

button.nav-link {
  background: transparent;
  border: none;
  font: inherit;
  text-align: left;
}

/* Icon rail */
.sidebar-collapsed .app-sidebar {
  --sidebar-width: 56px;
}
.sidebar-collapsed .app-sidebar .sidebar-label,
.sidebar-collapsed .app-sidebar .sidebar-group-toggle,
.sidebar-collapsed .app-sidebar .sidebar-machines,
.sidebar-collapsed .app-sidebar .badge-count {
  display: none;
}
.sidebar-collapsed .sidebar-top {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  min-height: var(--header-height);
  box-sizing: border-box;
  padding: 0 2px;
  gap: 2px;
}
.sidebar-collapsed .sidebar-top .brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 2px;
}
.sidebar-collapsed .sidebar-top .brand-logo {
  width: 22px;
  height: 22px;
}
.sidebar-collapsed .sidebar-top .sidebar-collapse-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  flex-shrink: 0;
}
.sidebar-collapsed .sidebar-top .sidebar-collapse-btn svg {
  width: 14px;
  height: 14px;
}
.sidebar-collapsed .app-sidebar .nav-link {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}
.sidebar-collapsed .sidebar-bottom {
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0.25rem;
}
.sidebar-collapsed .sidebar-bottom .sidebar-account {
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  flex: none;
  justify-content: center;
}
.sidebar-collapsed .sidebar-bottom .sidebar-logout {
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  justify-content: center;
}

/* Content column: open-tabs strip on top, view below */
.app-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.app-topbar {
  display: flex;
  align-items: stretch;
  height: var(--header-height);
  min-height: var(--header-height);
  box-sizing: border-box;
  flex-shrink: 0;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  z-index: 15;
}
.app-topbar .tab-strip {
  flex: 1;
  min-width: 0;
  height: 100%;
  min-height: 0;
  box-sizing: border-box;
  border-bottom: none;
}
.topbar-theme-toggle {
  align-self: center;
  margin: 0 0.375rem 0 0.5rem;
}

.topbar-profile {
  align-self: center;
  margin: 0 0.75rem 0 0;
  text-decoration: none;
}
.topbar-profile:hover {
  text-decoration: none;
  color: var(--text-main);
}

.sidebar-hamburger {
  display: none;
  align-self: center;
  margin-left: 0.5rem;
}

.sidebar-backdrop {
  display: none;
}

/* Narrow screens: off-canvas drawer */
@media (max-width: 768px) {
  .app-sidebar,
  .sidebar-collapsed .app-sidebar {
    --sidebar-width: 260px;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar-open .app-sidebar {
    transform: translateX(0);
  }
  .sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    background-color: rgba(0, 0, 0, 0.4);
  }
  .sidebar-collapse-btn {
    display: none;
  }
  .sidebar-hamburger {
    display: inline-flex;
  }
  /* The rail is a desktop preference; the drawer always shows labels */
  .sidebar-collapsed .app-sidebar .sidebar-label,
  .sidebar-collapsed .app-sidebar .sidebar-group-toggle {
    display: inline;
  }
  .sidebar-collapsed .app-sidebar .sidebar-group-toggle {
    display: inline-flex;
  }
  .sidebar-collapsed .app-sidebar .sidebar-machines:not(.hidden) {
    display: block;
  }
  .sidebar-collapsed .app-sidebar .badge-count:not(.hidden) {
    display: inline-flex;
  }
  .sidebar-collapsed .sidebar-top {
    flex-direction: row;
    justify-content: space-between;
    padding: 0 0.75rem 0 1rem;
    height: var(--header-height);
    min-height: var(--header-height);
    box-sizing: border-box;
    gap: 0.5rem;
  }
  .sidebar-collapsed .sidebar-top .brand-logo {
    width: 24px;
    height: 24px;
  }
  .sidebar-collapsed .app-sidebar .nav-link {
    justify-content: flex-start;
    padding-left: 0.875rem;
    padding-right: 0.875rem;
  }
  .sidebar-bottom .sidebar-logout,
  .sidebar-collapsed .sidebar-bottom .sidebar-logout {
    width: 32px;
    height: 32px;
    min-width: 32px;
    padding: 0;
    justify-content: center;
  }
  .sidebar-collapsed .sidebar-bottom {
    flex-direction: row;
    align-items: center;
    padding: 0.5rem;
    gap: 0.25rem;
  }
  .sidebar-collapsed .sidebar-bottom .sidebar-account {
    flex: 1;
    min-width: 0;
    width: auto;
    height: auto;
    justify-content: flex-start;
    padding: 0.5rem 0.625rem;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
  text-decoration: none;
}
.brand:hover {
  text-decoration: none;
}

.brand svg {
  color: var(--text-main);
}

.brand-logo {
  flex-shrink: 0;
}
.brand-logo rect {
  fill: currentColor;
}
.brand-logo path {
  fill: none;
  stroke: var(--bg-base);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-md);
  color: var(--text-dim);
  font-weight: 500;
  transition: all 0.15s ease;
  cursor: pointer;
  text-decoration: none;
}

.nav-link:hover {
  background-color: var(--bg-elevated);
  color: var(--text-main);
  text-decoration: none;
}

.nav-link.active {
  background-color: var(--bg-hover);
  color: var(--text-main);
  font-weight: 600;
}

/* Theme Toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-md);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.theme-toggle:hover {
  background-color: var(--bg-hover);
  border-color: var(--text-muted);
}
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* Global Tab Strip */
.tab-strip {
  display: flex;
  align-items: stretch;
  min-height: 38px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0.25rem 0.75rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  scrollbar-width: thin;
  gap: 0.25rem;
  flex-shrink: 0;
  z-index: 15;
}

.tab-strip::-webkit-scrollbar {
  height: 3px;
}
.tab-strip::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.tab-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background-color: transparent;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition: all 0.15s ease;
  position: relative;
  max-width: 240px;
}

.tab-item:hover {
  background-color: var(--bg-elevated);
  color: var(--text-main);
}

.tab-item.active {
  background-color: var(--bg-base);
  color: var(--text-main);
  font-weight: 600;
  border-color: var(--border-color);
  border-bottom: 1px solid var(--bg-base);
  margin-bottom: -1px;
}

.tab-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background-color: var(--primary);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.tab-item.tab-pinned {
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

.tab-group-start {
  margin-left: 0.35rem;
  border-left: 2px solid var(--border-color) !important;
}

.tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  margin-left: 0.25rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  line-height: 1;
  transition: all 0.1s ease;
}

.tab-close-btn:hover {
  background-color: var(--bg-hover);
  color: var(--danger);
}

/* Tab Panel Containers */
.tab-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  min-height: 0;
}

.tab-panel.hidden {
  display: none !important;
}

/* Main Body Area: fills the space under the tab strip; does not scroll itself */
.app-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Full Viewport Width (1400px cap removed) */
.view-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 768px) {
  .view-container {
    padding: 1rem;
  }
}

/* Full remaining width/height. Each tab panel is sized to it and scrolls
   on its own, so views can fit the visible area exactly */
.app-main > .view-container {
  flex: 1;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0;
  overflow: hidden;
}
.app-main > .view-container > .tab-panel {
  overflow-y: auto;
  padding: 1.5rem;
}

@media (max-width: 768px) {
  .app-main > .view-container > .tab-panel {
    padding: 1rem;
  }
}

/* Prevent admin panel cards and views from collapsing in column flexbox */
.app-main > .view-container > .tab-panel.admin-panel > * {
  flex-shrink: 0;
}

/* Tool tab panels hosting full-height app views (shell, files, resources, texteditor, logwatch) */
.app-main > .view-container > .tab-panel:has(.app-view-container),
.tab-panel:has(.app-view-container),
.tab-panel.tool-tab-panel {
  height: 100%;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

@media (max-width: 768px) {
  .app-main > .view-container > .tab-panel:has(.app-view-container),
  .tab-panel:has(.app-view-container),
  .tab-panel.tool-tab-panel {
    padding: 0;
  }
}

/* View Header */
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.view-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.view-title {
  font-size: 1.5rem;
  font-weight: 700;
}

.view-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.view-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.table td .view-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.table td.actions-cell {
  white-space: nowrap;
}

/* View Switch (Table / Wall) */
.view-switch {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-elevated);
  padding: 2px;
  gap: 2px;
}

.view-switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}
.view-switch-btn:hover {
  color: var(--text-main);
  text-decoration: none;
}
.view-switch-btn.active {
  background-color: var(--bg-surface);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.9375rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1.25;
  background-color: var(--bg-elevated);
  color: var(--text-main);
  text-decoration: none;
}

.btn:hover:not(:disabled) {
  background-color: var(--bg-hover);
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--primary);
  color: var(--primary-contrast);
  border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
}
.btn-danger:hover:not(:disabled) {
  background-color: var(--danger-hover);
}

.btn-secondary {
  background-color: var(--bg-elevated);
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-secondary:hover:not(:disabled) {
  background-color: var(--bg-hover);
}

.btn-sm {
  padding: 0.25rem 0.625rem;
  font-size: 0.85rem;
}

.btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius-md);
}

/* Forms & Inputs */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.form-label {
  font-weight: 500;
  color: var(--text-dim);
  font-size: 0.875rem;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--border-color);
}

.form-help {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Themed dropdowns (js/ui_select.js); the native select stays hidden as the value source */
.ui-select {
  position: relative;
  display: block;
  max-width: 100%;
}
.ui-select.ui-select-inline {
  display: inline-block;
}
.ui-select-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}
.ui-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  padding: 0.625rem 0.875rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.25;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}
.ui-select-trigger:hover:not(:disabled) {
  background-color: var(--bg-hover);
}
.ui-select-trigger:focus-visible,
.ui-select-trigger[aria-expanded="true"] {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--border-color);
}
.ui-select-trigger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.ui-select-label {
  overflow: hidden;
  text-overflow: ellipsis;
}
.ui-select-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}
.ui-select-trigger[aria-expanded="true"] .ui-select-chevron {
  transform: rotate(180deg);
}
.ui-select-list {
  position: fixed;
  z-index: 1000;
  overflow-y: auto;
  padding: 0.25rem;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
}
.ui-select-option {
  display: flex;
  align-items: center;
  padding: 0.4rem 0.625rem 0.4rem 1.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  white-space: nowrap;
  cursor: pointer;
  position: relative;
}
.ui-select-option.active {
  background-color: var(--bg-hover);
}
.ui-select-option.selected {
  font-weight: 600;
}
.ui-select-option.selected::before {
  content: '';
  position: absolute;
  left: 0.65rem;
  top: 50%;
  width: 4px;
  height: 8px;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: translateY(-65%) rotate(45deg);
}
.ui-select-option.disabled {
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Themed checkboxes */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0;
  border: 1.5px solid var(--text-muted);
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface);
  cursor: pointer;
  vertical-align: middle;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="checkbox"]:hover:not(:disabled) {
  border-color: var(--text-main);
}
input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--border-color);
  border-color: var(--primary);
}
input[type="checkbox"]:checked {
  background-color: var(--primary);
  border-color: var(--primary);
}
input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4.5px;
  top: 1.5px;
  width: 4px;
  height: 8px;
  border: solid var(--primary-contrast);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
input[type="checkbox"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Auth Pages (Setup, Login, Signup, Reset) */
.auth-wrapper {
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 1.5rem;
  background-color: var(--bg-base);
  position: relative;
}

.auth-card {
  margin: auto 0;
  width: 100%;
  max-width: 440px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.25rem;
  box-shadow: var(--shadow-lg);
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
  position: relative;
}

.auth-header .brand {
  justify-content: center;
  margin-bottom: 1rem;
}

.auth-title {
  font-size: 1.35rem;
  margin-bottom: 0.5rem;
}

.auth-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.auth-footer-links {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.auth-theme-toggle-corner {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 20;
}

/* Enrollment View Grid */
.enrollment-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.enrollment-grid > .card {
  min-width: 0;
}

@media (max-width: 900px) {
  .enrollment-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
  }
}

/* Account View Grid */
.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: 1.5rem;
  max-width: 900px;
}

.account-grid > .card {
  min-width: 0;
}

/* Cards & Tables */
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-surface);
}

.card-title {
  font-size: 1.05rem;
  font-weight: 600;
}

.card-body {
  padding: 1.25rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.table th, .table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.table th {
  background-color: var(--bg-surface);
  font-weight: 600;
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table tbody tr:hover {
  background-color: var(--bg-hover);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.badge-online {
  background-color: var(--success-subtle);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-offline {
  background-color: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.badge-pending {
  background-color: var(--warning-subtle);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-danger {
  background-color: var(--danger-subtle);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 700;
  background-color: var(--primary);
  color: var(--primary-contrast);
  line-height: 1;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: currentColor;
}

.status-dot.pulse {
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Inline Edit */
.inline-edit {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
}

.inline-edit-input {
  font-size: 0.85rem;
  padding: 0.2rem 0.45rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  max-width: 180px;
}

.inline-edit-input:focus {
  outline: none;
  border-color: var(--primary);
}

.inline-edit-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
}
.inline-edit-btn:hover {
  color: var(--text-main);
  background-color: var(--bg-hover);
}

.inline-edit-label {
  cursor: pointer;
  border-bottom: 1px dashed var(--border-color);
  padding-bottom: 1px;
}
.inline-edit-label:hover {
  border-bottom-color: var(--text-main);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1rem;
}

.tab-btn {
  padding: 0.5rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

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

.tab-btn.active {
  color: var(--text-main);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

/* Media Wall Grid */
.wall-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  width: 100%;
}

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

.wall-tile {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.wall-tile.wall-tile-clickable {
  cursor: pointer;
}
.wall-tile.wall-tile-clickable:hover {
  border-color: var(--text-muted);
  box-shadow: var(--shadow-md);
}

.wall-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background-color: var(--bg-base);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-bottom: 1px solid var(--border-subtle);
}

.wall-thumb canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background-color: var(--bg-base);
}

.wall-tile-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  background-color: rgba(0, 0, 0, 0.45);
  color: #fafafa;
  font-size: 0.8rem;
  gap: 0.5rem;
  pointer-events: none;
}

.wall-tile-overlay.overlay-static {
  background-color: var(--bg-elevated);
  color: var(--text-dim);
}

.wall-tile-info {
  padding: 0.875rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.wall-tile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.wall-tile-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wall-tile-host {
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wall-tile-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

/* Agent Apps Shell / Desktop / Files / etc. */
.app-view-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: var(--bg-base);
  overflow: hidden;
}

.app-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1rem;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.app-toolbar-left, .app-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.app-content {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Shell / Terminal */
.terminal-container {
  flex: 1;
  background-color: var(--bg-base);
  padding: 0.5rem;
  overflow: hidden;
  height: 100%;
}

.terminal-container .xterm {
  height: 100%;
}

/* Remote Desktop */
.desktop-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-base);
  overflow: auto;
  position: relative;
  user-select: none;
}

.desktop-canvas {
  background-color: var(--bg-base);
  box-shadow: var(--shadow-lg);
  image-rendering: auto;
  cursor: default;
}

.desktop-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 1.5rem 2rem;
  border-radius: var(--radius-lg);
  text-align: center;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
}

.btn-audio-active {
  color: var(--primary) !important;
  border-color: var(--primary) !important;
}

.btn-audio-warning {
  color: var(--warning) !important;
  border-color: var(--warning) !important;
}

.btn-audio-error {
  color: var(--danger) !important;
  border-color: var(--danger) !important;
}

/* File Explorer */
.file-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 1rem;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.breadcrumb-item {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.4rem;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
}

.breadcrumb-item:hover {
  background-color: var(--bg-hover);
  color: var(--text-main);
  text-decoration: none;
}

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

.file-list-container {
  flex: 1;
  overflow-y: auto;
}

.file-row {
  cursor: pointer;
  user-select: none;
}

.file-row:hover {
  background-color: var(--bg-hover);
}

.file-name-cell {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-weight: 500;
}

.file-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}
.file-icon.folder { color: #f59e0b; }
.file-icon.file { color: var(--text-muted); }

.btn-file-view-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.btn-icon-only {
  padding: 0.3rem;
  line-height: 0;
}
.btn-icon-only .btn-file-view-icon {
  width: 16px;
  height: 16px;
}

/* Read-only file viewer overlay */
.file-viewer-dialog {
  max-width: min(1100px, 100%);
  height: min(85vh, 100%);
  display: flex;
  flex-direction: column;
}

.file-viewer-header {
  gap: 0.75rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.file-viewer-title {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 0;
  flex: 1 1 12rem;
}

.file-viewer-name {
  font-weight: 600;
  min-width: 0;
}

.file-viewer-meta {
  font-size: 0.8rem;
  flex-shrink: 0;
}

.file-viewer-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.file-viewer-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background-color: var(--bg-base);
}

.file-viewer-content {
  margin: 0;
  padding: 1rem 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-main);
  white-space: pre;
  tab-size: 4;
  user-select: text;
}

.file-viewer-content.wrap {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.file-viewer-notice {
  padding: 1.5rem 1.25rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.file-viewer-notice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

@media (max-width: 600px) {
  .file-viewer-backdrop {
    padding: 0;
  }
  .file-viewer-dialog {
    height: 100%;
    border-radius: 0;
    border: none;
  }
  .file-viewer-header {
    padding: 0.75rem 1rem;
  }
  .file-viewer-content {
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
  }
}

/* Resources View */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.metric-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 500;
}

.metric-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.progress-bar {
  height: 8px;
  background-color: var(--bg-elevated);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background-color: var(--text-main);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.progress-fill.warning { background-color: var(--warning); }
.progress-fill.danger { background-color: var(--danger); }

/* Logwatch View */
.log-viewer {
  flex: 1;
  background-color: var(--bg-base);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.825rem;
  padding: 1rem;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.6;
}

/* Text Editor View */
.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-base);
  overflow: hidden;
}

.editor-textarea {
  flex: 1;
  width: 100%;
  background: transparent;
  color: var(--text-main);
  border: none;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  padding: 1rem;
  resize: none;
  outline: none;
  line-height: 1.5;
  tab-size: 4;
}

.editor-statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 1rem;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Modal Dialog */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  animation: fadeIn 0.15s ease-out;
}

.modal-dialog {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: scaleIn 0.15s ease-out;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
  max-width: 380px;
  pointer-events: none;
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  pointer-events: auto;
  animation: slideUp 0.2s ease-out;
}

.toast.toast-success { border-left: 4px solid var(--success); }
.toast.toast-danger { border-left: 4px solid var(--danger); }
.toast.toast-warning { border-left: 4px solid var(--warning); }
.toast.toast-info { border-left: 4px solid var(--text-main); }

/* Alerts */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
  line-height: 1.4;
}

.alert-danger {
  background-color: var(--danger-subtle);
  border: 1px solid var(--danger);
  color: var(--danger);
}

.alert-success {
  background-color: var(--success-subtle);
  border: 1px solid var(--success);
  color: var(--success);
}

.alert-warning {
  background-color: var(--warning-subtle);
  border: 1px solid var(--warning);
  color: var(--warning);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from { transform: scale(0.96); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Utilities */
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.font-mono { font-family: var(--font-mono); }
.hidden { display: none !important; }
.flex-1 { flex: 1; }
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* === desktop view fit === */

/* Ensure the desktop tab panel and its containers fill available height without scrolling */
.app-main > .view-container > .tab-panel:has(.desktop-app-view),
.app-main > .view-container > .tab-panel:has(.desktop-viewport),
.app-main > .view-container > .tab-panel.desktop-tab-panel,
.tab-panel:has(.desktop-app-view),
.tab-panel:has(.desktop-viewport),
.tab-panel.desktop-tab-panel {
  height: 100%;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

@media (max-width: 768px) {
  .app-main > .view-container > .tab-panel:has(.desktop-app-view),
  .app-main > .view-container > .tab-panel:has(.desktop-viewport),
  .app-main > .view-container > .tab-panel.desktop-tab-panel {
    padding: 0;
  }
}

/* Ensure view container and app-main flex children don't overflow when desktop is active */
.app-main:has(.desktop-viewport) {
  min-height: 0;
  overflow: hidden;
}

.view-container:has(.desktop-viewport) {
  min-height: 0;
  height: 100%;
  padding: 0;
}

/* The desktop app container occupies full height and width of its tab panel */
.app-view-container.desktop-app-view,
.desktop-tab-panel > .app-view-container {
  height: 100%;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Desktop toolbar stays visible, wraps if needed, but never shrinks below content */
.app-view-container.desktop-app-view .app-toolbar,
.app-view-container:has(.desktop-viewport) .app-toolbar {
  flex-shrink: 0;
}

/* Desktop viewport occupies exactly the remaining height and width */
.desktop-viewport {
  flex: 1;
  min-height: 0;
  min-width: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  user-select: none;
  background-color: var(--bg-base);
}

/* In actual 1:1 scale mode, scroll inside viewport only, never the page */
.desktop-viewport.scale-actual {
  overflow: auto;
}

/* Desktop canvas styling */
.desktop-canvas {
  flex-shrink: 0;
  box-sizing: border-box;
  margin: auto;
  image-rendering: auto;
  cursor: default;
  touch-action: none;
}

/* Control off: view-only, the canvas sends no input */
.desktop-viewport.view-only .desktop-canvas {
  cursor: default;
  touch-action: auto;
}

/* Fullscreen mode support */
.app-view-container:fullscreen {
  width: 100vw;
  height: 100vh;
  background-color: var(--bg-base);
  display: flex;
  flex-direction: column;
}

.app-view-container:fullscreen .desktop-viewport {
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-base);
}

.wall-previews-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}

/* ==========================================================================
   Text Mirror View Styles
   ========================================================================== */

/* Floating panel and settings modal mount inside the desktop view (also in fullscreen) */
.app-view-container.desktop-app-view {
  position: relative;
}

/* Toggle buttons in the desktop toolbar (Control, Text Mirror) */
.app-toolbar .btn[aria-pressed="true"] {
  color: var(--primary);
  border-color: var(--primary);
}

/* Placement box over the desktop canvas; the stream shows the real overlay */
.tm-place-box {
  /* Pin light-theme tokens so the box and handles stay dark in every theme */
  --primary: #0a0a0a;
  --text-dim: #525252;
  position: absolute;
  box-sizing: border-box;
  border: 2px solid var(--primary);
  background: rgba(128, 128, 128, 0.12);
  user-select: none;
  touch-action: none;
  z-index: 5;
}

.tm-place-box.disabled {
  border-style: dashed;
  border-color: var(--text-dim);
}

/* Text field filling the box; font, colors and padding are set from the overlay state */
.tm-place-text {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  outline: none;
  resize: none;
  overflow: auto;
  line-height: normal;
  white-space: pre-wrap;
  background: transparent;
  user-select: text;
  touch-action: pan-x pan-y;
  cursor: text;
}

.tm-place-box.tm-ctrl-move .tm-place-text {
  cursor: move;
}

.tm-place-box.tm-box-readonly {
  cursor: move;
}

.tm-place-box.tm-box-readonly .tm-place-text {
  pointer-events: none;
  cursor: move;
  user-select: none;
}

/* Resize handles: 12px hit areas sitting half outside the box */
.tm-place-handle {
  position: absolute;
  z-index: 1;
  touch-action: none;
}

.tm-place-n, .tm-place-s { left: 8px; right: 8px; height: 12px; cursor: ns-resize; }
.tm-place-e, .tm-place-w { top: 8px; bottom: 8px; width: 12px; cursor: ew-resize; }
.tm-place-n { top: -7px; }
.tm-place-s { bottom: -7px; }
.tm-place-e { right: -7px; }
.tm-place-w { left: -7px; }

.tm-place-ne, .tm-place-nw, .tm-place-se, .tm-place-sw {
  width: 12px;
  height: 12px;
  box-sizing: border-box;
  background: var(--primary);
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 2px;
  z-index: 2;
}

.tm-place-nw { top: -7px; left: -7px; cursor: nwse-resize; }
.tm-place-se { bottom: -7px; right: -7px; cursor: nwse-resize; }
.tm-place-ne { top: -7px; right: -7px; cursor: nesw-resize; }
.tm-place-sw { bottom: -7px; left: -7px; cursor: nesw-resize; }

.tm-place-box.disabled .tm-place-ne,
.tm-place-box.disabled .tm-place-nw,
.tm-place-box.disabled .tm-place-se,
.tm-place-box.disabled .tm-place-sw,
.tm-place-box.disabled .tm-place-move {
  background: var(--text-dim);
}

/* Move tab straddling the top edge */
.tm-place-move {
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  min-width: 32px;
  height: 20px;
  padding: 0 6px;
  box-sizing: border-box;
  border-radius: 4px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  line-height: 20px;
  text-align: center;
  cursor: move;
  touch-action: none;
}

.tm-place-move:active {
  cursor: grabbing;
}

.tm-float-panel {
  position: absolute;
  top: 3.75rem;
  right: 1rem;
  z-index: 20;
  width: 320px;
  max-width: calc(100% - 2rem);
  max-height: calc(100% - 4.75rem);
  display: flex;
  flex-direction: column;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.tm-float-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  cursor: move;
  user-select: none;
  touch-action: none;
}

.tm-float-title {
  font-weight: 600;
  font-size: 0.9rem;
}

.tm-float-spacer {
  flex: 1;
}

.tm-header-mic {
  padding: 0.25rem 0.4rem;
}

.tm-header-mic.active,
.tm-header-mic.btn-danger {
  background-color: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
  animation: tm-mic-pulse 1.5s infinite;
}

.tm-header-mic:disabled {
  animation: none;
}

@keyframes tm-mic-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(239, 68, 68, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
  }
}

.tm-float-body {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.75rem;
  overflow-y: auto;
}

.tm-float-body .alert {
  margin: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
}

.tm-float-body textarea {
  width: 100%;
  resize: vertical;
}

.tm-float-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.tm-float-row .form-input {
  min-width: 0;
  flex: 1;
}

.tm-float-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tm-float-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border-color);
}

.tm-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-weight: 500;
}

.tm-style-section {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.tm-style-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  width: fit-content;
}

.tm-style-toggle:hover {
  color: var(--text-main);
}

.tm-style-chevron {
  flex-shrink: 0;
  transition: transform 0.15s ease;
  transform: rotate(0deg);
}

.tm-style-toggle[aria-expanded="true"] .tm-style-chevron {
  transform: rotate(90deg);
}

.tm-style-content {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.tm-panel-controls-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.tm-panel-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  font-weight: 500;
  flex: 1;
  min-width: 0;
}

.tm-panel-label {
  white-space: nowrap;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.tm-panel-input {
  width: 100%;
  padding: 0.2rem 0.35rem;
  font-size: 0.8rem;
  text-align: right;
}

.tm-panel-select {
  width: 100%;
  min-width: 0;
  padding: 0.2rem 0.35rem;
  font-size: 0.8rem;
}

.tm-settings-dialog {
  max-width: 560px;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
}

.tm-settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
  overflow-y: auto;
}

.tm-span-2 {
  grid-column: span 2;
}

.tm-color {
  width: 40px;
  height: 36px;
  padding: 2px;
  cursor: pointer;
}

.tm-toggle-label input[type="checkbox"] {
  accent-color: var(--primary);
}

/* ==========================================================================
   User Permissions Modal & Feature Grid
   ========================================================================== */

.permissions-feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.feature-checkbox-item {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.5rem 0.625rem;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.feature-checkbox-item:hover {
  background-color: var(--bg-hover);
  border-color: var(--text-dim);
}

.feature-checkbox-item input[type="checkbox"] {
  margin-top: 0.15rem;
  accent-color: var(--primary);
  cursor: pointer;
}

.feature-checkbox-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.feature-checkbox-label {
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-main);
}

.feature-checkbox-desc {
  font-size: 0.75rem;
  line-height: 1.25;
}

/* ==========================================================================
   Desktop Toolbar Modernized Icon Buttons
   ========================================================================== */

.desktop-app-view .app-toolbar .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 0.5rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  outline: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.desktop-app-view .app-toolbar .btn svg {
  flex-shrink: 0;
  pointer-events: none;
}

.desktop-app-view .app-toolbar .btn:hover:not(:disabled) {
  background-color: var(--bg-hover);
  color: var(--text-main);
}

.desktop-app-view .app-toolbar .btn:focus-visible {
  box-shadow: 0 0 0 2px var(--bg-base), 0 0 0 4px var(--primary);
}

.desktop-app-view .app-toolbar .btn[aria-pressed="true"] {
  background-color: var(--primary-subtle);
  border-color: var(--primary);
  color: var(--primary);
}

.desktop-app-view .app-toolbar .btn.btn-audio-active {
  color: var(--success);
  border-color: var(--success);
}

.desktop-app-view .app-toolbar .btn.btn-audio-warning {
  color: var(--warning);
  border-color: var(--warning);
}

.desktop-app-view .app-toolbar .btn.btn-audio-error {
  color: var(--danger);
  border-color: var(--danger);
}

/* Account Settings Scoped Styles */
.settings-layout {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  min-width: 0;
  width: 100%;
}

.settings-nav {
  display: flex;
  flex-direction: column;
  width: 200px;
  min-width: 180px;
  flex-shrink: 0;
  gap: 0.25rem;
  border-right: 1px solid var(--border-color);
  padding-right: 1.25rem;
}

.settings-nav-btn {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
  min-width: 0;
}

.settings-nav-btn:hover {
  background-color: var(--bg-elevated);
  color: var(--text-main);
}

.settings-nav-btn.active {
  background-color: var(--bg-elevated);
  color: var(--text-main);
  font-weight: 600;
}

.settings-content {
  flex: 1;
  min-width: 0;
  max-width: 750px;
  width: 100%;
}

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

.settings-panel.hidden {
  display: none !important;
}

.settings-panel input,
.settings-panel select,
.settings-panel textarea {
  max-width: 100%;
}

/* Feature Defaults Sub-Tabs */
.feature-tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  min-width: 0;
}

.feature-tab-btn {
  padding: 0.5rem 1rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  flex-shrink: 0;
}

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

.feature-tab-btn.active {
  color: var(--text-main);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.feature-subpanel {
  min-width: 0;
  width: 100%;
}

.feature-subpanel.hidden {
  display: none !important;
}

@media (max-width: 768px) {
  .settings-layout {
    flex-direction: column;
    gap: 1.25rem;
  }

  .settings-nav {
    flex-direction: row;
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding-right: 0;
    padding-bottom: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    gap: 0.5rem;
  }

  .settings-nav-btn {
    width: auto;
    white-space: nowrap;
    flex-shrink: 0;
  }

  .settings-content {
    max-width: 100%;
    width: 100%;
  }

  .settings-panel {
    max-width: 100% !important;
    width: 100%;
  }

  .settings-layout * {
    min-width: 0;
  }
}

/* Admin Per-User Drill-Down View */
.user-drilldown-link {
  color: var(--text-main);
  text-decoration: none;
  transition: color 0.15s ease;
}

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

.admin-user-subtabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.25rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   Server Monitor View
   ========================================================================== */

.server-monitor-view {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
  box-sizing: border-box;
}

.server-monitor-view .page-header {
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.server-monitor-view .page-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
}

.server-monitor-view .page-header p {
  margin: 0.25rem 0 0 0;
  font-size: 0.85rem;
}

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

.metric-cards-grid .metric-card {
  padding: 1.25rem;
}

.metric-cards-grid .progress-bar {
  margin-bottom: 0.75rem;
  height: 8px;
  background-color: var(--bg-hover, rgba(255, 255, 255, 0.1));
  border-radius: 4px;
  overflow: hidden;
}

.metric-cards-grid .progress-fill {
  height: 100%;
  background-color: var(--primary, #3b82f6);
  border-radius: 4px;
  transition: width 0.3s ease;
}

@media (max-width: 768px) {
  .server-monitor-view {
    padding: 1rem;
  }

  .metric-cards-grid {
    grid-template-columns: 1fr;
  }
}


