/**
 * Contact Widget Styles
 *
 * Styles for the multi-state contact widget (call, email, meeting, note).
 * Works with widget-chrome.css for base widget styles.
 *
 * Widget States:
 * - card (280x80): Minimized draft view
 * - mini (340x220): Quick notes with type selector
 * - expanded (480x600): Full form with email editor
 */

/* ==========================================
   CONTACT TYPE COLORS
   ========================================== */
:root {
  --type-call: #22d3ee;
  --type-email: #c084fc;
  --type-meeting: #f472b6;
  --type-note: #fbbf24;
}

/* Apply color based on contact type */
.widget-contact[data-contact-type="call"] {
  --widget-color: var(--type-call);
}
.widget-contact[data-contact-type="email"] {
  --widget-color: var(--type-email);
}
.widget-contact[data-contact-type="meeting"] {
  --widget-color: var(--type-meeting);
}
.widget-contact[data-contact-type="note"] {
  --widget-color: var(--type-note);
}

/* ==========================================
   WIDGET CHROME INTEGRATION
   Note: Base widget chrome (handle, size buttons, etc.)
   comes from widget-chrome.css. This file only adds
   contact-specific content styles.
   ========================================== */

/* Widget body needs padding-top for the floating handle */
.widget-contact .widget-body {
  padding-top: 14px;
}

/* ==========================================
   PERFORMANCE OPTIMIZATIONS
   ========================================== */

/* Layout containment for better performance */
.widget[data-widget-type="contact"] {
  contain: layout style;
}

/* GPU acceleration for panels */
.contact-widget .history-panel,
.contact-widget .profile-panel {
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Optimize animations */
.contact-widget .panel-backdrop {
  will-change: opacity;
}

/* Remove will-change after animation completes (via JS) */
.contact-widget .history-panel.animation-complete,
.contact-widget .profile-panel.animation-complete {
  will-change: auto;
}

/* Content visibility for off-screen panels */
.contact-widget .history-panel:not(.is-open),
.contact-widget .profile-panel:not(.is-open) {
  content-visibility: hidden;
}

/* ==========================================
   CONTACT WIDGET BASE
   ========================================== */
.contact-widget {
  display: flex;
  flex-direction: column;
  height: 100%;
  color: var(--text-primary, #f4f4f6);
}

/* ==========================================
   CARD STATE (280x80)
   Minimized draft view
   ========================================== */
.contact-widget-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
}

.contact-widget-card .card-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--widget-color, var(--type-call)) 20%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.contact-widget-card .card-icon svg {
  width: 16px;
  height: 16px;
  stroke: var(--widget-color, var(--type-call));
  stroke-width: 2;
}

