:root {
  --ink: #14212b;
  --ink-soft: #3a4a57;
  --paper: #f3efe6;
  --paper-2: #e8e2d4;
  --panel: #0f1a22;
  --line: rgba(20, 33, 43, 0.12);
  --accent: #0f7a6a;
  --accent-2: #c45c26;
  --user: #dce8e5;
  --assistant: #fffdf8;
  --danger: #9b2c2c;
  --radius: 14px;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(15, 122, 106, 0.14), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(196, 92, 38, 0.1), transparent 55%),
    var(--paper);
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

.sidebar {
  background: linear-gradient(180deg, #12202a 0%, #0c151c 100%);
  color: #e8efe9;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border-right: 1px solid rgba(255,255,255,0.06);
}

.brand { display: flex; gap: 0.75rem; align-items: center; }
.brand-mark {
  width: 2.4rem; height: 2.4rem; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent);
  font-family: var(--display);
  font-weight: 700; font-size: 1.25rem;
}
.brand-name { font-family: var(--display); font-size: 1.2rem; line-height: 1.1; }
.brand-sub { font-size: 0.72rem; opacity: 0.65; letter-spacing: 0.02em; }

.agent-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}
.agent-tab {
  text-align: left;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: inherit;
  border-radius: 12px;
  padding: 0.55rem 0.65rem;
  cursor: pointer;
  font-family: var(--font);
}
.agent-tab strong { display: block; font-size: 0.82rem; }
.agent-tab span { display: block; font-size: 0.68rem; opacity: 0.55; margin-top: 0.15rem; }
.agent-tab:hover { background: rgba(255,255,255,0.08); }
.agent-tab.active {
  border-color: rgba(15, 122, 106, 0.55);
  background: rgba(15, 122, 106, 0.22);
}

.btn-primary, .btn-send {
  border: 0; cursor: pointer;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-family: var(--font);
  border-radius: 999px;
  padding: 0.7rem 1rem;
}
.btn-primary:hover, .btn-send:hover { filter: brightness(1.06); }
.btn-send:disabled, .btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  font-family: var(--font);
  color: inherit;
}
.btn-ghost.sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }

.sidebar-section { flex: 1; overflow: auto; min-height: 0; }
.section-label {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
  opacity: 0.5; margin-bottom: 0.5rem;
}
.chat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.chat-list li button {
  width: 100%; text-align: left;
  background: rgba(255,255,255,0.04);
  border: 1px solid transparent;
  color: inherit;
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
  font-family: var(--font);
}
.chat-list li button:hover { background: rgba(255,255,255,0.08); }
.chat-list li.active button {
  border-color: rgba(15, 122, 106, 0.5);
  background: rgba(15, 122, 106, 0.2);
}
.chat-list .meta { display: block; font-size: 0.72rem; opacity: 0.55; margin-top: 0.2rem; }

.sidebar-foot .hint { font-size: 0.75rem; line-height: 1.4; opacity: 0.55; margin: 0; }

.main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  background: rgba(255, 253, 248, 0.55);
  backdrop-filter: blur(8px);
}

.topbar {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  margin: 0; font-family: var(--display); font-size: 1.45rem; font-weight: 500;
}
.top-meta { margin: 0.25rem 0 0; color: var(--ink-soft); font-size: 0.85rem; }
.top-actions { display: flex; gap: 0.75rem; align-items: center; }

.btn-pdf {
  border: 0;
  cursor: pointer;
  background: var(--accent-2);
  color: white;
  font-weight: 600;
  font-family: var(--font);
  border-radius: 999px;
  padding: 0.55rem 1rem;
}
.btn-pdf.sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  margin-top: 0.65rem;
}
.btn-pdf:hover { filter: brightness(1.06); }
.btn-pdf:disabled { opacity: 0.45; cursor: not-allowed; }

