/*
 * Perfect Afternoon — AI Analytics Platform
 * One cohesive stylesheet. Light theme, refined neutral palette + a tasteful indigo accent.
 * Aesthetic reference: Linear / Vercel / Stripe Dashboard / Notion. System font stack,
 * subtle borders, comfortable spacing, responsive. No external fonts or assets.
 */

/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --sidebar-bg: #fafafb;

  --text: #1a1d24;
  --text-muted: #5b6472;
  --text-faint: #8a909c;

  --border: #e7e8ec;
  --border-strong: #d7d9df;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0fe;
  --accent-text: #ffffff;

  --success: #15803d;
  --success-soft: #e8f6ed;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warning: #b45309;

  --code-bg: #f3f4f7;
  --code-border: #e3e5ea;

  --radius-sm: 6px;
  --radius: 9px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow: 0 4px 16px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, 0.12);

  --sidebar-w: 276px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── Buttons (shared) ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 550;
  font-size: 14px;
  cursor: pointer;
  padding: 9px 14px;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}
.icon-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ── Login page ────────────────────────────────────────────────────────── */
.login-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, #eef0fe 0%, rgba(238, 240, 254, 0) 60%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 40px 36px;
  text-align: center;
}
.login-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 18px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.5px;
  box-shadow: var(--shadow-sm);
}
.login-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.login-sub {
  margin: 0 0 26px;
  color: var(--text-muted);
  font-size: 14px;
}
.login-error {
  margin: 0 0 18px;
  padding: 11px 14px;
  border-radius: var(--radius);
  background: var(--danger-soft);
  border: 1px solid #f6cccc;
  color: #991b1b;
  font-size: 13px;
  text-align: left;
}
.btn-google {
  width: 100%;
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
  padding: 11px 16px;
  font-weight: 550;
}
.btn-google:hover {
  background: var(--surface-2);
  box-shadow: var(--shadow-sm);
}
.google-icon {
  flex: none;
}
.login-note {
  margin: 18px 0 0;
  font-size: 12.5px;
  color: var(--text-faint);
}
.login-footer {
  margin-top: 22px;
  color: var(--text-faint);
  font-size: 12px;
}

/* ── App shell ─────────────────────────────────────────────────────────── */
.app-body {
  overflow: hidden;
}
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  min-height: 0;
}
.sidebar-head {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 14px;
  padding: 2px;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex: none;
}
.brand-name {
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: -0.01em;
}
.btn-new {
  width: 100%;
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
.btn-new:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 8px 16px;
}
.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  padding: 4px 8px 8px;
}
.sidebar-empty {
  padding: 8px 10px;
  margin: 0;
  color: var(--text-faint);
  font-size: 13px;
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.convo-item {
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
  padding: 0 4px 0 2px;
  transition: background 0.12s ease;
}
.convo-item:hover {
  background: rgba(79, 70, 229, 0.06);
}
.convo-item.active {
  background: var(--accent-soft);
}
.convo-select {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: none;
  font: inherit;
  color: var(--text);
  padding: 8px 8px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.convo-item.active .convo-select {
  color: var(--accent);
  font-weight: 550;
}
.convo-title {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13.5px;
}
.convo-actions {
  display: none;
  gap: 1px;
}
.convo-item:hover .convo-actions,
.convo-item.active .convo-actions {
  display: flex;
}
.icon-btn.icon-btn,
.convo-actions .icon-btn {
  width: 26px;
  height: 26px;
}
.convo-rename {
  flex: 1;
  min-width: 0;
  margin: 4px;
  padding: 5px 8px;
  font: inherit;
  font-size: 13.5px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  outline: none;
  background: var(--surface);
  color: var(--text);
}

/* ── Main column ───────────────────────────────────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.sidebar-toggle {
  display: none;
}
.topbar-title {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}
.topbar-product {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}
.topbar-sub {
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user {
  display: flex;
  align-items: center;
  gap: 9px;
}
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 650;
  overflow: hidden;
  flex: none;
}
.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.user-name {
  font-size: 13.5px;
  color: var(--text-muted);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Chat area ─────────────────────────────────────────────────────────── */
.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 28px 20px 12px;
}

/* Empty state */
.empty-state {
  max-width: 720px;
  margin: 6vh auto 0;
  text-align: center;
  padding: 0 8px 40px;
}
.empty-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 20px;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 21px;
  box-shadow: var(--shadow);
}
.empty-title {
  margin: 0 0 8px;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.empty-sub {
  margin: 0 auto 28px;
  max-width: 480px;
  color: var(--text-muted);
  font-size: 15px;
}
.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  text-align: left;
}
.suggestion-chip {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: border-color 0.14s ease, box-shadow 0.14s ease, transform 0.14s ease;
}
.suggestion-chip:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.suggestion-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.suggestion-cat {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}
.suggestion-label {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

/* Messages */
.msg {
  display: flex;
  gap: 13px;
  max-width: 820px;
  margin: 0 auto 22px;
}
.msg-avatar {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 650;
  margin-top: 2px;
}
.msg-user .msg-avatar {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
}
.msg-assistant .msg-avatar {
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #fff;
}
.msg-body {
  min-width: 0;
  flex: 1;
  padding-top: 3px;
}
.msg-content {
  color: var(--text);
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.msg-user .msg-content {
  white-space: pre-wrap;
}

/* Tool chips */
.tool-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 10px;
}
.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.tool-chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex: none;
}
.tool-chip-running .tool-chip-dot {
  background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}
