:root {
  --ink: #172521;
  --muted: #68766f;
  --paper: #f5f3eb;
  --panel: #fffdf7;
  --line: #dcded4;
  --green: #176b55;
  --green-dark: #0e493b;
  --green-soft: #dfece4;
  --amber: #e4a84a;
  --danger: #a53f35;
  --shadow: 0 18px 50px rgb(33 56 47 / 9%);
  --font-sans:
    "Segoe UI Variable Text", "Segoe UI", "Noto Sans", Roboto, "Helvetica Neue", Arial,
    "Liberation Sans", sans-serif;
  --font-display:
    "Segoe UI Variable Display", "Segoe UI", "Noto Sans", Roboto, "Helvetica Neue", Arial,
    "Liberation Sans", sans-serif;
  --font-mono:
    "Cascadia Mono", "Cascadia Code", Consolas, "Noto Sans Mono", "SFMono-Regular",
    "Liberation Mono", monospace;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

html {
  font-size: 16px;
  text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  line-height: 1.5;
  text-rendering: auto;
  background:
    radial-gradient(circle at 85% 5%, rgb(228 168 74 / 13%), transparent 26rem),
    var(--paper);
}

button,
input,
textarea,
select {
  font: inherit;
  line-height: 1.4;
}

button {
  color: inherit;
  line-height: 1.25;
}

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  padding: 28px;
  place-items: center;
  background:
    radial-gradient(circle at 20% 15%, rgb(23 107 85 / 16%), transparent 28rem),
    radial-gradient(circle at 85% 80%, rgb(228 168 74 / 16%), transparent 24rem),
    var(--paper);
}

.login-card {
  width: min(440px, 100%);
  padding: clamp(30px, 6vw, 48px);
  background: rgb(255 253 247 / 96%);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 30px 90px rgb(28 50 42 / 15%);
}

.login-brand {
  display: flex;
  gap: 13px;
  align-items: center;
  margin-bottom: 42px;
}

.login-brand strong,
.login-brand small {
  display: block;
}

.login-brand strong {
  font-family: var(--font-display);
  font-size: 22px;
}

.login-brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.login-card h1 {
  margin: 7px 0 8px;
  font-family: var(--font-display);
  font-size: 44px;
  font-weight: 600;
}

