:root {
  color-scheme: light;
  --bg: #f3f1eb;
  --surface: #fffdf8;
  --ink: #17201f;
  --muted: #65706d;
  --line: #d8d2c6;
  --accent: #176b5d;
  --accent-ink: #ffffff;
  --user: #183b4a;
  --assistant: #ffffff;
  --pending: #a65f19;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
}

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

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  max-width: 860px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 4px 12px;
}

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

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.12;
  letter-spacing: 0;
}

h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.status {
  flex: 0 0 auto;
  min-width: 74px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.status.busy {
  color: var(--pending);
}

.action-sheet {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
  margin: 0 2px 10px;
  box-shadow: 0 8px 28px rgba(23, 32, 31, 0.12);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

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

.sheet-grid label {
  display: grid;
  gap: 4px;
}

.sheet-grid span {
  color: var(--muted);
  font-size: 11px;
}

.sheet-grid select {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 8px;
  outline: none;
}

.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.messages {
  overflow-y: auto;
  padding: 4px 2px 10px;
  scroll-behavior: smooth;
}

.empty {
  display: grid;
  min-height: 100%;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.bubble-row {
  display: flex;
  align-items: flex-start;
  margin: 6px 0;
}

.bubble-row.user {
  justify-content: flex-end;
}

.bubble {
  width: fit-content;
  max-width: min(82%, 620px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--assistant);
  box-shadow: 0 1px 0 rgba(23, 32, 31, 0.04);
  line-height: 1.36;
  font-size: 14px;
}

.user .bubble {
  max-width: min(76%, 540px);
  border-color: transparent;
  background: var(--user);
  color: white;
}

.pending .bubble {
  color: var(--pending);
  min-width: 0;
}

.meta {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.composer {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.attachment-tray {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

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

textarea {
  min-height: 44px;
  max-height: 160px;
  resize: none;
  padding: 11px 12px;
  line-height: 1.35;
}

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

textarea:focus,
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 93, 0.14);
}

button {
  height: 44px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

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

.text-button {
  width: auto;
  height: 32px;
  padding: 0 8px;
  background: transparent;
  color: var(--accent);
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
}

.secondary-button.danger {
  color: #9f3128;
}

.send-button {
  padding: 0 15px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.icon-button {
  width: 44px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent);
  font-size: 24px;
  line-height: 1;
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.attachment-chip,
.pending-attachment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(23, 107, 93, 0.08);
  color: var(--ink);
  padding: 5px 8px;
  font-size: 12px;
  line-height: 1.2;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.pending-attachment button {
  width: 22px;
  height: 22px;
  background: transparent;
  color: var(--muted);
  padding: 0;
  font-size: 17px;
}

.lock-panel {
  align-self: center;
  margin: 16px 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.lock-panel form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.lock-panel button {
  padding: 0 16px;
  background: var(--accent);
  color: white;
}

@media (max-width: 520px) {
  .sheet-grid,
  .sheet-actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111716;
    --surface: #1b2422;
    --ink: #eff5f1;
    --muted: #98a4a0;
    --line: #31413d;
    --accent: #62c7ad;
    --accent-ink: #08211d;
    --user: #19485b;
    --assistant: #17201f;
    --pending: #e1a060;
  }
}
