:root {
  --bg: #f6f3ee;
  --panel: #fffdf9;
  --ink: #1c2420;
  --muted: #6b7280;
  --line: #e5ded3;
  --accent: #0f766e;
  --accent-soft: #d9ece9;
  --user-bubble: #0f766e;
  --danger: #b42318;
  --radius: 14px;
  font-size: 16px;
}
* { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--ink); height: 100vh; overflow: hidden;
}
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- auth ---------- */
#auth { height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 36px 32px; width: 100%; max-width: 380px; box-shadow: 0 8px 30px rgba(28,36,32,.06);
}
.brand { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; }
.tagline { color: var(--muted); font-size: 13.5px; line-height: 1.5; margin: 10px 0 22px; }
#auth h2 { font-size: 17px; margin-bottom: 12px; }
#auth input {
  width: 100%; padding: 11px 13px; margin-bottom: 10px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; font: inherit;
}
#auth input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.primary {
  width: 100%; padding: 11px; background: var(--accent); color: #fff; border: 0;
  border-radius: 10px; font-weight: 600;
}
.primary:hover { filter: brightness(1.07); }
.swap { margin-top: 14px; font-size: 13.5px; color: var(--muted); text-align: center; }
.swap a { color: var(--accent); cursor: pointer; font-weight: 600; }
.err { color: var(--danger); font-size: 13px; margin-bottom: 8px; min-height: 16px; }

/* ---------- layout ---------- */
#main { display: flex; height: 100vh; }
#hamburger {
  display: none; position: fixed; top: 10px; left: 10px; z-index: 40;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  width: 38px; height: 38px; font-size: 17px;
}
#scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 29; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 272px; flex-shrink: 0; background: #10312c;
  color: #e9efec; display: flex; flex-direction: column; height: 100vh;
}
.side-head { padding: 18px 16px 12px; }
#sidebar .brand { color: #fff; font-size: 17px; margin-bottom: 14px; }
.newchat {
  width: 100%; padding: 10px; border-radius: 10px; border: 1px solid rgba(255,255,255,.22);
  background: transparent; color: #fff; font-weight: 600; text-align: left; padding-left: 14px;
}
.newchat:hover { background: rgba(255,255,255,.08); }
#convlist { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv {
  position: relative; padding: 9px 30px 9px 12px; border-radius: 9px; font-size: 13.5px;
  color: #cfdad5; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv:hover { background: rgba(255,255,255,.07); }
.conv.active { background: rgba(255,255,255,.13); color: #fff; }
.conv .tools {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  display: none; gap: 2px;
}
.conv:hover .tools { display: flex; }
.conv .tools button {
  background: none; border: 0; color: #9fb3ab; font-size: 13px; padding: 2px 4px; border-radius: 5px;
}
.conv .tools button:hover { color: #fff; background: rgba(255,255,255,.12); }
#side-foot { padding: 10px 16px 14px; border-top: 1px solid rgba(255,255,255,.1); }
#appr-badge {
  background: #b45309; color: #fff; font-size: 12.5px; border-radius: 8px;
  padding: 7px 10px; margin-bottom: 10px; font-weight: 600;
}
#filelist h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: #8fa69d; margin-bottom: 6px; }
#files { max-height: 110px; overflow-y: auto; font-size: 12.5px; }
#files a { color: #cfdad5; text-decoration: none; display: block; padding: 3px 0; }
#files a:hover { color: #fff; text-decoration: underline; }
#files .none { color: #7d938a; }
.ghost {
  width: 100%; margin-top: 10px; padding: 8px; background: none; border: 1px solid rgba(255,255,255,.18);
  color: #cfdad5; border-radius: 9px; font-size: 13px;
}
.ghost:hover { background: rgba(255,255,255,.08); }
.model { margin-top: 8px; font-size: 11px; color: #7d938a; }

/* ---------- chat ---------- */
#chatwrap { flex: 1; display: flex; flex-direction: column; height: 100vh; min-width: 0; }
#chat { flex: 1; overflow-y: auto; padding: 28px 20px 12px; }
.col { max-width: 760px; margin: 0 auto; }

/* welcome */
.welcome { text-align: center; padding: 12vh 16px 0; }
.welcome h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.welcome p { color: var(--muted); margin: 10px 0 26px; font-size: 14.5px; }
.chips { display: flex; flex-direction: column; gap: 9px; max-width: 460px; margin: 0 auto; }
.chip {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 16px; font-size: 13.5px; text-align: left; color: var(--ink);
}
.chip:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(15,118,110,.08); }

/* messages */
.msg { display: flex; margin-bottom: 22px; }
.msg .avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none; margin-right: 12px; margin-top: 2px;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #fff;
}
.msg.assistant .avatar { background: var(--accent); }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--user-bubble); color: #fff; border-radius: 16px 16px 4px 16px;
  padding: 10px 15px; max-width: 78%; font-size: 14.5px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word;
}
.msg.assistant .bubble { max-width: 82%; font-size: 14.5px; line-height: 1.65; }
.msg.assistant.processing .bubble { color: var(--muted); font-style: italic; }
.msg .files { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.msg .files a {
  display: inline-flex; align-items: center; gap: 6px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 9px; padding: 7px 11px;
  font-size: 12.5px; color: var(--accent); text-decoration: none; width: fit-content;
}
.msg .files a:hover { border-color: var(--accent); }

/* markdown content */
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 15.5px; margin: 14px 0 8px; }
.bubble ul, .bubble ol { margin: 6px 0 10px 20px; }
.bubble li { margin-bottom: 3px; }
.bubble code {
  background: #efe9df; border-radius: 5px; padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
}
.bubble pre {
  background: #20312b; color: #e9efec; border-radius: 10px; padding: 12px 14px;
  overflow-x: auto; margin: 8px 0 12px;
}
.bubble pre code { background: none; color: inherit; padding: 0; }
.bubble a { color: var(--accent); }
.msg.user .bubble code { background: rgba(255,255,255,.2); color: #fff; }

/* typing indicator */
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: blink 1.2s infinite; opacity: .35;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .35; } 40% { opacity: 1; } }

