:root {
  --ink: #14231c;
  --muted: #69776f;
  --surface: rgba(255, 255, 255, .78);
  --surface-solid: #f9fbf9;
  --line: rgba(28, 58, 43, .11);
  --green: #176b49;
  --green-soft: #dff2e8;
  --amber: #b56b12;
  --red: #b5443f;
  --shadow: 0 22px 70px rgba(36, 68, 51, .12);
  --radius: 24px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #eef3ef; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  background:
    radial-gradient(circle at 15% 10%, rgba(255,255,255,.9), transparent 30%),
    linear-gradient(145deg, #e9f0eb 0%, #f5f2e9 100%);
  overflow-x: hidden;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.ambient { position: fixed; border-radius: 999px; filter: blur(80px); opacity: .38; pointer-events: none; }
.ambient-a { width: 360px; height: 360px; background: #9bd1b5; top: -120px; right: -80px; }
.ambient-b { width: 280px; height: 280px; background: #ead49b; bottom: -100px; left: -70px; }

.app-shell { position: relative; width: 100%; max-width: 1440px; min-width: 0; min-height: 100vh; margin: 0 auto; padding: 30px 34px 40px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 24px; }
.eyebrow, .kicker { margin: 0 0 6px; color: var(--green); font-size: 12px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
h1 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: clamp(30px, 4vw, 48px); letter-spacing: -.035em; }
h2 { margin: 0; font-size: 20px; letter-spacing: -.02em; }
.connection-pill { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.64); font-size: 13px; font-weight: 700; }
.pulse-dot { width: 9px; height: 9px; border-radius: 50%; background: #d69535; box-shadow: 0 0 0 5px rgba(214,149,53,.12); }
.connection-pill.online .pulse-dot { background: #28a66a; box-shadow: 0 0 0 5px rgba(40,166,106,.12); animation: breathe 2.2s infinite; }
@keyframes breathe { 50% { box-shadow: 0 0 0 8px rgba(40,166,106,.03); } }

.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.summary-card { display: flex; flex-direction: column; padding: 17px 19px; border: 1px solid var(--line); border-radius: 19px; background: rgba(255,255,255,.58); backdrop-filter: blur(18px); }
.summary-card strong { font-family: Georgia, serif; font-size: 27px; line-height: 1; }
.summary-card span { margin-top: 7px; color: var(--muted); font-size: 12px; }

.node-tabs { display: flex; width: 100%; max-width: 100%; gap: 9px; overflow-x: auto; padding: 3px 2px 14px; scrollbar-width: none; }
.node-tab { min-width: 112px; padding: 12px 15px; border: 1px solid var(--line); border-radius: 16px; color: var(--ink); background: rgba(255,255,255,.55); text-align: left; transition: .2s ease; }
.node-tab.active { color: white; background: var(--ink); transform: translateY(-1px); box-shadow: 0 12px 25px rgba(20,35,28,.16); }
.node-tab span { display: block; font-weight: 800; }
.node-tab small { display: block; margin-top: 4px; color: inherit; opacity: .65; }
.node-tab.offline { opacity: .48; }

.workspace-grid { display: grid; width: 100%; min-width: 0; grid-template-columns: 370px minmax(0, 1fr); gap: 16px; min-height: 630px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); backdrop-filter: blur(22px); box-shadow: var(--shadow); overflow: hidden; }
.session-panel { min-width: 0; max-width: 100%; }
.panel-heading, .conversation-head { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 22px; border-bottom: 1px solid var(--line); }
.heading-actions { display: flex; gap: 8px; align-items: center; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 13px; color: var(--green); background: white; font-size: 23px; }
.session-list { max-height: 680px; overflow-y: auto; padding: 10px; }
.session-item { width: 100%; display: grid; grid-template-columns: 12px 1fr auto; gap: 12px; align-items: start; padding: 15px 13px; border: 0; border-radius: 16px; color: inherit; background: transparent; text-align: left; }
.session-item > span:nth-child(2) { min-width: 0; }
.session-item:hover, .session-item.active { background: rgba(222,238,228,.78); }
.state-dot { width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; background: #a7b0aa; }
.state-dot.active { background: #21a367; box-shadow: 0 0 0 5px rgba(33,163,103,.1); }
.state-dot.open { background: #438d74; box-shadow: 0 0 0 4px rgba(67,141,116,.09); }
.state-dot.systemError { background: var(--red); }
.session-name { display: block; overflow: hidden; font-weight: 800; white-space: nowrap; text-overflow: ellipsis; }
.session-preview { display: -webkit-box; margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 12px; line-height: 1.5; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.session-time { color: var(--muted); font-size: 10px; white-space: nowrap; }
.list-empty { padding: 50px 20px; color: var(--muted); text-align: center; }

.conversation-panel { position: relative; display: flex; flex-direction: column; min-width: 0; }
.empty-state { margin: auto; padding: 60px 20px; color: var(--muted); text-align: center; }
.empty-state h2 { margin: 18px 0 8px; color: var(--ink); }
.empty-orbit { position: relative; width: 70px; height: 70px; margin: auto; border: 1px solid rgba(23,107,73,.2); border-radius: 50%; }
.empty-orbit:after { content: ""; position: absolute; inset: 13px; border: 1px solid rgba(23,107,73,.35); border-radius: 50%; }
.empty-orbit span { position: absolute; width: 12px; height: 12px; top: 7px; left: 29px; border-radius: 50%; background: var(--green); box-shadow: 0 0 22px rgba(23,107,73,.5); }
.conversation { display: flex; flex: 1; min-height: 0; flex-direction: column; }
.session-breadcrumb { margin-bottom: 5px; color: var(--green); font-size: 12px; font-weight: 800; }
.status-chip { padding: 7px 11px; border-radius: 999px; background: #edf1ee; font-size: 12px; font-weight: 800; white-space: nowrap; }
.status-chip.active { color: #11603e; background: var(--green-soft); }
.status-chip.open { color: #176b49; background: #e6f1eb; }
.metadata { display: flex; flex-wrap: wrap; gap: 8px; padding: 13px 22px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.metadata span { padding: 5px 8px; border-radius: 8px; background: rgba(238,242,239,.8); }
.timeline { flex: 1; min-height: 300px; max-height: 470px; overflow-y: auto; padding: 22px; scroll-behavior: smooth; }
.event { margin-bottom: 14px; padding: 13px 15px; border-left: 3px solid #c8d3cc; border-radius: 4px 14px 14px 4px; background: rgba(247,249,247,.86); }
.event.agent { border-color: var(--green); background: rgba(230,243,235,.82); }
.event.command { border-color: #b88635; font-family: Consolas, monospace; }
.event.error { border-color: var(--red); }
.event-label { margin-bottom: 6px; color: var(--muted); font: 700 10px/1 system-ui; letter-spacing: .08em; text-transform: uppercase; }
.event-body { white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.65; }
.history-more { display: block; margin: 0 auto 18px; color: var(--green); background: rgba(255,255,255,.8); }

.approval-box { margin: 0 18px 14px; padding: 16px; border: 1px solid rgba(181,107,18,.24); border-radius: 17px; background: #fff8e9; }
.button-row, .composer-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.composer { padding: 15px 18px 18px; border-top: 1px solid var(--line); background: rgba(250,252,250,.82); }
.composer textarea, .auth-card input { width: 100%; resize: none; outline: none; border: 1px solid var(--line); border-radius: 15px; color: var(--ink); background: white; padding: 13px 14px; transition: .2s; }
.composer textarea:focus, .auth-card input:focus { border-color: rgba(23,107,73,.55); box-shadow: 0 0 0 4px rgba(23,107,73,.07); }
.composer-actions { justify-content: flex-end; }
.button { border: 1px solid var(--line); border-radius: 12px; padding: 10px 13px; color: var(--ink); background: white; font-weight: 750; font-size: 12px; }
.button.primary { border-color: var(--green); color: white; background: var(--green); }
.button.danger { color: var(--red); }
.button.subtle { background: transparent; }
.button:disabled { cursor: not-allowed; opacity: .45; }

.auth-layer { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(230,237,232,.82); backdrop-filter: blur(18px); }
.auth-card { width: min(400px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 28px; background: white; box-shadow: var(--shadow); }
.brand-mark { display: grid; width: 48px; height: 48px; margin-bottom: 20px; place-items: center; border-radius: 15px; color: white; background: var(--green); font-family: Georgia, serif; font-size: 24px; }
.auth-card p { color: var(--muted); line-height: 1.6; }
.auth-card .button { width: 100%; margin-top: 12px; }
.form-error { min-height: 20px; margin-top: 10px; color: var(--red); font-size: 12px; }
.toast { position: fixed; z-index: 30; left: 50%; bottom: 25px; max-width: calc(100vw - 32px); padding: 11px 15px; border-radius: 12px; color: white; background: rgba(20,35,28,.92); opacity: 0; pointer-events: none; transform: translate(-50%, 16px); transition: .22s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 820px) {
  .app-shell { padding: max(18px, env(safe-area-inset-top)) 14px calc(22px + env(safe-area-inset-bottom)); }
  .topbar { margin-bottom: 17px; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace-grid { display: block; min-height: 0; }
  .session-panel { min-height: 520px; }
  .conversation-panel { position: fixed; z-index: 10; inset: 0; border: 0; border-radius: 0; background: #f7faf7; transform: translateX(105%); transition: transform .25s ease; }
  .conversation-panel.mobile-open { transform: translateX(0); }
  .conversation-head { padding-top: max(18px, env(safe-area-inset-top)); }
  .conversation-head:before { content: "‹"; margin-right: 2px; font-size: 32px; cursor: pointer; }
  .timeline { max-height: none; }
  .composer { padding-bottom: calc(15px + env(safe-area-inset-bottom)); }
  .composer-actions .button { flex: 1 1 calc(50% - 8px); }
}

/* Pure terminal theme. Keep this block last so it deliberately replaces the
   original dashboard styling without changing any realtime behavior. */
:root {
  --term-bg: #090c10;
  --term-panel: #0d1117;
  --term-panel-2: #11161d;
  --term-hover: #161b22;
  --term-border: #30363d;
  --term-text: #d8dee9;
  --term-bright: #f0f6fc;
  --term-muted: #7d8590;
  --term-green: #3fb950;
  --term-blue: #58a6ff;
  --term-amber: #d29922;
  --term-red: #f85149;
}

html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  color: var(--term-text);
  background: var(--term-bg);
  font-family: "Cascadia Code", "JetBrains Mono", Consolas, "Microsoft YaHei UI", monospace;
}

button, input, textarea { font-family: inherit; }
.ambient, .summary { display: none !important; }

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  height: 100dvh;
  min-height: 0;
  margin: 0;
  padding: 0;
  background: var(--term-bg);
}

.topbar {
  flex: 0 0 42px;
  min-height: 42px;
  margin: 0;
  padding: 0 12px;
  border-bottom: 1px solid var(--term-border);
  color: var(--term-bright);
  background: var(--term-panel);
}

.topbar > div:first-child { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.eyebrow { margin: 0; color: var(--term-muted); font-size: 11px; font-weight: 400; letter-spacing: 0; text-transform: none; }
h1 { margin: 0; overflow: hidden; color: var(--term-bright); font-family: inherit; font-size: 13px; font-weight: 600; letter-spacing: 0; white-space: nowrap; text-overflow: ellipsis; }
h1::before { content: "$ "; color: var(--term-green); }
h2 { color: var(--term-bright); font-size: 13px; font-weight: 600; letter-spacing: 0; }

.connection-pill {
  gap: 7px;
  padding: 3px 7px;
  border: 1px solid var(--term-border);
  border-radius: 2px;
  color: var(--term-muted);
  background: transparent;
  font-size: 10px;
  font-weight: 400;
}
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--term-amber); box-shadow: none; }
.connection-pill.online .pulse-dot { background: var(--term-green); box-shadow: none; animation: none; }

.node-tabs {
  flex: 0 0 38px;
  width: 100%;
  height: 38px;
  gap: 0;
  overflow-x: auto;
  padding: 0 8px;
  border-bottom: 1px solid var(--term-border);
  background: var(--term-panel);
}
.node-tab {
  min-width: auto;
  height: 37px;
  padding: 6px 14px;
  border: 0;
  border-right: 1px solid #21262d;
  border-radius: 0;
  color: var(--term-muted);
  background: transparent;
  text-align: left;
  transition: none;
}
.node-tab:first-child { border-left: 1px solid #21262d; }
.node-tab:hover { color: var(--term-text); background: var(--term-hover); }
.node-tab.active { border-bottom: 2px solid var(--term-blue); color: var(--term-bright); background: var(--term-hover); box-shadow: none; transform: none; }
.node-tab span { font-size: 11px; font-weight: 600; }
.node-tab small { margin-top: 1px; font-size: 9px; opacity: .7; }

.workspace-grid {
  display: grid;
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 0;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 0;
}
.panel { min-height: 0; border: 0; border-radius: 0; background: var(--term-bg); box-shadow: none; backdrop-filter: none; }
.session-panel { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--term-border); background: var(--term-panel); }
.panel-heading, .conversation-head {
  flex: 0 0 48px;
  min-height: 48px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--term-border);
  background: var(--term-panel);
}
.kicker { margin: 0 0 2px; color: var(--term-muted); font-size: 9px; font-weight: 400; letter-spacing: .08em; text-transform: uppercase; }
.heading-actions { gap: 4px; }
.icon-button {
  width: 27px;
  height: 27px;
  padding: 0;
  border: 1px solid var(--term-border);
  border-radius: 2px;
  color: var(--term-text);
  background: transparent;
  font-size: 16px;
}
.icon-button:hover { color: var(--term-bright); background: var(--term-hover); }
.session-list { flex: 1; min-height: 0; max-height: none; overflow-y: auto; padding: 3px; }
.session-item {
  grid-template-columns: 8px minmax(0, 1fr) auto;
  gap: 8px;
  padding: 9px 7px;
  border: 0;
  border-radius: 0;
  color: var(--term-text);
  background: transparent;
}
.session-item:hover, .session-item.active { background: var(--term-hover); }
.session-item.active { box-shadow: inset 2px 0 var(--term-blue); }
.state-dot { width: 6px; height: 6px; margin-top: 5px; box-shadow: none !important; }
.state-dot.active { background: var(--term-green); }
.state-dot.open { background: var(--term-blue); }
.state-dot.systemError { background: var(--term-red); }
.session-name { color: var(--term-bright); font-size: 11px; font-weight: 500; }
.session-preview { margin-top: 3px; color: var(--term-muted); font-size: 10px; line-height: 1.4; }
.session-time { color: #545d68; font-size: 9px; }
.list-empty { padding: 32px 12px; color: var(--term-muted); font-size: 11px; text-align: center; }

.conversation-panel { display: flex; min-width: 0; min-height: 0; flex-direction: column; background: var(--term-bg); }
.empty-state { margin: auto; padding: 30px 18px; color: var(--term-muted); font-size: 11px; }
.empty-state h2 { margin: 0 0 8px; color: var(--term-text); }
.empty-state p { margin: 0; }
.empty-orbit { display: none; }
.conversation { flex: 1; min-height: 0; }
.conversation-head { color: var(--term-text); }
.session-breadcrumb { margin-bottom: 2px; color: var(--term-blue); font-size: 9px; font-weight: 400; }
.status-chip { padding: 3px 6px; border: 1px solid var(--term-border); border-radius: 2px; color: var(--term-muted); background: transparent; font-size: 9px; font-weight: 400; }
.status-chip.active, .status-chip.open { border-color: #238636; color: var(--term-green); background: transparent; }
.metadata {
  flex: 0 0 auto;
  gap: 12px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--term-border);
  color: var(--term-muted);
  background: var(--term-panel);
  font-size: 9px;
}
.metadata span { padding: 0; border-radius: 0; background: transparent; }
.metadata span::before { content: "· "; color: #545d68; }
.timeline {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 8px 14px 14px;
  background: var(--term-bg);
  scroll-behavior: smooth;
}
.event {
  margin: 0;
  padding: 9px 4px 10px 10px;
  border: 0;
  border-bottom: 1px solid #161b22;
  border-left: 2px solid #30363d;
  border-radius: 0;
  color: var(--term-text);
  background: transparent;
}
.event.agent { border-left-color: var(--term-green); background: transparent; }
.event.command { border-left-color: var(--term-amber); color: #c9d1d9; background: transparent; font-family: inherit; }
.event.error { border-left-color: var(--term-red); }
.event-label { margin-bottom: 5px; color: var(--term-muted); font: 500 9px/1 inherit; letter-spacing: .04em; text-transform: none; }
.event.agent .event-label { color: var(--term-green); }
.event-body { color: inherit; white-space: pre-wrap; word-break: break-word; font-size: 12px; line-height: 1.55; }
.history-more { margin: 7px auto; color: var(--term-blue); background: transparent; }

.approval-box { margin: 0; padding: 10px 12px; border: 0; border-top: 1px solid var(--term-amber); border-radius: 0; color: var(--term-text); background: #16120a; }
.button-row, .composer-actions { gap: 5px; margin-top: 7px; }
.composer { flex: 0 0 auto; padding: 8px 10px 9px; border-top: 1px solid var(--term-border); background: var(--term-panel); }
.terminal-input-row { display: grid; grid-template-columns: auto minmax(0, 1fr) 34px; gap: 7px; align-items: stretch; }
.terminal-prompt { padding: 9px 0 0 2px; color: var(--term-green); font-size: 16px; line-height: 1; }
.terminal-send { border: 1px solid var(--term-border); border-radius: 2px; color: var(--term-green); background: var(--term-bg); font: 600 16px/1 inherit; }
.terminal-send:hover { border-color: var(--term-green); background: var(--term-hover); }
.composer textarea, .auth-card input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--term-border);
  border-radius: 2px;
  outline: none;
  color: var(--term-bright);
  background: var(--term-bg);
  caret-color: var(--term-green);
}
.composer textarea:focus, .auth-card input:focus { border-color: var(--term-blue); box-shadow: none; }
.composer textarea::placeholder, .auth-card input::placeholder { color: #545d68; }
.composer-actions { justify-content: flex-end; }
.button {
  padding: 6px 9px;
  border: 1px solid var(--term-border);
  border-radius: 2px;
  color: var(--term-text);
  background: transparent;
  font-size: 10px;
  font-weight: 500;
}
.button:hover { color: var(--term-bright); background: var(--term-hover); }
.button.primary { border-color: #238636; color: #fff; background: #238636; }
.button.primary:hover { background: #2ea043; }
.button.danger { border-color: #6e2825; color: var(--term-red); }
.button.subtle { background: transparent; }

.auth-layer { background: rgba(9, 12, 16, .96); backdrop-filter: none; }
.auth-card { width: min(430px, 100%); padding: 22px; border: 1px solid var(--term-border); border-radius: 2px; color: var(--term-text); background: var(--term-panel); box-shadow: none; }
.brand-mark { width: auto; height: auto; margin-bottom: 16px; place-items: start; border-radius: 0; color: var(--term-green); background: transparent; font-family: inherit; font-size: 13px; }
.brand-mark::before { content: "$ codex login "; }
.auth-card p { color: var(--term-muted); font-size: 11px; line-height: 1.6; }
.form-error { color: var(--term-red); }
.toast { bottom: 14px; padding: 7px 10px; border: 1px solid var(--term-border); border-radius: 2px; color: var(--term-text); background: var(--term-panel-2); font-size: 10px; }

* { scrollbar-width: thin; scrollbar-color: #30363d #0d1117; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: var(--term-panel); }
*::-webkit-scrollbar-thumb { background: #30363d; }

@media (max-width: 820px) {
  .app-shell { height: 100dvh; padding: 0; }
  .topbar { flex: 0 0 40px; min-height: 40px; margin: 0; padding: 0 9px; }
  .eyebrow { display: none; }
  .node-tabs { flex-basis: 36px; height: 36px; padding-left: 0; }
  .node-tab { height: 35px; padding: 5px 11px; }
  .workspace-grid { display: block; flex: 1; min-height: 0; }
  .session-panel { height: 100%; min-height: 0; border-right: 0; }
  .conversation-panel { position: fixed; z-index: 10; inset: 0; border: 0; border-radius: 0; background: var(--term-bg); transform: translateX(105%); transition: transform .18s ease; }
  .conversation-panel.mobile-open { transform: translateX(0); }
  .conversation-head { padding: max(7px, env(safe-area-inset-top)) 10px 7px; }
  .conversation-head:before { content: "‹"; margin-right: 4px; color: var(--term-blue); font-size: 25px; cursor: pointer; }
  .timeline { max-height: none; padding: 5px 8px 10px; }
  .event-body { font-size: 11px; }
  .composer { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .composer-actions .button { flex: 1 1 calc(50% - 5px); }
  .connection-pill { padding: 3px 5px; }
}
