:root {
  --bg: #0a1016;
  --bg2: #101820;
  --panel: #15202b;
  --line: #243547;
  --ink: #e9eef4;
  --muted: #8fa0b3;
  --acc: #2d9b6a;
  --acc-ink: #04140c;
  --acc-soft: color-mix(in srgb, var(--acc) 16%, var(--bg2));
  --ok: #3ecf8e;
  --bad: #e07a7a;
  --radius: 14px;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1000px 520px at 8% -12%, #16352c 0%, transparent 55%),
    radial-gradient(800px 420px at 100% 0%, #152536 0%, transparent 48%),
    var(--bg);
}

a { color: var(--ok); }
code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--bg2);
  padding: 1px 6px;
  border-radius: 6px;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  min-height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 20px 18px 28px;
  gap: 16px;
}

header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand h1 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
  font-weight: 650;
}
.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}
.meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.pill {
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  text-decoration: none;
}
.pill.live { color: var(--ok); border-color: #255c45; }
.pill.link:hover { color: var(--ink); border-color: var(--acc); }

.panel {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  min-height: 0;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0;
  padding: 14px 16px 10px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}

.side-body, .main-body {
  padding: 14px 16px 16px;
  overflow: auto;
  flex: 1;
}

.side-sub {
  margin: 16px 0 8px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 6px;
}
.field { margin-bottom: 12px; }
input, textarea, select {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid color-mix(in srgb, var(--acc) 55%, transparent);
  border-color: var(--acc);
}

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
button, .btn-link {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button.primary { background: var(--acc); color: var(--acc-ink); }
button.ghost, .btn-link.ghost, a.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
button:disabled { opacity: 0.5; cursor: wait; }

.profiles {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.profiles li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--bg2);
  cursor: pointer;
}
.profiles li.active {
  border-color: var(--acc);
  background: var(--acc-soft);
}
.profiles li span { font-size: 0.9rem; }
.profiles li button {
  padding: 4px 8px;
  font-size: 0.75rem;
  font-weight: 500;
}
.profile-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.profile-site {
  font-size: 0.75rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.profile-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 280px;
}
.bubble {
  max-width: 92%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg2);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
  line-height: 1.45;
}
.bubble.user {
  align-self: flex-end;
  background: var(--acc-soft);
  border-color: #2a5c45;
}
.bubble.agent { align-self: flex-start; }
.bubble.step {
  align-self: stretch;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
  background: transparent;
  border-style: dashed;
}
.bubble.ok { border-color: #2a5c45; color: var(--ok); }
.bubble.bad { border-color: #6a3030; color: #f0a0a0; }

.composer {
  border-top: 1px solid var(--line);
  padding: 12px 16px 16px;
  display: grid;
  gap: 10px;
}
.composer-top {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 640px) {
  .composer-top { grid-template-columns: 1fr; }
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 8px 0 0;
  line-height: 1.45;
}

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.login-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.login-brand h1 { margin: 0 0 6px; font-size: 1.65rem; letter-spacing: -0.03em; }
.login-brand > p, .login-card > p { color: var(--muted); margin: 0 0 20px; }
.login-card button { width: 100%; margin-top: 6px; }
#err { color: #f0a0a0; min-height: 1.2em; }

/* Mode chooser */
.choose-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 18px;
}
.choose-shell {
  width: min(1080px, 100%);
  display: grid;
  gap: 22px;
}
.choose-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
@media (max-width: 900px) {
  .mode-grid { grid-template-columns: 1fr; }
}
.mode-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px 22px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.mode-card:hover {
  border-color: var(--acc);
  transform: translateY(-2px);
}
.mode-card.accent {
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--acc) 18%, var(--panel)), var(--panel));
  border-color: #2a5c45;
}
.mode-kicker {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}
.mode-card h2 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}
.mode-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  flex: 1;
}
.mode-cta {
  margin-top: 10px;
  font-weight: 650;
  color: var(--ok);
}
.choose-foot {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

/* Remote browser layout */
.app.remote { max-width: 1400px; }
.remote-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.9fr);
  gap: 14px;
  min-height: 0;
}
@media (max-width: 980px) {
  .remote-layout { grid-template-columns: 1fr; }
}
.side-stack { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.browser-panel { min-height: 640px; }
.toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.url-bar { flex: 1; }
.viewport-wrap {
  position: relative;
  background: #070b10;
  flex: 1;
  min-height: 420px;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  outline: none;
}
.viewport-wrap:focus {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--acc) 55%, transparent);
}
#viewport {
  display: none;
  width: 100%;
  height: auto;
  cursor: none;
  user-select: none;
  -webkit-user-drag: none;
}
.rdp-cursor {
  display: none;
  position: absolute;
  width: 16px;
  height: 20px;
  pointer-events: none;
  z-index: 5;
  transform: translate(-1px, -1px);
  background: no-repeat left top / contain;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='20' viewBox='0 0 16 20'%3E%3Cpath fill='%23fff' stroke='%23111' stroke-width='1' d='M1 1 L1 16 L5 12 L8 18 L10.5 17 L7.5 11 L13 11 Z'/%3E%3C/svg%3E");
}
.rdp-cursor.pointer {
  width: 18px;
  height: 18px;
  transform: translate(-4px, -2px);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24'%3E%3Cpath fill='%23fff' stroke='%23111' stroke-width='1.2' d='M10 2v10.5l-2.2-2.2-1.4 1.4L11 17l6-6-1.4-1.4-2.6 2.6V2z'/%3E%3Cpath fill='none' stroke='%23111' stroke-width='1.5' d='M8 14c0 4 2 7 4 8'/%3E%3C/svg%3E");
}
.rdp-cursor.text {
  width: 10px;
  height: 18px;
  transform: translate(-4px, -8px);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='18' viewBox='0 0 10 18'%3E%3Cpath stroke='%23111' stroke-width='1.5' fill='none' d='M2 1h6M5 1v16M2 17h6'/%3E%3Cpath stroke='%23fff' stroke-width='1' fill='none' d='M2.5 1.5h5M5 2v14M2.5 16.5h5'/%3E%3C/svg%3E");
}
.rdp-cursor.progress, .rdp-cursor.wait {
  width: 18px;
  height: 18px;
  transform: translate(-8px, -8px);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 18 18'%3E%3Ccircle cx='9' cy='9' r='7' fill='none' stroke='%23111' stroke-width='2'/%3E%3Ccircle cx='9' cy='9' r='7' fill='none' stroke='%23fff' stroke-width='2' stroke-dasharray='10 30'/%3E%3C/svg%3E");
}
.rdp-cursor.not-allowed {
  width: 16px;
  height: 16px;
  transform: translate(-8px, -8px);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Ccircle cx='8' cy='8' r='6.5' fill='none' stroke='%23c33' stroke-width='2'/%3E%3Cpath stroke='%23c33' stroke-width='2' d='M4 4l8 8'/%3E%3C/svg%3E");
}
.viewport-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  text-align: center;
  color: var(--muted);
  line-height: 1.5;
}
.browser-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--line);
}
.browser-footer input { flex: 1; min-width: 140px; }

/* Agent workspace */
.app.agent-app { max-width: 1100px; }
.agent-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.7fr);
  gap: 14px;
  min-height: calc(100vh - 120px);
}
@media (max-width: 860px) {
  .agent-layout { grid-template-columns: 1fr; }
}
.agent-main {
  min-height: 560px;
}
.agent-main .chat {
  min-height: 360px;
}
.agent-composer {
  background: color-mix(in srgb, var(--bg2) 40%, transparent);
}
