/* ─── Variables ──────────────────────────────────────────────────────────── */
:root {
  --bg:          #080d08;
  --surface:     #0f180f;
  --surface2:    #152015;
  --surface3:    #1a2a1a;
  --border:      #1e3520;
  --accent:      #22c55e;
  --accent-dim:  #16a34a;
  --accent-glow: rgba(34, 197, 94, 0.15);
  --text:        #e2e8f0;
  --text-muted:  #6b8f6b;
  --success:     #4ade80;
  --error:       #f87171;
  --radius:      8px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

/* ─── Pairing Screen ─────────────────────────────────────────────────────── */
#pair-screen {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #0f1f0f 0%, var(--bg) 70%);
  overflow: auto;
}

#pair-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 48px 48px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 0 60px rgba(34, 197, 94, 0.07);
  width: 100%;
  max-width: 520px;
  text-align: center;
}

#pair-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

.pair-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
  max-width: 280px;
}

#pair-code-input {
  width: 100%;
  font-size: 2rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: 0.2em;
  text-align: center;
  padding: 16px 12px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

#pair-code-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#pair-code-input::placeholder { color: var(--surface3); letter-spacing: 0.15em; }

#pair-card button {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

#pair-card button:hover  { background: #16a34a; }
#pair-card button:active { transform: scale(0.98); }

#pair-error {
  min-height: 1.2em;
  color: var(--error);
  font-size: 0.85rem;
}

.btn-text-link,
#pair-card .btn-text-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 400;
  cursor: pointer;
  padding: 0;
  width: auto;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color 0.15s;
}
.btn-text-link:hover,
#pair-card .btn-text-link:hover { color: var(--accent); background: none; transform: none; }

#remember-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
#remember-label input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
}


/* ─── Main App ───────────────────────────────────────────────────────────── */
#main-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

#header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

#header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#device-name-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ─── Status badge ───────────────────────────────────────────────────────── */
.status {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.status.online  { background: rgba(34,197,94,0.12); color: var(--success); }
.status.offline { background: rgba(248,113,113,0.1); color: var(--error); }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
button {
  background: var(--accent-dim);
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  transition: background 0.15s;
}
button:hover    { background: var(--accent); color: #000; }
button:disabled { background: var(--surface3); color: var(--text-muted); cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 5px 12px;
}
.btn-ghost:hover { background: var(--surface3); color: var(--text); border-color: var(--accent); }
.btn-danger { border-color: #dc2626; color: #dc2626; }
.btn-danger:hover { background: rgba(220,38,38,0.1); border-color: #dc2626; color: #dc2626; }

.btn-sm {
  padding: 3px 10px;
  font-size: 0.75rem;
  margin-left: 8px;
}

/* ─── Inputs ─────────────────────────────────────────────────────────────── */
input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 11px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus { border-color: var(--accent); }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
main {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
  position: relative;
}

/* ─── Offline overlay ────────────────────────────────────────────────────── */
#offline-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg);
  color: var(--error);
}
.offline-title {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: 0.15em;
}
.offline-sub {
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* ─── Control section (LEFT, fills remaining space) ──────────────────────── */
#control-section {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-right: 1px solid var(--border);
  background: var(--bg);
}

/* ─── Screen section (RIGHT, fixed max width) ────────────────────────────── */
#screen-section {
  width: 480px;
  max-width: 480px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;  /* column so flex:1 on child controls HEIGHT */
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--surface);
  overflow: hidden;
}

#screen-container {
  /* flex:1 fills available height; aspect-ratio derives width from that height */
  flex: 1;
  min-height: 0;
  aspect-ratio: 9 / 16;   /* default portrait; JS updates to actual phone ratio */
  max-width: 100%;
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
}

#screen-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

#screen-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.82rem;
  pointer-events: none;
}

#screen-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.control-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.group-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  display: flex;
  align-items: center;
}

/* ─── Group row (two control-groups side by side) ───────────────────────── */
.group-row {
  display: flex;
  gap: 10px;
}
.group-row > .control-group {
  flex: 1;
  min-width: 0;
}

