:root {
  --bg: #f7f5f1;
  --surface: #fffdf9;
  --surface-2: #f0ece5;
  --text: #2d2926;
  --muted: #746c62;
  --line: #e3ddd4;
  --accent: #8f5e3b;
  --accent-dark: #6f4629;
  --danger: #9f3a38;
  --ok: #4f6f52;
  --shadow: 0 20px 50px rgba(45, 41, 38, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.sidebar {
  width: 280px;
  min-height: 100vh;
  padding: 28px 18px;
  border-right: 1px solid var(--line);
  background: #fbf8f2;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.brand { padding: 0 10px; }
.brand-kicker, .eyebrow {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 8px;
}
.brand-title { font-size: 22px; font-weight: 650; }
.nav { display: grid; gap: 6px; }
.nav-item {
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  font: inherit;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--text); color: #fffdf9; }
.sidebar-note {
  margin-top: auto;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.main {
  flex: 1;
  min-width: 0;
  height: 100vh;
  padding: 30px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
h1 { margin: 0; font-size: 30px; letter-spacing: -0.03em; }
h2 { margin: 0 0 8px; font-size: 20px; letter-spacing: -0.02em; }
h3 { margin: 0 0 10px; font-size: 15px; }
.muted { color: var(--muted); line-height: 1.55; margin-top: 0; }
.status-pill {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
}
.status-pill.ok { color: var(--ok); border-color: rgba(79,111,82,.35); }
.status-pill.bad { color: var(--danger); border-color: rgba(159,58,56,.35); }

.page { display: none; min-height: 0; }
.page.active { display: block; min-height: 0; flex: 1; overflow: auto; }
#page-chat.active { display: flex; overflow: hidden; }
.panel, .summary-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.grid.two { display: grid; grid-template-columns: 1.05fr .95fr; gap: 18px; align-items: start; }
.two-col-main, .approval-layout { display: grid; grid-template-columns: 1fr 320px; gap: 18px; }
.summary-card { box-shadow: none; background: #fbf8f2; }
.summary-card ul { padding-left: 18px; color: var(--muted); line-height: 1.7; }

.message { max-width: 720px; border-radius: 16px; padding: 14px 16px; line-height: 1.55; }
.message.bot { background: #efe8df; }

.input-row { display: flex; gap: 10px; }
input, select, textarea, button {
  font: inherit;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffefb;
  color: var(--text);
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: rgba(143,94,59,.7); box-shadow: 0 0 0 3px rgba(143,94,59,.12); }
button {
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  background: var(--text);
  color: #fffdf9;
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
}
button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); font-size: 13px; padding: 5px 10px; }
button.reject { background: #f3e8e6; color: var(--danger); }
button.revise { background: #efe8df; color: var(--accent-dark); }
button.approve { background: var(--ok); }
button:disabled { opacity: .55; cursor: not-allowed; }

.form-stack { display: grid; gap: 12px; }
.form-stack label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.result-list { display: grid; gap: 10px; margin-top: 16px; }
.result-item {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fbfaf7;
}
.result-list { display: grid; gap: 8px; }
.result-title { font-weight: 650; margin-bottom: 4px; }
.result-meta { color: var(--muted); font-size: 13px; line-height: 1.45; }
.empty-state { min-height: 340px; display: grid; align-content: center; }

.approval-card {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #fbfaf7;
  min-height: 360px;
  padding: 22px;
  display: grid;
  align-content: space-between;
}
.approval-title { font-size: 22px; font-weight: 680; letter-spacing: -0.02em; }
.risk { display: inline-flex; width: fit-content; margin: 12px 0; padding: 5px 10px; border-radius: 999px; background: #efe8df; color: var(--accent-dark); font-size: 12px; text-transform: uppercase; letter-spacing: .07em; }
.approval-actions { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 10px; margin-top: 18px; }
.feedback-box { margin-top: 10px; display: none; gap: 10px; }
.feedback-box.open { display: flex; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--text);
  color: #fffdf9;
  border-radius: 14px;
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: .18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  body { display: block; }
  .sidebar { width: 100%; min-height: auto; }
  .main { height: 100vh; padding: 20px; }
  .grid.two, .two-col-main, .approval-layout { grid-template-columns: 1fr; }
}

.split-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--text);
  color: #fffdf9;
  text-decoration: none;
  white-space: nowrap;
}
.legacy-frame {
  width: 100%;
  height: calc(100vh - 220px);
  min-height: 720px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
}
.secondary-link { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.deal-card { cursor: pointer; }
.deal-card:hover { border-color: rgba(143,94,59,.45); background: #fffdf9; }
.payment-row {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 8px;
  margin-top: 12px;
}
@media (max-width: 760px) { .payment-row { grid-template-columns: 1fr; } }


.chat-panel {
  height: 100%;
  min-height: 0;
  width: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  padding: 0;
  overflow: hidden;
}
.chat-header {
  padding: 22px 24px 14px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}
.chat-header-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.thread-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfaf7;
  flex: 0 0 auto;
}
.thread-tab {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 8px 11px;
  font-size: 13px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-tab.active { background: var(--text); color: #fffdf9; border-color: var(--text); }
.chat-box {
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 0;
  border-radius: 0;
  background: #fbfaf7;
  padding: 24px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-message {
  display: flex;
  width: 100%;
}
.chat-message.user { justify-content: flex-end; }
.chat-message.bot { justify-content: flex-start; }
.bubble {
  max-width: min(680px, 78%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  background: var(--surface);
}
.chat-message.user .bubble {
  background: var(--text);
  color: #fffdf9;
  border-color: var(--text);
  border-bottom-right-radius: 6px;
}
.chat-message.bot .bubble {
  background: #efe8df;
  color: var(--text);
  border-bottom-left-radius: 6px;
}
.quick-prompts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 16px 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}
.quick-prompts button { font-size: 13px; padding: 8px 10px; }
.chat-composer {
  display: flex;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  flex: 0 0 auto;
}
.chat-composer textarea { flex: 1; resize: vertical; min-height: 46px; max-height: 150px; }
.line-tools { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.check-row { display: flex !important; grid-template-columns: none !important; align-items: center; gap: 8px; }
.check-row input { width: auto; }

button.danger {
  background: #f3e8e6;
  color: var(--danger);
  border: 1px solid rgba(159,58,56,.28);
}
button.danger:hover { background: #ead7d4; }
.danger-text { color: var(--danger); }
.profile-compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 10px; }
.profile-compare-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--bg); }
.nav-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.nav-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--danger);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}
.nav-badge.hidden { display: none; }
.thread-tab.unread { border-color: rgba(159,58,56,.45); color: var(--danger); }
.thread-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--danger);
  display: inline-block;
  margin-left: 7px;
  vertical-align: middle;
}

.amount-cell { text-align: right; white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.items-table th, .items-table td { vertical-align: top; }
.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chart-row { display: grid; grid-template-columns: 110px 1fr 64px; gap: 10px; align-items: center; margin-top: 12px; }
.chart-label, .chart-value { color: var(--muted); font-size: 13px; }
.chart-track { height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.chart-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.approval-history-item { cursor: pointer; }
.approval-history-item:hover { border-color: rgba(143,94,59,.45); }
@media (max-width: 900px) { .analytics-grid { grid-template-columns: 1fr; } .chart-row { grid-template-columns: 1fr; } }

.toast-stack {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: grid;
  gap: 10px;
  z-index: 9999;
  max-width: min(380px, calc(100vw - 48px));
}
.toast-stack .toast {
  position: static;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: auto;
}
.history-action { font-weight: 750; }
.history-action.approve { color: var(--ok); }
.history-action.reject { color: var(--danger); }
.history-action.revise { color: var(--accent-dark); }
.history-action.neutral { color: var(--muted); }

.toast-stack .toast.show { opacity: 1; transform: translateY(0); }
.doc-filter.active { background: var(--text); color: #fffdf9; }

.soft-divider { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }
.status-chip { display:inline-flex; align-items:center; gap:4px; border-radius:999px; padding:3px 8px; font-size:12px; background:var(--surface-2); color:var(--muted); margin-right:6px; }
.status-chip.ok { background:#f1f8f1; color:var(--ok); }
.status-chip.warn { background:#fff7ed; color:var(--accent-dark); }
.deal-doc-grid { display:grid; gap:8px; margin-top:10px; }
.deal-doc-row { border:1px solid var(--line); border-radius:12px; padding:9px 10px; background:#fffdf9; }
