/* ── Full-page layout ──────────────────────────────────────────────────────
   body   flex column 100vh
     header.topbar        — 64px (from style.css)
     .chat-layout         — flex:1, flex-row
       aside.chat-sidebar — fixed 240px, scrollable
       .chat-main         — flex:1, CSS GRID (2 rows)
         .chat-messages   — 1fr  → overflow-y:auto (GUARANTEED by grid)
         .chat-input-area — auto → fixed height
────────────────────────────────────────────────────────────────────────── */

body {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* icon button for topbar sidebar toggle */
.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: flex; align-items: center;
  transition: all 100ms;
}
.icon-btn:hover { color: var(--accent); background: var(--accent-bg); }

/* ── Outer layout: sidebar + main ──────────────────────────────────────── */
.chat-layout {
  flex: 1;
  min-height: 0;          /* must have this so flex child can shrink */
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.chat-sidebar {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width 200ms ease, opacity 200ms ease;
}
.chat-sidebar.collapsed {
  width: 0;
  opacity: 0;
  pointer-events: none;
}

.sidebar-head {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.new-chat-btn {
  width: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--bg);
  color: var(--accent);
  font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all 120ms;
}
.new-chat-btn:hover { background: var(--accent-bg); border-color: var(--accent); }

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.history-empty {
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
  padding: 16px 8px;
  margin: 0;
}
.history-group-label {
  font-size: 10px; font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 10px 8px 4px;
}
.history-item {
  display: block; width: 100%;
  padding: 7px 10px;
  border: none; border-radius: var(--r-md);
  background: none; text-align: left;
  font-size: 13px; color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: all 100ms;
}
.history-item:hover { background: var(--accent-bg); color: var(--accent); }
.history-item.active { background: var(--accent-bg); color: var(--accent); font-weight: 500; }

/* ── Main chat area (CSS Grid → guaranteed 1fr for messages) ───────────── */
.chat-main {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto;  /* messages fills space; input is auto height */
  overflow: hidden;
}

/* ── Scrollable messages ───────────────────────────────────────────────── */
.chat-messages {
  overflow-y: auto;
  padding: 24px 32px 12px;
}

/* ── Empty state ───────────────────────────────────────────────────────── */
.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 80px 24px 40px;
  text-align: center;
  color: var(--text-muted);
}
.chat-empty p { font-size: 16px; margin: 0; }
.chat-empty.hidden { display: none; }

.example-chips {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  max-width: 560px;
}
.example-chip {
  padding: 8px 18px;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  background: var(--bg);
  font-size: 13px; color: var(--text-muted);
  cursor: pointer; box-shadow: var(--shadow-sm);
  transition: all 120ms;
}
.example-chip:hover {
  background: var(--accent-bg); border-color: var(--accent); color: var(--accent);
}

/* ── Blocks ────────────────────────────────────────────────────────────── */
#blocks { display: flex; flex-direction: column; gap: 16px; padding-bottom: 16px; }

.block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.block-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
}
.block-title {
  flex: 1; font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.block-query {
  font-size: 11px; color: var(--text-faint);
  max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.block-del {
  background: none; border: none; color: var(--text-faint);
  padding: 2px 6px; border-radius: var(--r-sm); cursor: pointer; font-size: 14px;
  transition: all 100ms;
}
.block-del:hover { color: var(--red); background: var(--red-bg); }
.block-body { padding: 16px; }

/* ── Loading block ─────────────────────────────────────────────────────── */
.block-loading {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 16px; color: var(--text-muted); font-size: 14px;
}
.loading-spinner {
  width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Block content types ───────────────────────────────────────────────── */
.block-metric { text-align: center; padding: 28px; }
.block-metric .val { font-size: 52px; font-weight: 700; color: var(--accent); line-height: 1; }
.block-metric .lbl { font-size: 14px; color: var(--text-muted); margin-top: 10px; }

.block-text { font-size: 14px; line-height: 1.7; }
.block-text h2, .block-text h3 { margin: 12px 0 4px; font-weight: 600; }
.block-text ul { margin: 8px 0; padding-left: 20px; }
.block-text strong { font-weight: 600; }

.block-table-wrap { overflow-x: auto; max-height: 380px; }
.block-table-wrap table { width: 100%; border-collapse: collapse; font-size: 13px; }
.block-table-wrap thead { position: sticky; top: 0; background: var(--bg-subtle); box-shadow: 0 1px 0 var(--border); }
.block-table-wrap th {
  padding: 9px 12px;
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em; text-align: left;
}
.block-table-wrap td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.block-table-wrap tbody tr:last-child td { border-bottom: none; }
.block-table-wrap tbody tr:hover { background: var(--accent-bg); cursor: pointer; }
.block-table-meta { font-size: 11px; color: var(--text-faint); text-align: right; padding-top: 6px; }

.block-chart-wrap { position: relative; height: 280px; }
.block-map { height: 300px; border-radius: var(--r-md); overflow: hidden; }
.block-contact { display: flex; flex-direction: column; gap: 14px; }

/* ── Follow-ups ────────────────────────────────────────────────────────── */
.followup-row {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0 8px;
}
.followup-chip {
  padding: 6px 14px; border-radius: var(--r-xl);
  border: 1px solid var(--border); background: var(--bg);
  font-size: 12px; color: var(--text-muted); cursor: pointer; transition: all 120ms;
}
.followup-chip:hover { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }

/* ── Input area ────────────────────────────────────────────────────────── */
.chat-input-area {
  padding: 12px 32px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  padding: 10px 10px 10px 18px;
  background: var(--bg);
  box-shadow: var(--shadow-sm);
  transition: border-color 150ms, box-shadow 150ms;
}
.chat-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm), 0 0 0 3px rgba(26,115,232,.1);
}
.chat-textarea {
  flex: 1;
  border: none; outline: none; resize: none;
  font-size: 15px; font-family: inherit;
  background: transparent; color: var(--text);
  max-height: 160px; line-height: 1.5; padding: 2px 0;
}
.chat-textarea::placeholder { color: var(--text-faint); }
.chat-send-btn {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); color: #fff; border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; cursor: pointer; transition: background 120ms;
}
.chat-send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.chat-send-btn:disabled { background: var(--border); cursor: not-allowed; }
.chat-hint {
  font-size: 11px; color: var(--text-faint); text-align: center; margin: 6px 0 0;
}

/* ── Clarification block ─────────────────────────────────────────────────── */
.clarification-block {
  background: var(--bg);
  border: 1px solid #c2d7fb;
  border-left: 4px solid var(--accent);
  border-radius: var(--r-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.clarification-q {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 16px;
  line-height: 1.5;
}
.clarification-icon {
  color: var(--accent);
  font-size: 20px;
  flex-shrink: 0;
  margin-top: 1px;
}

/* Suggested option chips */
.clarification-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.clarification-option {
  padding: 8px 18px;
  border: 1.5px solid var(--accent);
  border-radius: var(--r-xl);
  background: var(--bg);
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 120ms;
  line-height: 1;
}
.clarification-option:hover {
  background: var(--accent-bg);
}
.clarification-option.selected {
  background: var(--accent);
  color: #fff;
}

/* Manual input row */
.clarification-custom { }
.clarification-or {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.clarification-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.clarification-input {
  flex: 1;
  height: 38px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 150ms;
}
.clarification-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(26,115,232,.1);
}
