@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=Sora:wght@600;700;800&display=swap");

:root {
  --bg: #edf2f8;
  --ink: #11263d;
  --ink-soft: #4d6581;
  --surface: #ffffff;
  --surface-2: #f7fafe;
  --line: #d6e2ef;
  --line-strong: #b9ccdf;
  --brand: #0a5f8a;
  --brand-strong: #0b4766;
  --brand-soft: #e8f4ff;
  --ok-bg: #dcfce7;
  --ok-ink: #166534;
  --warn-bg: #fef3c7;
  --warn-ink: #92400e;
  --err-bg: #fee2e2;
  --err-ink: #991b1b;
  --pending-bg: #dbeafe;
  --pending-ink: #1e40af;
  --shadow-lg: 0 18px 40px rgba(10, 25, 44, 0.14);
  --shadow-sm: 0 8px 20px rgba(12, 31, 52, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 4%, rgba(6, 126, 183, 0.18), transparent 35%),
    radial-gradient(circle at 94% 8%, rgba(25, 160, 113, 0.16), transparent 34%),
    var(--bg);
}

.auth-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 22, 39, 0.58);
  z-index: 1400;
}

.auth-overlay.hidden {
  display: none;
}

.auth-card {
  width: min(460px, 96vw);
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: var(--shadow-lg);
  padding: 18px;
  display: grid;
  gap: 10px;
}

.auth-card h2 {
  font-size: 24px;
}

.auth-card p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.5;
}

.auth-card label {
  font-size: 13px;
  font-weight: 700;
  color: #1e3a5a;
}

.auth-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: "Sora", sans-serif;
  letter-spacing: -0.02em;
}

.app-shell {
  width: min(1560px, 97vw);
  margin: 16px auto;
  min-height: calc(100vh - 32px);
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 18px;
}

.sidebar,
.chat-layout {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-lg);
}

.sidebar {
  padding: 14px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 12px;
  overflow: hidden;
}

.sidebar-head {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  background: linear-gradient(160deg, #eaf6ff 0%, #ecfff7 100%);
}

.thuong-hieu {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--brand-strong);
  text-transform: uppercase;
}

.sidebar-head h1 {
  margin-top: 8px;
  font-size: 36px;
  line-height: 1.08;
}

.mo-ta-ngan {
  margin: 10px 0 14px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink-soft);
}

.sidebar-block {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.92);
  display: grid;
  gap: 10px;
}

.sidebar-history {
  min-height: 0;
  grid-template-rows: auto 1fr;
}

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

.block-head h2 {
  font-size: 16px;
}

.status-line {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: #29445e;
}

.status-line.subtle {
  color: var(--ink-soft);
}

.session-list {
  min-height: 0;
  max-height: 100%;
  overflow: auto;
  display: grid;
  gap: 8px;
  padding-right: 2px;
}

.session-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fbff;
  color: var(--ink);
  text-align: left;
  padding: 10px;
  display: grid;
  gap: 4px;
  cursor: pointer;
  transition: border-color 0.16s ease, transform 0.16s ease, background 0.16s ease;
}

.session-item:hover {
  border-color: #8fb0cf;
  transform: translateY(-1px);
}

.session-item.active {
  border-color: #6d9cc5;
  background: linear-gradient(145deg, #ebf6ff, #f0fffa);
}

.session-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
}

.session-meta {
  font-size: 12px;
  color: var(--ink-soft);
}

input,
textarea,
button {
  font: inherit;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.72;
  cursor: wait;
}

.btn-solid {
  color: #fff;
  background: linear-gradient(130deg, var(--brand), var(--brand-strong));
}

.btn-outline {
  border: 1px solid #90b1cc;
  background: #ecf6ff;
  color: #0d4972;
}

.btn-ghost {
  color: #334155;
  background: #e2e8f0;
}

.btn-danger {
  color: #fff;
  background: #b91c1c;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
  background: #e2e8f0;
  color: #334155;
  white-space: nowrap;
}

.pill-pending {
  background: var(--pending-bg);
  color: var(--pending-ink);
}

.pill-ok {
  background: var(--ok-bg);
  color: var(--ok-ink);
}

