:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1d1d1f;
  --muted: #6b6a66;
  --border: #e2dfd8;
  --accent: #b4532a;
  --accent-text: #ffffff;
  --user: #b4532a;
  --user-text: #ffffff;
  --ok: #2f7d4f;
  --warn: #a8471f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .06);
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --surface: #1f2024;
    --surface-2: #2a2b30;
    --text: #ececea;
    --muted: #9b9a96;
    --border: #33343a;
    --accent: #d9774b;
    --accent-text: #16171a;
    --user: #d9774b;
    --user-text: #16171a;
    --ok: #5cc28a;
    --warn: #e58a5f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  text-decoration: none; font-weight: 600; font-size: 15px;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; cursor: pointer; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }

/* sign in */
.signin { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.signin-card { width: 100%; max-width: 360px; text-align: center; }
.signin-card h1 { margin: 12px 0 4px; font-size: 24px; }
.signin-card p { margin: 0 0 20px; }
.mark {
  width: 56px; height: 56px; margin: 0 auto; border-radius: 16px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); font-size: 26px; font-weight: 700;
}

/* app shell */
.app { height: 100dvh; display: flex; flex-direction: column; max-width: 820px; margin: 0 auto; }
.top {
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.tabs { flex: 1; display: flex; justify-content: center; gap: 2px; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.tab {
  flex: 1; max-width: 120px; border: 0; background: transparent; border-radius: 9px; padding: 6px 4px;
  font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 2px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text); font-size: 11px; line-height: 18px; text-align: center;
}

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.list-view { overflow-y: auto; padding: 16px 16px calc(env(safe-area-inset-bottom) + 24px); display: block; }
.list-view h2 { margin: 4px 0; font-size: 20px; }
.chat-title { padding: 8px 16px 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* drawer */
.drawer {
  position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: min(320px, 86vw);
  background: var(--surface); border-right: 1px solid var(--border); box-shadow: var(--shadow);
  transform: translateX(-102%); transition: transform .2s ease;
  display: flex; flex-direction: column; padding-top: env(safe-area-inset-top);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 16px; font-weight: 700; }
.sessions { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
.sessions li {
  display: flex; align-items: center; gap: 4px; border-radius: 10px; padding: 0 0 0 12px; cursor: pointer;
}
.sessions li.active { background: var(--surface-2); }
.sessions .s-title { flex: 1; padding: 10px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.sessions .s-del { opacity: .5; }
.who { padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); margin: 0; border-top: 1px solid var(--border); }
.scrim { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .35); }

/* messages */
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.empty { margin: auto; text-align: center; max-width: 320px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: var(--radius); word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); color: var(--user-text); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg.assistant p { margin: 0 0 8px; }
.msg.assistant p:last-child, .msg.assistant ul:last-child, .msg.assistant ol:last-child, .msg.assistant pre:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { margin: 0 0 8px; padding-left: 20px; }
.msg.assistant pre { margin: 0 0 8px; padding: 10px; border-radius: 10px; background: var(--surface-2); overflow-x: auto; font: 13px/1.45 var(--mono); }
.msg.assistant code { font: 13px var(--mono); background: var(--surface-2); padding: 1px 4px; border-radius: 5px; }
.msg.assistant pre code { background: none; padding: 0; }
.msg .files { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.msg .file { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, .22); }
.msg.error { border-color: var(--warn); color: var(--warn); }
.activity { align-self: flex-start; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.dots span { display: inline-block; width: 5px; height: 5px; margin-right: 3px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* draft and idea cards */
.cards { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.messages .card { align-self: stretch; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head strong { font-size: 14px; }
.status { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.status.pending { color: var(--accent); }
.status.published, .status.approved { color: var(--ok); }
.card-text { white-space: pre-wrap; font-size: 15px; margin: 0 0 10px; }
.card-error { color: var(--warn); font-size: 13px; margin: 0 0 10px; }
.card-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }

/* composer */
.composer { border-top: 1px solid var(--border); background: var(--bg); padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.attach { flex: none; }
#input {
  flex: 1; min-width: 0; resize: none; max-height: 40dvh; min-height: 40px;
  padding: 8px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface); outline: none;
  font-size: 16px; line-height: 1.4;
}
#input:focus { border-color: var(--accent); }
.send {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-text); display: grid; place-items: center;
}
.send:disabled { opacity: .4; cursor: default; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 4px; }
.attachments:not(:empty) { padding-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 4px 6px 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: 13px;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.chip button { border: 0; background: transparent; cursor: pointer; padding: 0 4px; color: var(--muted); font-size: 16px; line-height: 1; }
.chip.busy { opacity: .6; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 84px); z-index: 30;
  max-width: 480px; margin: 0 auto; padding: 10px 14px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 14px; box-shadow: var(--shadow);
}
