@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root,
:root[data-theme='light'] {
  --bg: #faf9f8;
  --panel: #ffffff;
  --panel-border: #edebe9;
  --text-main: #242424;
  --text-muted: #605e5c;
  
  --brand: #0f6cbd;
  --brand-hover: #115ea3;
  --brand-pressed: #0f4e8a;
  --brand-light: #ebf3fc;
  
  --success: #107c41;
  --success-light: #dfefe6;
  --error: #d13438;
  --error-light: #fde7e9;
  --warning: #f7630c;
  --warning-light: #fef0e6;
  
  --shadow-soft: 0 2px 4px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.04);
  --shadow-medium: 0 8px 24px rgba(0, 0, 0, 0.06);
  --code-bg: #f3f2f1;
  --overlay: rgba(36, 36, 36, 0.4);
  --sidebar-width: 280px;
}

:root[data-theme='dark'] {
  --bg: #111111;
  --panel: #1f1f1f;
  --panel-border: #292929;
  --text-main: #f5f5f5;
  --text-muted: #adadad;
  
  --brand: #479ef5;
  --brand-hover: #62aef7;
  --brand-pressed: #2881d7;
  --brand-light: rgba(71, 158, 245, 0.15);
  
  --success: #108447;
  --success-light: rgba(16, 132, 71, 0.15);
  --error: #a80000;
  --error-light: rgba(168, 0, 0, 0.15);
  --warning: #f7630c;
  --warning-light: rgba(247, 99, 12, 0.15);
  
  --shadow-soft: 0 4px 8px rgba(0, 0, 0, 0.24), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-medium: 0 12px 36px rgba(0, 0, 0, 0.4);
  --code-bg: #292929;
  --overlay: rgba(0, 0, 0, 0.6);
}

/* Reset and Core layout */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-main);
  background-color: var(--bg);
  min-height: 100vh;
  overflow: hidden;
  position: relative;
  transition: background-color 0.2s, color 0.2s;
  
  /* Background subtle gradient details matching chatbot-ai */
  background-image: 
    radial-gradient(circle at 90% 0%, rgba(15, 108, 189, 0.04), transparent 50%),
    radial-gradient(circle at 10% 100%, rgba(99, 102, 241, 0.02), transparent 50%);
}

:root[data-theme='dark'] body {
  background-image: 
    radial-gradient(circle at 90% 0%, rgba(71, 158, 245, 0.07), transparent 50%),
    radial-gradient(circle at 10% 100%, rgba(99, 102, 241, 0.04), transparent 50%);
}

/* Ambient glow container - kept for structure but extremely soft and refined */
.bg-glow-container {
  display: none; /* Removed for a cleaner, modern look */
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--panel-border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Main Layout container */
#app {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
}

/* 1. LOGIN SCREEN */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  padding: 40px 32px;
  box-shadow: var(--shadow-medium);
  text-align: center;
  animation: slideUp 0.3s cubic-bezier(0.1, 0.9, 0.2, 1) both;
}

.logo-icon {
  width: 52px;
  height: 52px;
  background: var(--brand-light);
  border-radius: 12px;
  margin: 0 auto 20px auto;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--brand);
}

.logo-icon svg {
  width: 28px;
  height: 28px;
}

.login-card h2 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.login-card p {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 20px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 550;
  color: var(--text-main);
  margin-bottom: 6px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper input {
  width: 100%;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text-main);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-light);
}