#key-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}


/* ─── App list ───────────────────────────────────────────────────────────── */
#app-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}

.app-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.12s, border-color 0.12s;
}
.app-item:hover { background: var(--surface3); border-color: var(--accent-dim); }
.app-item small { color: var(--text-muted); font-size: 0.7rem; }

/* ─── UI Tree ────────────────────────────────────────────────────────────── */
#ui-tree-output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.72rem;
  max-height: 180px;
  overflow-y: auto;
  color: var(--text-muted);
}

.ui-node { padding: 2px 4px; border-radius: 3px; cursor: default; }
.ui-node:hover { background: var(--surface3); }
.ui-node.clickable { color: var(--success); cursor: pointer; }

/* ─── Log ────────────────────────────────────────────────────────────────── */
#log-output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.72rem;
  max-height: 160px;
  overflow-y: auto;
}

.log-entry { padding: 2px 0; border-bottom: 1px solid var(--surface2); }
.log-entry.success { color: var(--success); }
.log-entry.error   { color: var(--error); }

/* ─── File Manager (Miller Columns) ─────────────────────────────────────────── */
#file-path-bar {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
  word-break: break-all;
}

#file-columns {
  display: flex;
  flex-direction: row;
  height: 220px;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.file-column {
  min-width: 160px;
  width: 160px;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}
.file-column:last-child { border-right: none; }

.file-col-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  font-size: 0.77rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.file-col-item:hover { background: var(--surface2); }
.file-col-item.fc-selected { background: var(--accent-dim); color: #fff; }
.file-col-item.fc-selected .fc-icon,
.file-col-item.fc-selected .fc-size { color: rgba(255,255,255,0.6); }
.fc-icon { flex-shrink: 0; font-size: 0.65rem; color: var(--text-muted); width: 10px; }
.fc-dir .fc-icon { color: var(--accent); }
.fc-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-size { font-size: 0.67rem; color: var(--text-muted); flex-shrink: 0; }

.fc-separator { height: 1px; background: var(--border); margin: 2px 8px; }

.fc-item-actions { display: none; gap: 1px; margin-left: auto; flex-shrink: 0; padding-right: 2px; }
.file-col-item:hover .fc-item-actions { display: flex; }
.fc-act-btn {
  padding: 1px 3px;
  font-size: 0.58rem;
  line-height: 1.2;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 2px;
  cursor: pointer;
  font-weight: 400;
  opacity: 0.6;
}
.fc-act-btn:hover { background: var(--surface3); color: var(--text); opacity: 1; }
.fc-del-btn:hover { background: transparent; color: var(--error); }
.fc-del-action:hover { background: rgba(248,113,113,0.15) !important; color: var(--error) !important; border-color: rgba(248,113,113,0.4) !important; }

.file-column.fc-preview {
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  gap: 8px;
  min-width: 150px;
  width: 150px;
}
.fc-preview-name {
  font-size: 0.78rem;
  font-weight: 600;
  word-break: break-all;
  color: var(--text);
}
.fc-preview-size { font-size: 0.72rem; color: var(--text-muted); }

#file-upload-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
#file-upload-status { font-size: 0.75rem; color: var(--text-muted); }

/* ─── APK Install ────────────────────────────────────────────────────────── */
#apk-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  color: var(--text-muted);
  font-size: 0.8rem;
  user-select: none;
}
#apk-drop-zone:hover, #apk-drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--text);
}
#apk-progress-row { display: flex; align-items: center; gap: 8px; }
#apk-progress-bar-bg {
  flex: 1; height: 5px; background: var(--surface3); border-radius: 3px; overflow: hidden;
}
#apk-progress-bar {
  height: 100%; background: var(--accent); width: 0%; transition: width 0.15s; border-radius: 3px;
}
#apk-progress-label { font-size: 0.72rem; color: var(--text-muted); min-width: 30px; text-align: right; }
#apk-status { font-size: 0.75rem; color: var(--text-muted); }

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }
