:root {
  --bg: #faf7f2;
  --panel: #ffffff;
  --ink: #33302b;
  --ink-soft: #6f6a60;
  --accent: #4a7c59;
  --accent-soft: #e4efe7;
  --border: #e5dfd3;
  --user-bubble: #eef3ee;
  --radius: 14px;
  font-family: "Georgia", "Iowan Old Style", "Palatino", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---- login ---- */
.login {
  height: 100%; display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2.5rem 3rem; max-width: 30rem; text-align: center;
  box-shadow: 0 6px 30px rgba(60,50,30,.08);
}
.login-card h1 { margin: 0 0 .75rem; font-size: 1.6rem; color: var(--accent); }
.login-card p { color: var(--ink-soft); line-height: 1.5; }
.login-card input {
  width: 100%; padding: .7rem 1rem; margin: 1rem 0 .75rem; font: inherit;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.login-card button {
  width: 100%; padding: .7rem; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 1rem;
}
.login-fine { font-size: .78rem; margin-top: 1.25rem; }
.login-error {
  color: #c0392b; font-size: .85rem; margin: 0 0 .6rem; text-align: left;
  background: rgba(192,57,43,.08); border: 1px solid rgba(192,57,43,.25);
  border-radius: 8px; padding: .5rem .7rem; line-height: 1.4;
}
.login-tagline { font-size: 1.05rem; color: var(--accent); margin-top: 0; }
.login-explain { text-align: left; font-size: .92rem; }
.login-explain p { margin: .6rem 0; }

/* ---- modal ---- */
.modal {
  position: fixed; inset: 0; background: rgba(50,45,35,.45); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.modal-card {
  background: var(--panel); border-radius: var(--radius); max-width: 40rem;
  max-height: 85vh; overflow-y: auto; padding: 2rem 2.5rem; position: relative;
  line-height: 1.55; box-shadow: 0 10px 40px rgba(40,30,10,.25);
}
.modal-card h2 { color: var(--accent); margin-top: 0; }
.modal-card h3 { color: var(--accent); margin-bottom: .35rem; }
.modal-card ol { padding-left: 1.3rem; }
.modal-card li { margin-bottom: .5rem; }
.modal-close {
  position: absolute; top: .9rem; right: 1rem; border: none; background: none;
  font-size: 1.1rem; color: var(--ink-soft);
}
.linkish {
  border: none; background: none; color: var(--accent); text-decoration: underline;
  padding: 0; font-size: inherit;
}
.tier-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; }
.tier-card {
  border: 1px solid var(--border); border-radius: 10px; padding: .7rem .8rem;
  font-size: .8rem; background: var(--bg);
}
.tier-card.tier-mid { border-color: var(--accent); background: var(--accent-soft); }
.tier-card h4 { margin: 0 0 .1rem; font-size: .95rem; }
.tier-card .tier-for { margin: 0 0 .4rem; color: var(--ink-soft); font-size: .74rem; }
.tier-card ul { margin: 0; padding-left: 1rem; }
.tier-card li { margin-bottom: .25rem; }
.tier-note { font-size: .8rem; color: var(--ink-soft); }
@media (max-width: 700px) { .tier-grid { grid-template-columns: 1fr; } }

/* ---- layout ---- */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 270px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem; border-bottom: 1px solid var(--border);
}
.sidebar-head h2 { margin: 0; font-size: 1.05rem; color: var(--accent); }
.sidebar-head button {
  border: 1px solid var(--accent); color: var(--accent); background: none;
  border-radius: 8px; padding: .3rem .7rem;
}
.session-list { flex: 1; overflow-y: auto; padding: .5rem; }
.session-item {
  padding: .6rem .75rem; border-radius: 8px; cursor: pointer; margin-bottom: .25rem;
  display: flex; justify-content: space-between; gap: .5rem; align-items: baseline;
}
.session-item:hover { background: var(--accent-soft); }
.session-item.active { background: var(--accent-soft); font-weight: bold; }
.session-item .title {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem;
}
.session-item .del {
  border: none; background: none; color: var(--ink-soft); font-size: .8rem; visibility: hidden;
}
.session-item:hover .del { visibility: visible; }
.session-item .date { font-size: .7rem; color: var(--ink-soft); flex-shrink: 0; }
.sidebar-foot {
  padding: .75rem 1rem; border-top: 1px solid var(--border); font-size: .85rem;
  color: var(--ink-soft); display: flex; justify-content: space-between; align-items: center;
}
.sidebar-foot button { border: none; background: none; color: var(--accent); }

/* ---- chat ---- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.messages { flex: 1; overflow-y: auto; padding: 2rem 1rem; }
.empty-state { max-width: 42rem; margin: 6vh auto 0; text-align: center; color: var(--ink-soft); }
.empty-state h2 { color: var(--accent); }
.empty-state .fine { font-size: .85rem; }
.output-cards {
  display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin: 1.25rem 0; text-align: left;
}
.output-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: .7rem .9rem; font-size: .85rem; display: flex; flex-direction: column; gap: .25rem;
}
.output-card strong { color: var(--accent); }
.sample-btn {
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  border-radius: 999px; padding: .55rem 1.4rem; font-size: .95rem; margin: .25rem 0 .75rem;
}
.sample-btn:hover { opacity: .9; }
.sidebar-hint {
  font-size: .78rem; color: var(--ink-soft); padding: .6rem 1rem 0; margin: 0;
  line-height: 1.45;
}
.qa-label { font-size: .8rem; color: var(--ink-soft); align-self: center; margin-right: .15rem; }
.session-item .revisit-btn {
  border: none; background: none; color: var(--ink-soft); font-size: .85rem; visibility: hidden;
  padding: 0 .1rem;
}
.session-item:hover .revisit-btn { visibility: visible; }
.session-item .revisit-btn:hover { color: var(--accent); }
.revisit-mark { color: var(--accent); font-size: .8rem; margin-right: .15rem; }

/* ---- children ---- */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1rem 0;
}
.section-head h3 {
  margin: 0; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-soft);
}
.section-head button {
  border: 1px solid var(--border); color: var(--accent); background: none;
  border-radius: 6px; padding: .1rem .5rem; font-size: .78rem;
}
.child-list { padding: .35rem .5rem 0; max-height: 30vh; overflow-y: auto; }
.child-item {
  display: flex; align-items: baseline; gap: .5rem; padding: .45rem .75rem;
  border-radius: 8px; cursor: pointer; font-size: .9rem;
}
.child-item:hover, .child-item.active { background: var(--accent-soft); }
.child-item .cname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.child-item .ccount { font-size: .72rem; color: var(--ink-soft); flex-shrink: 0; }
.child-tag {
  font-size: .68rem; color: var(--accent); background: var(--accent-soft);
  border-radius: 999px; padding: 0 .45rem; margin-right: .3rem; flex-shrink: 0;
}

