@import url('https://fonts.googleapis.com/css2?family=Sora:wght@300;400;500;600;700;800&family=Instrument+Serif:ital@0;1&display=swap');

/* ── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg:           #f5f3ef;
  --surface:      #ffffff;
  --surface-2:    #faf9f7;
  --surface-3:    #f0ede8;
  --border:       rgba(30, 20, 10, 0.08);
  --border-mid:   rgba(30, 20, 10, 0.13);
  --ink:          #1a1208;
  --ink-2:        #3d3120;
  --ink-3:        #7a6a55;
  --ink-4:        #b8a898;

  --gold:         #c9963a;
  --gold-2:       #e8b45a;
  --gold-light:   #fdf6e8;
  --gold-mid:     #f3dca8;

  --blue:         #2563eb;
  --blue-2:       #3b75f5;
  --blue-light:   #eff4ff;
  --blue-mid:     #bfcffe;

  --green:        #16a34a;
  --green-light:  #f0fdf4;
  --green-mid:    #86efac;

  --radius-sm:    6px;
  --radius-md:    12px;
  --radius-lg:    20px;
  --radius-xl:    28px;
  --radius-full:  9999px;

  --shadow-xs:    0 1px 2px rgba(26,18,8,0.05);
  --shadow-sm:    0 2px 8px rgba(26,18,8,0.07), 0 1px 3px rgba(26,18,8,0.05);
  --shadow-md:    0 8px 24px rgba(26,18,8,0.09), 0 3px 8px rgba(26,18,8,0.06);
  --shadow-lg:    0 20px 60px rgba(26,18,8,0.11), 0 8px 20px rgba(26,18,8,0.07);
  --shadow-glow:  0 0 0 4px rgba(37,99,235,0.1);
  --shadow-gold:  0 4px 20px rgba(201,150,58,0.25);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; height: 100%; }

body {
  font-family: 'Sora', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-image:
    radial-gradient(ellipse 70% 50% at 15% 0%, rgba(201,150,58,0.08) 0%, transparent 55%),
    radial-gradient(ellipse 50% 40% at 90% 100%, rgba(37,99,235,0.05) 0%, transparent 50%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Cpath d='M 80 0 L 0 0 0 80' fill='none' stroke='%231a120808' stroke-width='0.5'/%3E%3C/svg%3E");
}

button, textarea, input { font: inherit; }
button { cursor: pointer; }

/* ── App Shell ─────────────────────────────────────────────────────────────── */

.shell {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 100vh;
}

/* ── Top Bar ───────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0 20px;
  flex-shrink: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-logo {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  /* background: linear-gradient(135deg, #1a1208 0%, #3d3120 100%); */
  display: grid;
  place-items: center;
  font-family: 'Instrument Serif', serif;
  font-size: 1.05rem;
  color: var(--gold-2);
  letter-spacing: 0.02em;
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.topbar-logo::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(232,180,90,0.15) 0%, transparent 60%);
}

.topbar-name {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.topbar-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.topbar-sub {
  font-size: 0.72rem;
  color: var(--ink-3);
  font-weight: 400;
  letter-spacing: 0.01em;
}

.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: var(--green-light);
  border: 1px solid var(--green-mid);
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--green);
  letter-spacing: 0.02em;
}

.topbar-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: blink 2.5s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 2px rgba(22,163,74,0.25); }
  50% { opacity: 0.6; box-shadow: 0 0 0 4px rgba(22,163,74,0.1); }
}

/* ── Chat Container ────────────────────────────────────────────────────────── */

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-mid);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  min-height: 0;
  /* keep it tall enough to be a real chat window */
  min-height: calc(100vh - 180px);
  max-height: calc(100vh - 140px);
}

/* ── Messages Area ─────────────────────────────────────────────────────────── */

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb {
  background: var(--border-mid);
  border-radius: 4px;
}

/* ── Message Rows ──────────────────────────────────────────────────────────── */

.message {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  animation: msgIn 240ms cubic-bezier(0.22, 1, 0.36, 1) both;
  margin-bottom: 10px;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user {
  flex-direction: row-reverse;
}

/* ── Avatar ────────────────────────────────────────────────────────────────── */

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: 0.05em;
}

