:root {
  --paper: #f5f1e8;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #172127;
  --muted: #687277;
  --line: #ded9cf;
  --accent: #e86438;
  --accent-dark: #c84820;
  --accent-soft: #fce6dc;
  --green: #3d7655;
  --green-soft: #ddeadf;
  --danger: #a83d35;
  --shadow: 0 18px 50px rgba(33, 38, 39, 0.08);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 11px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, textarea, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }

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

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 28px 20px 22px;
  background: #1b272d;
  color: #f9f5ed;
  border-right: 1px solid rgba(255,255,255,.07);
}

.brand { display: flex; align-items: center; gap: 12px; margin: 0 6px 32px; }
.brand-mark, .welcome-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--accent);
  color: white;
  font-family: "Segoe UI Variable", "Segoe UI", sans-serif;
  font-weight: 800;
  font-size: 20px;
  transform: rotate(-4deg);
  box-shadow: 0 8px 18px rgba(232,100,56,.25);
}
.brand strong { display: block; font-family: "Segoe UI Variable", "Segoe UI", sans-serif; font-size: 16px; }
.brand small { display: block; margin-top: 2px; color: #9fa9ac; font-size: 12px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 700;
  transition: transform .18s ease, background .18s ease, border-color .18s ease;
}
.button:not(:disabled):hover { transform: translateY(-1px); }
.button-wide { width: 100%; }
.button-primary { background: var(--accent); color: white; }
.button-primary:not(:disabled):hover { background: var(--accent-dark); }
.button-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.button-danger-ghost { background: transparent; border-color: #e9c8c4; color: var(--danger); }

.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 30px 7px 12px;
  color: #9fa9ac;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.icon-button {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 9px;
  color: #c8cecf;
  background: rgba(255,255,255,.06);
  font-size: 18px;
}

