:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f7f7f5;
  color: #202123;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

body.drawer-active {
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: #202123;
  color: white;
  padding: 10px 14px;
  cursor: pointer;
}

button.secondary,
.provider-pill {
  background: #ececf1;
  color: #202123;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #d9d9e3;
  border-radius: 8px;
  padding: 10px;
  background: white;
  color: #202123;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 650;
}

h1,
h2,
p {
  margin-top: 0;
}

.hidden {
  display: none !important;
}

.mobile-icon-button,
.drawer-backdrop {
  display: none;
}

.login {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 48px;
  align-items: center;
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px;
}

.shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 360px;
  overflow: hidden;
}

.thread-rail,
.harness {
  min-height: 0;
  overflow: auto;
  background: #f0f0f0;
  border-right: 1px solid #dddde6;
  padding: 14px;
}

.harness {
  background: #fafafa;
  border-right: 0;
  border-left: 1px solid #dddde6;
  display: grid;
  gap: 14px;
  align-content: start;
}

.rail-header,
.chat-header,
.model-strip,
.panel-title-row,
.setting-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.summary-box {
  white-space: pre-wrap;
  max-height: 220px;
  overflow: auto;
  background: #f7f7f8;
  border: 1px solid #ececf1;
  color: #202123;
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
}

.memory-screen {
  min-height: 100vh;
  padding: 24px;
  display: grid;
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.memory-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
}

.memory-header h1 {
  margin-bottom: 0;
}

.memory-header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.memory-toolbar {
  gap: 10px;
}

.memory-toolbar-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.memory-search {
  font-weight: 650;
}

.memory-filters {
  display: flex;
  gap: 8px;
}

.memory-filters .active {
  background: #202123;
  color: white;
}

.memory-grid {
  display: grid;
  gap: 12px;
}

.memory-card {
  display: grid;
  gap: 10px;
  background: white;
  border: 1px solid #e4e4eb;
  border-radius: 8px;
  padding: 14px;
}

.memory-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.memory-card-head strong {
  display: block;
  text-transform: capitalize;
}

.memory-card-head span,
.memory-card-meta {
  color: #6b7280;
  font-size: 12px;
}

.memory-card-meta {
  display: grid;
  justify-items: end;
}

.memory-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.danger {
  background: #b42318;
  color: white;
}

.memory-records {
  display: grid;
  gap: 8px;
}

.memory-record {
  display: grid;
  gap: 6px;
  background: #f7f7f8;
  border-radius: 8px;
  padding: 10px;
}

.memory-record footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  color: #6b7280;
  font-size: 12px;
}

.rail-header h1,
.chat-header h2 {
  margin-bottom: 0;
}

.eyebrow {
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b7280;
}

.subtle,
.status,
#context-note {
  color: #6b7280;
}

.error {
  color: #b42318;
}

.panel {
  display: grid;
  gap: 13px;
  background: white;
  border: 1px solid #e4e4eb;
  border-radius: 8px;
  padding: 14px;
}

.threads {
  display: grid;
  gap: 6px;
  margin: 12px 0;
}

.thread-button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: #202123;
  padding: 10px;
}

.thread-button.active,
.thread-button:hover {
  background: #e5e5ea;
}

.thread-button strong,
.thread-button span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-button span {
  color: #6b7280;
  font-size: 12px;
  margin-top: 3px;
}

.chat-shell {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: white;
}

.chat-header {
  padding: 16px 22px;
  border-bottom: 1px solid #ececf1;
}

.model-strip {
  font-size: 13px;
  color: #4b5563;
}

.context-meter {
  display: grid;
  gap: 8px;
  padding: 10px 22px;
  border-bottom: 1px solid #ececf1;
}

.context-meter > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.meter {
  height: 8px;
  border-radius: 999px;
  background: #ececf1;
  overflow: hidden;
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: #10a37f;
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 24px;
  display: grid;
  align-content: start;
  gap: 18px;
}

.empty-state {
  max-width: 620px;
  margin: 16vh auto 0;
  text-align: center;
}