.pdf-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  background: rgba(196, 92, 38, 0.1);
  border: 1px solid rgba(196, 92, 38, 0.25);
}
.pdf-bar-label { font-size: 0.85rem; color: var(--ink-soft); }

.bubble.is-draft {
  border-color: rgba(196, 92, 38, 0.35);
  box-shadow: inset 3px 0 0 var(--accent-2);
}
.bubble-actions { margin-top: 0.35rem; }

.dialog-note {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin: 0 0 1rem;
  line-height: 1.45;
}

.messages {
  overflow: auto;
  padding: 1.25rem 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.empty {
  margin: auto;
  max-width: 34rem;
  text-align: center;
  padding: 2rem 1rem;
}
.empty h2 { font-family: var(--display); font-weight: 500; margin: 0 0 0.75rem; }
.empty p { color: var(--ink-soft); line-height: 1.55; }
.mode-legend {
  text-align: left; display: inline-block;
  margin: 1.25rem auto 0; color: var(--ink-soft); font-size: 0.9rem;
  line-height: 1.7;
}

.bubble {
  max-width: min(720px, 92%);
  padding: 0.9rem 1.05rem;
  border-radius: var(--radius);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 0 rgba(20,33,43,0.04);
}
.bubble.user {
  align-self: flex-end;
  background: var(--user);
  border: 1px solid rgba(15, 122, 106, 0.18);
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--assistant);
  border: 1px solid var(--line);
}
.bubble .role {
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-soft); margin-bottom: 0.35rem; font-weight: 600;
}
.bubble .files {
  display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.55rem;
}
.chip {
  font-size: 0.75rem;
  background: var(--paper-2);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--line);
}
.bubble .outputs { margin-top: 0.75rem; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.outputs a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid rgba(15,122,106,0.35);
}
.status-line {
  align-self: center;
  font-size: 0.8rem;
  color: var(--ink-soft);
  font-style: italic;
}
.error-line {
  align-self: center;
  color: var(--danger);
  font-size: 0.9rem;
  background: #fde8e8;
  padding: 0.5rem 0.85rem;
  border-radius: 10px;
}

.composer {
  border-top: 1px solid var(--line);
  padding: 0.85rem 1.25rem 1.1rem;
  background: rgba(243, 239, 230, 0.9);
}
.attach-row {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.analysis-row {
  margin-bottom: 0.5rem;
}
.checkline {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
  user-select: none;
}
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; flex: 1; }
.input-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.55rem;
  align-items: end;
}
.attach-btn {
  display: inline-flex; align-items: center;
  padding: 0.7rem 0.9rem;
  border-radius: 999px;
  border: 1px dashed var(--ink-soft);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  background: white;
}
.attach-btn input { display: none; }
textarea {
  width: 100%;
  resize: none;
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 0.75rem 0.95rem;
  font: inherit;
  background: white;
  color: var(--ink);
  min-height: 3rem;
  max-height: 10rem;
}
textarea:focus { outline: 2px solid rgba(15,122,106,0.35); border-color: transparent; }
.composer-hint {
  margin: 0.55rem 0 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
}

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.25rem;
  width: min(420px, 92vw);
  background: var(--assistant);
  color: var(--ink);
  font-family: var(--font);
}
dialog::backdrop { background: rgba(15, 20, 25, 0.45); }
dialog h3 { margin: 0 0 1rem; font-family: var(--display); font-weight: 500; }
dialog label { display: block; margin-bottom: 0.85rem; font-size: 0.9rem; }
dialog input[type="text"], dialog input:not([type]) {
  width: 100%; margin-top: 0.35rem;
  padding: 0.55rem 0.7rem; border-radius: 10px;
  border: 1px solid var(--line); font: inherit;
}
dialog .check { display: flex; gap: 0.5rem; align-items: flex-start; font-size: 0.85rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .input-row { grid-template-columns: auto 1fr; }
  .btn-send { grid-column: 1 / -1; }
}