/* Buttons */
.btn-primary {
  width: 100%;
  padding: 11px 16px;
  background-color: var(--brand);
  border: none;
  border-radius: 8px;
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.btn-primary:hover {
  background-color: var(--brand-hover);
}

.btn-primary:active {
  background-color: var(--brand-pressed);
  transform: scale(0.98);
}

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

.error-message {
  color: var(--error);
  background-color: var(--error-light);
  border: 1px solid rgba(209, 52, 56, 0.15);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 20px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: shake 0.4s ease;
}

.error-message svg {
  flex-shrink: 0;
}

/* 2. DASHBOARD LAYOUT */
.dashboard-layout {
  display: flex;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}

/* SIDEBAR Component */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 10;
  transition: background-color 0.2s, border-color 0.2s, width 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* Sidebar collapsed state rules */
.sidebar.collapsed {
  width: 68px !important;
}
.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .menu-text,
.sidebar.collapsed .user-info {
  display: none !important;
}
.sidebar.collapsed .sidebar-header {
  flex-direction: column;
  gap: 12px;
  align-items: center;
  padding: 20px 10px;
}
.sidebar.collapsed .sidebar-logo {
  margin: 0;
}
.sidebar.collapsed .menu-item {
  justify-content: center;
  padding: 10px;
}
.sidebar.collapsed .sidebar-footer {
  justify-content: center;
  padding: 16px 10px;
  flex-direction: column;
  gap: 12px;
}
.sidebar.collapsed .btn-icon-logout {
  padding: 8px;
}

/* Sidebar toggle button styling */
.sidebar-toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s, color 0.15s;
}
.sidebar-toggle-btn:hover {
  background-color: var(--code-bg);
  color: var(--text-main);
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  background: var(--brand);
  color: #ffffff;
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.sidebar-logo svg {
  width: 18px;
  height: 18px;
}

.sidebar-title h1 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.sidebar-title span {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
}

.sidebar-menu {
  flex-grow: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
  border: none;
  background: transparent;
}

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

.menu-item.active {
  background-color: var(--brand-light);
  color: var(--brand);
}

.menu-item svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
}

/* Sidebar Participants */
.sidebar-participants {
  flex-grow: 1;
  padding: 16px 20px;
  border-top: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.sidebar.collapsed .sidebar-participants {
  display: none !important;
}

.participants-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.count-badge {
  background-color: var(--code-bg);
  border: 1px solid var(--panel-border);
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-main);
}

.participants-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.participant-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background-color 0.15s;
}

.participant-item:hover {
  background-color: var(--code-bg);
}

.participant-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--brand-light);
  color: var(--brand);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid rgba(0, 120, 212, 0.15);
  flex-shrink: 0;
}

.participant-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.participant-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.participant-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-main);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.self-badge {
  background: var(--brand-light);
  color: var(--brand);
  font-size: 9px;
  font-weight: 600;
  padding: 0 4px;
  border-radius: 4px;
  flex-shrink: 0;
}

.participant-status {
  font-size: 10.5px;
  font-weight: 500;
}

.participant-status.presenting {
  color: var(--success);
}

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

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--panel);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--code-bg);
  border: 1px solid var(--panel-border);
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  color: var(--brand);
  font-size: 12px;
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 13px;
  font-weight: 550;
  color: var(--text-main);
  max-width: 130px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 10px;
  color: var(--text-muted);
}

.btn-icon-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: background-color 0.15s, color 0.15s;
}

.btn-icon-logout:hover {
  background-color: var(--error-light);
  color: var(--error);
}

/* MAIN CONTENT AREA */
.main-content {
  flex-grow: 1;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--bg);
}

.content-header {
  height: 60px;
  border-bottom: 1px solid var(--panel-border);
  background-color: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  z-index: 5;
  transition: background-color 0.2s, border-color 0.2s;
}

.content-header h2 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

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

/* Mobile hamburger button (hidden on desktop) */
.mobile-menu-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  padding: 6px;
  margin-right: 4px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s;
}
.mobile-menu-btn:hover {
  background-color: var(--code-bg);
}

