/* ===== Theme Variables ===== */
:root {
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --bg-topbar: rgba(255,255,255,0.82);
  --bg-hover: #f5f7fa;
  --bg-input: #ffffff;
  --bg-code: #f5f7f9;
  --bg-badge: #f3f5f8;
  --bg-badge-online: #edf7f0;
  --bg-badge-paused: #fdf8ee;
  --bg-toast: #1e293b;
  --bg-dialog: #ffffff;
  --bg-empty: linear-gradient(135deg, #f8fafc 0%, #eef2f7 100%);
  --bg-login: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-rc-screen: #0f0f0f;
  --bg-rc-sidebar: #f6f7f8;
  --bg-rc-nav: #2a2a2a;

  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-heading: #0f172a;
  --text-link: #3b82f6;
  --text-badge: #8392a5;
  --text-badge-online: #16a34a;
  --text-badge-paused: #ca8a04;
  --text-danger: #ef4444;
  --text-rc-btn: #16a34a;

  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --border-badge: #e2e8f0;
  --border-badge-online: #bbf7d0;
  --border-badge-paused: #fde68a;
  --border-input: #cbd5e1;
  --border-input-focus: #3b82f6;

  --primary-bg: #3b82f6;
  --primary-bg-hover: #2563eb;
  --primary-text: #ffffff;
  --secondary-bg: #ffffff;
  --secondary-bg-hover: #f1f5f9;
  --secondary-text: #475569;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.06);
  --shadow-glow: 0 0 20px rgba(59,130,246,0.15);

  --gradient-accent: linear-gradient(135deg, #3b82f6, #8b5cf6);
  --gradient-success: linear-gradient(135deg, #22c55e, #16a34a);
  --topbar-border: rgba(0,0,0,0.06);

  font: 13px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
}

/* ===== Dark Theme ===== */
[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-topbar: rgba(15,23,42,0.88);
  --bg-hover: #334155;
  --bg-input: #1e293b;
  --bg-code: #1e293b;
  --bg-badge: #334155;
  --bg-badge-online: #064e3b;
  --bg-badge-paused: #78350f;
  --bg-toast: #f1f5f9;
  --bg-dialog: #1e293b;
  --bg-empty: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  --bg-login: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
  --bg-rc-screen: #000000;
  --bg-rc-sidebar: #1e293b;
  --bg-rc-nav: #334155;

  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-heading: #f1f5f9;
  --text-link: #60a5fa;
  --text-badge: #94a3b8;
  --text-badge-online: #4ade80;
  --text-badge-paused: #fbbf24;
  --text-danger: #f87171;
  --text-rc-btn: #4ade80;

  --border: #334155;
  --border-light: #1e293b;
  --border-badge: #475569;
  --border-badge-online: #065f46;
  --border-badge-paused: #92400e;
  --border-input: #475569;
  --border-input-focus: #60a5fa;

  --primary-bg: #3b82f6;
  --primary-bg-hover: #60a5fa;
  --primary-text: #ffffff;
  --secondary-bg: #334155;
  --secondary-bg-hover: #475569;
  --secondary-text: #e2e8f0;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.2);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.5), 0 4px 12px rgba(0,0,0,0.3);
  --shadow-glow: 0 0 20px rgba(96,165,250,0.2);

  --gradient-accent: linear-gradient(135deg, #60a5fa, #a78bfa);
  --gradient-success: linear-gradient(135deg, #4ade80, #22c55e);
  --topbar-border: rgba(255,255,255,0.06);
}

/* ===== Keyframe Animations ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideInDown {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59,130,246,0); }
  50% { box-shadow: 0 0 12px 2px rgba(59,130,246,0.15); }
}
@keyframes badgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}
@keyframes toastSlide {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.92) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes backdropIn {
  from { backdrop-filter: blur(0); background: transparent; }
  to { backdrop-filter: blur(6px); background: rgba(15,23,42,0.4); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* ===== Base ===== */
* { box-sizing: border-box; }
body { margin: 0; transition: background 0.4s ease, color 0.4s ease; }
button, input { font: inherit; }
button { cursor: pointer; transition: all 0.25s cubic-bezier(0.4,0,0.2,1); }
button:disabled { opacity: 0.5; cursor: wait; }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--primary-bg);
  outline-offset: 2px;
  border-radius: 4px;
}
a { color: var(--text-link); text-underline-offset: 3px; transition: color 0.2s, opacity 0.2s; }
a:hover { opacity: 0.8; }
.hidden { display: none !important; }

/* ===== Topbar ===== */
.topbar {
  height: 58px;
  background: var(--bg-topbar);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--topbar-border);
  padding: 0 32px;
  display: flex;
  align-items: center;
  gap: 22px;
  position: sticky;
  top: 0;
  z-index: 100;
  animation: slideInDown 0.4s ease-out;
  transition: background 0.4s ease, border-color 0.4s ease;
}
.wordmark {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}
.top-divider { height: 18px; border-left: 1px solid var(--border); transition: border-color 0.4s; }
.section-name { font-size: 12px; color: var(--text-muted); }
.top-actions { display: flex; align-items: center; gap: 22px; margin-left: auto; }
.server-host { font: 11px ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--text-muted); transition: color 0.3s; }
.plain {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  position: relative;
}
.plain:hover { color: var(--text); background: var(--bg-hover); }

/* ===== Main ===== */
main {
  max-width: 1680px;
  margin: 0 auto;
  padding: 31px 32px 60px;
}
.page-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 23px;
  animation: fadeInUp 0.5s ease-out 0.1s both;
}
h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.3;
  margin: 0;
  color: var(--text-heading);
  transition: color 0.3s;
}
h2 { font-size: 15px; font-weight: 600; margin: 0; color: var(--text-heading); transition: color 0.3s; }
.page-heading p { margin: 7px 0 0; color: var(--text-muted); font-size: 12px; }

