/* GLOBAL & RESET */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-x pan-y;
}

/* ── СВЕТЛАЯ ТЕМА (по умолчанию) ─────────────────────────────── */
:root {
  --bg-color: #eef0f5;
  --header-bg: rgba(232, 236, 246, 0.94);
  --card-bg: rgba(255, 255, 255, 0.88);
  --modal-bg: #f3f5fb;
  --modal-overlay-bg: rgba(0, 0, 0, 0.45);
  --gesture-card-bg: rgba(255, 255, 255, 0.92);
  --dropdown-bg: #f3f5fb;
  --scroll-btn-bg: rgba(210, 215, 232, 0.92);

  --login-gradient: radial-gradient(circle at center, #dde2f3 0%, #cacfe8 100%);

  --surface-1: rgba(0, 0, 0, 0.04);
  --surface-2: rgba(0, 0, 0, 0.06);
  --surface-hover: rgba(0, 0, 0, 0.07);
  --surface-active: rgba(0, 0, 0, 0.12);
  --input-bg: rgba(0, 0, 0, 0.06);
  --badge-bg: rgba(0, 0, 0, 0.06);

  --border-color: rgba(0, 0, 0, 0.09);
  --text-primary: #1e2035;
  --text-secondary: #64748b;
  --text-on-input: #1e2035;

  --accent-blue: #3b82f6;
  --accent-blue-glow: rgba(59, 130, 246, 0.3);
  --accent-red: #ef4444;
  --accent-red-glow: rgba(239, 68, 68, 0.3);
  --accent-purple: #8b5cf6;
  --accent-purple-glow: rgba(139, 92, 246, 0.3);
  --success-color: #10b981;
}

/* ── ТЁМНАЯ ТЕМА (автоматически по системе) ──────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #0f1019;
    --header-bg: rgba(13, 15, 25, 0.94);
    --card-bg: rgba(22, 24, 36, 0.8);
    --modal-bg: #13151f;
    --modal-overlay-bg: rgba(0, 0, 0, 0.75);
    --gesture-card-bg: rgba(24, 27, 42, 0.78);
    --dropdown-bg: #151722;
    --scroll-btn-bg: rgba(22, 24, 36, 0.92);

    --login-gradient: radial-gradient(circle at center, #1b2035 0%, #0c0d12 100%);

    --surface-1: rgba(255, 255, 255, 0.04);
    --surface-2: rgba(255, 255, 255, 0.05);
    --surface-hover: rgba(255, 255, 255, 0.08);
    --surface-active: rgba(255, 255, 255, 0.15);
    --input-bg: rgba(0, 0, 0, 0.35);
    --badge-bg: rgba(255, 255, 255, 0.05);

    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #e8eaf0;
    --text-secondary: #8c92a4;
    --text-on-input: #e8eaf0;
  }
}

/* ── BASE BODY ────────────────────────────────────────────────── */
/* html paints the theme bg on the root canvas so no uncovered region
   (e.g. the iOS home-indicator safe-area) ever shows white. */
html {
  background-color: var(--bg-color);
}

body {
  position: relative;
  background-color: var(--bg-color);
  color: var(--text-primary);
  height: 100vh;
  height: 100svh;
  /* dvh fills down through the bottom safe-area inset so the bottom bar /
     content background paints into the home-indicator area, not white. */
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* SCREEN MANAGEMENT */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* GLASS EFFECT CARD */
.glass-card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.15);
  border-radius: 20px;
}

/* LOGIN SCREEN */
#login-screen {
  align-items: center;
  justify-content: center;
  background: var(--login-gradient);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 30px 24px;
  text-align: center;
}

.logo-area {
  margin-bottom: 25px;
  position: relative;
}

.logo-pulse {
  width: 60px;
  height: 60px;
  background: var(--accent-blue);
  border-radius: 50%;
  margin: 0 auto 15px;
  box-shadow: 0 0 20px var(--accent-blue-glow);
  position: relative;
}

.logo-pulse::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid var(--accent-blue);
  opacity: 0.5;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.8; }
  100% { transform: scale(1.3); opacity: 0; }
}

.login-card h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.subtitle {
  font-size: 13px;
  color: var(--text-secondary);
}