.tool-chip-running {
  border-color: var(--accent-soft);
  color: var(--accent);
  background: var(--accent-soft);
}
.tool-chip-done .tool-chip-dot {
  background: var(--success);
}
.tool-chip-done {
  background: var(--success-soft);
  border-color: #cdeed8;
  color: var(--success);
}
.tool-chip-error .tool-chip-dot {
  background: var(--danger);
}
.tool-chip-error {
  background: var(--danger-soft);
  border-color: #f6cccc;
  color: #991b1b;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

/* Thinking + error notes */
.thinking {
  color: var(--text-faint);
  font-style: italic;
  font-size: 14px;
}
.error-note {
  background: var(--danger-soft);
  border: 1px solid #f6cccc;
  color: #991b1b;
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 14px;
}

/* Typing indicator */
.typing {
  display: inline-flex;
  gap: 5px;
  padding: 4px 0;
}
.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: typing 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ── Markdown content ──────────────────────────────────────────────────── */
.markdown > *:first-child { margin-top: 0; }
.markdown > *:last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 12px; }
.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4 {
  margin: 20px 0 10px;
  font-weight: 640;
  letter-spacing: -0.01em;
  line-height: 1.3;
}
.markdown h1 { font-size: 20px; }
.markdown h2 { font-size: 18px; }
.markdown h3 { font-size: 16px; }
.markdown h4 { font-size: 15px; }
.markdown ul,
.markdown ol {
  margin: 0 0 12px;
  padding-left: 24px;
}
.markdown li { margin: 3px 0; }
.markdown a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(79, 70, 229, 0.3);
}
.markdown a:hover {
  border-bottom-color: var(--accent);
}
.markdown strong { font-weight: 640; color: var(--text); }
.markdown em { font-style: italic; }
.markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}
.markdown blockquote {
  margin: 0 0 12px;
  padding: 4px 14px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}
.markdown code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 5px;
  padding: 1px 5px;
}
.markdown pre {
  margin: 0 0 14px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
}
.markdown pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.55;
}
.markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 16px;
  font-size: 13.5px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.markdown thead {
  background: var(--surface-2);
}
.markdown th,
.markdown td {
  text-align: left;
  padding: 9px 13px;
  border-bottom: 1px solid var(--border);
}
.markdown th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12.5px;
}
.markdown tbody tr:last-child td {
  border-bottom: none;
}
.markdown tbody tr:hover {
  background: var(--surface-2);
}

/* ── Composer ──────────────────────────────────────────────────────────── */
.composer-wrap {
  padding: 8px 20px 18px;
  background: linear-gradient(to top, var(--bg) 70%, rgba(247, 248, 250, 0));
}
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 820px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 9px 9px 9px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.composer-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: transparent;
  max-height: 220px;
  padding: 6px 0;
}
.composer-input::placeholder {
  color: var(--text-faint);
}
.composer-input:disabled {
  color: var(--text-faint);
}
.btn-send {
  flex: none;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-send:hover:not(:disabled) {
  background: var(--accent-hover);
}
.composer-hint {
  max-width: 820px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
}

/* ── Scrollbars ────────────────────────────────────────────────────────── */
.messages,
.sidebar-scroll,
.markdown pre,
.markdown table {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.messages::-webkit-scrollbar,
.sidebar-scroll::-webkit-scrollbar,
.markdown pre::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.messages::-webkit-scrollbar-thumb,
.sidebar-scroll::-webkit-scrollbar-thumb,
.markdown pre::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 6px;
  border: 3px solid transparent;
  background-clip: content-box;
}
.messages::-webkit-scrollbar-thumb:hover,
.sidebar-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
  background-clip: content-box;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-toggle {
    display: inline-flex;
  }
  .suggestion-grid {
    grid-template-columns: 1fr;
  }
  .user-name {
    display: none;
  }
}

/* ── GA4 property picker (top bar) ── */
.property-picker {
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--surface, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  padding: 6px 28px 6px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text, #111827);
  cursor: pointer;
  max-width: 260px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M6 8l4 4 4-4' stroke='%236b7280' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
}
.property-picker:hover {
  border-color: var(--border-strong, #d1d5db);
}
.property-picker:disabled {
  opacity: 0.7;
  cursor: default;
}
.property-picker:focus-visible {
  outline: 2px solid var(--accent, #4f46e5);
  outline-offset: 1px;
}