/* Backdrop shared by the mobile nav drawer and the mobile chat overlay */
.mobile-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(2px);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.mobile-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.ip-badge {
  font-size: 11px;
  padding: 4px 10px;
  background-color: var(--code-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  color: var(--text-muted);
  font-weight: 500;
}

.ip-badge span {
  color: var(--brand);
  font-weight: 600;
}

/* Theme Toggle Button styling */
.icon-btn.theme-toggle-btn {
  background: transparent;
  border: none;
  outline: none;
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background-color 0.15s, color 0.15s;
}

.icon-btn.theme-toggle-btn:hover {
  background-color: var(--code-bg);
  color: var(--text-main);
}

.icon-btn.theme-toggle-btn svg {
  width: 18px;
  height: 18px;
}

/* Toggle Sun/Moon icons dynamically based on data-theme */
:root[data-theme='dark'] .theme-toggle-btn .sun-icon {
  display: block;
}
:root[data-theme='dark'] .theme-toggle-btn .moon-icon {
  display: none;
}

:root[data-theme='light'] .theme-toggle-btn .sun-icon {
  display: none;
}
:root[data-theme='light'] .theme-toggle-btn .moon-icon {
  display: block;
}

/* Fallback default when no theme state is set yet (defaults to dark theme icons) */
:root:not([data-theme]) .theme-toggle-btn .sun-icon {
  display: block;
}
:root:not([data-theme]) .theme-toggle-btn .moon-icon {
  display: none;
}

/* Browser Viewport Frame */
.browser-viewport {
  flex-grow: 1;
  background-color: #000000;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Sharing Control Bar */
.sharing-control-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background-color: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  height: 44px;
  box-sizing: border-box;
  flex-shrink: 0;
}

.control-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-muted);
  transition: background-color 0.2s, box-shadow 0.2s;
}

.status-indicator-dot.presenting {
  background-color: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-indicator-dot.occupied {
  background-color: var(--warning);
  box-shadow: 0 0 8px var(--warning);
}

.status-indicator-dot.idle {
  background-color: var(--text-muted);
}

#control-status-text {
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text-main);
}

.control-actions {
  display: flex;
  gap: 8px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 11.5px;
  border-radius: 4px;
}

/* Neko Frame Wrapper & Block Overlay */
.neko-frame-wrapper {
  position: relative;
  flex-grow: 1;
  width: 100%;
  height: calc(100% - 44px);
}

.neko-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background-color: #000000;
}

.view-only-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.03);
  pointer-events: all;
  cursor: not-allowed;
  z-index: 5;
}

.overlay-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background-color: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #ffffff;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  backdrop-filter: blur(4px);
  z-index: 6;
}

/* 3. ADMIN SETTINGS PANELS */
.admin-view {
  flex-grow: 1;
  padding: 28px 24px;
  overflow-y: auto;
  animation: fadeIn 0.25s ease;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}

.settings-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 8px;
}

.settings-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

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

.settings-tab-btn.active {
  background-color: var(--brand-light);
  color: var(--brand);
}

.settings-tab-btn svg {
  width: 16px;
  height: 16px;
}

.tab-description {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.5;
}

.settings-tab-content {
  animation: fadeIn 0.2s ease;
}

.panel-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow-soft);
  transition: background-color 0.2s, border-color 0.2s;
}

.panel-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 10px;
}

.panel-card h3 svg {
  color: var(--brand);
  width: 18px;
  height: 18px;
}

/* Toggle Switches */
.toggle-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.toggle-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toggle-label span:first-child {
  font-weight: 600;
  font-size: 13px;
}

.toggle-label span:last-child {
  font-size: 11.5px;
  color: var(--text-muted);
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--panel-border);
  transition: .2s;
  border-radius: 20px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: #ffffff;
  transition: .2s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--brand);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

/* Lists and Items */
.list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 16px;
  padding-right: 2px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background-color: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  transition: background-color 0.15s;
}

.list-item:hover {
  background-color: var(--code-bg);
}

.list-item-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.role-badge {
  font-size: 9.5px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.role-badge.admin {
  background-color: var(--warning-light);
  color: var(--warning);
  border: 1px solid rgba(247, 99, 12, 0.1);
}

.role-badge.user {
  background-color: var(--brand-light);
  color: var(--brand);
  border: 1px solid rgba(15, 108, 189, 0.1);
}

.btn-icon-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
}

.btn-icon-delete:hover {
  background-color: var(--error-light);
  color: var(--error);
}

.btn-icon-delete svg {
  width: 16px;
  height: 16px;
}

/* Form layouts */
.form-row {
  display: flex;
  gap: 8px;
}

.form-row input {
  flex-grow: 1;
  padding: 8px 12px;
  background-color: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text-main);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.form-row input:focus {
  border-color: var(--brand);
}

.btn-accent {
  padding: 8px 16px;
  background-color: var(--brand-light);
  color: var(--brand);
  border: 1px solid rgba(15, 108, 189, 0.1);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, transform 0.1s;
}