/* ===== Buttons ===== */
.primary, .secondary {
  border: 1px solid;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
.primary {
  background: var(--gradient-accent);
  border-color: transparent;
  color: var(--primary-text);
  box-shadow: var(--shadow-sm), 0 0 0 0 rgba(59,130,246,0);
}
.primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md), 0 4px 16px rgba(59,130,246,0.25);
}
.primary:active { transform: translateY(0); }
.secondary {
  border-color: var(--border);
  background: var(--secondary-bg);
  color: var(--secondary-text);
  box-shadow: var(--shadow-sm);
}
.secondary:hover {
  background: var(--secondary-bg-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.secondary:active { transform: translateY(0); }

/* ===== Summary Stats ===== */
.summary {
  display: flex;
  gap: 16px;
  margin-bottom: 21px;
  flex-wrap: wrap;
  animation: fadeInUp 0.5s ease-out 0.2s both;
}
.summary > span {
  display: flex;
  gap: 8px;
  align-items: baseline;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  box-shadow: var(--shadow-sm);
  color: var(--text-secondary);
  font-size: 12px;
  transition: all 0.3s ease, transform 0.25s, box-shadow 0.25s;
}
.summary > span:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.summary strong {
  font-weight: 700;
  font-size: 18px;
  color: var(--text-heading);
  font-variant-numeric: tabular-nums;
  transition: color 0.3s;
}

/* ===== Device List Card ===== */
.device-list {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  animation: fadeInUp 0.5s ease-out 0.3s both;
  transition: all 0.4s ease;
}
.toolbar {
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--border);
  transition: border-color 0.4s;
}
.filters { display: flex; gap: 3px; }
.filter {
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.filter:hover { background: var(--bg-hover); color: var(--text-secondary); }
.filter.selected {
  background: var(--primary-bg);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(59,130,246,0.25);
}
.search-label { margin: 0 0 0 auto; display: block; width: 245px; }
.search-label input {
  width: 100%;
  margin: 0;
  padding: 7px 12px;
  font-size: 12px;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  color: var(--text);
  transition: all 0.25s ease;
}
.search-label input:focus {
  border-color: var(--border-input-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; white-space: nowrap; }
th {
  font-size: 11px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  padding: 11px 16px;
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all 0.3s;
}
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  font-size: 12px;
  vertical-align: middle;
  transition: all 0.2s ease;
}
tbody tr { transition: background 0.2s ease, transform 0.2s ease; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg-hover); }
.device-name { font-size: 12px; font-weight: 600; display: block; color: var(--text-heading); transition: color 0.3s; }
.device-model { display: block; color: var(--text-muted); font-size: 10px; margin-top: 3px; }

/* ===== Badges ===== */
.badge {
  font-size: 10px;
  padding: 3px 8px;
  border: 1px solid var(--border-badge);
  border-radius: 20px;
  background: var(--bg-badge);
  color: var(--text-badge);
  display: inline-block;
  line-height: 1.4;
  font-weight: 500;
  transition: all 0.3s ease;
}
.badge.online {
  background: var(--bg-badge-online);
  color: var(--text-badge-online);
  border-color: var(--border-badge-online);
  animation: badgePulse 3s ease-in-out infinite;
}
.badge.paused {
  background: var(--bg-badge-paused);
  color: var(--text-badge-paused);
  border-color: var(--border-badge-paused);
}

.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; color: var(--text-secondary); }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.actions-heading { font-size: 0; width: 85px; }

