/* ── Reset & Variables ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0a0c10;
  --bg2:      #111318;
  --bg3:      #181c24;
  --bg4:      #1f2430;
  --border:   #252b38;
  --accent:   #3ecf8e;
  --accent2:  #3b82f6;
  --danger:   #f43f5e;
  --warn:     #f59e0b;
  --text:     #dde3f0;
  --muted:    #6b7694;
  --faint:    #323849;
  --mono:     'JetBrains Mono', monospace;
  --sans:     'DM Sans', sans-serif;
  --r:        5px;
  --sw:       240px;
}

html, body { height: 100%; overflow: hidden; }
body { font-family: var(--sans); background: var(--bg); color: var(--text); font-size: 14px; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sw); flex-shrink: 0;
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}

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

.logo { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.version-badge { background: var(--accent); color: #000; font-size: 9px; font-weight: 700; padding: 1px 5px; border-radius: 3px; }

.sidebar-label { font-size: 10px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); padding: 12px 16px 6px; }

#device-list { flex: 1; overflow-y: auto; }

.device-item { padding: 10px 16px; cursor: pointer; border-left: 2px solid transparent; transition: all 0.12s; }
.device-item:hover  { background: var(--bg3); border-left-color: var(--muted); }
.device-item.active { background: var(--bg3); border-left-color: var(--accent); }

.di-name   { font-size: 13px; font-weight: 500; }
.di-serial { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 2px; }
.di-meta   { font-size: 11px; color: var(--accent); margin-top: 2px; display: flex; gap: 8px; }

.stream-indicator { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent); animation: pulse 1.5s ease-in-out infinite; margin-left: 4px; }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:0.3;} }

.empty-state { padding: 18px 16px; font-size: 13px; color: var(--muted); }

.sidebar-footer { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot.online  { background: var(--accent); box-shadow: 0 0 5px var(--accent); }
.dot.offline { background: var(--danger); }

/* ── Main ────────────────────────────────────────────────────────────────── */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.hidden { display: none !important; }

