:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --ink: #191816;
  --muted: #68635b;
  --line: #cfc6b8;
  --panel: #fffdf8;
  --accent: #1f7a5b;
  --accent-dark: #165941;
  --danger: #9d2d2d;
  --shadow: 0 16px 36px rgba(30, 25, 18, 0.1);
}

* {
  box-sizing: border-box;
}

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

button,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--ink);
  color: #fffdf8;
  cursor: pointer;
  padding: 0 14px;
}

button:hover {
  background: #000;
}

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

.shell {
  width: min(1500px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.top-actions {
  display: flex;
  gap: 8px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 760;
}

h2 {
  font-size: 15px;
  font-weight: 740;
}

#statusText {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
  gap: 16px;
  padding-top: 16px;
}

.notice {
  margin-top: 12px;
  border: 1px solid #b58b28;
  border-radius: 8px;
  background: #fff2c9;
  color: #4c3600;
  padding: 10px 12px;
  line-height: 1.4;
}

.notice code {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.92em;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
}

.panel-header button {
  min-width: 84px;
  background: transparent;
  color: var(--ink);
}

.panel-header button:hover {
  background: #eee7dc;
}

.chat-panel {
  display: flex;
  min-height: calc(100vh - 116px);
  flex-direction: column;
}

.chat-log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 14px;
}

.message {
  max-width: 84%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  white-space: pre-wrap;
  line-height: 1.42;
}

.message.user {
  align-self: flex-end;
  border-color: #2c604f;
  background: #e7f3ed;
}

.message.assistant {
  align-self: flex-start;
  background: #fff8ea;
}

.message.mock {
  border-color: #b58b28;
  background: #fff2c9;
}

.message.error {
  align-self: flex-start;
  border-color: var(--danger);
  color: var(--danger);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 12px;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffefa;
  color: var(--ink);
  line-height: 1.4;
  padding: 10px;
}

textarea:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(31, 122, 91, 0.18);
}

.side {
  display: grid;
  gap: 16px;
}

.context-input {
  min-height: 220px;
  border: 0;
  border-radius: 0 0 8px 8px;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13px;
}

.contract-view {
  max-height: calc(100vh - 424px);
  min-height: 280px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  white-space: pre-wrap;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

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

  .chat-panel {
    min-height: 68vh;
  }

  .contract-view {
    max-height: 420px;
  }
}

@media (max-width: 560px) {
  .shell {
    padding: 10px;
  }

  .topbar,
  .panel-header,
  .composer {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
  }

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

  .composer {
    display: flex;
    flex-direction: column;
  }

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