.pill-warn {
  background: var(--warn-bg);
  color: var(--warn-ink);
}

.pill-err {
  background: var(--err-bg);
  color: var(--err-ink);
}

.chat-layout {
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  min-height: calc(100vh - 32px);
}

.chat-head {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(165deg, #f4fbff 0%, #f2fffa 100%);
}

.chat-head h2 {
  font-size: clamp(26px, 2.8vw, 44px);
  line-height: 1.12;
}

.chat-head p {
  margin: 9px 0 0;
  font-size: 19px;
  line-height: 1.42;
  color: #284862;
  max-width: 95ch;
}

.head-right {
  display: grid;
  gap: 8px;
  justify-items: end;
  min-width: 220px;
}

.chat-thread {
  padding: 18px;
  overflow: auto;
  display: grid;
  gap: 14px;
  align-content: start;
}

.chat-empty {
  border: 1px dashed #abc5dc;
  border-radius: 14px;
  background: #f8fbff;
  color: var(--ink-soft);
  padding: 14px;
  font-size: 14px;
}

.msg {
  display: grid;
  gap: 8px;
  max-width: min(1120px, 96%);
  animation: floatIn 0.22s ease;
}

@keyframes floatIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg.user {
  justify-self: end;
}

.msg.assistant {
  justify-self: start;
}

.msg-top {
  font-size: 12px;
  color: #5a738f;
  display: flex;
  align-items: center;
  gap: 8px;
}

.bubble {
  border-radius: 16px;
  padding: 12px 14px;
  border: 1px solid transparent;
  line-height: 1.55;
  font-size: 15px;
  white-space: pre-wrap;
}

.msg.user .bubble {
  color: #ffffff;
  border-color: #0f5d85;
  background: linear-gradient(130deg, #0b6996, #0c4f71);
}

.msg.assistant .bubble {
  border-color: #bdd4e8;
  background: #f5f9ff;
}

.process-wrap {
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.process-head {
  padding: 11px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #f2f8ff;
  border-bottom: 1px solid var(--line);
}

.process-head strong {
  font-size: 13px;
}

.process-summary {
  margin: 0;
  padding: 10px 13px;
  font-size: 13px;
  line-height: 1.45;
  color: #2f4a63;
  border-bottom: 1px dashed #d0dfec;
}

.thinking-block {
  margin: 0;
}

.thinking-block > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 13px;
  font-size: 13px;
  font-weight: 800;
  color: #143755;
}

.thinking-block > summary::-webkit-details-marker {
  display: none;
}

.thinking-content {
  border-top: 1px solid var(--line);
  padding: 12px;
  display: grid;
  gap: 12px;
}

.timeline-item {
  font-size: 12px;
  line-height: 1.42;
  color: #2f4c66;
  border-left: 2px solid #bcd8f2;
  padding-left: 8px;
}

.doc-grid {
  display: grid;
  gap: 10px;
}

.doc-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px;
  background: #fbfdff;
  display: grid;
  gap: 10px;
}

.doc-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.doc-head strong {
  font-size: 14px;
}

.doc-sub {
  margin-top: 2px;
  font-size: 12px;
  color: #4e6782;
}

.facts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 7px;
}

.facts-item {
  border: 1px solid #d4e3f1;
  border-radius: 10px;
  padding: 7px;
  background: #f7fbff;
}

.facts-item b {
  display: block;
  margin-bottom: 3px;
  font-size: 11px;
  color: #48627e;
}

.facts-item span {
  font-size: 12px;
}

.step-list {
  display: grid;
  gap: 7px;
}

.step-row {
  border: 1px solid #dce8f3;
  border-radius: 10px;
  padding: 8px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  background: #ffffff;
}

.step-row b {
  display: block;
  margin-bottom: 2px;
  font-size: 12px;
}

.step-row small {
  display: block;
  font-size: 11px;
  line-height: 1.4;
  color: #58718c;
}

.step-state {
  border-radius: 999px;
  padding: 3px 8px;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 800;
}

.step-row.done {
  border-color: #9fddba;
  background: #f0fff5;
}