/* approval cards */
.appr-card {
  border: 1px solid #e8c07a; background: #fdf6e9; border-radius: 12px;
  padding: 13px 15px; margin: 0 0 22px 40px; max-width: 82%; font-size: 13.5px;
}
.appr-card .kind { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: #92590a; }
.appr-card .summary { margin: 6px 0 10px; line-height: 1.5; }
.appr-card .simwarn { margin: 0 0 10px; padding: 7px 10px; border-radius: 7px; background: #fdf0dc; border: 1px solid #e3c78f; color: #92590a; font-size: 12.5px; font-weight: 600; line-height: 1.45; }
.appr-card .actions { display: flex; gap: 8px; }
.appr-card button { padding: 7px 16px; border-radius: 8px; border: 0; font-weight: 600; font-size: 13px; }
.appr-card .yes { background: var(--accent); color: #fff; }
.appr-card .no { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.appr-card.done { opacity: .75; }
.appr-card .result { margin-top: 8px; color: var(--muted); font-size: 12.5px; white-space: pre-wrap; }

/* ---------- composer ---------- */
#composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 12px 20px 6px;
  max-width: 800px; margin: 0 auto; width: 100%;
}
#composer .clip {
  flex: none; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; cursor: pointer; color: var(--muted); font-size: 17px;
}
#composer .clip:hover { background: var(--accent-soft); color: var(--accent); }
#msgbox {
  flex: 1; resize: none; border: 1px solid var(--line); background: var(--panel);
  border-radius: 20px; padding: 10px 16px; font: inherit; font-size: 14.5px;
  line-height: 1.45; max-height: 140px; outline: none;
}
#msgbox:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#sendbtn {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 16px;
}
#sendbtn:hover { filter: brightness(1.07); }
#sendbtn:disabled { opacity: .45; cursor: default; }
.hint { text-align: center; color: var(--muted); font-size: 11.5px; padding: 5px 16px 12px; }

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  #hamburger { display: block; }
  #sidebar {
    position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-100%);
    transition: transform .22s ease;
  }
  #sidebar.open { transform: translateX(0); }
  #scrim.show { display: block; }
  #sidebar .side-head { padding-top: 58px; }
  #chat { padding: 56px 14px 10px; }
  .msg.user .bubble, .msg.assistant .bubble { max-width: 92%; }
  .appr-card { margin-left: 0; max-width: 100%; }
  #composer { padding: 10px 12px 4px; }
}
