:root {
  color-scheme: light;
  --bg: #f6f1eb;
  --paper: #fffdf9;
  --panel: #eee5dc;
  --panel-2: #f9f5ef;
  --ink: #241f1b;
  --muted: #7a6f66;
  --line: #ded2c6;
  --accent: #2f7d68;
  --accent-2: #b56b45;
  --danger: #b84a42;
  --shadow: 0 18px 48px rgba(79, 59, 38, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button,
textarea,
input {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.appView[hidden] {
  display: none !important;
}

.shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(310px, 390px) minmax(0, 1fr);
}

.leftPane {
  display: grid;
  grid-template-rows: auto minmax(240px, 1fr) auto;
  gap: 18px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #ede2d7;
}

.brandRow {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.brand {
  font-size: 18px;
  font-weight: 760;
}

.tagline {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.portraitWrap {
  min-height: 0;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  box-shadow: var(--shadow);
}

.portrait,
.portraitFallback {
  width: 100%;
  height: 100%;
  min-height: 260px;
  object-fit: cover;
  display: block;
}

.portraitFallback {
  display: grid;
  place-items: center;
  background:
    linear-gradient(145deg, rgba(47, 125, 104, 0.18), rgba(181, 107, 69, 0.14)),
    var(--panel-2);
}

.fallbackInitial {
  width: 118px;
  height: 118px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid rgba(36, 31, 27, 0.14);
  font-size: 28px;
  font-weight: 780;
  background: rgba(255, 255, 255, 0.45);
}

.clarityPanel,
.chatPane,
dialog,
.adminTopbar,
.adminSide,
.adminMain,
.loginBox {
  background: var(--paper);
}

.clarityPanel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 14px;
}

.panelHeader,
.meterTop,
.chatHeader,
.dialogHeader,
.adminTopbar,
.adminHero,
.editorActions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

#phaseBadge,
.statusPill {
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(47, 125, 104, 0.1);
  color: var(--accent);
  font-size: 12px;
}

.meterTop {
  color: var(--muted);
  font-size: 13px;
}

.track {
  height: 8px;
  border-radius: 999px;
  background: #e3d8cc;
  overflow: hidden;
  margin-top: 7px;
}

.track span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.24s ease;
}

.nextStep {
  border-top: 1px solid var(--line);
  padding-top: 13px;
  color: var(--muted);
  font-size: 13px;
}

.nextStep p {
  color: var(--ink);
  margin: 8px 0 0;
  line-height: 1.5;
}

.chatPane {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100dvh;
}

.chatHeader {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

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

h1,
h2,
p {
  margin: 0;
}

.chatHeader h1 {
  font-size: 23px;
  line-height: 1.15;
}

.chatHeader p,
.adminHero p,
.loginBox p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.mobileStatus {
  display: none;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  background: var(--panel-2);
}

.mobileStatus span {
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--muted);
}

.messages {
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: min(720px, 88%);
  padding: 12px 14px;
  border-radius: 8px;
  line-height: 1.52;
  white-space: pre-wrap;
  box-shadow: 0 1px 0 rgba(36, 31, 27, 0.04);
}

.message.assistant {
  align-self: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.message.user {
  align-self: flex-end;
  background: #2f7d68;
  color: #ffffff;
}

.message.typing {
  color: var(--muted);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 16px 22px 20px;
  border-top: 1px solid var(--line);
  background: #ede2d7;
}

textarea,
input {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fffaf4;
  color: var(--ink);
  outline: none;
}

textarea {
  resize: none;
  min-height: 52px;
  max-height: 220px;
  padding: 13px 14px;
}

input {
  height: 42px;
  padding: 0 12px;
}

textarea:focus,
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 125, 104, 0.12);
}

button,
.ghostLink {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

#sendButton,
.primaryButton {
  min-height: 44px;
  padding: 0 18px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 760;
}

#sendButton:hover,
.primaryButton:hover {
  background: #276c59;
}

.ghostButton,
.ghostLink,
.iconButton {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 8px 12px;
}

.ghostButton:hover,
.ghostLink:hover,
.iconButton:hover {
  border-color: var(--accent);
  color: var(--accent);
}

dialog {
  width: min(720px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(38, 30, 22, 0.42);
}

.dialogHeader {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.memoryContent {
  padding: 16px;
  max-height: min(70dvh, 620px);
  overflow: auto;
  display: grid;
  gap: 12px;
  color: var(--muted);
  line-height: 1.55;
}

.memoryBlock {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.memoryBlock b {
  color: var(--ink);
}

.adminShell {
  min-height: 100dvh;
  background: var(--bg);
}

.adminTopbar {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
}

.adminBrand {
  color: var(--ink);
}

.adminLogin {
  min-height: calc(100dvh - 70px);
  display: grid;
  place-items: center;
  padding: 24px;
}

.loginBox {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.loginBox label,
.promptEditor label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.formError {
  color: var(--danger);
  font-size: 13px;
}

.adminWorkspace {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.adminSide,
.adminMain {
  border: 1px solid var(--line);
  border-radius: 8px;
}

.adminSide {
  align-self: start;
  padding: 14px;
}

.adminSectionTitle {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.promptTabs {
  display: grid;
  gap: 8px;
}

.promptTab {
  text-align: left;
  padding: 11px 12px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.promptTab.active {
  background: rgba(47, 125, 104, 0.1);
  border-color: rgba(47, 125, 104, 0.35);
  color: var(--accent);
}

.adminMain {
  min-width: 0;
  padding: 18px;
}

.adminHero {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.promptEditor {
  display: grid;
  gap: 14px;
  padding-top: 16px;
}

.promptMeta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

#promptText {
  min-height: 420px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
}

#promptSaveStatus {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .leftPane {
    display: none;
  }

  .mobileStatus {
    display: flex;
  }

  .chatPane {
    height: 100dvh;
  }

  .message {
    max-width: 96%;
  }

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

  #sendButton {
    height: 48px;
  }

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

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

  .adminHero,
  .editorActions {
    align-items: flex-start;
    flex-direction: column;
  }
}