/* ===== Text Buttons ===== */
.text-button {
  font-size: 11px;
  border: 0;
  background: transparent;
  padding: 4px 8px;
  color: var(--text-link);
  white-space: nowrap;
  border-radius: 4px;
  font-weight: 500;
}
.text-button:hover { background: rgba(59,130,246,0.08); }

/* ===== Empty / No Results ===== */
.empty {
  text-align: center;
  padding: 74px 20px 79px;
  background: var(--bg-empty);
  animation: fadeIn 0.6s ease-out;
}
.empty h2 { font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.empty p { font-size: 12px; color: var(--text-muted); line-height: 1.8; margin: 11px 0 19px; }
.empty .secondary { font-size: 11px; padding: 6px 12px; }
.no-results { text-align: center; padding: 42px 20px; color: var(--text-muted); font-size: 12px; }

/* ===== Footer ===== */
.list-footer {
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  font-size: 10px;
  color: var(--text-muted);
  transition: all 0.3s;
}
.note { color: var(--text-muted); font-size: 10px; margin: 15px 0 0; max-width: 900px; line-height: 1.7; }

/* ===== Banner ===== */
.banner {
  padding: 12px 16px;
  background: var(--bg-badge-paused);
  color: var(--text-badge-paused);
  border: 1px solid var(--border-badge-paused);
  border-radius: 8px;
  margin-bottom: 18px;
  font-size: 12px;
  animation: fadeInUp 0.3s ease-out;
}

/* ===== Login ===== */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg-login);
  animation: fadeIn 0.6s ease-out;
}
.login-form {
  width: 380px;
  max-width: 100%;
  padding: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.5s ease-out;
  transition: background 0.4s, border-color 0.4s;
}
.login-form .wordmark { font-size: 13px; margin-bottom: 24px; }
.login-form h1 { font-size: 22px; margin-bottom: 24px; }
.login-form label { font-size: 12px; margin: 16px 0 6px; color: var(--text-secondary); }
.login-form .primary { width: 100%; margin-top: 10px; padding: 11px; font-size: 13px; }
.login-form .error { min-height: 17px; margin-bottom: 8px; }

/* ===== Form Elements ===== */
label { display: block; font-size: 12px; color: var(--text-secondary); margin: 16px 0 6px; transition: color 0.3s; }
input, select {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  color: var(--text);
  background: var(--bg-input);
  font: inherit;
  transition: all 0.25s ease;
}
input::placeholder { color: var(--text-muted); }
input:focus, select:focus {
  border-color: var(--border-input-focus);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
  outline: none;
}

