/* Light-mode CTAs: dark text needs a brighter lilac gradient end so it holds
   contrast across the whole pill, not just the light half. */
html[data-theme="light"] .new-task,
html[data-theme="light"] .send-btn {
  background: linear-gradient(135deg, #a78bfa, #e9d5ff);
}

/* ============================= HEADER ============================= */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: 64px;
  display: flex; align-items: center; gap: var(--space-md);
  padding: 0 var(--space-lg);
  background: rgba(15,10,26,0.55);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
html[data-theme="light"] .topbar { background: rgba(247,245,250,0.72); }

.brand { display: flex; align-items: center; gap: 12px; margin-right: var(--space-sm); }
.brand .mark {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  background: linear-gradient(135deg, #7c3aed, #d896ff);
  display: grid; place-items: center; color: #0f0a1a;
  box-shadow: var(--glow-accent);
}
.brand .mark svg { width: 22px; height: 22px; }
.brand .wordmark { display: flex; flex-direction: column; line-height: 1.15; }
.brand .wordmark b { font-weight: 800; font-size: 1.32rem; letter-spacing: -0.01em; }
.brand .wordmark span {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--accent);
}

.topbar .spacer { flex: 1; }

.provider-pill {
  display: flex; align-items: center; gap: 9px;
  font-family: var(--font-mono); font-size: 12px; color: var(--text2);
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-pill); padding: 6px 14px; height: 34px;
}
.provider-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); animation: pulse 2.2s ease-in-out infinite; }
.provider-pill .prov { color: var(--text1); }
.provider-pill .switch {
  color: var(--warning); border-left: 1px solid var(--border);
  padding-left: 10px; margin-left: 2px;
}

.cost-pill {
  font-family: var(--font-mono); font-size: 12px; color: var(--text1);
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-pill); padding: 6px 14px; height: 34px;
  display: flex; align-items: center; gap: 8px;
}
.cost-pill .lbl { color: var(--text3); text-transform: uppercase; letter-spacing: 0.08em; font-size: 10px; }
.cost-pill .bar { width: 64px; height: 5px; background: var(--surface3); border-radius: var(--radius-pill); overflow: hidden; }
.cost-pill .bar i { display: block; height: 100%; width: 9%; background: var(--accent); border-radius: var(--radius-pill); }

.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: var(--surface3); border: 2px solid var(--background);
  display: grid; place-items: center; font-family: var(--font-body);
  font-weight: 600; font-size: 13px; color: var(--text1);
  position: relative; cursor: pointer;
}
.avatar::after {
  content: ""; position: absolute; bottom: -1px; right: -1px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--success); border: 2px solid var(--background);
}

.theme-btn {
  width: 34px; height: 34px; border-radius: var(--radius-control);
  background: transparent; border: 1px solid var(--border); color: var(--text2);
  display: grid; place-items: center; cursor: pointer;
  transition: all 120ms ease;
}
.theme-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ============================= LAYOUT ============================= */
.app {
  display: grid;
  grid-template-columns: 264px minmax(0,1fr) 320px;
  gap: 0;
  height: calc(100vh - 64px - 6px);
  max-width: 1560px;
  margin: 0 auto;
}
.panel { overflow-y: auto; }
.panel::-webkit-scrollbar { width: 8px; }
.panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ============================= SIDEBAR ============================= */
.sidebar { border-right: 1px solid var(--border); padding: var(--space-lg) var(--space-md); display: flex; flex-direction: column; gap: var(--space-md); }

.new-task {
  width: 100%; height: 44px; border-radius: var(--radius-control);
  border: none; cursor: pointer;
  background: linear-gradient(135deg, #7c3aed, #d896ff);
  color: #0f0a1a; font-family: var(--font-body); font-weight: 700; font-size: 15px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: var(--glow-accent);
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.new-task:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(216,150,255,0.42); }
.new-task:active { transform: translateY(0); }

.side-label {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--text3);
  padding: var(--space-sm) var(--space-xs) 0;
}
.agent-mode {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text3);
}