.contact-widget-card .card-content {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.contact-widget-card .card-context {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary, #f4f4f6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-widget-card .card-snippet {
  font-size: 12px;
  color: var(--text-secondary, #a1a1aa);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.contact-widget-card .card-time {
  font-size: 11px;
  color: var(--text-tertiary, #71717a);
  flex-shrink: 0;
}

.contact-widget-card .card-menu {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: transparent;
  border: none;
  color: var(--text-tertiary, #71717a);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.contact-widget-card:hover .card-menu {
  opacity: 1;
}

.contact-widget-card .card-menu:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary, #f4f4f6);
}

/* ==========================================
   MINI STATE (340x220)
   Quick notes with type selector
   ========================================== */
.contact-widget-mini {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 8px 0;
}

/* Context bar */
.contact-widget-mini .context-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.contact-widget-mini .context-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: color-mix(in srgb, var(--widget-color, var(--type-call)) 15%, transparent);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--widget-color, var(--type-call));
}

.contact-widget-mini .context-badge svg {
  width: 12px;
  height: 12px;
  stroke-width: 2;
}

.contact-widget-mini .context-name {
  flex: 1;
  font-size: 12px;
  color: var(--text-secondary, #a1a1aa);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-widget-mini .context-clear {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: transparent;
  border: none;
  color: var(--text-tertiary, #71717a);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.15s;
}

.contact-widget-mini:hover .context-clear {
  opacity: 1;
}

/* ==========================================
   PROMINENT CONTEXT BANNER (Mini State)
   Makes company/site context unmistakably clear
   ========================================== */
.context-banner-mini {
  margin: 0 8px 8px;
  border-radius: 10px;
  overflow: hidden;
  transition: all 0.2s ease;
}

/* Entity type color coding */
.context-banner-mini.context-company {
  --banner-gradient-start: #3b82f6;
  --banner-gradient-end: #1d4ed8;
}

.context-banner-mini.context-site {
  --banner-gradient-start: #22c55e;
  --banner-gradient-end: #16a34a;
}

/* Default/fallback (no specific entity type) */
.context-banner-mini:not(.context-company):not(.context-site).has-context {
  --banner-gradient-start: #6366f1;
  --banner-gradient-end: #4f46e5;
}

/* Banner with context - prominent gradient background */
.context-banner-mini.has-context {
  background: linear-gradient(135deg, var(--banner-gradient-start), var(--banner-gradient-end));
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.context-banner-mini .banner-content {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  color: white;
}

.context-banner-mini .banner-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.context-banner-mini .banner-icon svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.context-banner-mini .banner-info {
  flex: 1;
  min-width: 0;
}

.context-banner-mini .banner-type {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.85;
  margin-bottom: 2px;
}

.context-banner-mini .banner-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.context-banner-mini .banner-clear {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.7;
  transition: all 0.15s;
}

.context-banner-mini .banner-clear:hover {
  background: rgba(255, 255, 255, 0.25);
  opacity: 1;
}

.context-banner-mini .banner-clear svg {
  width: 14px;
  height: 14px;
  stroke-width: 2.5;
}

/* Empty state - no context linked yet */
.context-banner-mini .banner-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  color: var(--text-tertiary, #71717a);
  font-size: 12px;
}

.context-banner-mini .banner-empty svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
  opacity: 0.6;
}

.context-banner-mini .banner-empty kbd {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--text-secondary, #a1a1aa);
}

/* Animation when context is set */
.context-banner-mini.context-just-set {
  animation: bannerPulse 0.5s ease-out;
}

@keyframes bannerPulse {
  0% {
    transform: scale(0.98);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.01);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Type selector */
.contact-widget-mini .type-selector {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
}

.contact-widget-mini .type-btn {
  flex: 1;
  padding: 6px 8px;
  border: none;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  color: var(--text-secondary, #a1a1aa);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}

.contact-widget-mini .type-btn svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

.contact-widget-mini .type-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary, #f4f4f6);
}

.contact-widget-mini .type-btn.active {
  background: color-mix(in srgb, var(--widget-color, var(--type-call)) 20%, transparent);
  color: var(--widget-color, var(--type-call));
}

/* Keyboard shortcut hints */
.contact-widget-mini .shortcut-hint {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  font-family: ui-monospace, monospace;
  font-size: 9px;
  font-weight: 600;
  color: var(--text-tertiary, #71717a);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

/* Show hints on hover */
.contact-widget-mini .type-selector:hover .shortcut-hint,
.contact-widget-mini .type-btn:focus .shortcut-hint {
  opacity: 1;
}

/* Active button hint styling */
.contact-widget-mini .type-btn.active .shortcut-hint {
  background: rgba(255, 255, 255, 0.15);
  color: var(--widget-color, var(--type-call));
}

/* Type button needs position relative for hint positioning */
.contact-widget-mini .type-btn {
  position: relative;
}

/* Notes field */
.contact-widget-mini .notes-field {
  flex: 1;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  position: relative; /* Required for star-search absolute positioning */
}

.contact-widget-mini .notes-textarea {
  flex: 1;
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text-primary, #f4f4f6);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
}

.contact-widget-mini .notes-textarea::placeholder {
  color: var(--text-tertiary, #71717a);
}

.contact-widget-mini .notes-textarea:focus {
  border-color: var(--widget-color, var(--type-call));
}

/* Star trigger search dropdown */
.contact-widget-mini .star-search {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 8px; /* Position at bottom of notes field */
  background: rgba(26, 29, 36, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  max-height: 180px;
  overflow-y: auto;
  z-index: 50;
}

.contact-widget-mini .star-search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.contact-widget-mini .star-search-item:last-child {
  border-bottom: none;
}

.contact-widget-mini .star-search-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.contact-widget-mini .star-search-icon {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
}

.contact-widget-mini .star-search-icon svg {
  width: 12px;
  height: 12px;
  stroke-width: 2;
  color: var(--text-secondary, #a1a1aa);
}

.contact-widget-mini .star-search-name {
  font-size: 13px;
  color: var(--text-primary, #f4f4f6);
}

.contact-widget-mini .star-search-type {
  font-size: 11px;
  color: var(--text-tertiary, #71717a);
  margin-left: auto;
}

/* Action bar */
.contact-widget-mini .action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.contact-widget-mini .panel-triggers {
  display: flex;
  gap: 4px;
}

.contact-widget-mini .panel-trigger {
  padding: 6px 10px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--text-tertiary, #71717a);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}

.contact-widget-mini .panel-trigger:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--text-secondary, #a1a1aa);
}

.contact-widget-mini .panel-trigger svg {
  width: 12px;
  height: 12px;
  stroke-width: 2;
}

.contact-widget-mini .save-btn {
  padding: 8px 16px;
  background: var(--widget-color, var(--type-call));
  border: none;
  border-radius: 6px;
  color: #000;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.contact-widget-mini .save-btn:hover {
  filter: brightness(1.1);
}

.contact-widget-mini .save-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.contact-widget-mini .save-btn svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

/* ==========================================
   EXPANDED STATE (480x600)
   Full form with email editor
   ========================================== */
.contact-widget-expanded {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 8px 0;
}

/* Header with context */
.contact-widget-expanded .expanded-header {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.contact-widget-expanded .context-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--widget-color, var(--type-call)) 15%, transparent) 0%,
    color-mix(in srgb, var(--widget-color, var(--type-call)) 8%, transparent) 100%
  );
  border-radius: 10px;
}

.contact-widget-expanded .context-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--widget-color, var(--type-call)) 25%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.contact-widget-expanded .context-icon svg {
  width: 20px;
  height: 20px;
  stroke: var(--widget-color, var(--type-call));
  stroke-width: 2;
}

.contact-widget-expanded .context-info {
  flex: 1;
  min-width: 0;
}

.contact-widget-expanded .context-type {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary, #71717a);
}

.contact-widget-expanded .context-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary, #f4f4f6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-widget-expanded .last-contact {
  font-size: 11px;
  color: var(--text-tertiary, #71717a);
  margin-top: 2px;
}

/* Form area */
.contact-widget-expanded .form-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* Type and direction row */
.contact-widget-expanded .type-direction-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.contact-widget-expanded .form-group {
  flex: 1;
}

.contact-widget-expanded .form-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary, #71717a);
  margin-bottom: 6px;
}

.contact-widget-expanded .form-select {
  width: 100%;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-primary, #f4f4f6);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}

.contact-widget-expanded .form-select:focus {
  border-color: var(--widget-color, var(--type-call));
}

.contact-widget-expanded .form-input {
  width: 100%;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-primary, #f4f4f6);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.contact-widget-expanded .form-input::placeholder {
  color: var(--text-tertiary, #71717a);
}

.contact-widget-expanded .form-input:focus {
  border-color: var(--widget-color, var(--type-call));
}

/* Email-specific fields */
.contact-widget-expanded .email-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.contact-widget-expanded .recipient-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.contact-widget-expanded .recipient-label {
  width: 36px;
  font-size: 12px;
  color: var(--text-tertiary, #71717a);
  flex-shrink: 0;
}

.contact-widget-expanded .recipient-input {
  flex: 1;
}

.contact-widget-expanded .recipient-add {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-tertiary, #71717a);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.contact-widget-expanded .recipient-add:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--text-secondary, #a1a1aa);
}

/* Editor area */
.contact-widget-expanded .editor-area {
  flex: 1;
  min-height: 200px;
  margin-top: 12px;
}

.contact-widget-expanded .editor-area .form-textarea {
  width: 100%;
  height: 100%;
  min-height: 200px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 12px;
  color: var(--text-primary, #f4f4f6);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
}

.contact-widget-expanded .editor-area .form-textarea:focus {
  border-color: var(--widget-color, var(--type-call));
}

/* Call-specific fields */
.contact-widget-expanded .call-fields {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.contact-widget-expanded .outcome-select {
  flex: 2;
}

.contact-widget-expanded .duration-input {
  flex: 1;
}

/* Footer actions */
.contact-widget-expanded .expanded-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.contact-widget-expanded .footer-panels {
  display: flex;
  gap: 4px;
}

.contact-widget-expanded .footer-btn {
  padding: 8px 12px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--text-tertiary, #71717a);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.contact-widget-expanded .footer-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--text-secondary, #a1a1aa);
}

.contact-widget-expanded .footer-btn svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

.contact-widget-expanded .footer-actions {
  display: flex;
  gap: 8px;
}

.contact-widget-expanded .generate-btn {
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-secondary, #a1a1aa);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.contact-widget-expanded .generate-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary, #f4f4f6);
}

.contact-widget-expanded .generate-btn svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

.contact-widget-expanded .send-btn,
.contact-widget-expanded .save-btn-expanded {
  padding: 10px 20px;
  background: var(--widget-color, var(--type-call));
  border: none;
  border-radius: 8px;
  color: #000;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.contact-widget-expanded .send-btn:hover,
.contact-widget-expanded .save-btn-expanded:hover {
  filter: brightness(1.1);
}

.contact-widget-expanded .send-btn:disabled,
.contact-widget-expanded .save-btn-expanded:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.contact-widget-expanded .send-btn svg,
.contact-widget-expanded .save-btn-expanded svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

/* ==========================================
   STATUS MESSAGES
   ========================================== */
.contact-widget .status-message {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.contact-widget .status-message.error {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.contact-widget .status-message.success {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
}

.contact-widget .status-message svg {
  width: 14px;
  height: 14px;
  stroke-width: 2;
}

/* ==========================================
   DIRTY INDICATOR
   ========================================== */
.contact-widget .dirty-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--widget-color, var(--type-call));
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ==========================================
   LOADING STATE
   ========================================== */
.contact-widget .loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--widget-color, var(--type-call));
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ==========================================
   MICRO-INTERACTIONS & POLISH
   ========================================== */

/* Widget appearance animation */
.contact-widget {
  animation: widgetAppear 0.25s ease-out;
}

@keyframes widgetAppear {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Button press effect */
.contact-widget button:active:not(:disabled) {
  transform: scale(0.97);
}

/* Type button selection ripple */
.contact-widget-mini .type-btn.active {
  position: relative;
  overflow: hidden;
}

.contact-widget-mini .type-btn.active::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255, 255, 255, 0.15) 0%, transparent 70%);
  animation: typeSelectPulse 0.4s ease-out;
  pointer-events: none;
}

@keyframes typeSelectPulse {
  from {
    opacity: 0.8;
    transform: scale(0.5);
  }
  to {
    opacity: 0;
    transform: scale(1.5);
  }
}

/* Save/Send button glow on hover */
.contact-widget .save-btn:hover:not(:disabled),
.contact-widget .save-btn-expanded:hover:not(:disabled),
.contact-widget .send-btn:hover:not(:disabled) {
  box-shadow: 0 0 20px color-mix(in srgb, var(--widget-color, var(--type-call)) 40%, transparent);
}

/* Textarea focus glow */
.contact-widget .notes-textarea:focus,
.contact-widget .form-input:focus,
.contact-widget .form-select:focus,
.contact-widget .form-textarea:focus {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--widget-color, var(--type-call)) 20%, transparent);
}

/* Search result hover highlight */
.contact-widget-mini .star-search-item {
  transition: all 0.15s ease;
}

.contact-widget-mini .star-search-item:hover {
  background: color-mix(in srgb, var(--widget-color, var(--type-call)) 10%, transparent);
  padding-left: 16px;
}

/* Card hover lift effect */
.contact-widget-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.contact-widget-card:hover {
  transform: translateY(-2px);
}

/* History item hover slide */
.contact-widget .history-item {
  transition: all 0.15s ease;
}

.contact-widget .history-item:hover {
  padding-left: 16px;
}

/* Profile contact hover effect */
.contact-widget .profile-contact {
  transition: all 0.15s ease;
}

.contact-widget .profile-contact:hover {
  transform: translateX(4px);
}

/* Edge trigger pulse hint (shown briefly on widget open) */
.contact-widget .edge-trigger {
  animation: edgeTriggerHint 2s ease-out 1s;
}

@keyframes edgeTriggerHint {
  0%, 100% {
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
}

/* Success message bounce */
.contact-widget .status-message.success {
  animation: successBounce 0.4s ease-out;
}

@keyframes successBounce {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.95);
  }
  50% {
    transform: translateY(-2px) scale(1.02);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Error message shake */
.contact-widget .status-message.error {
  animation: errorShake 0.4s ease-out;
}

@keyframes errorShake {
  0%, 100% {
    transform: translateX(0);
  }
  20%, 60% {
    transform: translateX(-4px);
  }
  40%, 80% {
    transform: translateX(4px);
  }
}

/* Smooth icon color transitions */
.contact-widget svg {
  transition: stroke 0.15s ease, color 0.15s ease;
}

/* ==========================================
   CONTEXT ANIMATIONS
   ========================================== */
.contact-widget .context-bar,
.contact-widget .context-banner {
  animation: contextSlideIn 0.3s ease-out;
}

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

/* Context flash when entity is set */
.contact-widget.context-just-set .context-bar,
.contact-widget.context-just-set .context-banner {
  animation: contextFlash 0.6s ease-out;
}

@keyframes contextFlash {
  0% {
    background: rgba(255, 255, 255, 0.3);
  }
  100% {
    background: transparent;
  }
}

/* ==========================================
   SWIPE PANELS
   ========================================== */
.contact-widget-panels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: inherit;
}

/* History Panel (left edge) */
.contact-widget .history-panel {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 280px;
  background: linear-gradient(
    90deg,
    rgba(17, 21, 32, 0.98) 0%,
    rgba(17, 21, 32, 0.95) 100%
  );
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.contact-widget .history-panel.is-open {
  transform: translateX(0);
}

.contact-widget .history-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.contact-widget .history-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary, #f4f4f6);
  display: flex;
  align-items: center;
  gap: 8px;
}

.contact-widget .history-panel-title svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
  color: var(--text-secondary, #a1a1aa);
}

.contact-widget .history-panel-close {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: transparent;
  border: none;
  color: var(--text-tertiary, #71717a);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.contact-widget .history-panel-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary, #f4f4f6);
}

.contact-widget .history-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.contact-widget .history-item {
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 4px;
}

.contact-widget .history-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.contact-widget .history-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.contact-widget .history-item-type {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.contact-widget .history-item-type svg {
  width: 12px;
  height: 12px;
  stroke-width: 2;
}

.contact-widget .history-item-type.type-call {
  background: color-mix(in srgb, var(--type-call) 20%, transparent);
  color: var(--type-call);
}

.contact-widget .history-item-type.type-email {
  background: color-mix(in srgb, var(--type-email) 20%, transparent);
  color: var(--type-email);
}

.contact-widget .history-item-type.type-meeting {
  background: color-mix(in srgb, var(--type-meeting) 20%, transparent);
  color: var(--type-meeting);
}

.contact-widget .history-item-type.type-note {
  background: color-mix(in srgb, var(--type-note) 20%, transparent);
  color: var(--type-note);
}

.contact-widget .history-item-date {
  font-size: 11px;
  color: var(--text-tertiary, #71717a);
  margin-left: auto;
}

.contact-widget .history-item-snippet {
  font-size: 12px;
  color: var(--text-secondary, #a1a1aa);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-widget .history-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-tertiary, #71717a);
  font-size: 12px;
}

/* Buyer Profile Panel (right edge) */
.contact-widget .profile-panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 280px;
  background: linear-gradient(
    270deg,
    rgba(17, 21, 32, 0.98) 0%,
    rgba(17, 21, 32, 0.95) 100%
  );
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.contact-widget .profile-panel.is-open {
  transform: translateX(0);
}

.contact-widget .profile-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.contact-widget .profile-panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary, #f4f4f6);
  display: flex;
  align-items: center;
  gap: 8px;
}

.contact-widget .profile-panel-title svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
  color: var(--text-secondary, #a1a1aa);
}

.contact-widget .profile-panel-close {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: transparent;
  border: none;
  color: var(--text-tertiary, #71717a);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.contact-widget .profile-panel-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary, #f4f4f6);
}

.contact-widget .profile-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.contact-widget .profile-section {
  margin-bottom: 16px;
}

.contact-widget .profile-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary, #71717a);
  margin-bottom: 8px;
}

.contact-widget .profile-info-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.contact-widget .profile-info-label {
  font-size: 12px;
  color: var(--text-secondary, #a1a1aa);
}

.contact-widget .profile-info-value {
  font-size: 12px;
  color: var(--text-primary, #f4f4f6);
  font-weight: 500;
}

.contact-widget .profile-contact {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 6px;
  margin-bottom: 6px;
}

.contact-widget .profile-contact:hover {
  background: rgba(255, 255, 255, 0.04);
}

.contact-widget .profile-contact-avatar {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: white;
}

.contact-widget .profile-contact-info {
  flex: 1;
  min-width: 0;
}

.contact-widget .profile-contact-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary, #f4f4f6);
}

.contact-widget .profile-contact-role {
  font-size: 11px;
  color: var(--text-tertiary, #71717a);
}

.contact-widget .profile-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-tertiary, #71717a);
  font-size: 12px;
}

/* Edge triggers (visible tabs) */
.contact-widget .edge-trigger {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  z-index: 5;
  opacity: 0.6;
  transition: opacity 0.2s, transform 0.2s;
}

.contact-widget .edge-trigger:hover {
  opacity: 1;
}

.contact-widget .edge-trigger-left {
  left: 0;
  border-radius: 0 4px 4px 0;
  background: rgba(255, 255, 255, 0.06);
}

.contact-widget .edge-trigger-left:hover {
  transform: translateY(-50%) translateX(2px);
}

.contact-widget .edge-trigger-right {
  right: 0;
  border-radius: 4px 0 0 4px;
  background: rgba(255, 255, 255, 0.06);
}

.contact-widget .edge-trigger-right:hover {
  transform: translateY(-50%) translateX(-2px);
}

.contact-widget .edge-trigger svg {
  width: 12px;
  height: 12px;
  stroke-width: 2;
  color: var(--text-tertiary, #71717a);
}

/* Panel overlay backdrop */
.contact-widget .panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.contact-widget .panel-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

/* ==========================================
   RESPONSIVE - TABLET
   ========================================== */
@media (max-width: 768px) {
  /* Slightly larger touch targets on tablet */
  .contact-widget-mini .type-btn {
    padding: 8px 10px;
    min-height: 44px;
  }

  .contact-widget .edge-trigger {
    width: 24px;
    height: 56px;
  }
}

/* ==========================================
   RESPONSIVE - MOBILE (Bottom Sheet Pattern)
   ========================================== */
@media (max-width: 640px) {
  /* Widget becomes bottom sheet on mobile */
  .widget[data-widget-type="contact"] {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: none !important;
    border-radius: 16px 16px 0 0 !important;
    transform: none !important;
    max-height: 90vh;
    max-height: 90dvh; /* Dynamic viewport height for mobile browsers */
  }

  /* Card state on mobile - slim bar at bottom */
  .widget[data-widget-type="contact"][data-widget-state="card"] {
    height: auto !important;
    min-height: 64px;
  }

  .contact-widget-card {
    padding: 16px 20px;
    gap: 16px;
  }

  .contact-widget-card .card-icon {
    width: 40px;
    height: 40px;
  }

  .contact-widget-card .card-icon svg {
    width: 20px;
    height: 20px;
  }

  .contact-widget-card .card-context {
    font-size: 14px;
  }

  .contact-widget-card .card-menu {
    width: 40px;
    height: 40px;
    opacity: 1; /* Always visible on mobile */
  }

  /* Mini state on mobile - half screen */
  .widget[data-widget-type="contact"][data-widget-state="mini"] {
    height: 50vh !important;
    height: 50dvh !important;
  }

  .contact-widget-mini {
    padding: 12px 0;
  }

  .contact-widget-mini .context-bar {
    padding: 0 16px 12px;
  }

  .contact-widget-mini .context-clear {
    width: 32px;
    height: 32px;
    opacity: 1;
  }

  /* Context banner mobile adjustments */
  .context-banner-mini {
    margin: 0 12px 12px;
  }

  .context-banner-mini .banner-content {
    padding: 14px 16px;
    gap: 12px;
  }

  .context-banner-mini .banner-icon {
    width: 36px;
    height: 36px;
  }

  .context-banner-mini .banner-icon svg {
    width: 20px;
    height: 20px;
  }

  .context-banner-mini .banner-name {
    font-size: 16px;
  }

  .context-banner-mini .banner-clear {
    width: 32px;
    height: 32px;
    min-width: 44px; /* Touch target */
    min-height: 44px;
    opacity: 1; /* Always visible on mobile */
  }

  .context-banner-mini .banner-empty {
    padding: 12px 16px;
    font-size: 13px;
  }

  /* Larger type buttons on mobile */
  .contact-widget-mini .type-selector {
    padding: 12px 16px;
    gap: 8px;
  }

  .contact-widget-mini .type-btn {
    padding: 12px 10px;
    min-height: 52px;
    font-size: 12px;
  }

  .contact-widget-mini .type-btn svg {
    width: 18px;
    height: 18px;
  }

  /* Hide keyboard shortcut hints on mobile (no keyboard) */
  .contact-widget-mini .shortcut-hint {
    display: none;
  }

  /* Larger notes area on mobile */
  .contact-widget-mini .notes-field {
    padding: 12px 16px;
  }

  .contact-widget-mini .notes-textarea {
    font-size: 16px; /* Prevent iOS zoom on focus */
    padding: 14px 16px;
  }

  /* Action bar adjustments */
  .contact-widget-mini .action-bar {
    padding: 12px 16px;
    gap: 8px;
  }

  .contact-widget-mini .panel-trigger {
    padding: 10px 14px;
    font-size: 12px;
    min-height: 44px;
  }

  .contact-widget-mini .save-btn {
    padding: 12px 20px;
    font-size: 14px;
    min-height: 44px;
  }

  /* Expanded state on mobile - nearly full screen */
  .widget[data-widget-type="contact"][data-widget-state="expanded"] {
    height: 85vh !important;
    height: 85dvh !important;
  }

  .contact-widget-expanded {
    padding: 12px 0;
  }

  .contact-widget-expanded .expanded-header {
    padding: 16px 20px;
  }

  .contact-widget-expanded .context-banner {
    padding: 16px 20px;
  }

  .contact-widget-expanded .context-icon {
    width: 48px;
    height: 48px;
  }

  .contact-widget-expanded .context-icon svg {
    width: 24px;
    height: 24px;
  }

  .contact-widget-expanded .context-name {
    font-size: 18px;
  }

  /* Form fields */
  .contact-widget-expanded .type-direction-row {
    flex-direction: column;
    gap: 12px;
  }

  .contact-widget-expanded .form-area {
    padding: 20px;
  }

  .contact-widget-expanded .form-label {
    font-size: 12px;
    margin-bottom: 8px;
  }

  .contact-widget-expanded .form-select,
  .contact-widget-expanded .form-input {
    padding: 14px 16px;
    font-size: 16px; /* Prevent iOS zoom */
    min-height: 48px;
  }

  .contact-widget-expanded .call-fields {
    flex-direction: column;
    gap: 12px;
  }

  .contact-widget-expanded .email-fields {
    gap: 16px;
  }

  .contact-widget-expanded .recipient-field {
    flex-wrap: wrap;
    gap: 8px;
  }

  .contact-widget-expanded .recipient-label {
    width: 40px;
    font-size: 13px;
  }

  .contact-widget-expanded .recipient-add {
    width: 44px;
    height: 44px;
  }

  .contact-widget-expanded .editor-area .form-textarea {
    font-size: 16px;
    min-height: 180px;
  }

  /* Footer actions */
  .contact-widget-expanded .expanded-footer {
    padding: 16px 20px;
    flex-wrap: wrap;
    gap: 12px;
  }

  .contact-widget-expanded .footer-panels {
    display: none; /* Use edge gestures on mobile instead */
  }

  .contact-widget-expanded .footer-actions {
    width: 100%;
    justify-content: space-between;
  }

  .contact-widget-expanded .generate-btn {
    flex: 1;
    justify-content: center;
    min-height: 48px;
    font-size: 14px;
  }

  .contact-widget-expanded .send-btn,
  .contact-widget-expanded .save-btn-expanded {
    flex: 1;
    justify-content: center;
    min-height: 48px;
    font-size: 14px;
  }

  /* Panels take full width on mobile */
  .contact-widget .history-panel,
  .contact-widget .profile-panel {
    width: 100%;
  }

  /* Edge triggers larger on mobile */
  .contact-widget .edge-trigger {
    width: 28px;
    height: 64px;
  }

  .contact-widget .edge-trigger svg {
    width: 16px;
    height: 16px;
  }

  /* Star search dropdown */
  .contact-widget-mini .star-search {
    left: 16px;
    right: 16px;
    max-height: 220px;
  }

  .contact-widget-mini .star-search-item {
    padding: 14px 16px;
    min-height: 52px;
  }

  .contact-widget-mini .star-search-icon {
    width: 32px;
    height: 32px;
  }

  .contact-widget-mini .star-search-icon svg {
    width: 16px;
    height: 16px;
  }

  .contact-widget-mini .star-search-name {
    font-size: 14px;
  }

  /* Drag handle for bottom sheet */
  .widget[data-widget-type="contact"]::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    z-index: 10;
  }

  /* Add padding top to account for drag handle */
  .contact-widget {
    padding-top: 8px;
  }
}

/* ==========================================
   RESPONSIVE - SMALL MOBILE
   ========================================== */
@media (max-width: 375px) {
  .contact-widget-mini .type-selector {
    gap: 4px;
  }

  .contact-widget-mini .type-btn {
    padding: 10px 6px;
    font-size: 10px;
  }

  .contact-widget-expanded .context-name {
    font-size: 16px;
  }

  .contact-widget-expanded .footer-actions {
    flex-direction: column;
    gap: 8px;
  }

  .contact-widget-expanded .generate-btn,
  .contact-widget-expanded .send-btn,
  .contact-widget-expanded .save-btn-expanded {
    width: 100%;
  }
}

/* ==========================================
   ACCESSIBILITY UTILITIES
   ========================================== */

/* Screen reader only - visually hidden but accessible */
.contact-widget .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus visible styles for keyboard navigation */
.contact-widget button:focus-visible,
.contact-widget input:focus-visible,
.contact-widget select:focus-visible,
.contact-widget textarea:focus-visible,
.contact-widget [tabindex]:focus-visible {
  outline: 2px solid var(--widget-color, var(--type-call));
  outline-offset: 2px;
}

/* High contrast focus ring */
@media (prefers-contrast: more) {
  .contact-widget button:focus-visible,
  .contact-widget input:focus-visible,
  .contact-widget select:focus-visible,
  .contact-widget textarea:focus-visible,
  .contact-widget [tabindex]:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 3px;
  }
}

/* Skip link for keyboard users */
.contact-widget .skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--widget-color, var(--type-call));
  color: #000;
  padding: 8px 16px;
  z-index: 100;
  text-decoration: none;
  font-weight: 600;
}

.contact-widget .skip-link:focus {
  top: 0;
}

/* ==========================================
   REDUCED MOTION
   ========================================== */
@media (prefers-reduced-motion: reduce) {
  .contact-widget .context-bar,
  .contact-widget .context-banner,
  .contact-widget .history-panel,
  .contact-widget .profile-panel {
    animation: none;
    transition: none;
  }

  @keyframes contextSlideIn {
    from, to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes contextFlash {
    from, to {
      background: transparent;
    }
  }
}