/* ===== Dialog / Modal ===== */
dialog {
  width: min(520px, calc(100% - 32px));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px 28px;
  color: var(--text);
  background: var(--bg-dialog);
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  transition: background 0.4s, border-color 0.4s;
}
dialog::backdrop {
  animation: backdropIn 0.3s ease-out forwards;
}
.modal-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; }
.close {
  border: 0;
  background: var(--bg-hover);
  font-size: 18px;
  color: var(--text-muted);
  padding: 4px 10px;
  line-height: 1;
  border-radius: 8px;
  transition: all 0.2s;
}
.close:hover { background: var(--border); color: var(--text); }

/* ===== Steps ===== */
.muted { font-size: 12px; color: var(--text-muted); line-height: 1.8; margin: 0; }
.step {
  border-bottom: 1px solid var(--border-light);
  padding: 14px 0;
  font-size: 12px;
  line-height: 1.7;
  animation: fadeInUp 0.3s ease-out both;
  transition: border-color 0.3s;
}
.step:first-child { padding-top: 0; }
.step strong { font-weight: 600; color: var(--text-heading); }
.step p { margin: 7px 0; color: var(--text-muted); }
.step a { font-size: 12px; }

code {
  display: block;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 11px/1.7 ui-monospace, SFMono-Regular, Consolas, monospace;
  padding: 10px 12px;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  margin-top: 6px;
  transition: all 0.3s;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 19px; }
.danger { color: var(--text-danger); }
.error { color: var(--text-danger); font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ===== Toast ===== */
#toast {
  position: fixed;
  bottom: 23px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-toast);
  color: var(--primary-text);
  padding: 11px 20px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transition: opacity 0.3s ease;
}
[data-theme="dark"] #toast { color: #0f172a; }
#toast.show { opacity: 1; animation: toastSlide 0.35s ease-out; }

/* ===== APK Settings ===== */
.apk-settings {
  margin-bottom: 18px;
  animation: fadeInUp 0.5s ease-out 0.25s both;
}
.apk-toggle {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-heading);
  cursor: pointer;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s ease;
}
.apk-toggle::before {
  content: '▸';
  font-size: 11px;
  transition: transform 0.3s ease;
  color: var(--text-muted);
}
details[open] .apk-toggle::before { transform: rotate(90deg); }
.apk-toggle:hover { background: var(--bg-hover); }
.apk-toggle::-webkit-details-marker { display: none; }
details[open] .apk-toggle { border-radius: 12px 12px 0 0; border-bottom-color: var(--border-light); }
.apk-form-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 12px 12px;
  padding: 22px;
  animation: fadeInUp 0.3s ease-out;
  transition: all 0.3s;
}
.apk-row { display: flex; gap: 20px; align-items: flex-start; }
.apk-icon-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; flex-shrink: 0; }
.apk-icon-img {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  border: 1px solid var(--border);
  object-fit: cover;
  background: var(--bg-hover);
  transition: all 0.3s;
}
.apk-icon-img:hover { transform: scale(1.05); box-shadow: var(--shadow-md); }
.apk-icon-label { font-size: 11px; padding: 5px 10px; text-align: center; cursor: pointer; display: inline-block; }
.apk-fields { flex: 1; }
.apk-fields label { margin-top: 0; }
.apk-fields input, .apk-fields select { margin-top: 4px; }
.apk-actions { display: flex; gap: 10px; align-items: center; margin-top: 16px; }
.apk-dl-btn { text-decoration: none; text-align: center; display: inline-block; }

/* ===== Tabs ===== */
.tab-nav { display: flex; gap: 3px; }
.tab-btn {
  border: 0;
  background: transparent;
  padding: 7px 16px;
  font-size: 12px;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  position: relative;
}
.tab-btn:hover { background: var(--bg-hover); color: var(--text); }
.tab-btn.selected {
  background: var(--primary-bg);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(59,130,246,0.2);
}

/* ===== Admin Panel ===== */
.tab-content { padding: 0; }
.admin-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  animation: fadeInUp 0.4s ease-out both;
  transition: all 0.3s ease;
}
.admin-card:nth-child(2) { animation-delay: 0.1s; }
.admin-card:nth-child(3) { animation-delay: 0.2s; }
.admin-card:nth-child(4) { animation-delay: 0.3s; }
.admin-card:hover { box-shadow: var(--shadow-md); }
.admin-card h2 { font-size: 14px; font-weight: 700; color: var(--text-heading); margin: 0 0 14px; }
.pw-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.pw-form input { width: 200px; margin: 0; }
.pw-actions { display: flex; gap: 10px; align-items: center; }
.dev-access-section { margin: 14px 0 6px; border: 1px solid var(--border); border-radius: 8px; padding: 12px; transition: border-color 0.3s; }
.dev-access-title { font-weight: 600; color: var(--text-heading); margin: 0 0 8px; display: block; }
.dev-check { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; margin: 4px 12px 4px 0; color: var(--text-secondary); cursor: pointer; }
.dev-check input { margin: 0; }
.device-access { max-width: 280px; white-space: normal; line-height: 1.6; }
.session-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.2s;
}
.session-item:last-child { border-bottom: 0; }
.sys-info { display: flex; gap: 24px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); }
.sys-info strong { color: var(--text-heading); }

/* ===== Remote Control ===== */
.rc-btn { color: var(--text-rc-btn); font-weight: 600; }
.rc-back-btn { font-size: 13px; font-weight: 500; }
.rc-title { font-size: 13px; display: flex; gap: 8px; align-items: baseline; }
.rc-layout { display: flex; gap: 0; height: calc(100vh - 58px); overflow: hidden; }
.rc-screen-wrap {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-rc-screen);
  padding: 16px;
  position: relative;
}
.rc-screen-img {
  max-height: calc(100vh - 150px);
  max-width: 400px;
  width: auto;
  border-radius: 8px;
  cursor: crosshair;
  user-select: none;
  background: #000;
  min-height: 300px;
  min-width: 200px;
  transition: border-radius 0.3s;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}