.btn-accent:hover {
  background-color: var(--brand);
  color: #ffffff;
}

.btn-accent:active {
  transform: scale(0.98);
}

/* Grid configuration fields */
.grid-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.grid-form .form-group {
  margin-bottom: 0;
}

.form-select {
  width: 100%;
  padding: 8px 12px;
  background-color: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text-main);
  font-size: 13px;
  outline: none;
}

.form-select option {
  background-color: var(--panel);
  color: var(--text-main);
}

.detected-ips {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.ip-badge-click {
  font-weight: 600;
  text-decoration: none !important;
  background-color: var(--code-bg);
  border: 1px dashed var(--panel-border);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
  margin-top: 2px;
}

.ip-badge-click:hover {
  background-color: var(--brand-light);
  color: var(--brand) !important;
}

/* System maintenance panel */
.system-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.action-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background-color: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
}

.action-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.action-info span:first-child {
  font-weight: 600;
  font-size: 13px;
}

.action-info span:last-child {
  font-size: 11px;
  color: var(--text-muted);
}

.btn-warning {
  padding: 8px 12px;
  background-color: var(--warning-light);
  border: 1px solid rgba(247, 99, 12, 0.2);
  color: var(--warning);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.btn-warning:hover {
  background-color: var(--warning);
  color: #ffffff;
}

.btn-danger {
  padding: 8px 12px;
  background-color: var(--error-light);
  border: 1px solid rgba(209, 52, 56, 0.2);
  color: var(--error);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

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

/* 4. MODALS & TOASTS */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  width: 100%;
  max-width: 440px;
  padding: 28px;
  box-shadow: var(--shadow-medium);
  animation: slideUp 0.25s cubic-bezier(0.1, 0.9, 0.2, 1) both;
}

.modal h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.modal p {
  color: var(--text-muted);
  font-size: 13.5px;
  margin-bottom: 20px;
  line-height: 1.5;
}

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

.btn-secondary {
  padding: 9px 14px;
  background: var(--code-bg);
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  transition: background-color 0.15s;
}

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

/* Toast System */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-left: 3px solid var(--brand);
  border-radius: 6px;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-soft);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 260px;
  animation: slideInRight 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.toast.success {
  border-left-color: var(--success);
}

.toast.error {
  border-left-color: var(--error);
}

.toast.info {
  border-left-color: var(--brand);
}

/* Keyframes */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

/* =========================================================
   RESPONSIVE  —  Tablet & laptop (<= 1024px)
   ========================================================= */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 240px;
  }
  /* Chat becomes an overlay (instead of squeezing the viewport) below ~1024px */
  .chat-panel {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    box-shadow: var(--shadow-medium);
    z-index: 45;
  }
}

/* =========================================================
   RESPONSIVE  —  Mobile (<= 768px)
   ========================================================= */