.message.assistant .avatar {
  /* background: linear-gradient(135deg, #1a1208, #3d3120); */
  color: var(--gold-2);
  box-shadow: var(--shadow-sm);
  font-family: 'Instrument Serif', serif;
  font-size: 0.8rem;
}

.message.user .avatar {
  background: linear-gradient(135deg, var(--blue), var(--blue-2));
  color: white;
  box-shadow: 0 3px 10px rgba(37,99,235,0.25);
}

/* ── Bubbles ───────────────────────────────────────────────────────────────── */

.bubble {
  max-width: min(560px, 75%);
  padding: 13px 17px;
  border-radius: var(--radius-lg);
  line-height: 1.65;
  font-size: 0.875rem;
  font-weight: 400;
  word-break: break-word;
}

.message.assistant .bubble {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
  border-bottom-left-radius: 5px;
  box-shadow: var(--shadow-xs);
}

.message.user .bubble {
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-2) 100%);
  color: white;
  border-bottom-right-radius: 5px;
  box-shadow: 0 4px 16px rgba(37,99,235,0.25);
}

/* ── Markdown ──────────────────────────────────────────────────────────────── */

.markdown-body p { margin: 0 0 7px; }
.markdown-body p:last-child { margin-bottom: 0; }
.markdown-body ul, .markdown-body ol { margin: 0 0 7px; padding-left: 18px; }
.markdown-body ul:last-child, .markdown-body ol:last-child { margin-bottom: 0; }
.markdown-body li + li { margin-top: 3px; }
.markdown-body strong { font-weight: 700; }
.markdown-body em { font-style: italic; }

.markdown-body code {
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.82em;
  background: rgba(37,99,235,0.07);
  color: var(--blue);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.message.user .bubble .markdown-body code {
  background: rgba(255,255,255,0.2);
  color: white;
}

.markdown-body pre {
  overflow-x: auto;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: #e8dcc8;
  font-size: 0.8em;
  margin-bottom: 7px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.markdown-body pre code {
  background: none;
  color: inherit;
  padding: 0;
}

.chart-preview {
  display: block;
  width: min(100%, 400px);
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
}

.typing .bubble {
  color: var(--ink-3);
  font-style: italic;
  font-size: 0.82rem;
}

/* ── Date Separator ────────────────────────────────────────────────────────── */

.date-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 14px;
  color: var(--ink-4);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.date-sep::before,
.date-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Quick Prompts Bar ─────────────────────────────────────────────────────── */

.quick-prompts {
  padding: 12px 28px 0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  background: linear-gradient(to bottom, var(--surface-2), var(--surface));
}

.quick-prompts-label {
  width: 100%;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-4);
  margin-bottom: 4px;
}

[data-prompt] {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 13px;
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 0.76rem;
  font-weight: 500;
  transition: all 160ms ease;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  flex-shrink: 0;
}

[data-prompt]:hover {
  border-color: var(--gold);
  background: var(--gold-light);
  color: var(--gold);
  box-shadow: var(--shadow-gold);
  transform: translateY(-1px);
}

[data-prompt]::before {
  content: '✦';
  font-size: 0.6rem;
  opacity: 0.5;
  transition: opacity 160ms ease;
}

[data-prompt]:hover::before {
  opacity: 1;
}

/* ── Column Selector Panel ─────────────────────────────────────────────────── */

.column-selector-panel {
  display: none;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  border-top: 1px solid var(--border);
  background: linear-gradient(to bottom, var(--gold-light), var(--surface-2));
  padding: 0 28px;
  transition: max-height 300ms cubic-bezier(0.4, 0, 0.2, 1), padding 300ms ease;
  max-height: 0;
}

.column-selector-panel.is-open {
  display: flex;
  max-height: 260px;
  padding: 16px 28px;
  animation: slideDown 260ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.column-selector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.column-selector-title {
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.column-selector-title::before {
  content: '';
  display: block;
  width: 16px;
  height: 2px;
  background: var(--gold);
  border-radius: 2px;
}

.column-selector-actions { display: flex; gap: 6px; }

.col-action-btn {
  height: 26px;
  padding: 0 11px;
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 140ms ease;
}

.col-action-btn:hover {
  background: var(--gold-light);
  border-color: var(--gold-mid);
  color: var(--gold);
}

.column-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow-y: auto;
  flex: 1;
  padding-right: 2px;
  padding-bottom: 2px;
}

.column-checkboxes::-webkit-scrollbar { width: 3px; }
.column-checkboxes::-webkit-scrollbar-track { background: transparent; }
.column-checkboxes::-webkit-scrollbar-thumb {
  background: var(--gold-mid);
  border-radius: 4px;
}

.col-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 10px 0 7px;
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: all 140ms ease;
  white-space: nowrap;
}

.col-chip input[type="checkbox"] { display: none; }

.col-chip:hover {
  border-color: var(--gold);
  background: var(--gold-light);
  color: var(--gold);
}

.col-chip.checked {
  border-color: var(--gold);
  background: var(--gold-light);
  color: var(--gold);
  font-weight: 600;
}

.col-chip.locked {
  border-color: var(--green-mid);
  background: var(--green-light);
  color: var(--green);
  font-weight: 700;
  cursor: default;
}

.chip-check {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  display: grid;
  place-items: center;
  font-size: 0.5rem;
  transition: all 140ms ease;
}

.col-chip.checked .chip-check {
  background: var(--gold);
  border-color: var(--gold);
  color: white;
}

.col-chip.locked .chip-check {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.column-selector-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.selected-count {
  font-size: 0.76rem;
  color: var(--ink-3);
  font-weight: 500;
}

.confirm-columns-btn {
  height: 34px;
  padding: 0 22px;
  border: none;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #c9963a 0%, #e8b45a 100%);
  color: white;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-gold);
  transition: all 160ms ease;
  letter-spacing: 0.02em;
}

.confirm-columns-btn:hover:not(:disabled) {
  box-shadow: 0 6px 24px rgba(201,150,58,0.38);
  transform: translateY(-1px);
}

.confirm-columns-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}