.notebook-list { display: flex; flex: 1; flex-direction: column; gap: 7px; overflow-y: auto; }
.notebook-item {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 13px;
  color: #dbe0df;
  background: transparent;
  text-align: left;
}
.notebook-item:hover { background: rgba(255,255,255,.055); }
.notebook-item.active { background: #2b3a40; border-color: rgba(255,255,255,.08); color: white; }
.notebook-avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #34464d;
  color: #f0b397;
  font-family: "Segoe UI Variable", "Segoe UI", sans-serif;
  font-weight: 800;
}
.notebook-item.active .notebook-avatar { background: var(--accent); color: white; }
.notebook-copy { min-width: 0; }
.notebook-name { display: block; overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.notebook-count { color: #8e9a9d; font-size: 11px; }
.notebook-arrow { color: #758285; }

.skeleton-row { height: 57px; border-radius: 13px; background: linear-gradient(90deg, #25343a, #2d3c42, #25343a); background-size: 220% 100%; animation: shimmer 1.4s infinite; }
.skeleton-row.short { width: 78%; }
@keyframes shimmer { to { background-position: -220% 0; } }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
  padding: 15px 10px 0;
  border-top: 1px solid rgba(255,255,255,.08);
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #d69a55; box-shadow: 0 0 0 4px rgba(214,154,85,.12); }
.status-dot.online { background: #73bd89; box-shadow: 0 0 0 4px rgba(115,189,137,.12); }
.status-dot.offline { background: #d16d64; box-shadow: 0 0 0 4px rgba(209,109,100,.12); }
.sidebar-footer strong { display: block; font-size: 12px; }
.sidebar-footer small { color: #859195; font-size: 11px; }

.workspace { padding: 34px 36px; min-width: 0; overflow-y: auto; }
.workspace-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding-bottom: 28px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
h1, h2, h3 { font-family: "Segoe UI Variable", "Segoe UI", sans-serif; }
h1 { margin: 0; max-width: 670px; font-size: clamp(28px, 3vw, 42px); line-height: 1.07; letter-spacing: -.04em; }
h2 { margin: 0; font-size: 22px; letter-spacing: -.025em; }
h3 { letter-spacing: -.015em; }
.notebook-meta { margin: 10px 0 0; color: var(--muted); }
.header-actions { display: flex; gap: 9px; }

.source-section { padding-top: 30px; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.source-heading-actions { display: flex; align-items: center; gap: 9px; }
.icon-button.light { color: var(--ink); background: var(--surface); border: 1px solid var(--line); }
.source-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.empty-state {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 330px;
  padding: 44px;
  border: 1px dashed #cfc8bb;
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,.38);
  text-align: center;
}
.empty-state h3 { margin: 15px 0 5px; }
.empty-state p { max-width: 310px; margin: 0; color: var(--muted); }
.empty-icon { display: grid; place-items: center; width: 60px; height: 60px; border-radius: 20px; background: var(--green-soft); color: var(--green); font-size: 30px; }

.source-card {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(31,37,39,.035);
}
.source-card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.source-type { display: inline-flex; align-items: center; gap: 7px; color: var(--green); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.source-type::before { content: ""; width: 8px; height: 8px; border-radius: 3px; background: var(--green); }
.source-card h3 { overflow: hidden; margin: 18px 0 8px; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.source-card p { margin: 0; color: var(--muted); font-size: 12px; }
.source-status { padding: 5px 8px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 10px; font-weight: 800; }
.source-status.processing { background: #f7ebcf; color: #8a6428; }
.source-status.error { background: #f7deda; color: var(--danger); }
.source-card-actions { display: flex; align-items: center; gap: 5px; }
.source-action {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: white;
  color: var(--muted);
  font-size: 14px;
}
.source-action:hover { color: var(--ink); border-color: #bfb7aa; }
.source-action.danger:hover { color: var(--danger); border-color: #deb6b1; }
.source-url { overflow: hidden; margin-top: 7px !important; text-overflow: ellipsis; white-space: nowrap; }
.source-loading { grid-column: 1 / -1; padding: 24px; color: var(--muted); text-align: center; }

.chat-panel {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 30px 24px 22px;
  border-left: 1px solid var(--line);
  background: var(--surface-strong);
}
.chat-header { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 22px; border-bottom: 1px solid var(--line); }
.spark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font-size: 19px; }
.chat-feed { flex: 1; overflow-y: auto; padding: 22px 4px; }
.welcome-card { padding: 24px; border-radius: 20px; background: #f3efe6; }
.welcome-card h3 { margin: 20px 0 8px; font-size: 19px; line-height: 1.3; }
.welcome-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.welcome-mark { width: 34px; height: 34px; border-radius: 10px; font-size: 15px; }

.message { margin-bottom: 18px; }
.message-user { margin-left: 46px; padding: 13px 15px; border-radius: 16px 16px 4px 16px; background: #25343a; color: white; font-size: 13px; line-height: 1.5; }
.message-answer { padding: 18px; border: 1px solid var(--line); border-radius: 4px 18px 18px 18px; background: var(--surface); font-size: 13px; line-height: 1.65; }
.message-answer p { margin: 0 0 10px; }
.citation-summary { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--green); font-size: 11px; font-weight: 700; }
.typing { display: flex; gap: 5px; padding: 16px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite alternate; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { to { opacity: .25; transform: translateY(-3px); } }

.ask-form { padding: 12px; border: 1px solid #cbc5b9; border-radius: 18px; background: #fbf9f4; box-shadow: var(--shadow); }
.ask-form textarea { width: 100%; min-height: 68px; resize: none; border: 0; outline: 0; color: var(--ink); background: transparent; line-height: 1.5; }
.ask-form textarea::placeholder { color: #91999b; }
.ask-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ask-actions span { color: var(--muted); font-size: 10px; }
.send-button { width: 38px; height: 38px; border: 0; border-radius: 12px; background: var(--accent); color: white; font-size: 20px; font-weight: 800; }

.toast-region { position: fixed; right: 24px; bottom: 24px; z-index: 50; display: grid; gap: 10px; }
.toast { max-width: 360px; padding: 13px 16px; border-radius: 13px; background: #1e2a30; color: white; box-shadow: var(--shadow); font-size: 13px; animation: toast-in .22s ease; }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.modal {
  width: min(640px, calc(100vw - 28px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: transparent;
  overflow: visible;
}
.modal::backdrop { background: rgba(15, 22, 25, .58); backdrop-filter: blur(5px); }
.modal-card { max-height: calc(100vh - 40px); padding: 28px; border-radius: 24px; background: var(--surface-strong); box-shadow: 0 30px 90px rgba(15,22,25,.28); overflow-y: auto; }
.modal-card.compact { width: min(460px, 100%); margin: auto; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.modal-close { width: 36px; height: 36px; border: 0; border-radius: 11px; background: #f0ede6; color: var(--ink); font-size: 22px; }
.field-label { display: block; margin: 16px 0 7px; font-size: 12px; font-weight: 800; }
.field-label span { color: var(--muted); font-weight: 500; }
.text-input { width: 100%; min-height: 45px; padding: 11px 13px; border: 1px solid #cfc9be; border-radius: 11px; outline: none; color: var(--ink); background: #fffefb; }
.text-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.text-input { resize: vertical; line-height: 1.5; }
.text-input.large { min-height: 180px; }
.field-help { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 26px; }

.source-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; padding: 5px; border-radius: 13px; background: #efebe3; }
.source-tab { min-height: 39px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; font-size: 12px; font-weight: 800; }
.source-tab.active { color: var(--ink); background: white; box-shadow: 0 3px 10px rgba(28,35,38,.08); }
.source-panel { display: none; padding-top: 7px; }
.source-panel.active { display: block; }
.drop-zone { display: grid; place-items: center; min-height: 205px; margin-top: 16px; padding: 24px; border: 1px dashed #bdb5a8; border-radius: 17px; background: #faf7f0; text-align: center; cursor: pointer; }
.drop-zone:hover { border-color: var(--accent); background: #fff9f4; }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop-zone small { max-width: 390px; margin-top: 5px; color: var(--muted); }
.drop-icon { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: 12px; border-radius: 15px; background: var(--accent-soft); color: var(--accent); font-size: 24px; font-weight: 800; }
.file-name { margin-top: 15px; padding: 6px 10px; border-radius: 999px; color: var(--green); background: var(--green-soft); font-size: 11px; font-weight: 700; }
.button-danger { color: white; background: var(--danger); }
.danger-card { text-align: center; }
.danger-card p { margin: 10px auto 0; max-width: 350px; color: var(--muted); line-height: 1.5; }
.danger-symbol { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 18px; border-radius: 18px; color: var(--danger); background: #f8dfdb; font-size: 25px; font-weight: 800; }
.danger-card .modal-actions { justify-content: center; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 250px 1fr; }
  .chat-panel { position: fixed; right: 18px; bottom: 18px; top: auto; z-index: 20; width: min(410px, calc(100vw - 36px)); height: 70vh; border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 24px 70px rgba(26,34,38,.2); }
  .workspace { padding-right: 42px; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { min-height: auto; padding: 18px; }
  .brand { margin-bottom: 18px; }
  .notebook-list { max-height: 220px; margin-top: 4px; }
  .sidebar-footer { display: none; }
  .workspace { padding: 24px 18px 390px; }
  .workspace-header, .section-heading { align-items: stretch; flex-direction: column; }
  .header-actions { width: 100%; }
  .header-actions .button { flex: 1; }
  .source-grid { grid-template-columns: 1fr; }
  .chat-panel { right: 10px; bottom: 10px; width: calc(100vw - 20px); height: 360px; padding: 18px; }
  .chat-header { padding-bottom: 12px; }
  .chat-header h2 { font-size: 18px; }
}
