:root {
  --bg: #f4f7f2;
  --panel: #ffffff;
  --ink: #17201a;
  --muted: #647067;
  --line: #d8e2d7;
  --accent: #e4573d;
  --accent-strong: #bd3e29;
  --sage: #416d56;
  --sage-soft: #dcebe1;
  --user: #173f35;
  --assistant: #ffffff;
  --shadow: 0 20px 60px rgba(28, 45, 35, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Aptos", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(228, 87, 61, 0.11), transparent 34%),
    radial-gradient(circle at 80% 10%, rgba(65, 109, 86, 0.22), transparent 28%),
    var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  padding: 11px 15px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.ghost-button {
  background: transparent;
  color: var(--sage);
  border: 1px solid var(--line);
}

.ghost-button:hover {
  background: var(--sage-soft);
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-strong);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 34px;
}

h2 {
  font-size: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(65, 109, 86, 0.14);
}

.error-line {
  min-height: 20px;
  margin: 0;
  color: var(--accent-strong);
}

.app-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr) minmax(300px, 390px);
}

.sidebar,
.inspector {
  display: grid;
  align-content: start;
  gap: 22px;
  padding: 24px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(12px);
}

.sidebar {
  border-right: 1px solid var(--line);
}

.inspector {
  max-height: 100vh;
  overflow-y: auto;
  border-left: 1px solid var(--line);
}

.topline,
.chat-header,
.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.summary,
.profile-details p,
.status-line {
  color: var(--muted);
  line-height: 1.5;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.meta-row span,
.chips span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--sage-soft);
  color: var(--sage);
  font-size: 13px;
}

.profile-details,
.import-block,
.danger-block,
.memory-block,
.events-block,
.artifacts-block,
.context-block {
  display: grid;
  gap: 10px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

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

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

.source-form input:nth-child(2),
.source-form input:nth-child(3) {
  grid-column: 1 / -1;
}

.source-form button {
  grid-column: 1 / -1;
}

.inline-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.memory-form button {
  grid-column: 1 / -1;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
}

.stack-list {
  display: grid;
  gap: 8px;
}

.list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.7);
}

