:root {
  --bg: #f5f4ef;
  --card: #ffffff;
  --border: #e7e5dd;
  --text: #171614;
  --text-muted: #6b6862;
  --accent: #b8862f;
  --accent-soft: #f2e6cf;
  --black: #16150f;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 18, 10, 0.04), 0 8px 24px rgba(20, 18, 10, 0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.app {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding: 0 6px;
}

.brand-accent { color: var(--accent); }

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  background: var(--black);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.new-chat-btn:hover { opacity: 0.85; }
.new-chat-btn svg { width: 16px; height: 16px; }

.nav-section { display: flex; flex-direction: column; gap: 2px; }

.nav-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 8px 10px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 10px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.nav-item:hover { background: rgba(0,0,0,0.04); }
.nav-item.active { background: #ece9df; font-weight: 600; }
.nav-item svg { width: 17px; height: 17px; color: var(--text-muted); }
.nav-item.active svg { color: var(--text); }

.sidebar-footer { margin-top: auto; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; }
.user-plan { font-size: 11.5px; color: var(--text-muted); }
.settings-icon { width: 16px; height: 16px; color: var(--text-muted); }

/* Main */
.main {
  padding: 36px 44px;
  max-width: 1080px;
}

.view.hidden { display: none; }

.header-row { display: flex; justify-content: space-between; align-items: center; }
.header-date { font-size: 13px; color: var(--text-muted); font-weight: 500; }

.greeting {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 6px 0 26px;
}

.page-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 20px;
}

/* Ask bar */
.ask-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 10px 8px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.ask-bar svg { color: var(--text-muted); }
.ask-bar input {
  flex: 1;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 15px;
  background: transparent;
  padding: 8px 0;
}
.ask-bar button {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: var(--black);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.ask-bar button:hover { opacity: 0.85; }
.ask-bar button svg { width: 17px; height: 17px; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
}

.panel-card { margin-bottom: 22px; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15.5px;
  font-weight: 600;
}
.panel-title svg { width: 17px; height: 17px; color: var(--text-muted); }

.link-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 13px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
}
.link-btn:hover { background: rgba(0,0,0,0.03); }
.link-btn svg { width: 14px; height: 14px; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 36px 10px;
  color: var(--text-muted);
  text-align: center;
}
.empty-state svg { color: var(--border); }
.empty-state p { margin: 0; font-size: 14px; }
.empty-state.small { padding: 20px 10px; }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.btn-secondary:hover { background: rgba(0,0,0,0.03); }

/* Quick actions */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}

.quick-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 26px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.quick-card:hover { border-color: var(--accent); }

.quick-icon {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}
.quick-icon svg { color: var(--accent); }

.bottom-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.doc-row-mini {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  color: inherit;
  text-decoration: none;
}
.doc-row-mini:last-child { border-bottom: none; }
.doc-row-mini .muted { font-size: 12px !important; }
.doc-row-mini.clickable { cursor: pointer; border-radius: var(--radius-sm); margin: 0 -8px; padding: 10px 8px; }
.doc-row-mini.clickable:hover { background: rgba(0,0,0,0.03); }

.filename-link {
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.filename-link:hover { color: var(--accent); text-decoration: underline; }

/* Documents view */
.upload-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  border-style: dashed;
  border-width: 2px;
  padding: 40px 20px;
  cursor: pointer;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.upload-card:hover { border-color: var(--accent); }
.upload-card svg { color: var(--text-muted); margin-bottom: 6px; }
.upload-card p { margin: 0; font-size: 14px; }
.upload-card strong { color: var(--text); }
.upload-card.dragover { border-color: var(--accent); background: var(--accent-soft); }
.muted { color: var(--text-muted); font-size: 12.5px !important; }

.meta-fields {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}
.meta-fields input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13.5px;
  background: var(--card);
}
.meta-fields input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.status-line {
  min-height: 18px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 18px;
}
.status-line.error { color: #b3413a; }
.status-line.success { color: #3a7d4f; }

.doc-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.doc-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.doc-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
}
.doc-table tr:last-child td { border-bottom: none; }
.row-delete {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 6px;
}
.row-delete:hover { color: #b3413a; background: rgba(179,65,58,0.08); }
.row-delete svg { width: 16px; height: 16px; }

/* Chat view */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.scope-select {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 14px;
  font-family: inherit;
  font-size: 13.5px;
  background: var(--card);
  color: var(--text);
}

.chat-thread {
  min-height: 360px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 18px;
}

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }

.bubble {
  max-width: 640px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 14.5px;
  line-height: 1.55;
}
.msg.user .bubble {
  background: var(--black);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant .bubble {
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-bottom-left-radius: 4px;
}

.sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.source-chip {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: default;
}

.thinking { color: var(--text-muted); font-style: italic; }

.chat-ask-bar { margin-bottom: 0; }

/* Responsive */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 24px; }
  .quick-actions { grid-template-columns: 1fr; }
  .bottom-row { grid-template-columns: 1fr; }
  .meta-fields { grid-template-columns: 1fr; }
}
