:root {
  color-scheme: light dark;
  --bg: #f1ede4;
  --bg-warm: #e7e0d3;
  --panel: #faf8f3;
  --panel-soft: #f4f0e8;
  --ink: #1a1a19;
  --ink-soft: #514b40;
  --line: #d8cfbf;
  --line-strong: #c9bea9;
  --muted: #7f7567;
  --accent: #1c3f80;
  --accent-soft: rgba(28, 63, 128, 0.14);
  --warn: #a35308;
  --ok: #2f6f31;
  --error: #99342f;
  --radius: 16px;
  --shadow: 0 12px 28px rgba(22, 22, 20, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151a21;
    --bg-warm: #10141a;
    --panel: #1a212a;
    --panel-soft: #1e2733;
    --ink: #edf0f8;
    --ink-soft: #c8cfdb;
    --line: #2f3845;
    --line-strong: #3d4858;
    --muted: #97a4b7;
    --accent: #8bb3ff;
    --accent-soft: rgba(139, 179, 255, 0.15);
    --warn: #f2a65a;
    --ok: #78c47f;
    --error: #f18882;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.34);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Manrope", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 7% 5%, rgba(28, 63, 128, 0.16), transparent 35%),
    radial-gradient(circle at 84% 12%, rgba(163, 83, 8, 0.1), transparent 31%),
    linear-gradient(150deg, var(--bg), var(--bg-warm));
  overflow: hidden;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  line-height: 1.2;
}

a {
  color: inherit;
}

.shell {
  width: min(1280px, 100vw);
  height: 100dvh;
  margin: 0 auto;
  padding: 0.7rem 0.9rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.72rem;
}

.topbar {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 90%, white 10%);
  box-shadow: var(--shadow);
  padding: 0.64rem 0.82rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 530px);
  align-items: center;
  gap: 0.9rem;
}

.topbar-left {
  display: grid;
  gap: 0.52rem;
}

.runtime-stack {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(160deg, var(--accent), color-mix(in srgb, var(--accent) 58%, #ffffff 42%));
}

.brand-title {
  font-size: 1rem;
}

.runtime {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0.2rem 0.54rem;
  font-size: 0.76rem;
  color: var(--muted);
  background: var(--panel-soft);
}

.layout {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
  gap: 0.75rem;
}

.auth-panel {
  margin-top: 0;
}

.auth-panel-inline {
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  padding: 0.14rem 0 0.14rem 0.86rem;
  min-width: 0;
}

.auth-inline-head {
  margin-bottom: 0.32rem;
  display: flex;
  align-items: center;
  gap: 0.52rem;
  flex-wrap: wrap;
}

.auth-inline-title {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.auth-inline-endpoint {
  font-size: 0.74rem;
  color: var(--muted);
}

.auth-inline-form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.42rem;
}

.auth-inline-form button,
.auth-inline-form input {
  font: inherit;
}

.auth-inline-form button {
  border: 1px solid var(--line-strong);
  background: var(--panel-soft);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.34rem 0.62rem;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.84rem;
}

.auth-inline-form button:disabled,
.auth-inline-form input:disabled {
  opacity: 0.62;
}

.auth-inline-form input {
  border: 1px solid var(--line-strong);
  background: var(--panel-soft);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.37rem 0.58rem;
  min-width: 210px;
  font-size: 0.84rem;
}

.auth-panel .status-line {
  padding: 0;
  margin-top: 0.3rem;
  font-size: 0.74rem;
  color: var(--muted);
}

.auth-panel.auth-panel-compact .auth-inline-head {
  margin-bottom: 0.28rem;
}

.auth-panel.auth-panel-compact #password-input,
.auth-panel.auth-panel-compact #unlock-btn {
  display: none;
}

.auth-panel.auth-panel-compact .status-line {
  margin-top: 0.32rem;
}

.panel {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 94%, white 6%);
  box-shadow: var(--shadow);
}

.layout .panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.8rem;
  padding: 0.82rem 0.82rem 0.6rem;
}

.kicker {
  margin: 0;
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel-title {
  margin-top: 0.15rem;
  font-size: clamp(1.18rem, 1.7vw, 1.42rem);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.42rem;
  padding: 0 0.82rem 0.62rem;
}

.toolbar button,
.toolbar input,
.composer textarea,
.composer button {
  font: inherit;
}

.toolbar button,
.network-actions button {
  border: 1px solid var(--line-strong);
  background: var(--panel-soft);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.38rem 0.65rem;
  cursor: pointer;
  font-weight: 700;
}

.tool-form button:disabled,
.tool-form input:disabled,
.tool-form textarea:disabled {
  opacity: 0.62;
}

.toolbar button:disabled,
.composer button:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.toolbar input {
  border: 1px solid var(--line-strong);
  background: var(--panel-soft);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.42rem 0.58rem;
  min-width: 210px;
}

.tool-row input {
  border: 1px solid var(--line-strong);
  background: var(--panel-soft);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.46rem 0.65rem;
}

.session-row {
  padding: 0 1rem 0.6rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.42rem;
  border-bottom: 1px solid var(--line);
}

.activity {
  margin: 0.45rem 1rem 0.62rem;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel-soft) 84%, white 16%);
}