/* ── Composer ──────────────────────────────────────────────────────────────── */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.composer-inner {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 0;
  background: var(--surface-2);
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius-lg);
  padding: 4px 6px 4px 14px;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.composer-inner:focus-within {
  border-color: var(--blue);
  box-shadow: var(--shadow-glow);
  background: var(--surface);
}

textarea {
  flex: 1;
  min-height: 38px;
  max-height: 150px;
  resize: none;
  border: none;
  background: transparent;
  outline: none;
  line-height: 1.55;
  font-size: 0.88rem;
  color: var(--ink);
  padding: 8px 6px 8px 0;
}

textarea::placeholder { color: var(--ink-4); }

#send-button {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-md);
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-2) 100%);
  box-shadow: 0 3px 12px rgba(37,99,235,0.3);
  transition: all 160ms ease;
  align-self: flex-end;
  margin-bottom: 3px;
}

#send-button:hover:not(:disabled) {
  transform: translateY(-1px) scale(1.04);
  box-shadow: 0 6px 18px rgba(37,99,235,0.38);
}

#send-button:active:not(:disabled) {
  transform: translateY(0) scale(0.97);
}

#send-button:disabled {
  cursor: wait;
  opacity: 0.5;
  box-shadow: none;
}

#send-button svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 680px) {
  .shell { padding: 12px 12px; }

  .chat-container {
    min-height: calc(100vh - 120px);
    max-height: calc(100vh - 100px);
    border-radius: var(--radius-lg);
  }

  #messages { padding: 18px 16px; }

  .quick-prompts { padding: 10px 16px 0; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0; }
  .quick-prompts::-webkit-scrollbar { display: none; }

  .column-selector-panel.is-open { padding: 14px 16px; }

  .composer { padding: 10px 12px 14px; }

  .bubble { max-width: 88%; }

  .topbar { padding-bottom: 14px; }
}

@media (max-width: 420px) {
  .avatar { display: none; }
  .bubble { max-width: 95%; }
  .topbar-sub { display: none; }
}