.message {
  max-width: 820px;
  width: min(820px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 8px;
}

.message-role {
  font-size: 12px;
  font-weight: 800;
  color: #6b7280;
  text-transform: uppercase;
}

.message-body {
  white-space: pre-wrap;
  line-height: 1.55;
}

.message.assistant {
  background: #f7f7f8;
  border-radius: 8px;
  padding: 14px;
}

.citations {
  font-size: 12px;
  color: #6b7280;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 16px 22px 22px;
  border-top: 1px solid #ececf1;
}

.composer textarea {
  min-height: 54px;
  max-height: 180px;
}

.composer-actions {
  display: flex;
  gap: 8px;
  align-items: end;
}

.voice-select {
  grid-column: 1 / -1;
  padding: 8px 10px;
  font-size: 13px;
}

#mic-button.recording {
  background: #b42318;
  color: white;
}

#voice-toggle.active {
  background: #10a37f;
  color: white;
}

.inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.results,
.config-stack {
  display: grid;
  gap: 10px;
}

.result {
  border-left: 3px solid #202123;
  padding-left: 10px;
}

.setting-row {
  display: grid;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid #ececf1;
}

.setting-row:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.setting-label {
  margin: 0;
  font-weight: 800;
}

.setting-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.provider-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.provider-pill {
  padding: 7px 10px;
}

.provider-pill.active {
  background: #202123;
  color: white;
}

.test-result {
  font-size: 13px;
  padding: 9px 10px;
  border-radius: 8px;
  background: #eef8f4;
  color: #0f6b50;
}

.test-result.error {
  background: #fff1f0;
  color: #b42318;
}

.harness-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.harness-grid div {
  display: grid;
  gap: 3px;
  background: #f7f7f8;
  border-radius: 8px;
  padding: 10px;
}

.harness-grid span {
  color: #6b7280;
  font-size: 12px;
}

.tool-registry,
.trace-panel {
  display: grid;
  gap: 8px;
}

.tool-row {
  display: grid;
  gap: 4px;
  background: #f7f7f8;
  border-radius: 8px;
  padding: 10px;
}

.tool-row span,
.trace-panel {
  color: #6b7280;
  font-size: 12px;
}

.trace-panel {
  white-space: pre-wrap;
  background: #f7f7f8;
  border-radius: 8px;
  padding: 10px;
}

@media (max-width: 1100px) {
  .shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }

  .harness {
    display: none;
  }
}

@media (max-width: 760px) {
  body {
    background: white;
  }

  .login,
  .shell {
    grid-template-columns: 1fr;
  }

  .shell {
    position: relative;
    height: 100dvh;
  }

  .memory-screen {
    padding: 16px 14px 24px;
  }

  .memory-header {
    align-items: start;
    flex-direction: column;
  }

  .memory-toolbar-row {
    grid-template-columns: 1fr;
  }

  .memory-card-actions .danger {
    width: 100%;
  }

  .drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: block;
    background: rgba(32, 33, 35, 0.36);
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
  }

  .shell.drawer-left-open .drawer-backdrop,
  .shell.drawer-right-open .drawer-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 10px;
    background: #f7f7f8;
    color: #202123;
    border: 1px solid #ececf1;
    font-weight: 800;
  }

  .thread-rail {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    display: block;
    width: min(86vw, 340px);
    min-height: 100dvh;
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
    transform: translateX(-102%);
    transition: transform 180ms ease;
    box-shadow: 12px 0 30px rgba(15, 23, 42, 0.16);
  }

  .harness {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 30;
    display: grid;
    width: min(92vw, 390px);
    min-height: 100dvh;
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
    transform: translateX(102%);
    transition: transform 180ms ease;
    box-shadow: -12px 0 30px rgba(15, 23, 42, 0.16);
  }

  .shell.drawer-left-open .thread-rail,
  .shell.drawer-right-open .harness {
    transform: translateX(0);
  }

  .chat-header {
    position: sticky;
    top: 0;
    z-index: 10;
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
  }

  .chat-header > div:first-of-type {
    min-width: 0;
  }

  .chat-header h2 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
  }

  .model-strip {
    display: none;
  }

  .context-meter {
    padding: 8px 14px;
    background: white;
  }

  .messages {
    padding: 18px 14px;
  }

  .message {
    max-width: 100%;
  }

  .message.assistant {
    padding: 12px;
  }

  .empty-state {
    margin-top: 10vh;
  }

  .composer,
  .context-meter > div:first-child {
    grid-template-columns: 1fr;
  }

  .composer {
    padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
  }

  .composer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
  }

  .voice-select {
    font-size: 12px;
  }

  .panel {
    border-radius: 8px;
    padding: 12px;
  }

  .summary-box {
    max-height: 180px;
  }
}