.list-item p {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.artifact-open {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.artifact-open:hover {
  background: transparent;
  color: var(--ink);
}

.artifact-open small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.empty-line {
  color: var(--muted);
  font-size: 14px;
}

.small-button {
  padding: 7px 10px;
  font-size: 13px;
}

.icon-button {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  padding: 0;
  font-size: 20px;
}

.context-row {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  text-align: left;
  padding: 9px 10px;
}

.context-row:hover {
  background: var(--sage-soft);
  color: var(--ink);
}

.context-detail {
  max-height: 420px;
  margin: 0;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(23, 32, 26, 0.04);
  color: var(--ink);
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

.chat-area {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
}

.chat-header {
  padding: 22px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 247, 242, 0.75);
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.message {
  max-width: min(760px, 86%);
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--line);
}

.message.user {
  align-self: flex-end;
  color: #fff;
  background: var(--user);
  border-color: var(--user);
}

.message.assistant {
  align-self: flex-start;
  color: var(--ink);
  background: var(--assistant);
}

.message.system {
  align-self: center;
  max-width: 640px;
  color: var(--muted);
  background: transparent;
  border-style: dashed;
}

.message .time {
  display: block;
  margin-top: 8px;
  color: inherit;
  opacity: 0.62;
  font-size: 12px;
}

.message strong {
  font-weight: 750;
}

.message code {
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(23, 32, 26, 0.08);
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 0.92em;
}

.message.user code {
  background: rgba(255, 255, 255, 0.16);
}

.danger-button {
  background: #842f2b;
}

.danger-button:hover {
  background: #6d2522;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: 16px 26px 22px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.composer textarea {
  resize: none;
  min-height: 48px;
  max-height: 160px;
}

.attachment-picker {
  align-self: stretch;
  min-width: 96px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--sage);
  border-radius: 7px;
  color: var(--sage);
  background: rgba(220, 235, 225, 0.55);
  cursor: pointer;
}

.attachment-picker input {
  display: none;
}

.attachment-status {
  grid-column: 1 / -1;
  min-height: 18px;
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 820px) {
  .app-view {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .inspector {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .inspector {
    max-height: none;
    border-left: 0;
  }

  .chat-area {
    height: 70vh;
  }

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

  .message {
    max-width: 94%;
  }
}

/* V2.2 modern chat shell */
:root {
  --bg: #eef3ea;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #fffdf8;
  --ink: #18231d;
  --muted: #6d766e;
  --line: rgba(31, 47, 38, 0.12);
  --accent: #d95a3a;
  --accent-strong: #a93d27;
  --sage: #315f48;
  --sage-soft: #dcece2;
  --user: #173f35;
  --assistant: #fffdf8;
  --soft-shadow: 0 18px 55px rgba(21, 39, 29, 0.12);
  --tight-shadow: 0 8px 24px rgba(21, 39, 29, 0.08);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --font-ui: "Aptos", "Trebuchet MS", sans-serif;
  --font-display: "Georgia", "Times New Roman", serif;
}

body {
  font-family: var(--font-ui);
  background:
    radial-gradient(circle at 18% 12%, rgba(217, 90, 58, 0.16), transparent 30%),
    radial-gradient(circle at 84% 4%, rgba(49, 95, 72, 0.22), transparent 28%),
    linear-gradient(145deg, #f7f0e4 0%, #edf4ed 45%, #e8efe8 100%);
}

button,
input,
textarea,
select {
  border-radius: 999px;
}

button {
  box-shadow: 0 8px 18px rgba(217, 90, 58, 0.18);
  transition:
    transform 0.16s ease,
    box-shadow 0.16s ease,
    background 0.16s ease;
}

button:hover {
  transform: translateY(-1px);
}

.ghost-button {
  background: rgba(255, 255, 255, 0.68);
  box-shadow: none;
}

.app-view {
  grid-template-columns: 288px minmax(420px, 1fr) 410px;
  gap: 16px;
  padding: 16px;
}

.sidebar,
.inspector,
.chat-area {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--tight-shadow);
  backdrop-filter: blur(18px);
}

.sidebar {
  border-right: 1px solid var(--line);
  border-radius: var(--radius-xl);
  gap: 18px;
}

.profile-block,
.profile-details,
.settings-section,
.import-block,
.danger-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 253, 248, 0.72);
}

.profile-block {
  background:
    linear-gradient(145deg, rgba(255, 253, 248, 0.92), rgba(220, 236, 226, 0.82)),
    var(--panel-solid);
}

h1,
h2 {
  font-family: var(--font-display);
  font-weight: 700;
}

.profile-block h1 {
  font-size: 38px;
}

.summary,
.profile-details p,
.settings-copy,
.status-line {
  font-size: 14px;
}

.meta-row span,
.chips span {
  border: 0;
  background: rgba(49, 95, 72, 0.1);
}

.chat-area {
  overflow: hidden;
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.92), rgba(255, 253, 248, 0.72)),
    var(--panel-solid);
}

.chat-header {
  min-height: 92px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(255, 253, 248, 0.96), rgba(220, 236, 226, 0.78)),
    var(--panel-solid);
}

.chat-header h2 {
  font-size: 28px;
}

.chat-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.mobile-only {
  display: none;
}

.messages {
  padding: 28px min(7vw, 76px);
  gap: 16px;
  background:
    linear-gradient(rgba(255, 253, 248, 0.64), rgba(255, 253, 248, 0.64)),
    radial-gradient(circle at 50% 0, rgba(49, 95, 72, 0.08), transparent 36%);
}

.message {
  max-width: min(720px, 82%);
  padding: 0;
  border: 0;
  background: transparent;
}

.message-bubble {
  padding: 13px 15px 11px;
  border: 1px solid var(--line);
  border-radius: 21px;
  box-shadow: 0 6px 16px rgba(21, 39, 29, 0.06);
}

