:root {
  --bg: #0b0c10;
  --panel: #111827;
  --panel-border: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #374151;
  --success: #10b981;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, Arial, sans-serif;
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.app-header {
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
}

.app-main {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: 1fr;
  gap: 16px;
  padding: 16px;
  flex: 1 1 auto;
  overflow: hidden;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 12px;
  height: 100%;
  min-height: 0;
  overflow: auto;
}

.row { display: flex; gap: 8px; align-items: center; }
.space-between { justify-content: space-between; }

.grid.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pad { padding: 8px 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }

input, select, button {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 6px 8px;
}

input { width: 100%; }
button { cursor: pointer; }
button.icon-btn { border-radius: 50%; width: 28px; height: 28px; display: inline-grid; place-items: center; }

.kbd { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 12px; padding: 2px 4px; background: var(--panel-border); border-radius: 4px; }
.pill { font-size: 12px; padding: 2px 6px; border-radius: 999px; border: 1px solid var(--accent); background: var(--bg); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot.green { background: var(--success); }
.dot.red { background: var(--danger); }

/* Clients list */
.clients .list-item { padding: 8px; border-radius: 6px; cursor: pointer; }
.clients .list-item:hover { background: var(--panel-border); }

/* Control grid with three columns: controls, preview, agent */
.control .control-grid {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(300px, 420px) minmax(280px, 350px);
  gap: 16px;
}

/* Removed in favor of screenshot modal */

/* Video preview */
.video-wrap {
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px;
  background: #0b0c10;
  overflow: hidden;
}

#videoCanvas {
  display: block;
  /* Let HTML width/height attributes define the render size */
  /* Optional caps to avoid overflow; adjust/remove if exact size is desired */
  max-width: 100%;
  max-height: 85vh;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
}

#videoCanvasWrap { display: inline-block; }

/* Center the preview block while keeping text left-aligned
   and aligning label/helper with the video left edge */
.preview-centered {
  display: block;
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
  text-align: left;
}

/* Modal */
.modal { position: fixed; inset: 0; display: none; }
.modal[aria-hidden="false"] { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-dialog {
  position: relative;
  width: min(900px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  margin: 16px auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  display: flex; flex-direction: column;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px; border-bottom: 1px solid var(--panel-border); }
.modal-body { padding: 12px; overflow: auto; }
.modal-footer { padding: 12px; border-top: 1px solid var(--panel-border); display: flex; justify-content: flex-end; gap: 8px; }

#full-info-pre { white-space: pre-wrap; font-size: 12px; line-height: 1.4; }



/* Screenshot modal sizing */
#screenshot-modal .modal-dialog {
  width: calc(100vw - 32px);
  height: calc(100vh - 32px);
  max-height: none;
}

#screenshot-modal .modal-body {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

#screenshot-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
}

/* Apps modal */
.apps-modal-body {
  max-height: 60vh;
  overflow-y: auto;
}

.apps-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  padding: 8px 0;
}

.app-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  background: var(--bg);
  transition: background-color 0.2s;
  cursor: pointer;
}

.app-item:hover {
  background: var(--panel-border);
}

.app-icon {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: var(--panel-border);
  flex-shrink: 0;
  object-fit: cover;
}

.app-info {
  flex: 1;
  min-width: 0;
}

.app-name {
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
  word-break: break-word;
  font-size: 14px;
}

.app-package {
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.apps-loading, .apps-error {
  text-align: center;
  padding: 32px;
  color: var(--muted);
}

.apps-error {
  color: var(--danger);
}

/* Agent panels */
.agent-status-panel, .agent-todo-panel {
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 8px;
  background: var(--bg);
}

.agent-status-panel {
  margin-bottom: 8px;
}

.agent-status {
  margin-top: 8px;
}

.status-indicator {
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--panel-border);
  font-size: 14px;
  font-weight: 500;
}

.status-indicator.ready {
  background: var(--panel-border);
  color: var(--text);
}

.status-indicator.running {
  background: #1e3a8a;
  color: #93c5fd;
}

.status-indicator.completed {
  background: #14532d;
  color: #86efac;
}

.status-indicator.failed {
  background: #7f1d1d;
  color: #fca5a5;
}

/* Agent todos */
.agent-todos {
  margin-top: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.todo-item {
  padding: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  margin-bottom: 6px;
  background: var(--panel);
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.todo-item:last-child {
  margin-bottom: 0;
}

.todo-status {
  flex-shrink: 0;
  font-size: 16px;
  line-height: 1;
  margin-top: 1px;
}

.todo-status.pending {
  color: var(--muted);
}

.todo-status.completed {
  color: var(--success);
}

.todo-status.failed {
  color: var(--danger);
}

.todo-content {
  flex: 1;
  font-size: 13px;
  line-height: 1.3;
  word-break: break-word;
}

.todo-content.completed {
  text-decoration: line-through;
  color: var(--muted);
}

.task-agent {
  margin-top: 2px;
  font-style: italic;
  opacity: 0.8;
}

.no-tasks {
  text-align: center;
  padding: 16px;
  color: var(--muted);
}

/* Small buttons */
.small-btn {
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 4px;
}

/* Textarea styling */
textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 8px;
  width: 100%;
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
  line-height: 1.4;
}

textarea:focus {
  outline: none;
  border-color: var(--success);
}

/* Tooltips */
.tooltip-trigger {
  cursor: help;
  opacity: 0.7;
  font-size: 10px;
  display: inline-block;
  margin-left: 4px;
  position: relative;
}

.tooltip-trigger:hover {
  opacity: 1;
}

/* Checkbox group layout */
.checkbox-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.checkbox-item {
  display: flex;
  align-items: flex-start;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.3;
  margin: 0;
}

.checkbox-label input[type="checkbox"] {
  margin: 0;
  margin-top: 2px;
  width: auto;
  flex-shrink: 0;
}

.checkbox-label span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Navigation */
.header-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.nav-links {
  display: flex;
  gap: 16px;
}

.nav-links a {
  color: var(--text);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 6px;
  transition: background-color 0.2s;
}

.nav-links a:hover {
  background: var(--accent);
}

.nav-links a.active {
  background: var(--success);
  color: white;
}