* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2d3148;
  --text: #e4e6f0;
  --text-dim: #8b8fa8;
  --accent: #6c5ce7;
  --accent-glow: rgba(108, 92, 231, 0.3);
  --green: #00d68f;
  --red: #ff6b6b;
  --yellow: #ffd93d;
  --blue: #4da6ff;
  --radius: 12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
}

/* ========== HEADER ========== */
header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo span {
  background: linear-gradient(135deg, var(--accent), var(--blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stats {
  flex: 1;
  color: var(--text-dim);
  font-size: 14px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* ========== BUTTONS ========== */
.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-warn:hover {
  background: var(--red);
  border-color: var(--red);
}

.btn-green {
  background: var(--green);
  color: #000;
  border-color: var(--green);
}

.btn-green:hover {
  opacity: 0.9;
}

/* ========== DEVICE GRID ========== */
main {
  padding: 24px;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
}

.device-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
  transform: translateY(-2px);
}

.device-card.offline {
  opacity: 0.5;
}

.device-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--green);
}

.device-card.offline::before {
  background: var(--red);
}

.device-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.device-name {
  font-weight: 600;
  font-size: 16px;
}

.device-status {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-online {
  background: rgba(0, 214, 143, 0.15);
  color: var(--green);
}

.status-offline {
  background: rgba(255, 107, 107, 0.15);
  color: var(--red);
}

.device-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.device-info span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.device-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ========== MODAL ========== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 95vw;
  max-width: 1000px;
  height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.modal-close:hover {
  background: var(--surface2);
  color: var(--text);
}

/* ========== TABS ========== */
.modal-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  padding: 8px 16px;
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 8px;
  font-size: 13px;
  white-space: nowrap;
  transition: all 0.2s;
}

.tab:hover {
  background: var(--surface2);
  color: var(--text);
}

.tab.active {
  background: var(--accent);
  color: #fff;
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
}

/* ========== TERMINAL ========== */
.terminal-output {
  flex: 1;
  background: #0a0c10;
  border-radius: 8px;
  padding: 12px;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  overflow-y: auto;
  min-height: 300px;
  max-height: 50vh;
}

.term-line {
  white-space: pre-wrap;
  word-break: break-all;
}

.term-cmd {
  color: var(--green);
}

.term-cmd::before {
  content: '$ ';
  color: var(--accent);
}

.term-output {
  color: var(--text-dim);
}

.term-error {
  color: var(--red);
}

.term-info {
  color: var(--blue);
  font-style: italic;
}

.term-waiting {
  color: var(--yellow);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

.terminal-input-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
}

.prompt {
  color: var(--accent);
  font-family: monospace;
  font-weight: 700;
  font-size: 15px;
}

.terminal-input-row input {
  flex: 1;
  background: #0a0c10;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-family: monospace;
  font-size: 13px;
}

.terminal-input-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.quick-commands {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.quick-commands button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-dim);
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.2s;
}

.quick-commands button:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* ========== LIVE VIEW ========== */
.liveview-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.liveview-status {
  color: var(--text-dim);
  font-size: 13px;
  margin-left: auto;
}

.liveview-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #0a0c10;
  border-radius: 8px;
  position: relative;
  min-height: 400px;
  overflow: hidden;
}

#liveviewImage {
  max-width: 100%;
  max-height: 100%;
  display: none;
  border-radius: 4px;
}

.liveview-placeholder {
  text-align: center;
  color: var(--text-dim);
  font-size: 48px;
}

.liveview-placeholder div:last-child {
  font-size: 14px;
  margin-top: 12px;
}

/* ========== FILE BROWSER ========== */
.file-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}

.file-toolbar input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-family: monospace;
  font-size: 13px;
}

.file-toolbar input:focus {
  outline: none;
  border-color: var(--accent);
}

.file-list {
  flex: 1;
  background: #0a0c10;
  border-radius: 8px;
  overflow-y: auto;
  min-height: 200px;
  max-height: 45vh;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(45, 49, 72, 0.4);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s;
}

.file-item:hover {
  background: var(--surface2);
}

.file-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.file-name {
  flex: 1;
  font-family: monospace;
}

.file-size {
  color: var(--text-dim);
  font-size: 12px;
}

.file-perms {
  color: var(--text-dim);
  font-size: 11px;
  font-family: monospace;
}

.file-empty {
  padding: 30px;
  text-align: center;
  color: var(--text-dim);
}

.file-editor-area {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
}

.file-editor-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface2);
  border-radius: 8px 8px 0 0;
  font-family: monospace;
  font-size: 13px;
  color: var(--accent);
}

.file-editor-header .btn {
  margin-left: auto;
}

#fileEditor {
  width: 100%;
  min-height: 200px;
  max-height: 30vh;
  background: #0a0c10;
  color: var(--text);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 12px;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
}

#fileEditor:focus {
  outline: none;
  border-color: var(--accent);
}

/* ========== APPS ========== */
.apps-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.app-list {
  flex: 1;
  background: #0a0c10;
  border-radius: 8px;
  overflow-y: auto;
  max-height: 55vh;
}

.app-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(45, 49, 72, 0.4);
  font-size: 13px;
  font-family: monospace;
}

.app-item button {
  padding: 3px 8px;
  border: 1px solid var(--red);
  background: none;
  color: var(--red);
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  margin-left: auto;
}

.app-item button:hover {
  background: var(--red);
  color: #fff;
}

/* ========== APK UPLOAD ========== */
.apk-upload-section {
  margin-bottom: 12px;
}

.apk-upload-area {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  background: rgba(108, 92, 231, 0.03);
}

.apk-upload-area:hover,
.apk-upload-area.drag-over {
  border-color: var(--accent);
  background: rgba(108, 92, 231, 0.08);
  box-shadow: 0 0 20px var(--accent-glow);
}

.upload-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.upload-text {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 4px;
}

.upload-hint {
  font-size: 12px;
  color: var(--text-dim);
}

.upload-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--surface2);
  border-radius: 8px;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}

.progress-text {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

.apk-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.apk-list {
  background: #0a0c10;
  border-radius: 8px;
  max-height: 180px;
  overflow-y: auto;
}

.apk-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(45, 49, 72, 0.4);
}

.apk-icon {
  font-size: 20px;
}

.apk-info {
  flex: 1;
}

.apk-name {
  font-family: monospace;
  font-size: 13px;
}

.apk-meta {
  font-size: 11px;
  color: var(--text-dim);
}

.apk-install-status {
  padding: 8px 12px;
  font-size: 13px;
  text-align: center;
  animation: pulse 1.5s infinite;
}

/* ========== INFO ========== */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.info-item {
  background: var(--surface2);
  border-radius: 8px;
  padding: 14px;
}

.info-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.info-value {
  font-size: 16px;
  font-weight: 600;
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .device-grid {
    grid-template-columns: 1fr;
  }

  .modal {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .header-actions {
    display: none;
  }
}

/* ========== QUICK COMMAND CATEGORIES ========== */
.quick-cmd-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  max-height: 180px;
  overflow-y: auto;
  padding: 4px;
}

.cmd-category {
  flex: 1;
  min-width: 160px;
}

.cmd-cat-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
  padding-left: 2px;
}

.cmd-category .quick-commands {
  margin-top: 0;
}

/* ========== DEVICE CONTROLS (Live View) ========== */
.liveview-main {
  display: flex;
  gap: 12px;
  flex: 1;
  min-height: 0;
}

.liveview-main .liveview-container {
  flex: 1;
}

.device-controls {
  width: 160px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding: 4px;
}

.ctrl-section {
  background: var(--surface2);
  border-radius: 8px;
  padding: 8px;
}

.ctrl-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  text-align: center;
}

.ctrl-row {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.ctrl-row-wrap {
  flex-wrap: wrap;
}

.ctrl-btn {
  width: 40px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.ctrl-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.05);
}

.ctrl-btn:active {
  transform: scale(0.95);
  background: var(--green);
}

.ctrl-home {
  width: 48px;
  background: var(--surface2);
  border-color: var(--accent);
}

.ctrl-wide {
  width: auto;
  font-size: 11px;
  padding: 4px 6px;
  flex: 1;
  min-width: 60px;
}

.ctrl-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  justify-items: center;
}

.ctrl-grid .ctrl-btn {
  width: 36px;
  height: 32px;
  font-size: 14px;
}

@media (max-width: 900px) {
  .liveview-main {
    flex-direction: column;
  }

  .device-controls {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    overflow-x: auto;
  }

  .ctrl-section {
    min-width: 140px;
  }
}

/* ========== USER BADGE & LOGOUT ========== */
.user-badge {
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 10px;
  background: var(--surface2);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.btn-logout {
  background: rgba(239, 68, 68, 0.15) !important;
  border-color: rgba(239, 68, 68, 0.3) !important;
  color: #ff6b6b !important;
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.3) !important;
}

/* ========== MAIN TABS ========== */
.main-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface2);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.main-tab {
  padding: 6px 16px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.main-tab:hover {
  color: var(--text);
  background: rgba(108, 92, 231, 0.1);
}

.main-tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(108, 92, 231, 0.4);
}

/* ========== ANDROID TOOLBAR ========== */
.android-toolbar {
  display: flex;
  gap: 8px;
  padding: 0 20px 12px;
}

/* ========== MC TAB ========== */
.mc-tab {
  padding: 16px 20px;
}

.mc-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.mc-status {
  font-size: 13px;
  color: var(--text-dim);
}

.mc-content {
  min-height: 200px;
}

.mc-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

.mc-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface2);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.mc-group-stats {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dim);
  background: var(--surface);
  padding: 2px 8px;
  border-radius: 4px;
}

.mc-group-devices {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1px;
  background: var(--border);
}

.mc-device-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  cursor: pointer;
  transition: background 0.15s;
}

.mc-device-card:hover {
  background: var(--surface2);
}

.mc-dev-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.mc-dev-status.online {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.mc-dev-status.offline {
  background: #555;
}

.mc-dev-info {
  min-width: 0;
}

.mc-dev-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mc-online .mc-dev-name {
  color: var(--text);
}

.mc-offline .mc-dev-name {
  color: var(--text-dim);
}

.mc-dev-os {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mc-loading,
.mc-empty,
.mc-error {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
  font-size: 14px;
}

.mc-error {
  color: var(--red);
}