.input-group {
  margin-bottom: 16px;
  position: relative;
}

.input-group input {
  width: 100%;
  padding: 14px 16px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-on-input);
  font-size: 16px;
  outline: none;
  text-align: center;
  transition: all 0.3s ease;
}

.input-group input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 10px var(--accent-blue-glow);
}

#login-pin {
  font-size: 24px;
  letter-spacing: 6px;
  font-weight: bold;
}

/* CUSTOM NUMERIC KEYPAD */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 20px 0;
}

.num-btn {
  padding: 16px 0;
  background: var(--surface-2);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: background 0.2s, transform 0.1s;
}

.num-btn:active {
  background: var(--surface-active);
  transform: scale(0.95);
}

.clear-btn {
  color: var(--accent-red);
}

.back-btn {
  color: var(--text-secondary);
  font-size: 16px;
}

.error-text {
  color: var(--accent-red);
  font-size: 13px;
  margin: 10px 0;
  min-height: 18px;
}

.error-text.hidden {
  display: none;
}

.primary-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent-blue);
  border: none;
  border-radius: 12px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s, box-shadow 0.3s;
}

.primary-btn:hover {
  background: #2563eb;
  box-shadow: 0 0 15px var(--accent-blue-glow);
}

.primary-btn:active {
  transform: scale(0.99);
}

.secondary-btn {
  padding: 12px 20px;
  background: var(--surface-hover);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

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

.danger-btn {
  background: var(--accent-red);
}
.danger-btn:hover {
  background: #dc2626;
  box-shadow: 0 0 15px var(--accent-red-glow);
}

/* MAIN PANEL HEADER */
.header {
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  backdrop-filter: blur(12px);
}

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

.live-dot {
  width: 6px;
  height: 6px;
  background: var(--success-color);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--success-color);
  animation: blink 2s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.header-left h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

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

.username {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  background: var(--badge-bg);
  padding: 3px 8px;
  border-radius: 16px;
  border: 1px solid var(--border-color);
}

.icon-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  color: var(--text-primary);
}

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

/* QUICK CONTROLS — без подложек */
.controls-section {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 6px 12px;
}

.control-btn {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface-1);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}

#btn-manage-users {
  grid-column: span 2;
}

.control-btn:active {
  transform: scale(0.97);
}

.control-btn .btn-icon {
  font-size: 16px;
}

.control-btn .btn-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

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

.control-btn.accent-blue:hover {
  background: rgba(59, 130, 246, 0.1);
}

.control-btn.accent-red:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* BUSY / LOADING STATE FOR ACTION BUTTONS (screenshot, restarts, reboot) */
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

.btn-busy {
  position: relative;
  pointer-events: none;
  opacity: 0.75;
}

.btn-busy > * {
  visibility: hidden;
}

.btn-busy::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  opacity: 0.9;
  animation: btn-spin 0.7s linear infinite;
}

.control-btn.accent-purple:hover {
  background: rgba(139, 92, 246, 0.1);
}

/* CHAT FEED */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(80px + env(safe-area-inset-bottom, 0px)) 16px;
  background: var(--bg-color);
  display: flex;
  flex-direction: column;
}

.chat-feed {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

/* CHAT SYSTEM & ACTION PILLS */
.system-msg-pill {
  align-self: center;
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border-color);
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  max-width: 90%;
  letter-spacing: 0.2px;
}

.system-msg-pill.system-reboot {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.2);
  color: #3b82f6;
}

.system-msg-pill.action-reboot {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.2);
  color: var(--accent-red);
}

.system-msg-pill.action-users {
  background: rgba(139, 92, 246, 0.12);
  border-color: rgba(139, 92, 246, 0.2);
  color: var(--accent-purple);
}

.system-msg-pill.action-app-launch {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.2);
  color: var(--success-color);
}

/* CHAT LOG MESSAGE BUBBLES */
.gesture-message {
  align-self: flex-start;
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gesture-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  padding-left: 6px;
}

.gesture-card {
  padding: 6px;
  background: var(--gesture-card-bg);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.screenshot-wrapper {
  position: relative;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  cursor: pointer;
  margin: 0 auto;
}

.screenshot-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 1;
  transition: opacity 0.3s;
}

