*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #7c3aed;
  --accent-light: #ede9fe;
  --surface: #ffffff;
  --bg: #f4f6fa;
  --border: rgba(0,0,0,0.08);
  --ink-1: #111317;
  --ink-2: #6b7280;
  --ink-3: #9ca3af;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink-1);
  min-height: 100vh;
}

#app { height: 100vh; }

.app {
  display: grid;
  grid-template-columns: 1fr 380px;
  height: 100vh;
  overflow: hidden;
}

/* ── Dashboard ── */
.dashboard {
  overflow-y: auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.dash-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.dash-header h1 { font-size: 1.5rem; font-weight: 700; }

.subtitle { font-size: .85rem; color: var(--ink-2); margin-top: .25rem; }
.subtitle code { font-size: .8rem; background: var(--accent-light); color: var(--accent); padding: 0 .35em; border-radius: 4px; }

.btn-clear {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .35rem .75rem;
  font-size: .8rem;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
}
.btn-clear:hover { border-color: var(--accent); color: var(--accent); }

/* ── Metrics Grid ── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.metric-card {
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  text-align: left;
  cursor: pointer;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.metric-card:hover { border-color: var(--accent); box-shadow: 0 4px 20px rgba(124,58,237,.12); }
.metric-card.active { border-color: var(--accent); background: var(--accent-light); box-shadow: 0 4px 20px rgba(124,58,237,.18); }

.metric-label { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
.metric-value { font-size: 2rem; font-weight: 700; color: var(--ink-1); line-height: 1; }
.metric-delta { font-size: .82rem; font-weight: 500; }
.metric-delta.positive { color: #16a34a; }
.metric-delta.negative { color: #dc2626; }

/* ── Table ── */
.table-section h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: .9rem; }

.deals-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.deals-table th {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-2);
  padding: .75rem 1rem;
  text-align: left;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.deal-row td {
  padding: .85rem 1rem;
  font-size: .9rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.deal-row:last-child td { border-bottom: none; }

.deal-row:hover td { background: #f9f5ff; }
.deal-row.active td { background: var(--accent-light); }

.company { font-weight: 600; }
.value { font-variant-numeric: tabular-nums; font-weight: 600; }

.risk-badge {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ── Tip ── */
.tip {
  font-size: .84rem;
  color: var(--ink-2);
  padding: .85rem 1.1rem;
  background: #fffbeb;
  border: 1px solid #fef3c7;
  border-radius: var(--radius);
}

/* ── AI Panel ── */
.ai-panel {
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Context box */
.context-box {
  border-bottom: 1px solid var(--border);
  padding: 1rem;
  flex-shrink: 0;
}

.context-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .6rem;
}

.context-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
}

.btn-copy {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .2rem .55rem;
  font-size: .75rem;
  cursor: pointer;
  color: var(--ink-2);
}
.btn-copy:hover { border-color: var(--accent); color: var(--accent); }

.context-pre {
  font-family: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, monospace;
  font-size: .72rem;
  line-height: 1.6;
  color: var(--ink-1);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 8px;
  padding: .75rem;
}

/* Chat */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .85rem;
}

.message { display: flex; flex-direction: column; gap: .3rem; }

.msg-role {
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-3);
}

.msg-text {
  font-size: .88rem;
  line-height: 1.55;
  color: var(--ink-1);
  background: var(--bg);
  border-radius: 10px;
  padding: .65rem .85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .msg-text { background: var(--accent-light); color: var(--accent); }
.message.user .msg-role { color: var(--accent); }
.typing { color: var(--ink-3) !important; }

.chat-input-row {
  border-top: 1px solid var(--border);
  padding: .85rem;
  display: flex;
  gap: .6rem;
  align-items: flex-end;
}

.chat-input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem .8rem;
  font-size: .88rem;
  font-family: inherit;
  line-height: 1.45;
  color: var(--ink-1);
  background: var(--bg);
  outline: none;
}
.chat-input-row textarea:focus { border-color: var(--accent); }
.chat-input-row textarea:disabled { opacity: .5; }

.btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: .6rem 1rem;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn-send:hover:not(:disabled) { background: #6d28d9; }
.btn-send:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .ai-panel { height: 360px; border-left: none; border-top: 1px solid var(--border); }
  .metrics-grid { grid-template-columns: 1fr; }
}