.step-row.done .step-state {
  color: var(--ok-ink);
  background: var(--ok-bg);
}

.step-row.active {
  border-color: #a5c7e7;
  background: #f1f8ff;
}

.step-row.active .step-state {
  color: var(--pending-ink);
  background: var(--pending-bg);
}

.step-row.pending {
  border-color: #dce8f3;
  background: #f8fbff;
}

.step-row.pending .step-state {
  color: #334155;
  background: #e2e8f0;
}

.step-row.error {
  border-color: #f2b8b8;
  background: #fff5f5;
}

.step-row.error .step-state {
  color: var(--err-ink);
  background: var(--err-bg);
}

.proposal-grid {
  display: grid;
  gap: 10px;
}

.proposal-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fff;
  display: grid;
  gap: 9px;
}

.proposal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.proposal-head strong {
  font-size: 14px;
}

.proposal-sub {
  margin-top: 3px;
  font-size: 12px;
  color: #4e6780;
}

.table-wrap {
  border: 1px solid #d5e2ef;
  border-radius: 10px;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 340px;
}

th,
td {
  border-bottom: 1px solid #e3edf6;
  padding: 7px;
  font-size: 12px;
  text-align: left;
}

th {
  background: #f3f8fe;
  color: #294763;
  font-weight: 800;
}

.ref-list {
  margin: 0;
  padding-left: 16px;
  display: grid;
  gap: 5px;
}

.ref-list li {
  font-size: 12px;
  line-height: 1.4;
}

.reasoning {
  margin: 0;
  font-size: 13px;
  line-height: 1.52;
  color: #233c52;
}

.risk-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.risk-tag {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 800;
  background: #ffedd5;
  color: #9a3412;
}

.decision-grid {
  display: grid;
  gap: 8px;
}

.decision-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.decision-grid label {
  font-size: 11px;
  font-weight: 800;
  color: #3e5771;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.decision-lines {
  min-height: 100px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
}

.action-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.composer {
  border-top: 1px solid var(--line);
  padding: 12px;
  display: grid;
  gap: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(246, 252, 255, 0.94));
}

.composer-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.hint {
  font-size: 12px;
  color: #4f6882;
}

.file-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #b7d1e7;
  border-radius: 999px;
  background: #edf7ff;
  color: #164970;
  font-size: 12px;
  padding: 4px 9px;
}

.file-chip button {
  border: 0;
  background: transparent;
  color: #164970;
  font-weight: 800;
  cursor: pointer;
  padding: 0;
}

.composer-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 10px;
}

#composerInput {
  min-height: 74px;
  max-height: 190px;
}

.toast-stack {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 100;
  display: grid;
  gap: 8px;
}

.toast {
  min-width: 260px;
  padding: 10px 12px;
  border-radius: 12px;
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
}

.toast.info {
  background: #0369a1;
}

.toast.ok {
  background: #15803d;
}

.toast.warn {
  background: #b45309;
}

.toast.err {
  background: #b91c1c;
}

.khong-du-lieu {
  border: 1px dashed #c4d8ea;
  border-radius: 10px;
  padding: 8px;
  font-size: 12px;
  color: #567089;
  background: #f8fcff;
}

@media (max-width: 1200px) {
  .app-shell {
    grid-template-columns: 300px 1fr;
    width: min(98vw, 98vw);
  }

  .chat-head {
    flex-direction: column;
  }

  .head-right {
    width: 100%;
    justify-items: start;
    grid-template-columns: 1fr auto;
    display: grid;
    align-items: center;
  }

  .chat-head h2 {
    font-size: clamp(24px, 3.8vw, 36px);
  }

  .chat-head p {
    font-size: 17px;
  }
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: unset;
  }

  .sidebar,
  .chat-layout {
    min-height: unset;
  }

  .sidebar {
    grid-template-rows: auto auto auto;
  }

  .session-list {
    max-height: 220px;
  }

  .chat-layout {
    min-height: calc(100vh - 28px);
  }

  .composer-input-row,
  .decision-row {
    grid-template-columns: 1fr;
  }

  .sidebar-head h1 {
    font-size: 30px;
  }
}