.message.user .message-bubble {
  color: #f8fff9;
  background: linear-gradient(145deg, #153d33, #1f5a49);
  border-color: rgba(255, 255, 255, 0.08);
  border-bottom-right-radius: 7px;
}

.message.assistant .message-bubble {
  color: var(--ink);
  background: rgba(255, 253, 248, 0.96);
  border-bottom-left-radius: 7px;
}

.message-label {
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 800;
  opacity: 0.68;
}

.message-content {
  white-space: pre-wrap;
}

.message .time {
  margin-top: 7px;
  font-size: 11px;
}

.message.pending .message-bubble {
  opacity: 0.82;
}

.message.pending.assistant .message-content::after {
  content: "";
  display: inline-block;
  width: 1.1em;
  height: 0.35em;
  margin-left: 0.2em;
  background: radial-gradient(circle, currentColor 42%, transparent 45%) 0 50% / 0.36em 0.36em repeat-x;
  opacity: 0.35;
  animation: thinking-dots 1s ease-in-out infinite;
}

.message.error .message-bubble {
  border-color: rgba(169, 61, 39, 0.3);
  background: rgba(217, 90, 58, 0.08);
}

@keyframes thinking-dots {
  0%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  50% {
    opacity: 0.8;
    transform: translateY(-1px);
  }
}

.composer {
  grid-template-columns: minmax(0, 1fr) 52px 52px;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
}

.composer textarea {
  min-height: 52px;
  padding: 15px 17px;
  border-radius: 22px;
  background: #ffffff;
}

.attachment-picker {
  min-width: 52px;
  border-radius: 999px;
}

.icon-action {
  width: 52px;
  height: 52px;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.icon-action svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.send-button {
  background: var(--user);
  color: #fff;
  box-shadow: 0 10px 20px rgba(23, 63, 53, 0.2);
}

.send-button:hover {
  background: #215b4a;
}

.inspector {
  border-left: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 18px;
  align-content: start;
}

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.settings-header h2 {
  font-size: 28px;
}

.settings-tabs {
  display: flex;
  align-items: center;
  gap: 7px;
  overflow-x: auto;
  min-height: 0;
  height: 46px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.72);
  box-shadow: none;
  scrollbar-width: none;
}

.settings-tabs::-webkit-scrollbar {
  display: none;
}

.settings-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  height: 34px;
  min-height: 0;
  padding: 7px 11px;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  transform: none;
}

.settings-tab:hover {
  transform: none;
}

.settings-tab:hover,
.settings-tab.active {
  background: var(--sage);
  color: #fff;
}

.settings-section {
  display: none;
  gap: 12px;
  margin-top: 0;
}

.settings-section.active {
  display: grid;
}

.memory-form {
  grid-template-columns: 128px minmax(0, 1fr) auto;
  align-items: center;
}

.memory-form button {
  grid-column: auto;
}

.source-form {
  grid-template-columns: minmax(0, 1fr) 84px;
}

.list-item {
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.68);
}

.danger-card {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  background: rgba(132, 47, 43, 0.08);
}

.danger-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.context-detail {
  max-height: 360px;
  border-radius: var(--radius-md);
}

@media (max-width: 1180px) {
  .app-view {
    grid-template-columns: 240px minmax(360px, 1fr) 360px;
    gap: 12px;
    padding: 12px;
  }

  .messages {
    padding-inline: 28px;
  }
}

@media (max-width: 900px) {
  body {
    overflow: hidden;
  }

  .app-view {
    min-height: 100dvh;
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0;
  }

  .sidebar {
    display: none;
  }

  .chat-area,
  .inspector {
    height: 100dvh;
    max-height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .inspector {
    display: none;
    padding: 14px;
    overflow-y: auto;
  }

  .app-view.settings-open .chat-area {
    display: none;
  }

  .app-view.settings-open .inspector {
    display: grid;
  }

  .mobile-only {
    display: inline-flex;
  }

  .chat-header {
    min-height: auto;
    padding: 14px 14px 12px;
    align-items: center;
  }

  .chat-header h2,
  .settings-header h2 {
    font-size: 24px;
  }

  .chat-subtitle {
    display: none;
  }

  .header-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  #refreshButton {
    display: none;
  }

  .messages {
    padding: 18px 12px;
    gap: 12px;
  }

  .message {
    max-width: 90%;
  }

  .message-bubble {
    padding: 12px 13px 10px;
    border-radius: 18px;
  }

  .composer {
    grid-template-columns: 48px minmax(0, 1fr) 48px;
    align-items: end;
    gap: 8px;
    padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  }

  .composer textarea {
    grid-column: 2;
    grid-row: 1;
    min-height: 46px;
    max-height: 118px;
    border-radius: 18px;
  }

  .attachment-picker {
    grid-column: 1;
    grid-row: 1;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
  }

  .send-button {
    grid-column: 3;
    grid-row: 1;
    width: 48px;
    height: 48px;
  }

  .attachment-status {
    grid-column: 1 / -1;
  }

  .settings-tabs {
    position: sticky;
    top: 0;
    z-index: 20;
    margin-bottom: 10px;
  }

  .settings-section.active {
    position: relative;
    z-index: 1;
  }

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

  .memory-form button {
    grid-column: 1;
  }

  .source-form {
    grid-template-columns: 1fr;
  }

  .source-form input,
  .source-form select,
  .source-form button {
    grid-column: 1;
  }

  .context-detail {
    max-height: 45dvh;
  }
}