.history { display: flex; flex-direction: column; gap: 4px; }
.history-item {
  display: flex; flex-direction: column; gap: 3px;
  padding: 11px 14px; border-radius: var(--radius-control);
  border: 1px solid transparent; cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.history-item:hover { background: var(--surface2); }
.history-item.active {
  background: var(--surface2);
  border-color: var(--border);
  border-left: 3px solid var(--accent);
}
.history-item .t { font-size: 14px; font-weight: 500; color: var(--text1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .m {
  font-family: var(--font-mono); font-size: 11px; color: var(--text3);
  display: flex; gap: 8px; align-items: center;
}
.history-item .m .st { width: 6px; height: 6px; border-radius: 50%; }
.history-item .m .st.done { background: var(--success); }
.history-item .m .st.run { background: var(--accent); animation: pulse 2.2s ease-in-out infinite; }

.side-context {
  margin-top: auto;
  border: 1px solid var(--border); border-radius: var(--radius-component);
  padding: var(--space-md); background: var(--surface1);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.side-context .h {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 8px;
  display: flex; align-items: center; gap: 7px;
}
.side-context p { margin: 0; font-size: 13px; color: var(--text2); line-height: 1.5; }
.side-context code {
  font-family: var(--font-mono); font-size: 12px; color: var(--text1);
  background: var(--surface2); padding: 1px 6px; border-radius: 6px;
}

/* ============================= MAIN STREAM ============================= */
.main { display: flex; flex-direction: column; }
.stream { flex: 1; overflow-y: auto; padding: var(--space-xl) var(--space-2xl) var(--space-lg); display: flex; flex-direction: column; gap: var(--space-lg); }

.session-head {
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border); padding: var(--space-md) var(--space-2xl);
}
.session-head .title { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.session-head .meta {
  font-family: var(--font-mono); font-size: 11px; color: var(--text3);
  display: flex; align-items: center; gap: 8px;
}

/* Live status line — always-visible "what's happening right now" indicator.
   Sits above the scrollable stream so it never scrolls out of view. */
.status-line {
  display: flex; align-items: center; gap: 7px;
  margin: var(--space-md) var(--space-2xl) 0;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface1);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text2);
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}
.status-line[hidden] { display: none; }
.status-line .pulse-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
  flex: none;
}
.status-line .pulse-dot.stopped { background: var(--success); animation: none; }
.status-line .phase { color: var(--accent); font-weight: 600; }
.status-line .breath { opacity: 0.4; animation: breath 1.6s ease-in-out infinite; }
.status-line .breath.off { animation: none; opacity: 0.3; }
@keyframes breath { 0%, 100% { opacity: 0.15; } 50% { opacity: 0.85; } }

.empty-state {
  margin: auto; text-align: center; max-width: 420px;
  display: flex; flex-direction: column; gap: var(--space-sm);
}
.empty-state .empty-title { font-size: 17px; font-weight: 600; color: var(--text1); }
.empty-state .empty-sub {
  font-family: var(--font-mono); font-size: 11px; color: var(--text3);
}

.msg { max-width: 760px; }
.msg.user { align-self: flex-end; }
.msg.user .bubble {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-component);
  padding: 14px 18px; font-size: 15px;
}
.msg.user .who {
  text-align: right; font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--text3); margin-top: 6px;
}

.agent-block { display: flex; flex-direction: column; gap: 12px; }

.step { border-left: 2px solid var(--border); padding-left: var(--space-md); }
.step.thinking { border-left-color: var(--accent); }
.step .row {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text3); margin-bottom: 6px;
}
.step.thinking .row { color: var(--accent); }
.step .body { font-size: 14px; color: var(--text2); line-height: 1.55; }

