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

:root {
  --brand: #4f46e5;
  --brand-light: #eef2ff;
  --brand-dark: #3730a3;
  --green: #16a34a;
  --green-light: #dcfce7;
  --red: #dc2626;
  --red-light: #fee2e2;
  --yellow: #d97706;
  --yellow-light: #fef3c7;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  max-width: 780px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 32px;
}

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

.logo-icon {
  font-size: 24px;
  color: var(--brand);
}

.logo-text {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-900);
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--gray-600);
  font-size: 15px;
}

/* Search card */
.search-card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.type-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
}

.toggle-btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--gray-200);
  background: white;
  color: var(--gray-600);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}

.toggle-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: white;
}

.input-row {
  display: flex;
  gap: 10px;
}

#query-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

#query-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}

#search-btn {
  padding: 10px 20px;
  background: var(--brand);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background .15s;
  white-space: nowrap;
}

#search-btn:hover { background: var(--brand-dark); }
#search-btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Contact picker */
#contact-picker {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

#contact-picker h3 {
  font-size: 15px;
  color: var(--gray-600);
  margin-bottom: 12px;
}

#contact-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#contact-list li {
  padding: 12px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

#contact-list li:hover {
  border-color: var(--brand);
  background: var(--brand-light);
}

#contact-list li strong { display: block; font-size: 14px; }
#contact-list li span { font-size: 13px; color: var(--gray-600); }

/* Results */
#results { margin-bottom: 24px; }

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

#contact-name {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

#contact-meta {
  font-size: 13px;
  color: var(--gray-600);
  margin-top: 2px;
}

.results-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-secondary {
  padding: 7px 14px;
  border: 1px solid var(--gray-200);
  border-radius: 7px;
  background: white;
  color: var(--gray-700);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: border-color .15s, background .15s;
}

.btn-secondary:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-light); }

/* Briefing card */
.briefing-card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.briefing-section {
  margin-bottom: 20px;
}

.briefing-section:last-child { margin-bottom: 0; }

.briefing-section h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--gray-400);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.briefing-section p {
  font-size: 15px;
  color: var(--gray-700);
}

.briefing-section ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.briefing-section ul li {
  font-size: 14px;
  color: var(--gray-700);
  padding-left: 16px;
  position: relative;
}

.briefing-section ul li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--brand);
  font-weight: 700;
}

.briefing-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 20px;
}

@media (max-width: 560px) { .briefing-cols { grid-template-columns: 1fr; } }

/* Badges */
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  text-transform: capitalize;
}

.badge-positive { background: var(--green-light); color: var(--green); }
.badge-frustrated { background: var(--red-light); color: var(--red); }
.badge-mixed { background: var(--yellow-light); color: var(--yellow); }
.badge-neutral { background: var(--gray-100); color: var(--gray-600); }

/* Conversations */
.conv-section {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.conv-toggle {
  width: 100%;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  cursor: pointer;
  transition: background .15s;
}

.conv-toggle:hover { background: var(--gray-50); }

.conv-list {
  list-style: none;
  border-top: 1px solid var(--gray-200);
}

.conv-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  border-bottom: 1px solid var(--gray-100);
  font-size: 13px;
}

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

.conv-list a {
  color: var(--gray-700);
  text-decoration: none;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-list a:hover { color: var(--brand); text-decoration: underline; }

.conv-date { color: var(--gray-400); white-space: nowrap; flex-shrink: 0; }

.conv-state {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  flex-shrink: 0;
}

.state-open { background: var(--green-light); color: var(--green); }
.state-closed { background: var(--gray-100); color: var(--gray-600); }
.state-snoozed { background: var(--yellow-light); color: var(--yellow); }

/* Error */
.error-box {
  background: var(--red-light);
  color: var(--red);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 14px;
  margin-bottom: 24px;
}

/* Bookmarklet */
.bookmarklet-section {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 32px;
  box-shadow: var(--shadow);
}

.bookmarklet-section h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}

.bookmarklet-section > p {
  font-size: 13px;
  color: var(--gray-600);
  margin-bottom: 14px;
}

.bookmarklet-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  margin-top: 32px;
  font-size: 13px;
  color: var(--gray-600);
}

.bookmarklet-btn {
  display: inline-block;
  padding: 7px 14px;
  background: var(--brand);
  color: white;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: grab;
  user-select: none;
  white-space: nowrap;
}

.bookmarklet-hint {
  font-size: 13px;
  color: var(--gray-400);
}

/* Utility */
.hidden { display: none !important; }