/* ---- session bar ---- */
.session-bar {
  display: flex; align-items: center; gap: .6rem; justify-content: center;
  padding: .5rem 1rem; border-bottom: 1px solid var(--border); background: var(--panel);
  font-size: .85rem; color: var(--ink-soft);
}
.session-bar select {
  font: inherit; border: 1px solid var(--border); border-radius: 8px; padding: .25rem .5rem;
  background: var(--bg); color: var(--ink);
}

/* ---- child view ---- */
.child-view { max-width: 46rem; margin: 0 auto; }
.child-view .cv-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: .5rem; }
.child-view h1 { color: var(--accent); margin: .25rem 0; font-size: 1.5rem; }
.cv-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.cv-actions button {
  border: 1px solid var(--accent); background: var(--panel); color: var(--accent);
  border-radius: 999px; padding: .35rem 1rem; font-size: .85rem;
}
.cv-actions button.primary { background: var(--accent); color: #fff; }
.cv-note {
  font-size: .82rem; color: var(--ink-soft); background: var(--accent-soft);
  border-radius: 10px; padding: .6rem .9rem; margin: .75rem 0 1rem; line-height: 1.45;
}
.cv-stats { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.cv-stat { text-align: center; }
.cv-stat .n { font-size: 1.4rem; color: var(--accent); font-weight: bold; }
.cv-stat .l { font-size: .72rem; color: var(--ink-soft); }
.cv-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.25rem; margin-bottom: 1rem;
}
.cv-card h2 { margin: 0 0 .35rem; font-size: 1.05rem; color: var(--accent); }
.cv-card .sub { font-size: .8rem; color: var(--ink-soft); margin: 0 0 .8rem; }
.dim-row { margin-bottom: .8rem; }
.dim-row .dim-label { display: flex; justify-content: space-between; font-size: .87rem; margin-bottom: .2rem; gap: .5rem; }
.dim-row .dim-label .dn { font-weight: bold; }
.dim-row .dim-label .dc { color: var(--ink-soft); font-size: .78rem; flex-shrink: 0; }
.dim-bar { height: 9px; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.dim-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.dim-row .dim-seen { font-size: .78rem; color: var(--ink-soft); margin-top: .25rem; }
.thread-chip {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: .2rem .7rem; font-size: .8rem; margin: 0 .3rem .3rem 0;
}
.cv-obs { display: flex; justify-content: space-between; gap: .5rem; padding: .4rem 0; border-bottom: 1px dashed var(--border); cursor: pointer; font-size: .88rem; }
.cv-obs:last-child { border-bottom: none; }
.cv-obs:hover .t { color: var(--accent); text-decoration: underline; }
.cv-obs .d { color: var(--ink-soft); font-size: .78rem; flex-shrink: 0; }
.cv-report { margin-top: .5rem; }
.cv-report img { max-width: 240px; border-radius: 8px; border: 1px solid var(--border); display: block; margin: .4rem 0 .2rem; }
.msg .bubble img { max-width: 240px; border-radius: 8px; border: 1px solid var(--border); display: block; margin: .4rem 0 .2rem; }

.msg { max-width: 46rem; margin: 0 auto 1.25rem; display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg .bubble {
  padding: .9rem 1.2rem; border-radius: var(--radius); line-height: 1.55;
  white-space: pre-wrap; overflow-wrap: break-word;
}
.msg.user .bubble { background: var(--user-bubble); border: 1px solid var(--border); max-width: 85%; white-space: pre-wrap; }
.msg.assistant .bubble {
  background: var(--panel); border: 1px solid var(--border); width: 100%; white-space: normal;
}
.msg .bubble h1 { font-size: 1.35rem; color: var(--accent); margin: .25rem 0 .75rem; }
.msg .bubble h2 { font-size: 1.15rem; color: var(--accent); margin: 1rem 0 .5rem; }
.msg .bubble h3 { font-size: 1rem; margin: 1rem 0 .35rem; }
.msg .bubble ul { margin: .35rem 0 .75rem; padding-left: 1.35rem; }
.msg .bubble li { margin-bottom: .3rem; }
.msg .bubble hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.msg .bubble p { margin: .5rem 0; }
.msg .attachments { display: flex; gap: .5rem; margin-bottom: .4rem; flex-wrap: wrap; }
.msg .attachments img {
  max-width: 160px; max-height: 120px; border-radius: 8px; border: 1px solid var(--border);
  object-fit: cover;
}
.msg-tools { display: flex; gap: .75rem; margin-top: .3rem; padding-left: .25rem; }
.msg-tools button {
  border: none; background: none; color: var(--ink-soft); font-size: .78rem; padding: 0;
}
.msg-tools button:hover { color: var(--accent); text-decoration: underline; }
.thinking { color: var(--ink-soft); font-style: italic; }

/* ---- composer ---- */
.composer-wrap { padding: 0 1rem 1rem; max-width: 48rem; margin: 0 auto; width: 100%; }
.quick-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.quick-actions button {
  border: 1px solid var(--accent); color: var(--accent); background: var(--panel);
  border-radius: 999px; padding: .3rem .9rem; font-size: .82rem;
}
.quick-actions button:hover { background: var(--accent-soft); }
.attach-preview { display: flex; gap: .5rem; flex-wrap: wrap; }
.attach-preview .chip {
  display: flex; align-items: center; gap: .4rem; background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; padding: .25rem .5rem;
  font-size: .8rem; margin-bottom: .4rem;
}
.attach-preview img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.attach-preview .x { border: none; background: none; color: var(--ink-soft); }
.composer {
  display: flex; align-items: flex-end; gap: .5rem; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .6rem;
}
.attach-btn { cursor: pointer; padding: .45rem .3rem; font-size: 1.05rem; }
.composer textarea {
  flex: 1; border: none; resize: none; font: inherit; background: none; outline: none;
  max-height: 200px; line-height: 1.45; padding: .45rem 0;
}
.composer #send {
  border: none; background: var(--accent); color: #fff; border-radius: 10px;
  width: 2.4rem; height: 2.4rem; font-size: 1rem; flex-shrink: 0;
}
.composer #send:disabled { opacity: .5; cursor: default; }
.composer #mic {
  border: none; background: none; border-radius: 10px; width: 2.4rem; height: 2.4rem;
  font-size: 1.05rem; flex-shrink: 0;
}
.composer #mic:hover { background: var(--accent-soft); }
.composer #mic.recording {
  background: #c0392b; animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192,57,43,.45); }
  50% { box-shadow: 0 0 0 8px rgba(192,57,43,0); }
}
.mic-hint { text-align: center; font-size: .78rem; color: #c0392b; margin: .35rem 0 0; }
.privacy-note { text-align: center; font-size: .72rem; color: var(--ink-soft); margin: .5rem 0 0; }

/* ---- print: only the selected output ---- */
@media print {
  body * { visibility: hidden; }
  .print-target, .print-target * { visibility: visible; }
  .print-target {
    position: absolute; left: 0; top: 0; width: 100%;
    border: none !important; box-shadow: none !important;
  }
  .msg-tools, .sidebar, .composer-wrap { display: none !important; }
}