.tool-card {
  border: 1px solid var(--border); border-radius: var(--radius-component);
  background: var(--surface1);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  overflow: hidden;
}
.tool-card .head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--surface2);
  font-family: var(--font-mono); font-size: 12px; color: var(--text2);
}
.tool-card .head .tag {
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-subtle);
  padding: 2px 8px; border-radius: var(--radius-pill);
}
.tool-card .head .path { color: var(--text3); }
.tool-card pre {
  margin: 0; padding: 14px 16px; overflow-x: auto;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.6; color: var(--text1);
}
.tool-card .result {
  padding: 10px 16px; font-family: var(--font-mono); font-size: 12px;
  color: var(--success); border-top: 1px solid var(--border); background: rgba(52,211,153,0.04);
}

.done-card {
  border: 1px solid var(--border); border-radius: var(--radius-component);
  padding: 18px 20px; background: var(--surface1);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 2px solid var(--accent);
}
.done-card .h { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.done-card .h .ic { color: var(--accent); display: grid; place-items: center; }
.done-card .h b { font-size: 15px; font-weight: 700; }
.done-card p { margin: 0 0 10px; font-size: 14px; color: var(--text2); }

/* Change receipt: the concrete "what changed" block under the done card. */
.receipt {
  border: 1px solid var(--border); border-radius: var(--radius-component);
  padding: 16px 18px; background: var(--surface1);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.receipt .h { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.receipt .h .ic { color: var(--success); display: grid; place-items: center; font-family: var(--font-mono); }
.receipt .h b { font-size: 14px; font-weight: 700; }
.receipt p { margin: 0; font-size: 13.5px; color: var(--text2); }
.receipt .muted { color: var(--text3); font-size: 13px; }
.receipt-files { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.receipt-files li { display: flex; align-items: baseline; gap: 12px; justify-content: space-between; }
.receipt-files .path {
  font-family: var(--font-mono); font-size: 12px; color: var(--text1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.receipt-files .delta {
  font-family: var(--font-mono); font-size: 11px; color: var(--success); flex: none;
  font-variant-numeric: tabular-nums;
}
.receipt-total {
  font-family: var(--font-mono); font-size: 11.5px; color: var(--text3);
  border-top: 1px solid var(--border); padding-top: 8px;
}
.receipt-commits { margin-top: 10px; }
.receipt-commits .sub {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text3); margin-bottom: 6px;
}
.receipt-commits .commit {
  display: flex; align-items: baseline; gap: 9px;
  font-size: 12.5px; color: var(--text2); line-height: 1.6;
}
.receipt-commits .commit code {
  font-family: var(--font-mono); font-size: 11px; color: var(--accent); flex: none;
}

.follow-ups { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.follow-ups .fl { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text3); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-size: 13px; color: var(--text2); background: transparent;
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 7px 14px; cursor: pointer; transition: all 120ms ease;
  font-family: var(--font-body);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ============================= COMPOSER ============================= */
.composer-wrap { padding: var(--space-md) var(--space-2xl) var(--space-lg); }
.composer {
  border: 1px solid var(--border-visible); border-radius: var(--radius-container);
  background: var(--surface1);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  padding: var(--space-md);
  box-shadow: var(--shadow-2);
}
.composer textarea {
  width: 100%; border: none; background: transparent; resize: none; outline: none;
  color: var(--text1); font-family: var(--font-body); font-size: 15px; line-height: 1.6;
  min-height: 56px;
}
.composer textarea::placeholder { color: var(--text3); }
.composer .bar { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.workspace-pick {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 12px; color: var(--text2);
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-control); padding: 7px 12px; cursor: pointer;
}
.workspace-pick .chev { color: var(--text3); }
.composer .spacer { flex: 1; }
.send-btn {
  width: 40px; height: 40px; border-radius: var(--radius-control); border: none; cursor: pointer;
  background: linear-gradient(135deg, #7c3aed, #d896ff); color: #0f0a1a;
  display: grid; place-items: center; box-shadow: var(--glow-accent);
  transition: transform 120ms ease;
}
.send-btn:hover { transform: translateY(-2px); }
.send-btn:active { transform: translateY(0); }

/* ============================= LOGIN ============================= */
body.logged-out .avatar,
body.logged-out .provider-pill,
body.logged-out .cost-pill { display: none; }
.login-wrap {
  min-height: calc(100vh - 70px);
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-lg);
}
.login-card { width: 100%; max-width: 380px; }
.login-title { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.01em; margin: 0 0 2px; }
.login-sub {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text3); margin: 0 0 var(--space-lg);
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-md); }
.field label {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text2);
}
.field input {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-control); color: var(--text1);
  font-family: var(--font-body); font-size: 15px; padding: 10px 12px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.login-error { font-size: 13px; color: var(--error); margin: 0 0 var(--space-md); }
.login-card .new-task { margin-top: var(--space-xs); }

/* ============================= RIGHT PANEL ============================= */
.right { border-left: 1px solid var(--border); padding: var(--space-lg) var(--space-md); display: flex; flex-direction: column; gap: var(--space-lg); }
.right-section { display: flex; flex-direction: column; gap: 10px; }
.right-section .h {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--text3);
  display: flex; align-items: center; gap: 8px;
}
.right-section .h .n { color: var(--accent); }

.subagent {
  border: 1px solid var(--border); border-radius: var(--radius-component);
  background: var(--surface1);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  padding: 14px 16px;
}
.subagent .head { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.subagent .head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 2.2s ease-in-out infinite; }
.subagent .head .dot.done { background: var(--success); animation: none; }
.subagent .head b { font-size: 13.5px; font-weight: 600; flex: 1; }
.subagent .head .m { font-family: var(--font-mono); font-size: 10px; color: var(--text3); }
.subagent .status { font-family: var(--font-mono); font-size: 11.5px; color: var(--text2); line-height: 1.5; }
.subagent .status .ok { color: var(--success); }

.cost-card {
  border: 1px solid var(--border); border-radius: var(--radius-component);
  padding: 16px; background: var(--surface1);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.cost-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; }
.cost-row .k { font-size: 13px; color: var(--text2); }
.cost-row .v { font-family: var(--font-mono); font-size: 13px; color: var(--text1); }
.cost-row .v.warn { color: var(--warning); }
.cost-divider { border-top: 1px solid var(--border); margin: 8px 0; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ============================= RESPONSIVE ============================= */
@media (max-width: 1080px) {
  .app { grid-template-columns: 220px minmax(0,1fr); }
  .right { display: none; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; height: auto; }
  .sidebar { display: none; }
  .right { display: none; }
  .topbar { padding: 0 var(--space-md); }
  .cost-pill { display: none; }
  .stream { padding: var(--space-lg) var(--space-md); }
  .composer-wrap { padding: var(--space-sm) var(--space-md) var(--space-lg); }
  .provider-pill .switch { display: none; }
  .composer .bar { flex-wrap: wrap; row-gap: 8px; }
  .workspace-pick { max-width: 148px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .session-head { flex-wrap: wrap; gap: 8px; }
}

/* Very narrow phones: keep the three essential controls, drop the chrome. */
@media (max-width: 480px) {
  .topbar { gap: 8px; }
  .brand { gap: 9px; margin-right: 0; }
  .brand .mark { width: 32px; height: 32px; border-radius: 9px; }
  .brand .mark svg { width: 18px; height: 18px; }
  .brand .wordmark b { font-size: 1.15rem; }
  .brand .wordmark span { display: none; }
  .provider-pill { padding: 6px 10px; max-width: 120px; }
  .provider-pill .prov { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .agent-mode { display: none; }
  .skills-pick { display: none; }
  .msg.user .bubble { font-size: 14px; }
  .done-card { padding: 14px 16px; }
}