.activity-title {
  margin: 0;
  padding: 0.42rem 0.62rem 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0 0.6rem 0.55rem;
  display: grid;
  gap: 0.25rem;
  max-height: 90px;
  overflow: auto;
}

.activity-item {
  font-size: 0.76rem;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  padding: 0.2rem 0.44rem;
}

.session-pill {
  border: 1px solid var(--line-strong);
  background: var(--panel-soft);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.22rem 0.62rem;
  font-size: 0.77rem;
  font-weight: 700;
  cursor: pointer;
}

.session-pill.active {
  background: var(--accent-soft);
  color: var(--ink);
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line-strong) 50%);
}

.messages {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
  padding: 0.68rem 0.82rem;
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 0.58rem;
}

.bubble {
  max-width: min(92%, 720px);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--panel-soft);
  padding: 0.58rem 0.74rem;
  animation: rise 180ms ease-out;
}

.bubble.user {
  margin-left: auto;
  background: color-mix(in srgb, var(--accent-soft) 55%, var(--panel-soft) 45%);
}

.bubble.assistant {
  margin-right: auto;
}

.bubble-role {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.bubble-copy {
  margin: 0.3rem 0 0;
  color: var(--ink);
  line-height: 1.45;
}

.bubble-copy > :first-child {
  margin-top: 0;
}

.bubble-copy > :last-child {
  margin-bottom: 0;
}

.bubble-copy p {
  margin: 0 0 0.56rem;
}

.bubble-copy h1,
.bubble-copy h2,
.bubble-copy h3,
.bubble-copy h4,
.bubble-copy h5,
.bubble-copy h6 {
  margin: 0.2rem 0 0.46rem;
  font-family: "Fraunces", serif;
  line-height: 1.2;
}

.bubble-copy h1 {
  font-size: 1.34rem;
}

.bubble-copy h2 {
  font-size: 1.2rem;
}

.bubble-copy h3 {
  font-size: 1.08rem;
}

.bubble-copy ul,
.bubble-copy ol {
  margin: 0.1rem 0 0.56rem 1.2rem;
  padding: 0;
}

.bubble-copy li + li {
  margin-top: 0.2rem;
}

.bubble-copy li.task-item {
  list-style: none;
  margin-left: -1.14rem;
  display: flex;
  align-items: flex-start;
  gap: 0.44rem;
}

.bubble-copy li.task-item input[type="checkbox"] {
  margin: 0.18rem 0 0;
}

.bubble-copy li.task-item span {
  flex: 1;
}

.bubble-copy blockquote {
  margin: 0.16rem 0 0.56rem;
  padding-left: 0.62rem;
  border-left: 3px solid color-mix(in srgb, var(--accent) 35%, var(--line-strong) 65%);
  color: var(--ink-soft);
}

.bubble-copy hr {
  margin: 0.62rem 0 0.66rem;
  border: 0;
  border-top: 1px solid var(--line-strong);
}

.bubble-copy pre {
  margin: 0.18rem 0 0.56rem;
  padding: 0.52rem 0.6rem;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: color-mix(in srgb, var(--bg) 70%, var(--panel) 30%);
  overflow: auto;
}

.bubble-copy pre code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.84rem;
  white-space: pre;
  display: block;
  border: 0;
  background: transparent;
  padding: 0;
}

.bubble-copy code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.84em;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: color-mix(in srgb, var(--panel-soft) 70%, var(--bg) 30%);
  padding: 0.04rem 0.28rem;
}