@media (max-width: 768px) {
  /* Show mobile-only controls */
  .mobile-menu-btn { display: inline-flex; }
  .mobile-backdrop { display: block; }

  /* Dashboard becomes a single column; sidebar turns into an off-canvas drawer */
  .dashboard-layout {
    position: relative;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    height: 100dvh;
    width: 270px !important;        /* override .collapsed width on mobile */
    max-width: 84vw;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
    border-right: 1px solid var(--panel-border);
    box-shadow: var(--shadow-medium);
    z-index: 50;
  }
  .sidebar.drawer-open {
    transform: translateX(0);
  }
  /* In the mobile drawer the sidebar is ALWAYS full — neutralise the desktop
     "collapsed" rail so it never shrinks to the 68px icon strip. */
  .sidebar.collapsed { width: 270px !important; }
  .sidebar.collapsed .sidebar-title,
  .sidebar.collapsed .menu-text,
  .sidebar.collapsed .sidebar-participants { display: flex !important; }
  .sidebar.collapsed .sidebar-title { display: block !important; }
  .sidebar.collapsed .menu-item { justify-content: flex-start; padding: 12px 14px; }
  .sidebar.collapsed .sidebar-header {
    flex-direction: row;
    align-items: center;
    padding: 20px;
  }
  /* The desktop collapse button is meaningless in the drawer */
  .sidebar-toggle-btn { display: none; }
  /* Larger tap targets in the drawer */
  .menu-item { padding: 12px 14px; font-size: 15px; }
  .menu-item svg { width: 20px; height: 20px; }

  /* Header: tighter padding, allow action row to wrap/scroll horizontally */
  .content-header {
    padding: 0 12px;
    height: 56px;
  }
  .content-header h2 {
    font-size: 15px;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .header-actions {
    gap: 6px;
  }
  /* Hide the verbose IP badge on phones to save space (still in Profile modal) */
  .ip-badge { display: none; }

  /* Browser viewport / control bar */
  .sharing-control-bar {
    padding: 8px 12px;
    height: auto;
    min-height: 44px;
    flex-wrap: wrap;
    gap: 8px;
  }
  #control-status-text { font-size: 12px; }

  /* Admin panels: full width, single-column forms */
  .admin-view {
    padding: 16px 12px;
  }
  .panel-card { padding: 18px 16px; }
  .settings-tabs {
    gap: 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 10px;
  }
  .settings-tabs::-webkit-scrollbar { display: none; }
  .settings-tab-btn {
    padding: 8px 12px;
    flex-shrink: 0;
    font-size: 13px;
  }
  .grid-form {
    grid-template-columns: 1fr;
  }
  /* Stack add-forms vertically so inputs/buttons get full width */
  .form-row {
    flex-direction: column;
    align-items: stretch;
  }
  .form-row .btn-accent,
  .form-row #new-role {
    width: 100% !important;
    max-width: none !important;
  }
  /* Stack toggle & action rows label-over-control */
  .action-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .action-row button { width: 100%; justify-content: center; }

  /* Chat: full-screen overlay on phones */
  .chat-panel {
    position: fixed;
    inset: 0;
    width: 100% !important;
    max-width: 100%;
    height: 100dvh;
    border-left: none;
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 60;
  }
  .chat-panel:not(.collapsed) {
    transform: translateY(0);
  }
  .chat-panel.collapsed {
    /* keep it laid out (so the transition runs) but off-screen & non-interactive */
    width: 100% !important;
    pointer-events: none;
  }
  .chat-message-item { max-width: 90%; }
  /* Bigger touch targets for chat input + clear the iOS home indicator */
  .chat-input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .chat-input-area input { height: 44px; font-size: 15px; }
  .chat-send-btn { width: 44px; height: 44px; flex-shrink: 0; }
  /* Respect the notch on the chat header too */
  .chat-header { padding-top: env(safe-area-inset-top); height: auto; min-height: 56px; }

  /* Resource banner: let stats wrap instead of overflowing */
  .resource-usage-banner {
    height: auto;
    min-height: 28px;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 6px 12px;
  }

  /* Modals: full-width with breathing room from screen edges */
  .overlay { padding: 16px; }
  .modal {
    max-width: 100%;
    padding: 22px 18px;
  }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; }

  /* Profile dropdown: anchor to screen edge so it never overflows */
  .profile-dropdown-menu {
    position: fixed;
    top: 60px;
    right: 12px;
    left: auto;
    width: calc(100vw - 24px);
    max-width: 280px;
  }

  /* Login card fills small screens comfortably */
  .login-container { padding: 16px; }
  .login-card { padding: 32px 22px; }
}

/* =========================================================
   RESPONSIVE  —  Small phones (<= 400px)
   ========================================================= */
@media (max-width: 400px) {
  /* Drop the least essential header icons on very narrow screens */
  .header-cast-btn { display: none !important; }
  .content-header h2 { font-size: 14px; }
}

/* Honor users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .chat-panel,
  .mobile-backdrop,
  .login-card,
  .modal,
  .toast { transition: none !important; animation: none !important; }
}

/* Profile Dropdown Styles */
.profile-dropdown-container {
  position: relative;
  display: inline-block;
}

.profile-dropdown-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--code-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 4px 10px 4px 6px;
  cursor: pointer;
  color: var(--text-main);
  transition: background-color 0.15s, border-color 0.15s;
}

.profile-dropdown-btn:hover {
  background: var(--panel-border);
  border-color: var(--text-muted);
}

