:root {
  --bg: #f3efe4;
  --paper: #fffaf2;
  --ink: #1f1f1f;
  --muted: #6a685f;
  --accent: #154734;
  --accent-soft: #d9eadb;
  --border: #ddd4c3;
  --shadow: 0 12px 32px rgba(45, 38, 24, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  background:
    radial-gradient(circle at top right, rgba(21, 71, 52, 0.12), transparent 25%),
    linear-gradient(180deg, #f6f2e9, var(--bg));
  color: var(--ink);
}
button, input, select, textarea { font: inherit; }
.shell { min-height: 100vh; display: grid; grid-template-columns: 320px 1fr; }
.sidebar {
  padding: 28px 20px; border-right: 1px solid var(--border); background: rgba(255, 250, 242, 0.92);
  display: flex; flex-direction: column; gap: 18px;
}
.main { padding: 28px; display: flex; flex-direction: column; gap: 18px; }
.hero, .panel { background: var(--paper); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); }
.hero { padding: 22px 24px; display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.hero-status { display: grid; gap: 8px; justify-items: end; }
.auth-inline { display: flex; align-items: center; gap: 8px; justify-self: end; }
.panel { padding: 18px; }
.compact { padding: 14px; }
.eyebrow { margin: 0 0 8px; font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
h1,h2,h3,h4,p { margin: 0; }
h1 { font-size: 2rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; margin-bottom: 12px; }
.muted { color: var(--muted); }
.row-between, .actions-inline { display: flex; align-items: center; gap: 12px; }
.row-between { justify-content: space-between; }
.inline-control { display: grid; gap: 6px; font-size: .86rem; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
form { display: grid; gap: 10px; }
label { display: grid; gap: 6px; font-size: .92rem; }
.select-help {
  display: block;
  font-size: .82rem;
  line-height: 1.35;
}
input, select, textarea {
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: #fffcf7;
}
.rich-input { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: #fffcf7; min-height: 150px; white-space: pre-wrap; overflow-y: auto; }
.rich-input:empty::before { content: attr(data-placeholder); color: var(--muted); }
textarea { resize: vertical; }
button { border: none; border-radius: 999px; padding: 10px 14px; cursor: pointer; transition: opacity .18s ease, transform .18s ease; }
button.is-busy { opacity: .72; cursor: wait; }
.primary { background: var(--accent); color: white; }
.secondary { background: var(--accent-soft); color: var(--accent); }
.ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.danger { color: #8c2f2f; border-color: #cfa8a8; }
.wide { width: 100%; }
.small { padding: 6px 10px; font-size: .86rem; }
.pill { padding: 8px 12px; background: #efe7d8; border-radius: 999px; color: var(--muted); border: 1px solid transparent; transition: transform .18s ease, background .18s ease, border-color .18s ease, color .18s ease; }
.pill.success { background: #eef8f1; border-color: #a7c5ae; color: #154734; }
.pill.error { background: #fff2f2; border-color: #deb0a7; color: #8c2f2f; }
.pill.warning { background: #fff9eb; border-color: #e0c58b; color: #6f581f; }
.pill.busy { background: #f0efe9; border-color: #d8cfbd; color: #5e594e; }
.company-list { display: grid; gap: 8px; }
.company-item { border: 1px solid var(--border); border-radius: 14px; padding: 12px; background: #fffcf7; cursor: pointer; text-align: left; }
.company-item.active { border-color: var(--accent); background: #f0f6f1; }
.callout, .thesis-card, .raw-note, .timeline { min-height: 70px; border: 1px dashed var(--border); border-radius: 14px; padding: 12px; background: #fffdf8; }
.callout[data-tone="success"] { border-style: solid; border-color: #8fb39b; background: #eef8f1; color: #154734; }
.callout[data-tone="error"] { border-style: solid; border-color: #cfa8a8; background: #fff2f2; color: #8c2f2f; }
.callout[data-tone="warning"] { border-style: solid; border-color: #d8c18f; background: #fff9eb; color: #6f581f; }
.editor { margin-top: 16px; border: 1px solid var(--border); border-radius: 14px; padding: 14px; background: #fcf8f0; }
.editor-modal {
  position: fixed;
  inset: 0;
  z-index: 980;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  margin-top: 0;
  border: none;
  background: rgba(27, 24, 19, 0.46);
  backdrop-filter: blur(3px);
  box-shadow: none;
}
.editor-modal-card {
  width: min(960px, 100%);
  max-height: calc(100vh - 56px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 20px 50px rgba(31, 31, 31, 0.22);
  padding: 20px;
  display: grid;
  gap: 14px;
}
.entry-mode-panel { margin: 14px 0; border: 1px solid var(--border); border-radius: 14px; padding: 14px; background: linear-gradient(180deg, #fcf8f0, #fffdf8); }
.review-panel { margin-top: 14px; border: 1px solid var(--border); border-radius: 14px; padding: 14px; background: linear-gradient(180deg, #fcf8f0, #fffdf8); display: grid; gap: 12px; }
.review-list { display: grid; gap: 12px; }
.review-item { border: 1px solid var(--border); border-radius: 14px; padding: 12px; background: #fffcf7; display: grid; gap: 10px; }
.review-raw { margin: 0; white-space: pre-wrap; word-break: break-word; max-height: 130px; overflow: auto; background: #fffdf8; border: 1px dashed var(--border); border-radius: 12px; padding: 10px; }
.material-preview-highlights { display: flex; gap: 8px; flex-wrap: wrap; }
.material-preview-highlights .count-chip { font-size: .8rem; }
.hidden { display: none; }
.empty { color: var(--muted); }
.thesis-card h4 { margin-top: 14px; margin-bottom: 6px; }
.thesis-card ul { padding-left: 22px; margin: 0; display: grid; gap: 8px; }
.thesis-card li { line-height: 1.45; padding-left: 2px; }
.editor-block { display: grid; gap: 8px; }
.editor-list { display: grid; gap: 10px; }
.editor-row { display: grid; gap: 8px; border: 1px solid var(--border); border-radius: 12px; padding: 10px; background: #fffcf7; }
.editor-row-pillar { grid-template-columns: 1fr; }
.target-list { display: grid; gap: 8px; max-height: 180px; overflow-y: auto; }
.target-item { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px; background: #fffcf7; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; }
.stat { border: 1px solid var(--border); border-radius: 14px; padding: 12px; background: #fffcf7; }
.stat strong { display: block; font-size: 1.5rem; margin-top: 4px; }
.timeline { display: grid; gap: 12px; }
.timeline-item { border: 1px solid var(--border); border-radius: 16px; padding: 14px; background: #fffcf7; }
.timeline-item.focused-card { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(21, 71, 52, 0.14); }
.flash-update { animation: sectionFlash 1s ease; }
.pillar-sections { display: grid; gap: 16px; }
.pillar-section { border: 1px solid var(--border); border-radius: 18px; padding: 16px; background: linear-gradient(180deg, #fffdf8, #fbf4e7); display: grid; gap: 14px; position: relative; overflow: hidden; }
.pillar-section::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 7px; background: #b89c6a; }
.pillar-section[data-bias="positive"]::before { background: #4f8a63; }
.pillar-section[data-bias="negative"]::before { background: #b35a4b; }
.pillar-section[data-bias="mixed"]::before { background: #b89c6a; }
.pillar-breakdown { display: grid; gap: 10px; min-width: 240px; }
.pillar-counts { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.count-chip { display: inline-flex; align-items: center; padding: 5px 10px; border-radius: 999px; font-size: .82rem; border: 1px solid var(--border); background: #fffdf8; }
.count-chip.positive { color: #24573a; background: #edf7f0; border-color: #a7c5ae; }
.count-chip.negative { color: #8d3c32; background: #fff0ee; border-color: #deb0a7; }
.count-chip.mixed { color: #73551c; background: #fff8e8; border-color: #e0c58b; }
.signal-bar { display: flex; height: 9px; border-radius: 999px; overflow: hidden; background: #eee5d6; }
.signal-segment { height: 100%; }
.signal-segment.positive { background: #4f8a63; }
.signal-segment.negative { background: #b35a4b; }
.signal-segment.mixed { background: #c29b43; }
.summary-form { grid-template-columns: repeat(3, minmax(0,1fr)); align-items: start; }
.summary-output { display: grid; gap: 14px; }
.summary-block { border: 1px solid var(--border); border-radius: 14px; padding: 12px; background: #fffcf7; display: grid; gap: 10px; }
.summary-groups { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.summary-group { border: 1px solid var(--border); border-radius: 12px; padding: 12px; background: #fffdf8; display: grid; gap: 8px; }
.summary-group ul { margin: 0; padding-left: 18px; }
.summary-group li { display: grid; gap: 6px; margin-bottom: 8px; }
.summary-subgroups { display: grid; gap: 10px; }
.summary-subgroup { border-top: 1px dashed var(--border); padding-top: 10px; display: grid; gap: 8px; }
.summary-subgroup:first-of-type { border-top: none; padding-top: 0; }
.summary-link { justify-self: start; }
.ai-summary-note { border-left: 4px solid var(--accent); padding-left: 12px; }
.timeline-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.timeline-meta { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.timeline-summary { margin-top: 10px; line-height: 1.45; }
.timeline-signal { text-transform: uppercase; font-size: .75rem; letter-spacing: .08em; padding: 6px 8px; border-radius: 999px; background: #efe7d8; }
.timeline-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.raw-note pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
}
.modal.hidden { display: none; }
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(27, 24, 19, 0.46);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  z-index: 1;
  width: min(920px, 100%);
  max-height: calc(100vh - 56px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 20px 50px rgba(31, 31, 31, 0.22);
  padding: 20px;
}
.modal-head {
  margin-bottom: 10px;
  align-items: flex-start;
}
.raw-note-modal-card {
  display: grid;
  gap: 12px;
}
.llm-confirm-card {
  display: grid;
  gap: 14px;
  width: min(760px, 100%);
}
.llm-confirm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.llm-confirm-grid .summary-block {
  gap: 6px;
}
.modal-raw-note {
  margin: 0;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: #fffdf8;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 60vh;
  overflow: auto;
}
.toast-container {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 960;
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 10px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 250, 242, 0.98);
  box-shadow: 0 18px 38px rgba(31, 31, 31, 0.14);
  padding: 12px 14px;
  display: grid;
  gap: 6px;
  animation: toastIn .2s ease;
}
.toast.success { border-color: #a7c5ae; background: #eef8f1; color: #154734; }
.toast.warning { border-color: #e0c58b; background: #fff9eb; color: #6f581f; }
.toast.error { border-color: #deb0a7; background: #fff2f2; color: #8c2f2f; }
.toast-title { font-weight: 700; }
.toast-meta { font-size: .82rem; opacity: .82; }
.toast-close {
  justify-self: end;
  padding: 4px 8px;
}
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card { width: min(460px, 100%); }
.login-form { display: grid; gap: 12px; }
@keyframes sectionFlash {
  0% { box-shadow: 0 0 0 0 rgba(21, 71, 52, 0.24); }
  40% { box-shadow: 0 0 0 6px rgba(21, 71, 52, 0.10); }
  100% { box-shadow: none; }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (max-width: 1100px) {
  .shell, .grid { grid-template-columns: 1fr; }
  .summary-form, .summary-groups { grid-template-columns: 1fr; }
  .llm-confirm-grid { grid-template-columns: 1fr; }
  .hero-status { justify-items: start; }
  .auth-inline { justify-self: start; }
  .toast-container {
    right: 16px;
    left: 16px;
    bottom: 16px;
    width: auto;
  }
}