.bubble-copy a {
  color: color-mix(in srgb, var(--accent) 86%, #22424b 14%);
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.14em;
}

.bubble-copy .md-table-wrap {
  margin: 0.18rem 0 0.62rem;
  overflow-x: auto;
}

.bubble-copy table {
  width: 100%;
  min-width: 320px;
  border-collapse: collapse;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  overflow: hidden;
}

.bubble-copy th,
.bubble-copy td {
  border: 1px solid var(--line-strong);
  padding: 0.34rem 0.46rem;
  vertical-align: top;
}

.bubble-copy th {
  text-align: left;
  background: color-mix(in srgb, var(--panel-soft) 84%, white 16%);
  font-weight: 700;
}

.bubble-copy img {
  max-width: 100%;
  height: auto;
  margin: 0.14rem 0 0.48rem;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
}

.bubble-copy strong {
  font-weight: 700;
}

.bubble-copy em {
  font-style: italic;
}

.bubble-copy del {
  color: var(--ink-soft);
}

.bubble-time {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.72rem;
}

.thinking-row {
  max-width: min(92%, 720px);
  margin-right: auto;
  padding: 0.12rem 0.08rem;
  display: flex;
  align-items: center;
  color: var(--ink-soft);
  animation: rise 180ms ease-out;
}

.thinking-copy {
  margin: 0;
  color: var(--ink-soft);
  font-family: "Fraunces", serif;
  font-size: 1.05rem;
  font-style: italic;
  white-space: pre-wrap;
}

.composer {
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.58rem;
  padding: 0.62rem 0.82rem 0.74rem;
}

.composer textarea {
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--panel-soft);
  color: var(--ink);
  min-height: 48px;
  max-height: 130px;
  resize: vertical;
  padding: 0.62rem 0.7rem;
}

.composer button {
  min-width: 52px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--line-strong) 45%);
  background: var(--accent);
  color: #f5f8ff;
  font-size: 1.2rem;
  font-weight: 800;
}

.status-line {
  margin: 0;
  padding: 0 0.82rem 0.78rem;
  color: var(--muted);
  font-size: 0.81rem;
}

.status-line.error {
  color: var(--error);
}

.network-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.drawer {
  margin: 0 0.82rem 0.62rem;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel-soft) 78%, white 22%);
}

.drawer > summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.02em;
  padding: 0.42rem 0.62rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer > summary::after {
  content: "+";
  font-size: 0.9rem;
  line-height: 1;
}

.drawer[open] > summary::after {
  content: "−";
}

.drawer > summary::-webkit-details-marker {
  display: none;
}

.control-drawer .session-row {
  padding: 0.08rem 0.62rem 0.56rem;
}

.control-drawer .activity {
  margin: 0.38rem 0.62rem 0.6rem;
}

.tools-drawer .tool-card {
  margin: 0.36rem 0.62rem 0.62rem;
}

.tool-card {
  margin: 0.25rem 1rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel-soft) 76%, white 24%);
  padding: 0.58rem 0.64rem 0.66rem;
}

.tool-title {
  font-size: 0.88rem;
  font-family: "Fraunces", Georgia, serif;
  margin: 0 0 0.38rem;
}

.tool-form {
  display: grid;
  gap: 0.42rem;
}

.tool-form textarea,
.tool-form input {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel-soft);
  color: var(--ink);
  padding: 0.5rem 0.62rem;
  font: inherit;
}

.tool-form textarea {
  min-height: 66px;
  resize: vertical;
}

.tool-form button {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel-soft);
  color: var(--ink);
  padding: 0.42rem 0.65rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.tool-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.42rem;
}

.network-count {
  margin: 0;
  padding: 0 0.82rem 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.network-list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0.72rem 0.72rem;
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 0.56rem;
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
}

.trace {
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--panel-soft);
  padding: 0.55rem 0.68rem;
}

.trace-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.24rem;
}

.trace-badges {
  display: inline-flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.tag {
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  padding: 0.14rem 0.44rem;
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 86%, white 14%);
}

.tag.status.ok {
  color: var(--ok);
}

.tag.status.warn {
  color: var(--warn);
}

.tag.status.error {
  color: var(--error);
}

.trace-url {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.81rem;
  word-break: break-all;
}

.trace-note {
  margin: 0.38rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.trace details {
  margin-top: 0.42rem;
}

.trace summary {
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--muted);
}

.trace pre {
  margin: 0.42rem 0 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--panel) 70%, var(--bg) 30%);
  padding: 0.5rem;
  overflow-x: auto;
  font-size: 0.72rem;
}

.empty {
  margin: 0;
  color: var(--muted);
  padding: 0.5rem 0.82rem 0.8rem;
}

.spec-note {
  margin: 0.08rem 0.82rem 0.62rem;
  padding: 0.42rem 0.56rem;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  font-size: 0.74rem;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1020px) {
  body {
    overflow: auto;
  }

  .shell {
    height: auto;
    min-height: 100dvh;
  }

  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .shell {
    padding: 0.62rem 0.62rem 0.95rem;
    gap: 0.62rem;
  }

  .topbar {
    border-radius: 14px;
    grid-template-columns: 1fr;
    padding: 0.66rem 0.62rem;
  }

  .auth-panel-inline {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 0.58rem 0 0 0;
    width: 100%;
  }

  .toolbar input {
    min-width: 0;
    width: 100%;
  }

  .auth-inline-form input {
    min-width: 0;
    width: 100%;
  }

  .toolbar {
    gap: 0.4rem;
  }

  .layout .panel {
    min-height: 420px;
  }

  .messages,
  .network-list {
    min-height: 200px;
  }
}
