:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --text: #172026;
  --muted: #63717b;
  --line: #dbe2e6;
  --accent: #19706a;
  --accent-2: #b84c2f;
  --soft: #eef6f4;
  --danger: #a5362a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  max-width: 1460px;
  margin: 0 auto;
  padding: 24px;
}

.narrow {
  max-width: 980px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-size: 26px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

.topbar p,
.muted {
  color: var(--muted);
  margin-top: 4px;
}

.notice {
  background: #fff8ea;
  border: 1px solid #ead7aa;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 18px;
  line-height: 1.55;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(520px, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.user-rail {
  position: sticky;
  top: 16px;
}

.context-panel {
  position: fixed;
  top: 18px;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  width: min(420px, calc(100vw - 28px));
  overflow: auto;
  box-shadow: 0 18px 60px rgba(23, 32, 38, 0.18);
  transform: translateX(calc(100% + 28px));
  transition: transform 180ms ease;
}

.context-panel.open {
  transform: translateX(0);
}

.chat-panel {
  min-height: calc(100vh - 170px);
  display: grid;
  grid-template-rows: auto 1fr auto auto;
}

.panel-head,
.section-head,
.upload,
.chat-form {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-head {
  margin-bottom: 12px;
}

.counter {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.chat-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.ghost-button {
  background: #fff;
  color: var(--accent);
  border-color: var(--line);
  padding: 7px 10px;
}

.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.rail-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.rail-actions button {
  padding: 8px 9px;
}

.context-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fa;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.context-tab {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  padding: 8px 6px;
}

.context-tab.active {
  background: var(--panel);
  border-color: var(--line);
  color: var(--accent);
}

.context-pane {
  display: none;
}

.context-pane.active {
  display: block;
}

.section-head.compact {
  align-items: flex-start;
}

.form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea,
button,
.link-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
}

textarea {
  min-height: 72px;
  resize: vertical;
}

button,
.link-button {
  background: var(--accent);
  color: white;
  padding: 9px 12px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.wide {
  width: 100%;
  margin-top: 12px;
}

.status,
.chat-status {
  min-height: 20px;
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.45;
}

.top-flow-status {
  margin: 8px 0 12px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--accent);
  font-size: 13px;
  line-height: 1.45;
}

.panel.flash {
  animation: panel-flash 1.2s ease-out;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.result,
.chat,
.timeline {
  margin-top: 14px;
}

.chat {
  min-height: 560px;
  max-height: calc(100vh - 330px);
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.result-card,
.message,
.timeline-item,
.finding {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
}

.message.user {
  background: var(--soft);
  margin-left: 54px;
  border-color: #c9e3df;
}

.message.assistant {
  background: #fbfcfc;
  line-height: 1.6;
  margin-right: 28px;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.message-meta span {
  font-weight: 700;
  color: var(--accent);
}

.message.user .message-meta span {
  color: #315c58;
}

.message-body {
  overflow-wrap: anywhere;
}

.empty-chat {
  padding: 18px;
  text-align: center;
}

.message.pending {
  position: relative;
  color: var(--muted);
}

.message.pending::after {
  content: "";
  display: inline-block;
  width: 18px;
  height: 10px;
  margin-left: 8px;
  background:
    radial-gradient(circle at 3px 5px, var(--accent) 2px, transparent 3px),
    radial-gradient(circle at 9px 5px, var(--accent) 2px, transparent 3px),
    radial-gradient(circle at 15px 5px, var(--accent) 2px, transparent 3px);
  animation: pulse-dots 1s infinite ease-in-out;
}

.message.assistant h3,
.message.assistant h4 {
  margin: 14px 0 8px;
  line-height: 1.35;
}

.message.assistant h3 {
  font-size: 16px;
}

.message.assistant h4 {
  font-size: 14px;
}

.tag {
  display: inline-block;
  background: var(--soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 3px 8px;
  margin: 3px 4px 3px 0;
  font-size: 12px;
}

.profile-snapshot {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  font-size: 13px;
  line-height: 1.45;
}

.user-rail .profile-snapshot {
  max-height: calc(100vh - 380px);
  overflow: auto;
}

.profile-snapshot.updated {
  animation: snapshot-update 1.2s ease-out;
}

.profile-snapshot p {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  margin-top: 8px;
}

.profile-snapshot span {
  color: var(--muted);
}

.profile-tags {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.profile-tags section {
  display: grid;
  gap: 5px;
}

.profile-tags div {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.profile-tags b {
  display: inline-block;
  background: var(--soft);
  color: var(--accent);
  border: 1px solid #c9e3df;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
}

.snapshot-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.ok,
.locked,
.saving {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
}

.ok {
  background: var(--soft);
  color: var(--accent);
}

.locked {
  background: #fff8ea;
  color: #8a5a12;
}

.saving {
  background: #eef1f4;
  color: var(--muted);
}

.error {
  color: var(--danger);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

.report-page {
  line-height: 1.65;
}

.report-section {
  margin-top: 20px;
}

.finding strong {
  color: var(--accent-2);
}

.timeline {
  max-height: 340px;
  overflow: auto;
}

.timeline-item {
  position: relative;
  padding-left: 14px;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 16px;
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
}

@media (max-width: 900px) {
  .shell {
    padding: 14px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .user-rail {
    position: static;
  }

  .context-panel {
    top: 10px;
    right: 10px;
    bottom: 10px;
    width: calc(100vw - 20px);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .button-row {
    justify-content: flex-start;
  }

  .chat-panel {
    min-height: 620px;
  }

  .chat {
    min-height: 420px;
  }

  .message.user,
  .message.assistant {
    margin-left: 0;
    margin-right: 0;
  }
}

@keyframes pulse-dots {
  0%,
  100% {
    opacity: 0.35;
  }

  50% {
    opacity: 1;
  }
}

@keyframes panel-flash {
  0% {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(25, 112, 106, 0.16);
  }

  100% {
    border-color: var(--line);
    box-shadow: none;
  }
}

@keyframes snapshot-update {
  0% {
    border-color: var(--accent);
    background: #eef6f4;
    box-shadow: 0 0 0 4px rgba(25, 112, 106, 0.12);
  }

  100% {
    border-color: var(--line);
    background: #fbfcfc;
    box-shadow: none;
  }
}
