:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-hover: #1a3a6a;
  --bg-active: #2255aa;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0a0;
  --text-muted: #666;
  --accent: #4fc3f7;
  --accent-hover: #29b6f6;
  --border: #2a2a4a;
  --success: #66bb6a;
  --danger: #ef5350;
  --warning: #ffa726;
  --input-bg: #0d1b36;
  --radius: 8px;
  --sidebar-width: 280px;
  --topbar-height: 48px;
  --layout-transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* ============ Login ============ */
.login-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  text-align: center;
}

.login-box h1 {
  font-size: 28px;
  margin-bottom: 8px;
}

.login-box .subtitle {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.login-box input {
  width: 100%;
  padding: 12px 16px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  margin-bottom: 16px;
}

.login-box input:focus { border-color: var(--accent); }

.login-box button {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.login-box button:hover { background: var(--accent-hover); }

.login-error {
  color: var(--danger);
  font-size: 14px;
  margin-top: 12px;
  display: none;
}

/* ============ Layout ============ */
.app-layout {
  display: flex;
  height: 100vh;
}

/* ============ Sidebar ============ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width var(--layout-transition), border-color var(--layout-transition);
}

.sidebar > * {
  width: var(--sidebar-width);
}

.app-layout.sidebar-collapsed .sidebar {
  width: 0;
  border-right-color: transparent;
}

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

.sidebar-header h2 {
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.sidebar-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.sidebar-tab:hover { color: var(--text-primary); }
.sidebar-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--accent);
  color: #000;
  width: 100%;
  justify-content: center;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ============ Session List ============ */
.session-item {
  padding: 12px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.session-item:hover { background: var(--bg-hover); }
.session-item.active { background: var(--bg-active); }

.session-item .session-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.session-item .session-status {
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-left: 8px;
  flex-shrink: 0;
}
.session-status.running { background: var(--success); }
.session-status.stopped { background: var(--text-muted); }

/* ============ Profile List ============ */
.profile-item {
  padding: 12px;
  border-radius: var(--radius);
  margin-bottom: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.profile-item:hover { background: var(--bg-hover); }

.profile-item .profile-name {
  font-size: 14px;
  font-weight: 500;
}

.profile-item .profile-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.profile-item .profile-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

/* ============ Main Content ============ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.view-controls {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 20;
  display: flex;
  gap: 6px;
}

.view-control-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.view-control-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  border-color: var(--accent);
}

.view-control-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.view-control-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.topbar {
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px 0 92px;
  gap: 12px;
}

.topbar .session-title {
  font-size: 15px;
  font-weight: 500;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .session-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-area {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: #0a0a14;
}

/* ============ Empty State ============ */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.empty-state h2 {
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.empty-state p { font-size: 14px; }

/* ============ Modal ============ */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 480px;
  max-width: 90vw;
}

.modal h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

.modal .form-group {
  margin-bottom: 14px;
}

.modal label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.modal input, .modal select, .modal textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

.modal input:focus, .modal select:focus, .modal textarea:focus {
  border-color: var(--accent);
}

.modal textarea {
  font-family: 'Menlo', monospace;
  font-size: 12px;
  min-height: 200px;
  resize: vertical;
}

.modal .modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ============ Scrollbar ============ */
.sidebar-content::-webkit-scrollbar { width: 4px; }
.sidebar-content::-webkit-scrollbar-track { background: transparent; }
.sidebar-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.hidden { display: none !important; }

/* ============ Terminal (xterm.js) ============ */
.xterm { padding: 8px; }
.xterm-viewport::-webkit-scrollbar { width: 6px; }
.xterm-viewport::-webkit-scrollbar-track { background: transparent; }
.xterm-viewport::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ============ Skip Perms Toggle ============ */
.skip-perm-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.15s;
}
.skip-perm-toggle:hover { background: var(--hover); }
.skip-perm-toggle.disabled { opacity: 0.4; pointer-events: none; }
.skip-perm-toggle input { display: none; }
.skip-perm-toggle span {
  padding: 2px 8px;
  border-radius: 3px;
  border: 1px solid var(--border);
  transition: all 0.15s;
}
.skip-perm-toggle input:checked + span {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.version-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 16px;
  transition: color 0.15s;
}
.version-link:hover { color: var(--accent); }

/* Profile selector in topbar */
.profile-select {
  padding: 5px 26px 5px 10px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  max-width: 180px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color .2s, background .2s;
}
.profile-select:hover { border-color: var(--accent); background: var(--bg-secondary); }
.profile-select.hidden { display: none; }

.session-name {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.session-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-badge {
  flex: 0 0 auto;
  padding: 2px 6px;
  border-radius: 8px;
  font-size: 9px;
  line-height: 1.3;
  color: #fff;
  background: #7c4dff;
}

.agent-badge.codex { background: #168b72; }