/* ── Splash ──────────────────────────────────────────────────────────────── */
#no-device { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 40px; }
.splash-icon { font-size: 52px; opacity: 0.2; }
#no-device h2 { font-size: 22px; font-weight: 500; }
#no-device p  { color: var(--muted); line-height: 1.7; }
.steps { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.step-item { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.step-num { width: 24px; height: 24px; border-radius: 50%; background: var(--bg3); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: var(--accent); flex-shrink: 0; }

/* ── Device panel ────────────────────────────────────────────────────────── */
#device-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }

/* ── Topbar ──────────────────────────────────────────────────────────────── */
#topbar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--bg2); border-bottom: 1px solid var(--border); flex-wrap: wrap; flex-shrink: 0; }
#topbar-left { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
#dev-name    { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#dev-meta-row { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.meta-sep { color: var(--faint); }

#topbar-badges { display: flex; gap: 5px; flex-wrap: wrap; }
.badge { background: var(--bg3); border: 1px solid var(--border); padding: 2px 7px; border-radius: 20px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.stream-badge.live     { color: var(--accent); border-color: var(--accent); }
.stream-badge.fallback { color: var(--warn);   border-color: var(--warn); }

#topbar-keys { display: flex; gap: 4px; }
.key-btn { background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 4px 9px; border-radius: var(--r); cursor: pointer; font-size: 13px; transition: all 0.12s; white-space: nowrap; }
.key-btn:hover        { border-color: var(--accent); color: var(--accent); }
.key-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
#tabs { display: flex; background: var(--bg2); border-bottom: 1px solid var(--border); padding: 0 12px; flex-shrink: 0; overflow-x: auto; }
.tab { background: none; border: none; border-bottom: 2px solid transparent; color: var(--muted); padding: 9px 12px; font-size: 13px; font-family: var(--sans); cursor: pointer; transition: all 0.12s; white-space: nowrap; }
.tab:hover  { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-pane        { display: none; flex: 1; overflow: hidden; flex-direction: column; min-height: 0; }
.tab-pane.active { display: flex; }

/* ── Screen tab ──────────────────────────────────────────────────────────── */
#screen-layout { display: flex; flex-direction: column; height: 100%; min-height: 0; }

#stream-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 14px; background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0; }

.ctrl-group { display: flex; flex-direction: column; gap: 2px; }
.ctrl-label { font-size: 10px; color: var(--muted); font-weight: 500; }
#stream-controls select { background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 4px 8px; border-radius: var(--r); font-size: 12px; }

.start-btn { background: var(--accent); color: #000; border: none; padding: 7px 14px; border-radius: var(--r); cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap; }
.start-btn:hover { opacity: 0.85; }
.stop-btn  { background: var(--bg3); border: 1px solid var(--danger); color: var(--danger); padding: 7px 14px; border-radius: var(--r); cursor: pointer; font-size: 13px; white-space: nowrap; }
.stop-btn:hover { background: var(--danger); color: #fff; }

.stream-stats { font-size: 11px; color: var(--muted); font-family: var(--mono); }

#clipboard-row { display: flex; gap: 6px; flex: 1; min-width: 200px; }
#clipboard-input { flex: 1; background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 5px 10px; border-radius: var(--r); font-size: 12px; font-family: var(--mono); }
#clipboard-send  { background: var(--bg3); border: 1px solid var(--border); color: var(--muted); padding: 5px 10px; border-radius: var(--r); cursor: pointer; font-size: 12px; white-space: nowrap; }
#clipboard-send:hover { border-color: var(--accent2); color: var(--accent2); }

/* Screen body */
#screen-body { display: flex; flex: 1; min-height: 0; overflow: hidden; }

/* Side buttons */
#side-buttons { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 5px; background: var(--bg2); border-right: 1px solid var(--border); width: 46px; flex-shrink: 0; overflow-y: auto; }

.side-btn { background: none; border: none; color: var(--muted); font-size: 16px; width: 34px; height: 34px; border-radius: var(--r); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.12s; flex-shrink: 0; }
.side-btn:hover   { background: var(--bg3); color: var(--text); }
.side-btn.active  { color: var(--accent); }
.side-btn.recording { color: var(--danger); animation: pulse 1s infinite; }

.side-group-label { font-size: 8px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); text-align: center; margin-top: 4px; }
.side-divider { width: 28px; height: 1px; background: var(--border); margin: 4px 0; flex-shrink: 0; }

/* Video main */
#video-main { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; }

#video-wrap { flex: 1; display: flex; align-items: center; justify-content: center; background: #050608; overflow: hidden; position: relative; min-height: 0; }

#video-el  { max-width: 100%; max-height: 100%; object-fit: contain; cursor: crosshair; display: block; }
#video-img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: crosshair; }

#video-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #050608; transition: opacity 0.3s; }
#video-overlay.hidden { opacity: 0; pointer-events: none; }
#video-msg { color: var(--muted); font-size: 13px; }

/* Android nav buttons */
#android-buttons { display: flex; justify-content: center; align-items: center; gap: 44px; padding: 12px; background: #0a0c10; border-top: 1px solid var(--border); flex-shrink: 0; }
.android-btn { background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: all 0.12s; opacity: 0.65; }
.android-btn:hover  { background: var(--bg3); opacity: 1; }
.android-btn:active { transform: scale(0.9); }

#audio-bar { padding: 5px 14px; background: rgba(62,207,142,0.08); border-top: 1px solid rgba(62,207,142,0.2); font-size: 12px; color: var(--accent); text-align: center; flex-shrink: 0; }

/* ── Shell tab ───────────────────────────────────────────────────────────── */
#shell-wrap { display: flex; flex-direction: column; height: 100%; }
#shell-out  { flex: 1; overflow-y: auto; padding: 12px 14px; font-family: var(--mono); font-size: 12px; line-height: 1.7; background: #060709; white-space: pre-wrap; word-break: break-all; }
.sh-cmd { color: var(--accent); }
.sh-out { color: #98a8c5; }
.sh-err { color: var(--danger); }

#shell-quick { display: flex; flex-wrap: wrap; gap: 5px; padding: 8px 14px; border-top: 1px solid var(--border); background: var(--bg2); flex-shrink: 0; }
.qb { background: var(--bg3); border: 1px solid var(--border); color: var(--muted); padding: 3px 9px; border-radius: 20px; cursor: pointer; font-size: 11px; font-family: var(--mono); transition: all 0.12s; }
.qb:hover { border-color: var(--accent2); color: var(--accent2); }

#shell-input-row { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--border); background: var(--bg2); flex-shrink: 0; }
.ps1 { font-family: var(--mono); color: var(--accent); font-size: 15px; }
#shell-in { flex: 1; background: none; border: none; color: var(--text); font-family: var(--mono); font-size: 13px; outline: none; }
#shell-run   { background: var(--accent); color: #000; border: none; padding: 5px 12px; border-radius: var(--r); cursor: pointer; font-weight: 600; font-size: 12px; }
#shell-clear { background: var(--bg3); border: 1px solid var(--border); color: var(--muted); padding: 5px 9px; border-radius: var(--r); cursor: pointer; font-size: 12px; }
#shell-clear:hover { border-color: var(--danger); color: var(--danger); }

/* ── Apps tab ────────────────────────────────────────────────────────────── */
#apps-wrap { display: flex; flex-direction: column; height: 100%; }
#apps-bar  { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 14px; background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0; }
#apps-search { flex: 1; min-width: 150px; background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 5px 10px; border-radius: var(--r); font-size: 13px; }
#apps-reload, .upload-lbl { background: var(--bg3); border: 1px solid var(--border); color: var(--muted); padding: 5px 10px; border-radius: var(--r); cursor: pointer; font-size: 12px; white-space: nowrap; transition: all 0.12s; }
#apps-reload:hover, .upload-lbl:hover { border-color: var(--accent); color: var(--accent); }
.toggle-chip { display: flex; align-items: center; gap: 5px; background: var(--bg3); border: 1px solid var(--border); padding: 4px 9px; border-radius: 20px; cursor: pointer; font-size: 12px; color: var(--muted); }
.toggle-chip input { accent-color: var(--accent); }
#apps-progress { padding: 8px 14px; font-size: 13px; color: var(--accent); border-bottom: 1px solid var(--border); flex-shrink: 0; }
#apps-list { flex: 1; overflow-y: auto; }
.app-row { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--border); font-size: 12px; font-family: var(--mono); transition: background 0.1s; }
.app-row:hover { background: var(--bg3); }
.app-pkg  { flex: 1; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-btns { display: flex; gap: 5px; flex-shrink: 0; }
.app-btn  { background: var(--bg3); border: 1px solid var(--border); color: var(--muted); padding: 3px 8px; border-radius: var(--r); cursor: pointer; font-size: 11px; transition: all 0.12s; }
.app-btn:hover      { border-color: var(--accent2); color: var(--accent2); }
.app-btn.del:hover  { border-color: var(--danger);  color: var(--danger); }
.app-btn.stop:hover { border-color: var(--warn);    color: var(--warn); }

/* ── Files tab ───────────────────────────────────────────────────────────── */
#files-wrap { display: flex; flex-direction: column; height: 100%; }
#files-bar  { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0; }
#files-up, #files-refresh { background: var(--bg3); border: 1px solid var(--border); color: var(--muted); padding: 5px 10px; border-radius: var(--r); cursor: pointer; font-size: 13px; transition: all 0.12s; }
#files-up:hover, #files-refresh:hover { border-color: var(--accent); color: var(--accent); }
#files-path { flex: 1; font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#files-list { flex: 1; overflow-y: auto; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--border); font-size: 12px; cursor: pointer; transition: background 0.1s; }
.file-row:hover { background: var(--bg3); }
.file-icon { font-size: 14px; flex-shrink: 0; }
.file-name { flex: 1; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--muted); font-family: var(--mono); font-size: 11px; flex-shrink: 0; }
.file-date { color: var(--faint); font-size: 11px; flex-shrink: 0; }
.file-dl   { background: var(--bg3); border: 1px solid var(--border); color: var(--muted); padding: 2px 7px; border-radius: var(--r); cursor: pointer; font-size: 11px; flex-shrink: 0; }
.file-dl:hover { border-color: var(--accent2); color: var(--accent2); }

#files-upload-area { padding: 12px 14px; border-top: 1px solid var(--border); background: var(--bg2); flex-shrink: 0; }
#files-drop-zone { border: 2px dashed var(--border); border-radius: var(--r); padding: 16px; text-align: center; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; transition: all 0.15s; }
#files-drop-zone:hover, #files-drop-zone.over { border-color: var(--accent); background: rgba(62,207,142,0.04); }
.drop-icon { font-size: 20px; }
#files-drop-zone p { font-size: 12px; color: var(--muted); }
#files-upload-status { font-size: 12px; color: var(--muted); font-family: var(--mono); margin-top: 6px; }

/* ── Stats tab ───────────────────────────────────────────────────────────── */
#stats-wrap { display: flex; flex-direction: column; height: 100%; overflow: auto; padding: 16px; gap: 16px; }
#stats-header { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
#stats-refresh { background: var(--bg3); border: 1px solid var(--border); color: var(--muted); padding: 6px 12px; border-radius: var(--r); cursor: pointer; font-size: 12px; }
#stats-refresh:hover { border-color: var(--accent); color: var(--accent); }
#stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--r); padding: 14px; }
.stat-title { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.stat-body  { font-family: var(--mono); font-size: 11px; color: var(--text); white-space: pre-wrap; line-height: 1.7; }

/* ── Logcat tab ──────────────────────────────────────────────────────────── */
#logcat-wrap { display: flex; flex-direction: column; height: 100%; }
#logcat-bar  { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap; }
#logcat-filter { flex: 1; min-width: 120px; background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 5px 10px; border-radius: var(--r); font-size: 13px; }
#logcat-level, #logcat-lines { background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 5px 8px; border-radius: var(--r); font-size: 12px; }
#logcat-fetch, #logcat-clear { background: var(--bg3); border: 1px solid var(--border); color: var(--muted); padding: 5px 10px; border-radius: var(--r); cursor: pointer; font-size: 12px; transition: all 0.12s; }
#logcat-fetch:hover { border-color: var(--accent); color: var(--accent); }
#logcat-clear:hover { border-color: var(--danger); color: var(--danger); }
#logcat-out { flex: 1; overflow-y: auto; padding: 12px 14px; font-family: var(--mono); font-size: 11px; line-height: 1.7; white-space: pre-wrap; word-break: break-all; background: #060709; }
.lV { color: #444; } .lD { color: var(--muted); } .lI { color: #60a5fa; } .lW { color: var(--warn); } .lE { color: var(--danger); font-weight: 500; } .lF { color: #ff1744; font-weight: 700; }

/* ── Shared ──────────────────────────────────────────────────────────────── */
input:focus, select:focus { outline: 1px solid var(--accent); outline-offset: -1px; }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--muted); width: 28px; height: 28px; border-radius: var(--r); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 15px; transition: all 0.12s; }
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.mono { font-family: var(--mono); }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast { position: fixed; bottom: 20px; right: 20px; background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 9px 14px; border-radius: var(--r); font-size: 13px; pointer-events: none; opacity: 0; transform: translateY(8px); transition: all 0.2s; z-index: 9999; max-width: 320px; }
#toast.show { opacity: 1; transform: translateY(0); }
#toast.ok   { border-color: var(--accent); }
#toast.err  { border-color: var(--danger); }
#toast.warn { border-color: var(--warn); }

/* ── Scrollbars ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--faint); border-radius: 3px; }