.rc-nav-bar { display: flex; gap: 12px; margin-top: 14px; }
.rc-scroll-bar { display: flex; gap: 8px; margin-top: 8px; }
.rc-nav {
  width: 46px;
  height: 38px;
  border: 1px solid #475569;
  border-radius: 8px;
  background: var(--bg-rc-nav);
  color: #94a3b8;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.rc-nav:hover { background: #475569; color: #fff; transform: translateY(-1px); }
.rc-nav:active { transform: translateY(0); }
.rc-sidebar {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  background: var(--bg-rc-sidebar);
  transition: background 0.4s;
}
.rc-section {
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow-sm);
  animation: slideInRight 0.4s ease-out both;
  transition: all 0.3s;
}
.rc-section:nth-child(2) { animation-delay: 0.05s; }
.rc-section:nth-child(3) { animation-delay: 0.1s; }
.rc-section:nth-child(4) { animation-delay: 0.15s; }
.rc-section:nth-child(5) { animation-delay: 0.2s; }
.rc-section h3 { font-size: 13px; font-weight: 700; color: var(--text-heading); margin: 0 0 10px; display: flex; align-items: center; justify-content: space-between; }
.rc-input-row { display: flex; gap: 8px; }
.rc-input-row input { flex: 1; margin: 0; padding: 8px 12px; font-size: 12px; }
.rc-input-row .secondary { flex-shrink: 0; padding: 8px 14px; }
.rc-hint { margin: 0 0 10px; font-size: 11px; }
.rc-kbd-status {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  word-break: break-word;
  min-height: 34px;
  transition: all 0.3s;
}
.rc-camera-img { width: 100%; border-radius: 8px; margin-top: 10px; border: 1px solid var(--border); }
.rc-sms-list { max-height: 400px; overflow-y: auto; }
.sms-item { padding: 10px 0; border-bottom: 1px solid var(--border-light); font-size: 12px; transition: all 0.2s; }
.sms-item:last-child { border-bottom: 0; }
.sms-unread { background: rgba(59,130,246,0.06); border-radius: 6px; padding: 10px 8px; }
.sms-from { font-weight: 600; color: var(--text-heading); display: flex; justify-content: space-between; align-items: center; }
.sms-time { font-weight: 400; color: var(--text-muted); font-size: 10px; }
.sms-body { color: var(--text-secondary); margin-top: 4px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.rc-screen-status { max-width: 300px; margin-top: 8px; color: #94a3b8; font-size: 12px; line-height: 1.45; text-align: center; }
.rc-screen-status.hidden { display: none; }

/* ===== Theme Toggle ===== */
.theme-toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  z-index: 200;
  transition: all 0.35s cubic-bezier(0.4,0,0.2,1);
  line-height: 1;
}
.theme-toggle:hover {
  transform: scale(1.1) rotate(15deg);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}
.theme-toggle:active { transform: scale(0.95); }
.theme-toggle .icon-sun,
.theme-toggle .icon-moon { transition: opacity 0.3s, transform 0.4s; position: absolute; }
.theme-toggle .icon-sun { opacity: 1; transform: rotate(0); }
.theme-toggle .icon-moon { opacity: 0; transform: rotate(-90deg); }
[data-theme="dark"] .theme-toggle .icon-sun { opacity: 0; transform: rotate(90deg); }
[data-theme="dark"] .theme-toggle .icon-moon { opacity: 1; transform: rotate(0); }

/* ===== Safe Area ===== */
@supports (padding: env(safe-area-inset-bottom)) {
  main { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  .theme-toggle { bottom: calc(20px + env(safe-area-inset-bottom)); }
  #toast { bottom: calc(23px + env(safe-area-inset-bottom)); }
  .topbar { padding-left: calc(32px + env(safe-area-inset-left)); padding-right: calc(32px + env(safe-area-inset-right)); }
}

/* ===== Tablet (761–1024px) ===== */
@media (max-width: 1024px) {
  main { padding: 24px 20px 60px; }
  .summary > span { padding: 10px 14px; }
  .summary strong { font-size: 16px; }
  .pw-form { flex-direction: column; align-items: stretch; }
  .pw-form input { width: 100%; }
  .sys-info { gap: 16px; }
  .rc-screen-img { max-width: 340px; }
}

/* ===== Mobile (≤760px) ===== */
@media (max-width: 760px) {
  /* -- Topbar -- */
  .topbar {
    padding: 0 12px;
    gap: 6px;
    height: auto;
    min-height: 48px;
    flex-wrap: wrap;
    padding-top: 6px;
    padding-bottom: 6px;
  }
  .section-name, .top-divider { display: none; }
  .top-actions { gap: 8px; margin-left: auto; }
  .top-actions .server-host { display: none; }
  .wordmark { font-size: 13px; flex-shrink: 0; }
  .tab-nav { gap: 2px; order: 10; width: 100%; justify-content: center; padding-top: 2px; }
  .tab-btn { padding: 7px 14px; font-size: 12px; flex: 1; text-align: center; }
  .plain { padding: 6px 8px; font-size: 11px; }

  /* -- Main -- */
  main { padding: 16px 14px 80px; }
  .page-heading { flex-direction: column; align-items: stretch; gap: 10px; }
  .page-heading .primary { width: 100%; text-align: center; padding: 12px; font-size: 13px; }
  h1 { font-size: 20px; text-align: center; }
  .page-heading p { font-size: 11px; text-align: center; }

  /* -- Summary stats: 2x2 grid -- */
  .summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .summary > span {
    padding: 10px 8px;
    font-size: 11px;
    justify-content: center;
    text-align: center;
    flex-direction: column;
    gap: 2px;
  }
  .summary strong { font-size: 16px; display: block; }

  /* -- Devices table → card layout -- */
  .device-list .table-wrap table thead { display: none; }
  .device-list .table-wrap table,
  .device-list .table-wrap table tbody { display: block; width: 100%; }
  .device-list .table-wrap table tr {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
    gap: 6px 10px;
    padding: 14px 14px;
    border-bottom: 1px solid var(--border-light);
    align-items: center;
  }
  .device-list .table-wrap table tr:last-child { border-bottom: 0; }
  .device-list .table-wrap table td { padding: 0; border: 0; white-space: normal; font-size: 12px; }
  /* Row 1: device name + status badge */
  .device-list .table-wrap td:nth-child(1) { grid-column: 1; grid-row: 1; font-weight: 600; }
  .device-list .table-wrap td:nth-child(2) { grid-column: 2; grid-row: 1; text-align: right; display: flex; justify-content: flex-end; align-items: center; }
  /* Row 2: network + IP */
  .device-list .table-wrap td:nth-child(3) { grid-column: 1; grid-row: 2; font-size: 11px; color: var(--text-muted); }
  .device-list .table-wrap td:nth-child(3)::before { content: 'Сеть: '; color: var(--text-muted); }
  .device-list .table-wrap td:nth-child(4) { grid-column: 2; grid-row: 2; text-align: right; font-size: 11px; color: var(--text-muted); }
  /* Row 3: proxy address hidden, stats + actions */
  .device-list .table-wrap td:nth-child(5) { display: none; }
  .device-list .table-wrap td:nth-child(6) { display: none; }
  .device-list .table-wrap td:nth-child(7) { display: none; }
  .device-list .table-wrap td:nth-child(8) {
    grid-column: 1 / -1;
    grid-row: 3;
    display: flex;
    gap: 6px;
    margin-top: 2px;
    justify-content: flex-start;
  }
  .device-list .table-wrap td:nth-child(8) .text-button {
    padding: 7px 14px;
    background: var(--bg-hover);
    border-radius: 8px;
    font-size: 12px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  /* -- Admin users table → card layout -- */
  #admin-panel .table-wrap table thead { display: none; }
  #admin-panel .table-wrap table,
  #admin-panel .table-wrap table tbody { display: block; width: 100%; }
  #admin-panel .table-wrap table tr {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 4px 10px;
    padding: 14px 4px;
    border-bottom: 1px solid var(--border-light);
  }
  #admin-panel .table-wrap table tr:last-child { border-bottom: 0; }
  #admin-panel .table-wrap table td { padding: 0; border: 0; white-space: normal; }
  /* Login + Role */
  #admin-panel td:nth-child(1) { grid-column: 1; grid-row: 1; font-weight: 600; }
  #admin-panel td:nth-child(3) { grid-column: 2; grid-row: 1; text-align: right; }
  /* Name */
  #admin-panel td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; font-size: 11px; color: var(--text-muted); }
  /* Devices */
  #admin-panel td:nth-child(4) { grid-column: 1 / -1; grid-row: 3; font-size: 11px; }
  /* Last login */
  #admin-panel td:nth-child(5) { grid-column: 1; grid-row: 4; font-size: 10px; color: var(--text-muted); }
  /* Actions */
  #admin-panel td:nth-child(6) {
    grid-column: 2;
    grid-row: 4;
    display: flex;
    gap: 6px;
    justify-content: flex-end;
  }
  #admin-panel td:nth-child(6) .text-button {
    padding: 7px 12px;
    background: var(--bg-hover);
    border-radius: 8px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  /* -- Toolbar / Filters -- */
  .toolbar { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
  .search-label { width: 100%; margin: 0; order: -1; }
  .search-label input { padding: 10px 12px; font-size: 13px; border-radius: 10px; }
  .filters { width: 100%; display: flex; }
  .filter { flex: 1; text-align: center; padding: 9px 6px; font-size: 12px; }

  /* -- APK form -- */
  .apk-row { flex-direction: column; gap: 14px; }
  .apk-icon-wrap { flex-direction: row; gap: 12px; align-items: center; }
  .apk-icon-img { width: 56px; height: 56px; border-radius: 12px; }
  .apk-actions { flex-direction: column; align-items: stretch; gap: 8px; }
  .apk-actions .primary,
  .apk-actions .secondary { width: 100%; text-align: center; padding: 12px; }
  .apk-form-wrap { padding: 14px; }
  .apk-toggle { padding: 12px 14px; }

  /* -- Buttons: bigger touch targets -- */
  .primary, .secondary { padding: 11px 16px; font-size: 13px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
  .text-button { padding: 8px 12px; font-size: 12px; min-height: 36px; }

  /* -- Empty state -- */
  .empty { padding: 48px 16px; }
  .empty h2 { font-size: 15px; }
  .empty .secondary { padding: 10px 16px; font-size: 12px; min-height: 44px; }

  /* -- List footer -- */
  .list-footer { padding: 10px 12px; gap: 4px; flex-direction: column; align-items: center; text-align: center; }

  /* -- Dialog: nearly fullscreen on phone -- */
  dialog { width: calc(100% - 16px); max-height: 90vh; overflow-y: auto; padding: 18px 16px; border-radius: 14px; }
  dialog .actions { flex-direction: column; gap: 8px; }
  dialog .actions .primary,
  dialog .actions .secondary { width: 100%; }

  /* -- Password form -- */
  .pw-form { flex-direction: column; align-items: stretch; gap: 10px; }
  .pw-form input { width: 100%; }
  .pw-actions { flex-direction: column; align-items: stretch; gap: 8px; }

  /* -- Admin cards -- */
  .admin-card { padding: 14px; margin-bottom: 12px; border-radius: 10px; }
  .admin-card h2 { font-size: 14px; margin-bottom: 12px; }

  /* -- Sessions -- */
  .session-item { flex-wrap: wrap; gap: 6px; padding: 10px 0; }

  /* -- System info -- */
  .sys-info { flex-direction: column; gap: 6px; }

  /* -- Notes -- */
  .note { font-size: 11px; text-align: center; }

  /* -- RC: stacked layout -- */
  .rc-layout { flex-direction: column; height: auto; min-height: calc(100vh - 52px); overflow-y: auto; }
  .rc-screen-wrap { padding: 8px; flex: 0 0 auto; }
  .rc-screen-img { max-width: 100%; max-height: 55vh; min-height: 200px; min-width: 0; width: 100%; object-fit: contain; }
  .rc-nav-bar { margin-top: 10px; gap: 10px; }
  .rc-nav { width: 52px; height: 42px; font-size: 18px; }
  .rc-sidebar { padding: 10px; flex: 0 0 auto; }
  .rc-section { padding: 14px; margin-bottom: 10px; }
  .rc-input-row { flex-direction: column; gap: 8px; }
  .rc-input-row input { font-size: 14px; padding: 10px 12px; }
  .rc-input-row .secondary { width: 100%; padding: 10px; }
  .rc-back-btn { font-size: 12px; }
  .rc-title { font-size: 12px; }
  .rc-title .muted { display: none; }

  /* -- Theme toggle -- */
  .theme-toggle { bottom: 16px; right: 16px; width: 42px; height: 42px; font-size: 18px; }

  /* -- Login -- */
  .login { padding: 16px; }
  .login-form { padding: 24px 20px; border-radius: 14px; }
  .login-form h1 { font-size: 20px; margin-bottom: 18px; }
  .login-form .primary { padding: 12px; font-size: 14px; min-height: 46px; }
  .login-form input { padding: 11px 12px; font-size: 14px; }
}

/* ===== Small phones (≤380px) ===== */
@media (max-width: 380px) {
  .topbar { padding: 0 12px; gap: 6px; }
  .wordmark { font-size: 12px; }
  .tab-btn { padding: 5px 8px; font-size: 10px; }
  main { padding: 12px 12px 80px; }
  h1 { font-size: 18px; }
  .summary { grid-template-columns: 1fr 1fr; gap: 6px; }
  .summary > span { padding: 8px 10px; font-size: 10px; }
  .summary strong { font-size: 14px; }
  .device-list .table-wrap table tr { padding: 12px; }
  dialog { width: calc(100% - 8px); padding: 14px 12px; }
  .rc-nav { width: 48px; height: 40px; }
}

/* ===== Smooth All Transitions ===== */
*, *::before, *::after {
  transition-property: background-color, border-color, color, box-shadow, opacity;
  transition-duration: 0.3s;
  transition-timing-function: ease;
}
button, a, input, select, .badge, .rc-nav, .primary, .secondary, .filter, .tab-btn, .plain, .text-button, .close, .theme-toggle {
  transition: all 0.25s cubic-bezier(0.4,0,0.2,1);
}