.profile-avatar-small {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brand);
  color: #ffffff;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 600;
  font-size: 11.5px;
}

.dropdown-chevron {
  color: var(--text-muted);
  transition: transform 0.2s;
}

.profile-dropdown-container:focus-within .dropdown-chevron {
  transform: rotate(180deg);
}

.profile-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 220px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: var(--shadow-medium);
  padding: 8px 0;
  z-index: 90;
  animation: slideUp 0.15s cubic-bezier(0.1, 0.9, 0.2, 1) both;
}

.dropdown-user-info {
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
}

.dropdown-username {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-main);
}

.dropdown-role {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.dropdown-divider {
  border: 0;
  border-top: 1px solid var(--panel-border);
  margin: 6px 0;
}

.dropdown-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-main);
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  transition: background-color 0.15s;
}

.dropdown-item:hover {
  background-color: var(--code-bg);
}

.dropdown-item svg {
  color: var(--text-muted);
  transition: color 0.15s;
}

.dropdown-item:hover svg {
  color: var(--brand);
}

.dropdown-item.logout-item:hover {
  background-color: var(--error-light);
  color: var(--error);
}

.dropdown-item.logout-item:hover svg {
  color: var(--error);
}

/* Right Sidebar Chat Panel */
.chat-panel {
  width: 320px;
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  transition: width 0.25s cubic-bezier(0.1, 0.9, 0.2, 1), transform 0.25s ease;
  overflow: hidden;
  flex-shrink: 0;
  z-index: 5;
}

.chat-panel.collapsed {
  width: 0;
  border-left: none;
}

.chat-header {
  height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--panel);
  flex-shrink: 0;
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text-main);
  font-size: 14px;
}

.chat-close-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 50%;
  transition: background-color 0.15s, color 0.15s;
}

.chat-close-btn:hover {
  background-color: var(--code-bg);
  color: var(--text-main);
}

.chat-messages-container {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: var(--bg);
}

.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--panel-border);
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  flex-shrink: 0;
}

.chat-input-area input {
  flex: 1;
  height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: var(--code-bg);
  color: var(--text-main);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.chat-input-area input:focus {
  border-color: var(--brand);
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: none;
  background: var(--brand);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.15s, background-color 0.15s;
}

.chat-send-btn:hover {
  background-color: var(--brand);
  opacity: 0.9;
}

/* Chat Message Cards */
.chat-message-item {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px 12px 12px 2px;
  padding: 10px 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.chat-message-item.is-me {
  align-self: flex-end;
  background: var(--brand);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 12px 12px 2px 12px;
  color: #ffffff;
}

.chat-message-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--brand);
  margin-bottom: 4px;
}

.chat-message-item.is-me .chat-message-sender {
  color: rgba(255, 255, 255, 0.9);
}

.chat-message-text {
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
  color: var(--text-main);
}

.chat-message-item.is-me .chat-message-text {
  color: #ffffff;
}

.chat-message-time {
  font-size: 9.5px;
  color: var(--text-muted);
  align-self: flex-end;
  margin-top: 4px;
}

.chat-message-item.is-me .chat-message-time {
  color: rgba(255, 255, 255, 0.7);
}

/* Unread Badge Animation */
@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.unread-badge {
  animation: pulse 1.5s infinite;
}

/* Participant highlight for "Me" */
.participant-item.is-me {
  background-color: var(--brand-light);
  border: 1px solid rgba(0, 120, 212, 0.15);
}

.participant-item.is-me .participant-avatar {
  background: var(--brand);
  color: #ffffff;
}

.participant-item.is-me .self-badge {
  background: var(--brand);
  color: #ffffff;
}

/* Resource Usage Footer Banner */
.resource-usage-banner {
  height: 28px;
  background-color: var(--panel);
  border-top: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 5;
  font-size: 11px;
  color: var(--text-muted);
  transition: background-color 0.2s, border-color 0.2s;
}

.resource-usage-banner .stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.resource-usage-banner .stat-label {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  color: var(--text-muted);
}

.resource-usage-banner .stat-value {
  font-family: var(--font-code, monospace);
  font-weight: 500;
  color: var(--text-main);
}