.login-copy {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.login-form {
  display: grid;
  gap: 9px;
}

.login-form label {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.login-form .button {
  margin-top: 8px;
}

.login-error {
  margin: 3px 0 0;
  padding: 9px 11px;
  color: #7c2d26;
  font-size: 11px;
  line-height: 1.5;
  background: #fae8e5;
  border: 1px solid #efc5bf;
  border-radius: 9px;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 28px 20px 20px;
  background: #eef0e9;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 0 6px 30px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: white;
  font-family: var(--font-display);
  font-size: 24px;
  font-style: italic;
  background: var(--green);
  border-radius: 12px 12px 12px 4px;
  box-shadow: 0 8px 20px rgb(23 107 85 / 22%);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: var(--font-display);
  font-size: 21px;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.button {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 16px;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

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

.button:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.button-primary {
  color: white;
  background: var(--green);
  box-shadow: 0 8px 18px rgb(23 107 85 / 18%);
}

.button-primary:hover {
  background: var(--green-dark);
}

.button-dark {
  color: white;
  background: var(--ink);
}

.button-danger {
  color: var(--danger);
  background: #fff8f6;
  border-color: #e4bbb5;
}

.button-danger:hover {
  color: white;
  background: var(--danger);
}

.button-quiet {
  background: transparent;
  border-color: var(--line);
}

.button-copy {
  color: var(--green-dark);
  background: #f2f8f4;
  border-color: #c7dfd0;
}

.button-copy::before {
  width: 14px;
  height: 16px;
  content: "";
  border: 2px solid currentcolor;
  border-radius: 4px;
  box-shadow: 4px -4px 0 -1px #f2f8f4, 4px -4px 0 0 currentcolor;
}

.button-copy:hover {
  background: var(--green-soft);
  border-color: #9dc4ad;
}

.button-quiet:hover {
  background: white;
}

.button-full {
  width: 100%;
}

.button-icon {
  margin-top: -2px;
  font-size: 22px;
  font-weight: 400;
}

.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 28px 8px 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.icon-button {
  display: grid;
  width: 30px;
  height: 30px;
  padding: 6px;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.icon-button:hover {
  background: rgb(255 255 255 / 65%);
}

.icon-button svg,
.file-drop svg,
.send-button svg {
  width: 100%;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.notebook-list {
  display: grid;
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
}

.notebook-list-status {
  padding: 16px 10px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.notebook-item {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 10px;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
}

.notebook-item:hover {
  background: rgb(255 255 255 / 55%);
}

.notebook-item.active {
  background: white;
  border-color: #d9ded5;
  box-shadow: 0 6px 18px rgb(42 65 57 / 7%);
}

.notebook-glyph {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: var(--green-dark);
  font-family: var(--font-display);
  font-weight: 700;
  background: var(--green-soft);
  border-radius: 10px;
}

.notebook-copy {
  min-width: 0;
}

.notebook-copy strong,
.notebook-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notebook-copy strong {
  font-size: 13px;
}

.notebook-copy small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding: 18px 8px 2px;
  color: var(--muted);
  font-size: 11px;
  border-top: 1px solid var(--line);
}

.signed-in-user {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
  font-weight: 700;
}

.logout-button {
  padding: 5px 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.logout-button:hover {
  color: var(--danger);
  background: rgb(165 63 53 / 8%);
}

.status-dot {
  width: 7px;
  height: 7px;
  background: #47a47d;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgb(71 164 125 / 15%);
}

.main {
  min-width: 0;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 60px 24px;
  text-align: center;
}

.empty-state h1 {
  max-width: 720px;
  margin: 8px 0 18px;
  font-family: var(--font-display);
  font-size: clamp(38px, 6vw, 70px);
  font-weight: 600;
  line-height: 1.08;
}

.empty-state > p:not(.eyebrow) {
  max-width: 540px;
  margin: 0 0 26px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.65;
}

.empty-art {
  position: relative;
  width: 150px;
  height: 94px;
  margin-bottom: 22px;
}

.empty-art span {
  position: absolute;
  bottom: 0;
  width: 66px;
  height: 82px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px 8px 4px 4px;
  box-shadow: 0 14px 30px rgb(37 57 50 / 10%);
}

.empty-art span::before,
.empty-art span::after {
  position: absolute;
  left: 14px;
  width: 34px;
  height: 2px;
  content: "";
  background: #cbd2c9;
  box-shadow: 0 10px #cbd2c9, 0 20px #cbd2c9;
}

.empty-art span::before {
  top: 22px;
}

.empty-art span:first-child {
  left: 4px;
  transform: rotate(-10deg);
}

.empty-art span:nth-child(2) {
  left: 42px;
  z-index: 2;
  height: 92px;
  border-top: 5px solid var(--green);
}

.empty-art span:last-child {
  right: 2px;
  transform: rotate(9deg);
}

.workspace {
  padding: 34px clamp(24px, 4vw, 64px) 42px;
}

.workspace-header {
  display: flex;
  gap: 20px;
  align-items: end;
  justify-content: space-between;
  max-width: 1500px;
  margin: 0 auto 24px;
}

.workspace-header > div:first-child {
  min-width: 0;
}

.workspace-header h1 {
  margin: 4px 0 6px;
  overflow-wrap: anywhere;
  font-family: var(--font-display);
  font-size: clamp(34px, 4vw, 52px);
  font-weight: 600;
  line-height: 1.14;
}

.workspace-meta {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.workspace-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0;
  color: var(--green);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(420px, 1fr);
  gap: 18px;
  max-width: 1500px;
  min-height: calc(100vh - 176px);
  margin: 0 auto;
}

.panel {
  min-width: 0;
  background: rgb(255 253 247 / 92%);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 22px 16px;
}

.panel-heading h2 {
  margin: 3px 0 0;
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 600;
}

.count-badge {
  min-width: 28px;
  padding: 5px 8px;
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  background: var(--green-soft);
  border-radius: 999px;
}

.source-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin: 0 18px;
  padding: 4px;
  background: #eeefe9;
  border-radius: 10px;
}

.source-tab {
  padding: 8px 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.source-tab.active {
  color: var(--ink);
  background: white;
  box-shadow: 0 2px 7px rgb(32 52 44 / 8%);
}

.source-form {
  display: grid;
  gap: 9px;
  margin: 16px 18px 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.source-form label:not(.file-drop) {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.form-hint {
  margin: -2px 0 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

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

textarea {
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgb(23 107 85 / 10%);
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.input-row textarea {
  min-height: 82px;
}

.file-drop {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  padding: 22px 14px;
  text-align: center;
  border: 1px dashed #aeb8ad;
  border-radius: 12px;
  cursor: pointer;
}

.file-drop:hover {
  background: var(--green-soft);
  border-color: var(--green);
}

.file-drop svg {
  width: 25px;
  margin-bottom: 3px;
  color: var(--green);
}

.file-drop strong {
  font-size: 13px;
}

.file-drop span {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

.selected-file {
  min-height: 16px;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.upload-progress {
  display: grid;
  gap: 7px;
  padding: 11px 12px;
  background: #f0f3ee;
  border: 1px solid #dce3dc;
  border-radius: 10px;
}

.upload-progress-heading {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
}

.upload-progress-heading strong {
  color: var(--ink);
}

.upload-progress-heading span {
  color: var(--green-dark);
  font-weight: 800;
}

.upload-progress-track {
  height: 8px;
  overflow: hidden;
  background: #dce3dc;
  border-radius: 999px;
}

.upload-progress-track > span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--green), #50a47e);
  border-radius: inherit;
  transition: width 180ms ease;
}

.upload-progress.processing .upload-progress-track > span {
  background: linear-gradient(90deg, var(--green), var(--amber), var(--green));
  background-size: 200% 100%;
  animation: upload-shimmer 1.4s linear infinite;
}

.upload-progress.error {
  background: #fff2f0;
  border-color: #e8c4bf;
}

.upload-progress.error .upload-progress-track > span {
  background: var(--danger);
}

.upload-progress.complete .upload-progress-track > span {
  background: #47a47d;
}

.upload-progress p {
  margin: 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.45;
}

.source-import-status {
  margin: -4px 18px 18px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  background: #f0f3ee;
  border: 1px solid #dce3dc;
  border-radius: 10px;
}

.source-import-status.processing {
  color: #4d5f57;
  background: #eef5f1;
  border-color: #cfe0d6;
}

.source-import-status.complete {
  color: var(--green-dark);
  background: #eef8f1;
  border-color: #bcdcc7;
}

.source-import-status.error {
  color: #7c2d26;
  background: #fae8e5;
  border-color: #efc5bf;
}

.source-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 450px);
  padding: 0 18px 20px;
  overflow-y: auto;
}

.source-selection {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin: -3px 18px 12px;
  padding: 9px 10px;
  color: var(--muted);
  font-size: 10px;
  background: #f0f2ed;
  border-radius: 9px;
}

.source-selection label {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.source-selection input,
.source-choice input {
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  accent-color: var(--green);
  box-shadow: none;
  cursor: pointer;
}

.source-item {
  display: grid;
  grid-template-columns: 18px 34px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  background: #faf9f3;
  border: 1px solid #e4e4dc;
  border-radius: 11px;
}

.source-item.unselected {
  background: #f5f4ef;
  opacity: 0.68;
}

.source-choice {
  display: grid;
  place-items: center;
}

.source-actions {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.source-preview-button {
  padding: 6px 8px;
  color: var(--green-dark);
  font-size: 10px;
  font-weight: 800;
  background: transparent;
  border: 1px solid #cbd5cc;
  border-radius: 8px;
  cursor: pointer;
}

.source-delete-button {
  padding: 6px 8px;
  color: var(--danger);
  font-size: 10px;
  font-weight: 800;
  background: transparent;
  border: 1px solid #e2c2bd;
  border-radius: 8px;
  cursor: pointer;
}

.source-delete-button:hover {
  color: white;
  background: var(--danger);
  border-color: var(--danger);
}

.source-preview-button:hover {
  background: var(--green-soft);
  border-color: #a7bcae;
}

.source-preview-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.source-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 800;
  background: var(--green-soft);
  border-radius: 9px;
  text-transform: uppercase;
}

.source-copy {
  min-width: 0;
}

.source-copy strong {
  display: block;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-detail {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}

.source-status {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.source-status::before {
  width: 5px;
  height: 5px;
  content: "";
  background: #5a9b7b;
  border-radius: 50%;
}

.source-status.processing::before {
  background: var(--amber);
  animation: pulse 1.2s infinite;
}

.source-status.error::before {
  background: var(--danger);
}

.empty-list {
  padding: 28px 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 620px;
}

.chat-heading {
  border-bottom: 1px solid var(--line);
}

.work-mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  margin: 14px 20px 0;
  padding: 4px;
  background: #eceee8;
  border-radius: 11px;
}

.work-mode-tab {
  padding: 9px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.work-mode-tab.active {
  color: var(--green-dark);
  background: white;
  box-shadow: 0 3px 9px rgb(32 52 44 / 8%);
}

.live-label {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.live-label span {
  width: 6px;
  height: 6px;
  background: #4b9c78;
  border-radius: 50%;
}

.chat-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 18px;
  max-height: calc(100vh - 340px);
  padding: 26px clamp(18px, 4vw, 42px);
  overflow-y: auto;
}

.chat-workspace {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.chat-welcome {
  max-width: 520px;
  margin: auto;
  padding: 40px 20px;
  text-align: center;
}

.chat-welcome-mark {
  display: grid;
  width: 54px;
  height: 54px;
  margin: 0 auto 16px;
  place-items: center;
  color: white;
  font-family: var(--font-display);
  font-size: 26px;
  font-style: italic;
  background: var(--green);
  border-radius: 18px 18px 18px 5px;
}

.chat-welcome h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 600;
}

.chat-welcome p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.message {
  min-width: 0;
  max-width: min(760px, 92%);
}

.message-user {
  align-self: flex-end;
  padding: 11px 15px;
  color: white;
  background: var(--green);
  border-radius: 15px 15px 4px 15px;
}

.message-assistant {
  align-self: flex-start;
}

.message-label {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.answer-content {
  min-width: 0;
  font-size: 14px;
  line-height: 1.72;
  overflow-wrap: anywhere;
}

.answer-content p,
.answer-content ul,
.answer-content ol,
.answer-content pre,
.answer-content .markdown-table-scroll {
  margin: 0 0 12px;
}

.answer-content h1,
.answer-content h2,
.answer-content h3,
.answer-content h4,
.answer-content h5,
.answer-content h6 {
  margin: 18px 0 8px;
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.25;
}

.answer-content h1 {
  margin-top: 22px;
  font-size: 1.62em;
}

.answer-content h2 {
  font-size: 1.38em;
}

.answer-content h3 {
  font-size: 1.2em;
}

.answer-content h4,
.answer-content h5,
.answer-content h6 {
  font-size: 1.05em;
}

.answer-content hr {
  margin: 16px 0;
  border: none;
  border-top: 1px solid var(--line);
}

.answer-content code {
  padding: 2px 5px;
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: #e9ede7;
  border-radius: 5px;
}

.answer-content pre {
  padding: 13px;
  overflow-x: auto;
  background: #edf0eb;
  border-radius: 10px;
}

.answer-content pre code {
  padding: 0;
  background: transparent;
}

.markdown-table-scroll {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  scrollbar-width: thin;
}

.markdown-table {
  width: 100%;
  min-width: 460px;
  border-collapse: collapse;
  background: var(--panel);
}

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

.markdown-table th:last-child,
.markdown-table td:last-child {
  border-right: 0;
}

.markdown-table tbody tr:last-child td {
  border-bottom: 0;
}

.markdown-table th {
  color: var(--green-dark);
  font-size: 0.92em;
  font-weight: 800;
  background: var(--green-soft);
}

.markdown-table tbody tr:nth-child(even) {
  background: #f7f8f3;
}

.markdown-table .align-left {
  text-align: left;
}

.markdown-table .align-center {
  text-align: center;
}

.markdown-table .align-right {
  text-align: right;
}

.message-copy-btn {
  display: block;
  margin-top: 8px;
  padding: 3px 10px;
  color: var(--muted);
  font-size: 11px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.message-copy-btn:hover {
  background: var(--green-soft);
  color: var(--green-dark);
  border-color: transparent;
}

.citation-chip {
  display: inline-flex;
  gap: 2px;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin: 0 2px;
  padding: 0 6px;
  color: var(--green-dark);
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  vertical-align: text-top;
  background: var(--green-soft);
  border: 1px solid #c5ddcf;
  border-radius: 999px;
  user-select: none;
  -webkit-user-select: none;
}

.citation-marker {
  cursor: default;
}

.references {
  display: grid;
  gap: 7px;
  margin-top: 14px;
}

.reference {
  padding: 9px 11px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  background: #f0f1eb;
  border-left: 3px solid #8aab98;
  border-radius: 5px 9px 9px 5px;
}

.reference strong {
  color: var(--ink);
}

.typing {
  display: flex;
  gap: 5px;
  padding: 9px 0;
}

.typing span {
  width: 7px;
  height: 7px;
  background: #87a095;
  border-radius: 50%;
  animation: bounce 1.1s infinite;
}

.typing span:nth-child(2) {
  animation-delay: 130ms;
}

.typing span:nth-child(3) {
  animation-delay: 260ms;
}

.chat-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
  align-items: end;
  margin: 0 20px;
  padding: 8px;
  background: white;
  border: 1px solid #cbd2c9;
  border-radius: 15px;
  box-shadow: 0 7px 24px rgb(30 52 43 / 8%);
}

.chat-composer textarea {
  max-height: 160px;
  padding: 8px 9px;
  resize: none;
  border: 0;
  box-shadow: none;
}

.send-button {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 10px;
  place-items: center;
  color: white;
  background: var(--green);
  border: 0;
  border-radius: 11px;
  cursor: pointer;
}

.send-button:disabled {
  opacity: 0.55;
}

.composer-hint {
  margin: 8px 22px 16px;
  color: var(--muted);
  font-size: 9px;
  text-align: right;
}

.writer-workspace {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.writer-stop-bar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin: 14px clamp(20px, 5vw, 52px) 0;
  padding: 10px 12px 10px 14px;
  color: #704a14;
  font-size: 12px;
  font-weight: 700;
  background: rgb(255 242 215 / 96%);
  border: 1px solid #efd29a;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgb(74 52 18 / 10%);
  backdrop-filter: blur(8px);
}

.writer-stop-bar .button {
  min-height: 36px;
  padding-block: 7px;
}

.writer-form {
  display: grid;
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
  padding: 28px clamp(20px, 5vw, 52px) 32px;
}

.writer-form > label {
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.writer-intro {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  margin-bottom: 8px;
  padding: 16px;
  background: #f1f4ee;
  border: 1px solid #dfe4dc;
  border-radius: 14px;
}

.writer-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  color: white;
  font-family: var(--font-display);
  font-size: 24px;
  font-style: italic;
  background: var(--green);
  border-radius: 15px 15px 15px 5px;
}

.writer-intro h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 600;
}

.writer-intro p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.writer-submit {
  margin-top: 4px;
}

.writer-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 460px;
  padding: 50px 24px;
  text-align: center;
}

.writer-progress h3 {
  margin: 20px 0 6px;
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 600;
}

.writer-progress p {
  max-width: 420px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.progress-orbit {
  position: relative;
  width: 58px;
  height: 58px;
  border: 2px solid #c7d6cd;
  border-radius: 50%;
  animation: spin 1.2s linear infinite;
}

.progress-orbit span {
  position: absolute;
  top: -5px;
  left: 24px;
  width: 10px;
  height: 10px;
  background: var(--green);
  border-radius: 50%;
}

.writer-result {
  padding: 26px clamp(20px, 5vw, 52px) 42px;
}

.writer-result-heading {
  display: flex;
  gap: 18px;
  align-items: end;
  justify-content: space-between;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.writer-result-heading > div:first-child {
  min-width: 0;
}

.writer-result-heading h3 {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  line-height: 1.2;
}

.writer-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.writer-stream-status {
  margin: 18px 0 0;
  padding: 10px 13px;
  color: var(--green-dark);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.5;
  background: #eef8f1;
  border: 1px solid #c3ddcc;
  border-radius: 9px;
}

.writer-stream-status.error {
  color: #7c2d26;
  background: #fae8e5;
  border-color: #efc5bf;
}

.writer-notice {
  margin-top: 18px;
  padding: 11px 13px;
  color: #704a14;
  font-size: 11px;
  line-height: 1.5;
  background: #fff2d7;
  border: 1px solid #efd29a;
  border-radius: 9px;
}

.writer-output {
  padding: 24px 0 10px;
  font-size: 15px;
}

.writer-output.streaming {
  min-height: 220px;
  overflow-wrap: anywhere;
}

.writer-output.streaming::after {
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: -0.12em;
  content: "";
  background: var(--green);
  border-radius: 2px;
  animation: writer-caret 900ms steps(1) infinite;
}

@keyframes writer-caret {
  50% {
    opacity: 0.15;
  }
}

.writer-history {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px clamp(20px, 5vw, 52px) 24px;
  border-top: 1px solid var(--line);
}

.writer-history-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.writer-history-header strong {
  color: var(--ink);
  font-size: 13px;
}

.writer-history-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.writer-history-title {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.writer-history-date {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.writer-history-empty {
  margin: 0;
  padding: 14px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  background: #f4f5f0;
  border-radius: 10px;
}

.button-small {
  padding: 4px 10px;
  font-size: 11px;
}



.research-details {
  margin-top: 26px;
  padding: 14px 16px;
  background: #f0f2ed;
  border-radius: 12px;
}

.research-details summary {
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.research-details .answer-content {
  padding-top: 16px;
  font-size: 12px;
}

.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 25px 90px rgb(19 37 31 / 25%);
}

.preview-dialog {
  width: min(980px, calc(100vw - 32px));
  max-width: none;
}

.preview-shell {
  position: relative;
  padding: 28px;
}

.preview-heading {
  display: flex;
  gap: 18px;
  align-items: end;
  justify-content: space-between;
  padding: 0 44px 18px 0;
  border-bottom: 1px solid var(--line);
}

.preview-heading > div:first-child {
  min-width: 0;
}

.preview-heading h2 {
  margin: 4px 0 5px;
  overflow-wrap: anywhere;
  font-family: var(--font-display);
  font-size: 29px;
  font-weight: 600;
  line-height: 1.2;
}

.preview-heading p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.preview-loading {
  display: grid;
  min-height: 320px;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

.preview-content {
  max-height: min(68vh, 760px);
  margin: 20px 0 0;
  padding: 18px;
  overflow: auto;
  color: #26342f;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f0f2ed;
  border: 1px solid #dde2db;
  border-radius: 12px;
}

.preview-warning {
  margin: 10px 0 0;
  color: #8a5a19;
  font-size: 10px;
}

.dialog::backdrop {
  background: rgb(17 30 26 / 48%);
  backdrop-filter: blur(3px);
}

.dialog form {
  position: relative;
  display: grid;
  gap: 12px;
  padding: 30px;
}

.dialog h2 {
  margin: 0;
  overflow-wrap: anywhere;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  line-height: 1.2;
}

.dialog p:not(.eyebrow) {
  margin: -4px 0 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.dialog label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.dialog-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  font-size: 22px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.dialog-close:hover {
  background: #eceee7;
}

.dialog-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

.confirm-dialog form {
  padding-top: 34px;
}

.confirm-dialog.danger .confirm-mark,
.confirm-dialog.danger #confirm-action-button {
  background: var(--danger);
}

.confirm-dialog.danger #confirm-action-button {
  color: white;
  border-color: var(--danger);
  box-shadow: 0 8px 18px rgb(165 63 53 / 18%);
}

.confirm-mark {
  display: grid;
  width: 46px;
  height: 46px;
  margin-bottom: 4px;
  place-items: center;
  color: white;
  font-family: var(--font-display);
  font-size: 24px;
  background: var(--green);
  border-radius: 15px 15px 15px 5px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 11px;
  align-items: center;
  width: min(390px, calc(100vw - 48px));
  max-width: min(390px, calc(100vw - 48px));
  padding: 13px 15px;
  color: var(--ink);
  pointer-events: none;
  visibility: hidden;
  background: #fffef9;
  border: 1px solid #dce3dc;
  border-radius: 14px;
  box-shadow: 0 12px 36px rgb(17 32 27 / 25%);
  opacity: 0;
  transform: translateY(8px);
  transition: 180ms ease;
}

.toast-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: white;
  font-size: 12px;
  font-weight: 800;
  background: var(--green);
  border-radius: 10px;
}

.toast-copy,
.toast-copy strong,
.toast-copy span {
  display: block;
}

.toast-copy strong {
  margin-bottom: 2px;
  font-size: 12px;
}

.toast-copy span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.toast.show {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  border-color: #e8c4bf;
}

.toast.error .toast-icon {
  background: var(--danger);
}

.toast.info .toast-icon {
  color: var(--ink);
  background: var(--amber);
}

@keyframes bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-5px);
  }
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes upload-shimmer {
  to {
    background-position: -200% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .writer-output.streaming::after {
    animation: none;
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .workspace {
    padding: 26px 20px 30px;
  }

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

  .source-list {
    max-height: 420px;
  }

  .source-item {
    grid-template-columns: 18px 34px minmax(0, 1fr) minmax(130px, auto);
  }

  .chat-messages {
    min-height: 420px;
    max-height: 620px;
  }
}

@media (max-width: 900px) {
  .workspace-header,
  .writer-result-heading,
  .preview-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace-actions,
  .writer-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .workspace-actions .button,
  .writer-actions .button {
    flex: 1 1 160px;
  }
}

@media (max-width: 700px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: relative;
    height: auto;
    padding: 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    margin: 0 0 16px;
  }

  .sidebar-footer {
    margin-top: 16px;
    padding-top: 14px;
  }

  .sidebar-heading {
    margin-top: 18px;
  }

  .notebook-list {
    display: flex;
    padding-bottom: 4px;
    overflow-x: auto;
  }

  .notebook-item {
    flex: 0 0 190px;
  }

  .empty-state {
    min-height: calc(100vh - 138px);
  }

  .workspace-actions .button {
    flex: 1 1 170px;
    padding-inline: 11px;
    font-size: 11px;
  }

  .workspace-grid {
    min-height: auto;
  }

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

  .chat-messages {
    min-height: 380px;
    max-height: 560px;
  }

  .writer-actions .button {
    flex: 1;
  }

  .source-item {
    grid-template-columns: 18px 34px minmax(0, 1fr);
  }

  .source-actions {
    grid-column: 2 / -1;
    justify-content: flex-start;
  }

  .markdown-table {
    min-width: 380px;
  }
}