/* GESTURE DOTS / ARROWS */
.svg-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.pulse-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--accent-red);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 6px var(--accent-red);
}

.pulse-dot::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1px solid var(--accent-red);
  animation: dot-pulse 1.5s infinite;
  box-sizing: border-box;
  left: 0;
  top: 0;
}

@keyframes dot-pulse {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(3.5); opacity: 0; }
}

/* MODAL WINDOWS */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay-bg);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  transition: opacity 0.25s ease;
  padding: 16px;
}

.modal-overlay.hidden {
  display: none;
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--modal-bg);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  animation: modal-zoom 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modal-zoom {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
}

.modal-divider {
  border: 0;
  height: 1px;
  background: var(--border-color);
  margin: 18px 0;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-form h4 {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.modal-input-group input {
  width: 100%;
  padding: 12px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-on-input);
  font-size: 16px;
  outline: none;
}

.modal-input-group input:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 8px var(--accent-purple-glow);
}

/* Admin checkbox row in Add User form — opt out of the full-width text-input styling */
.modal-checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
}

.modal-checkbox-group input[type="checkbox"] {
  width: auto;
  margin: 0;
  padding: 0;
  flex: none;
  accent-color: var(--accent-purple);
}

/* USERS LIST IN MODAL */
.users-list-container h4 {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

#users-list {
  list-style: none;
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#users-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

#users-list li span {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.delete-user-btn {
  background: none;
  border: none;
  color: var(--accent-red);
  cursor: pointer;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 4px;
}

.delete-user-btn:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* CONFIRM CARD */
.confirm-card {
  max-width: 320px;
  text-align: center;
}

.confirm-card .modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.warning-icon {
  font-size: 40px;
  margin-bottom: 4px;
}

.confirm-card h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.confirm-card p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 12px;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

.confirm-actions button {
  flex: 1;
}

/* SCREENSHOT VIEWER MODAL */
.viewer-overlay {
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  flex-direction: column;
}

.viewer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.viewer-container {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.viewer-image-wrapper {
  position: relative;
  max-width: 100%;
  max-height: 80vh;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 9 / 16;
}

.viewer-image-wrapper img {
  max-width: 100%;
  max-height: 80vh;
  width: auto;
  height: auto;
  display: block;
}

.viewer-footer {
  width: 100%;
  max-width: 600px;
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 110;
}

.viewer-info {
  font-size: 12px;
  color: var(--text-secondary);
}

.hd-toggle-btn {
  padding: 6px 14px;
  background: var(--surface-hover);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  color: var(--text-primary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.hd-toggle-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  box-shadow: 0 0 8px var(--accent-blue-glow);
  color: #fff;
}

/* RESPONSIVE DESIGN */
@media (min-width: 768px) {
  .controls-section {
    grid-template-columns: repeat(2, 1fr);
    padding: 8px 20px;
    gap: 4px;
  }

  .control-btn {
    padding: 10px 16px;
    flex-direction: row;
    gap: 10px;
  }

  .control-btn .btn-text {
    font-size: 13px;
  }

  .gesture-message {
    max-width: 65%;
  }
}

/* BURGER MENU */
.burger-menu {
  position: relative;
  display: inline-block;
}

#burger-btn {
  font-size: 20px;
  color: var(--text-primary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  transition: background 0.2s;
}

#burger-btn:hover {
  background: var(--surface-hover);
}

.burger-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 8px;
  width: 180px;
  background: var(--dropdown-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  padding: 6px 0;
}

.burger-dropdown.hidden {
  display: none;
}

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

.burger-item:hover {
  background: var(--surface-1);
}

.burger-item.accent-red {
  color: var(--accent-red);
}

.burger-item.accent-red:hover {
  background: rgba(239, 68, 68, 0.1);
}

.burger-divider {
  border: 0;
  height: 1px;
  background: var(--border-color);
  margin: 4px 0;
}

/* SCROLL TO BOTTOM BUTTON */
.scroll-bottom-btn {
  position: absolute;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--scroll-btn-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 100;
  transition: opacity 0.3s, transform 0.3s;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.scroll-bottom-btn.hidden {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

.scroll-bottom-btn:hover {
  background: var(--surface-hover);
  transform: translateY(-2px);
}
