:root {
  --bg: #f8fafc;
  --ink: #1f2933;
  --muted: #6b7280;
  --panel: #ffffff;
  --accent: #1f6f54;
  --accent-2: #fff6e5;
  --border: #e5e5e5;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Calibri", "Segoe UI", Arial, sans-serif;
  padding: 24px;
}

.topbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  width: 248px;
  position: fixed;
  left: 16px;
  top: 16px;
  bottom: 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #eef2f6;
  box-shadow: var(--shadow);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 84px;
}

.brand-text {
  display: grid;
  gap: 2px;
  min-height: 72px;
  align-content: center;
}

.brand-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.15;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--muted);
  min-height: 28px;
}

.brand-icon {
  width: 64px;
  height: 64px;
  object-fit: contain;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav a {
  display: block;
  text-decoration: none;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  padding: 8px 10px;
  box-shadow: var(--shadow);
}

.nav a:hover {
  color: var(--accent);
  border-color: #d9dde3;
}

.nav a.nav-disabled {
  opacity: 0.55;
  background: #f3f4f6;
}

.logout button {
  background: white;
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow);
}

.logout {
  display: flex;
  gap: 8px;
  margin-top: auto;
  flex-wrap: wrap;
  align-items: flex-start;
}

.user-chip {
  width: 100%;
  font-size: 11px;
  color: var(--muted);
}

.container {
  margin-left: 272px;
  width: calc(100% - 272px);
  max-width: none;
  padding: 0;
}

.hero {
  padding: 24px;
  background: linear-gradient(130deg, #fff9ea, #f4f7f1);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}

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

.stat {
  padding: 12px;
  background: #fbfaf6;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.stat .label {
  color: var(--muted);
  font-size: 14px;
}

.stat .meta {
  color: var(--muted);
  font-size: 14px;
  margin: 6px 0 10px 0;
}

.stat .value {
  font-size: 26px;
  font-weight: 700;
}

.search-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.search-form input[type="text"] {
  flex: 1;
  min-width: 260px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.search-form select,
.search-form button {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
}

.search-form button {
  background: var(--accent);
  color: white;
  border: none;
}

.search-status {
  align-self: center;
  color: var(--muted);
  font-size: 14px;
}

.search-header {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  margin-bottom: 8px;
}

.search-header h2 {
  margin: 0;
}

.help-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-weight: 700;
  line-height: 1;
}

.help-popup {
  position: absolute;
  top: 30px;
  left: 0;
  width: min(520px, 95vw);
  z-index: 30;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.08);
}

.help-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.help-line {
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 4px;
}

.list .item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.list .item:last-child {
  border-bottom: none;
}

.item .title {
  font-weight: 700;
  margin-bottom: 4px;
}

.item .meta {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 6px;
}

.item .snippet {
  color: #2c2c2c;
}

.answer-block {
  white-space: pre-wrap;
  line-height: 1.45;
}

.answer-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.answer-headline {
  font-weight: 700;
  margin-bottom: 8px;
}

@media (max-width: 980px) {
  body {
    padding: 16px;
  }

  .topbar {
    position: static;
    width: auto;
    left: auto;
    top: auto;
    bottom: auto;
    margin-bottom: 18px;
  }

  .brand-text {
    min-height: 0;
  }

  .nav {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .container {
    margin: 0 auto 48px auto;
    width: 100%;
    padding: 0;
  }
}

.answer-bullets {
  margin: 0 0 8px 18px;
  padding: 0;
}

.answer-bullets li {
  margin: 0 0 4px 0;
  line-height: 1.4;
}

.answer-details {
  color: var(--muted);
  font-size: 13px;
  display: grid;
  gap: 4px;
}

.details {
  width: 100%;
}

.details summary {
  cursor: pointer;
  list-style: none;
}

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

.detail-body {
  margin-top: 10px;
  padding: 12px;
  background: #faf8f3;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.collapsible-panel summary h3 {
  margin: 0;
}

.body {
  white-space: pre-wrap;
  font-family: "Calibri", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  color: #1f1f1f;
}

.thread-block {
  margin-top: 16px;
}

.thread-list {
  border-top: 1px solid var(--border);
  margin-top: 6px;
}

.thread-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.file-icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  border-radius: 4px;
  vertical-align: -3px;
  background: #cfd8dc;
}

.file-folder { background: #f3d49b; }
.file-pdf { background: #e07a5f; }
.file-image { background: #81b29a; }
.file-sheet { background: #6aa84f; }
.file-doc { background: #5b8def; }
.file-slide { background: #f2c14e; }
.file-generic { background: #9e9e9e; }

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

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

.table a {
  color: var(--ink);
  text-decoration: none;
}

.table a:hover {
  color: var(--accent);
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: #f4f4f4;
}

.status-proposed,
.status-under_review { background: #eef6ff; }
.status-approved { background: #e8f7e9; }
.status-in_progress { background: #fff7e6; }
.status-blocked,
.status-awaiting_dataset { background: #ffecec; }
.status-completed { background: #e8f7e9; }
.status-rejected,
.status-archived { background: #f1f1f1; }

.inline {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.inline input {
  width: 90px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.inline button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 10px;
  border-radius: 6px;
}

.button-link {
  display: inline-block;
  text-decoration: none;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--ink);
}

.chat-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  gap: 16px;
}

.chat-sidebar {
  margin-bottom: 0;
}

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

.chat-sidebar-head h2 {
  margin: 0;
}

.chat-session-list {
  display: grid;
  gap: 8px;
}

.chat-session-item {
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.chat-session-item.active {
  border-color: var(--accent);
  background: #f8fbf8;
}

.chat-session-title {
  font-weight: 700;
  margin-bottom: 4px;
}

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

.chat-main {
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
}

.chat-messages {
  display: grid;
  gap: 10px;
  align-content: start;
  max-height: 68vh;
  min-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

.chat-msg {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}

.chat-msg.user {
  background: #f6f7fb;
}

.chat-msg.assistant {
  background: #faf8f3;
}

.chat-msg-role {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.chat-msg-body {
  white-space: pre-wrap;
}

.chat-msg-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.chat-form {
  margin-top: 12px;
}

.chat-codex-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

body.chat-page {
  overflow: auto;
}

body.chat-page .container {
  max-width: 1500px;
  margin: 10px auto 12px auto;
  height: auto;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

body.chat-page .hero {
  margin-bottom: 12px;
  padding: 14px 18px;
}

body.chat-page .chat-layout {
  height: auto;
}

body.chat-page .chat-sidebar {
  overflow: auto;
}

body.chat-page .chat-main {
  min-height: 0;
}

body.chat-page .chat-form {
  position: static;
  bottom: auto;
  z-index: auto;
  background: transparent;
  padding-top: 0;
}

.tag-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.empty {
  color: var(--muted);
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  min-width: 320px;
}

.login-card .brand {
  font-size: 20px;
  margin-bottom: 12px;
}

.login-card label {
  display: block;
  margin-bottom: 12px;
}

.login-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.login-card button {
  width: 100%;
  padding: 10px 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
}

.error {
  color: #a12222;
  margin-bottom: 12px;
}

@media (max-width: 560px) {
  body.chat-page {
    overflow: auto;
  }

  body.chat-page .container {
    max-width: 1100px;
    height: auto;
    overflow: visible;
    margin: 24px auto 64px auto;
  }

  body.chat-page .chat-layout {
    height: auto;
  }

  body.chat-page .chat-form {
    position: static;
    bottom: auto;
    padding-top: 0;
  }

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

  .chat-layout {
    grid-template-columns: 1fr;
  }

  .chat-main {
    min-height: 55vh;
  }
}
