/* Import Inter font */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --accent: #1A56DB;         /* professional blue */
  --accent-dark: #1E40AF;
  --accent-light: #EFF6FF;
  --success: #059669;
  --warning: #D97706;
  --danger: #DC2626;
  --text: #1E293B;
  --text-muted: #64748B;
  --text-subtle: #94A3B8;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --font: 'Inter', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

/* HEADER */
.cf-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
}
#cf-logo { height: 70px; width: auto; object-fit: contain; }
.cf-title { font-size: 18px; font-weight: 700; color: var(--accent); }
.cf-subtitle { font-size: 11px; color: var(--text-muted); display: block; }
.cf-powered { font-size: 11px; color: var(--text-muted); }
.cf-powered strong { color: var(--accent); }
.cf-live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--success); margin-left: 8px;
  animation: pulse 2s infinite;
}
.cf-history-nav-btn {
  padding: 7px 14px; border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  background: white; color: var(--text-muted);
  font-size: 12px; font-weight: 600; cursor: pointer;
  font-family: var(--font); transition: all 0.2s;
}
.cf-history-nav-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.3); }
}

/* MAIN LAYOUT */
.cf-main {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 0;
  height: calc(100vh - 64px);
  margin-top: 64px;
  overflow: hidden;
}

/* CHAT SECTION */
.cf-chat-section {
  display: flex; flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

/* Suggestion chips */
.cf-chips {
  display: flex; gap: 8px; padding: 12px 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.cf-chip {
  padding: 6px 14px; border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text-muted);
  font-size: 12px; font-weight: 500; cursor: pointer;
  font-family: var(--font);
  transition: all 0.2s;
}
.cf-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.cf-chips.hidden { display: none; }

/* Messages */
.cf-messages {
  flex: 1; overflow-y: auto;
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}
.cf-messages::-webkit-scrollbar { width: 4px; }
.cf-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* Bubbles */
.cf-bubble { display: flex; align-items: flex-end; gap: 8px; max-width: 75%; animation: fadeIn 0.2s ease; }
.cf-bubble.agent { align-self: flex-start; }
.cf-bubble.user { align-self: flex-end; flex-direction: row-reverse; }

.cf-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: white;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.cf-bubble-body {
  padding: 10px 14px; border-radius: var(--radius);
  font-size: 14px; line-height: 1.6; word-break: break-word;
}
.cf-bubble.agent .cf-bubble-body {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}
.cf-bubble.user .cf-bubble-body {
  background: var(--accent); color: white;
  border-bottom-right-radius: 4px;
}

/* Blocked message styling */
.cf-bubble.blocked .cf-bubble-body {
  background: #FEF2F2; border: 1px solid #FECACA; color: var(--danger);
}

/* Typing indicator */
.cf-typing {
  display: flex; align-items: center; gap: 4px;
  padding: 12px 16px 0;
}
.cf-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); opacity: 0.4;
  animation: bounce 1.2s infinite;
}
.cf-typing span:nth-child(2) { animation-delay: 0.2s; }
.cf-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* Input bar */
.cf-input-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.cf-mic-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--accent-light); color: var(--accent);
  font-size: 16px; cursor: pointer; flex-shrink: 0;
  transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.cf-mic-btn:hover { background: var(--accent); color: white; }
.cf-mic-btn.recording { background: var(--danger); color: white; animation: pulse 0.8s infinite; }
.cf-mic-btn.processing { background: var(--warning); color: white; }

.cf-text-input {
  flex: 1; border: 1.5px solid var(--border); border-radius: var(--radius-pill);
  padding: 10px 16px; font-family: var(--font); font-size: 14px;
  color: var(--text); outline: none; background: var(--bg);
  transition: border-color 0.2s;
}
.cf-text-input:focus { border-color: var(--accent); background: white; }
.cf-text-input::placeholder { color: var(--text-subtle); }

.cf-send-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--accent); color: white;
  font-size: 14px; cursor: pointer; flex-shrink: 0;
  transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.cf-send-btn:hover { background: var(--accent-dark); transform: scale(1.05); }
.cf-send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* AUDIT SECTION */
.cf-audit-section {
  display: flex; flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}

.cf-audit-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.cf-audit-header h2 { font-size: 15px; font-weight: 700; color: var(--text); }
.cf-view-all-btn {
  font-size: 12px; font-weight: 600; color: var(--accent);
  background: var(--accent-light); border: none;
  padding: 5px 12px; border-radius: var(--radius-pill);
  cursor: pointer; font-family: var(--font);
  transition: all 0.2s;
}
.cf-view-all-btn:hover { background: var(--accent); color: white; }

/* Current field being captured */
.cf-audit-current {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  min-height: 80px; flex-shrink: 0;
}
.cf-audit-empty {
  font-size: 13px; color: var(--text-subtle);
  text-align: center; padding: 16px 0; font-style: italic;
}
.cf-current-card {
  background: var(--accent-light);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  animation: slideIn 0.3s ease;
}
.cf-current-label {
  font-size: 10px; font-weight: 700; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 4px;
}
.cf-current-value { font-size: 14px; font-weight: 600; color: var(--text); }

/* Captured fields */
.cf-audit-fields {
  flex: 1; overflow-y: auto; padding: 12px 20px;
  display: flex; flex-direction: column; gap: 8px;
}
.cf-audit-fields::-webkit-scrollbar { width: 4px; }
.cf-audit-fields::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.cf-field-card {
  background: var(--bg); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 10px 12px;
  animation: slideIn 0.3s ease;
}
.cf-field-card.verified { border-left-color: var(--success); }
.cf-field-card.warning { border-left-color: var(--warning); }
.cf-field-card.blocked { border-left-color: var(--danger); }

.cf-field-label {
  font-size: 10px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 3px;
}
.cf-field-value { font-size: 13px; font-weight: 500; color: var(--text); }
.cf-field-badge {
  display: inline-block; font-size: 10px; font-weight: 600;
  padding: 2px 8px; border-radius: var(--radius-pill);
  margin-top: 4px;
}
.cf-field-badge.success { background: #D1FAE5; color: var(--success); }
.cf-field-badge.warning { background: #FEF3C7; color: var(--warning); }
.cf-field-badge.danger { background: #FEE2E2; color: var(--danger); }

/* Audit actions */
.cf-audit-actions {
  padding: 12px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; flex-shrink: 0;
}
.cf-submit-btn {
  flex: 1; padding: 10px; border: none; border-radius: var(--radius-sm);
  background: var(--accent); color: white;
  font-size: 13px; font-weight: 600; font-family: var(--font);
  cursor: pointer; transition: all 0.2s;
}
.cf-submit-btn:hover:not(:disabled) { background: var(--accent-dark); }
.cf-submit-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.cf-new-btn {
  padding: 10px 16px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); background: white;
  font-size: 13px; font-weight: 600; font-family: var(--font);
  color: var(--text-muted); cursor: pointer; transition: all 0.2s;
}
.cf-new-btn:hover { border-color: var(--accent); color: var(--accent); }
.cf-end-btn {
  padding: 10px 16px;
  border: 1.5px solid var(--danger);
  border-radius: var(--radius-sm);
  background: white; color: var(--danger);
  font-size: 13px; font-weight: 600;
  font-family: var(--font); cursor: pointer;
  transition: all 0.2s;
}
.cf-end-btn:hover { background: var(--danger); color: white; }

/* Confirmation card */
.cf-confirmation {
  margin: 12px 20px; padding: 16px;
  background: #F0FDF4; border: 1px solid #BBF7D0;
  border-radius: var(--radius); text-align: center;
}
.cf-confirmation-check {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--success); color: white;
  font-size: 24px; display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px;
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.cf-confirmation h3 { font-size: 16px; font-weight: 700; color: var(--success); margin-bottom: 4px; }
.cf-confirmation-id {
  font-size: 13px; font-weight: 700; color: var(--text);
  background: white; border: 1px solid var(--border);
  padding: 4px 12px; border-radius: var(--radius-pill);
  display: inline-block; margin: 8px 0; font-family: monospace;
}
.cf-confirmation p { font-size: 12px; color: var(--text-muted); }

/* Priority badge colors */
.priority-5 { background: #FEE2E2; color: #991B1B; }
.priority-4 { background: #FEF3C7; color: #92400E; }
.priority-3 { background: #FFF7ED; color: #C2410C; }
.priority-2 { background: #F0FDF4; color: #166534; }
.priority-1 { background: #F8FAFC; color: #475569; }

/* MODAL */
.cf-modal, .cf-status-modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.cf-modal-content {
  background: white; border-radius: var(--radius);
  width: 100%; max-width: 600px; max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.cf-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.cf-modal-header h2 { font-size: 16px; font-weight: 700; }
.cf-modal-close, .cf-status-modal-close {
  background: none; border: none; font-size: 18px;
  cursor: pointer; color: var(--text-muted); padding: 4px;
}
.cf-modal-body {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 10px;
}

/* Status check inputs */
#cf-claim-id-input {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-family: var(--font);
  font-size: 14px; outline: none; margin-bottom: 10px;
}
#cf-claim-id-input:focus { border-color: var(--accent); }
#cf-check-status-btn {
  width: 100%; padding: 10px; background: var(--accent); color: white;
  border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; font-family: var(--font);
  cursor: pointer;
}

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: translateX(0); } }
@keyframes popIn { from { transform: scale(0); } to { transform: scale(1); } }

/* MOBILE RESPONSIVE */
@media (max-width: 768px) {
  body { overflow: auto; }

  /* Header */
  .cf-header {
    height: 56px;
    justify-content: flex-start;
    gap: 10px;
  }
  .cf-header-right {
    margin-left: auto;
    display: flex; align-items: center; gap: 8px;
  }
  #cf-logo { max-height: 32px; height: 32px; }
  .cf-header-center .cf-subtitle { display: none; }
  .cf-title { font-size: 16px; }
  .cf-history-nav-btn { padding: 6px 10px; font-size: 11px; }

  /* Main layout */
  .cf-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    height: auto; overflow: auto;
    margin-top: 56px;
  }
  .cf-chat-section {
    height: 55vh; border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .cf-audit-section {
    height: auto; min-height: unset;
    max-height: 45vh; overflow-y: auto;
  }

  /* Suggestion chips — single scrollable row */
  .cf-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 10px 12px;
    gap: 8px;
  }
  .cf-chips::-webkit-scrollbar { display: none; }
  .cf-chip {
    flex-shrink: 0;
    font-size: 12px;
    padding: 6px 12px;
  }

  /* Input bar */
  .cf-mic-btn, .cf-send-btn { width: 36px; height: 36px; }
  .cf-text-input { font-size: 16px; }

  /* Audit panel */
  .cf-audit-current { min-height: 60px; }
  .cf-audit-fields { max-height: 200px; overflow-y: auto; }
  .cf-audit-actions {
    position: sticky;
    bottom: 0;
    background: white;
    border-top: 1px solid var(--border);
    padding: 10px 12px;
    z-index: 10;
    flex-wrap: wrap;
  }
  .cf-audit-actions .cf-submit-btn,
  .cf-audit-actions .cf-new-btn,
  .cf-audit-actions .cf-end-btn {
    font-size: 12px;
    padding: 9px 10px;
  }

  /* Confirmation card */
  .cf-confirmation { padding: 12px; margin: 10px 12px; }
  .cf-confirmation h3 { font-size: 14px; }
  .cf-confirmation-id { font-size: 11px; padding: 3px 10px; }
  .cf-confirmation p { font-size: 11px; }

  /* Modals — full screen */
  .cf-modal, .cf-status-modal { padding: 0; }
  .cf-modal-content {
    width: 100%; height: 100%;
    max-width: 100%; max-height: 100vh;
    border-radius: 0;
  }
  .cf-modal-close, .cf-status-modal-close {
    width: 44px; height: 44px;
    font-size: 20px;
    display: flex; align-items: center; justify-content: center;
  }
}

@media (max-width: 600px) {
  .cf-powered { display: none; }
}

@media (max-width: 480px) {
  .cf-header { padding: 0 12px; }
  #cf-logo { height: 28px; }
  .cf-chips { padding: 8px 12px; }
  .cf-chip { font-size: 11px; padding: 5px 10px; }

  .cf-history-nav-btn {
    font-size: 0;
    width: 32px; height: 32px;
    padding: 0;
    display: flex; align-items: center; justify-content: center;
  }
  .cf-history-nav-btn::before {
    content: "📋";
    font-size: 16px;
  }
}

/* CLAIMS HISTORY PAGE */
body.cf-history-mode { overflow-y: auto; height: auto; }

.cf-history-page {
  padding: 80px 24px 40px;
  max-width: 1400px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
}
.cf-history-header {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 24px; flex-wrap: wrap;
}
.cf-history-header h2 { font-size: 20px; font-weight: 700; flex: 1; }
.cf-history-filters { display: flex; gap: 8px; }
.cf-filter-btn {
  padding: 6px 14px; border-radius: var(--radius-pill);
  border: 1.5px solid var(--border);
  background: white; color: var(--text-muted);
  font-size: 12px; font-weight: 600; cursor: pointer;
  font-family: var(--font); transition: all 0.2s;
}
.cf-filter-btn.active, .cf-filter-btn:hover {
  border-color: var(--accent); color: var(--accent);
  background: var(--accent-light);
}
.cf-back-btn {
  padding: 8px 16px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: white; color: var(--text-muted);
  font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: var(--font); transition: all 0.2s;
}
.cf-back-btn:hover { border-color: var(--accent); color: var(--accent); }
.cf-current-session-card {
  background: #FFF7ED; border: 1.5px solid var(--warning);
  border-radius: var(--radius); padding: 16px 20px;
  margin-bottom: 20px;
}
.cf-current-session-label {
  font-size: 11px; font-weight: 700; color: var(--warning);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 8px;
}
.cf-history-table-wrap {
  background: white; border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow-x: auto; box-shadow: var(--shadow);
}
.cf-history-table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.cf-history-table th {
  padding: 12px 16px; text-align: left;
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: var(--bg); white-space: nowrap;
}
.cf-history-table td {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  color: var(--text); vertical-align: middle;
}
.cf-history-table tr:last-child td { border-bottom: none; }
.cf-history-table tr:hover td { background: var(--bg); }
.cf-status-badge {
  display: inline-block; padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 700;
  white-space: nowrap;
}
.cf-status-badge.submitted { background: #D1FAE5; color: var(--success); }
.cf-status-badge.blocked_not_found,
.cf-status-badge.blocked_expired,
.cf-status-badge.blocked_lapsed,
.cf-status-badge.blocked_uncovered { background: #FEE2E2; color: var(--danger); }
.cf-status-badge.blocked_fraud { background: #FEF3C7; color: var(--warning); }
.cf-status-badge.abandoned { background: #F1F5F9; color: var(--text-muted); }
.cf-status-badge.in_progress { background: #EFF6FF; color: var(--accent); }
.cf-view-detail-btn {
  padding: 5px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: white;
  font-size: 11px; font-weight: 600; cursor: pointer;
  font-family: var(--font); color: var(--text-muted);
  transition: all 0.2s;
}
.cf-view-detail-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Mobile responsive for history page */
@media (max-width: 768px) {
  .cf-history-page { padding: 72px 12px 40px; }
  .cf-history-header { flex-direction: column; align-items: flex-start; }
  .cf-history-table { font-size: 11px; }
  .cf-history-table th, .cf-history-table td { padding: 8px 10px; }
}

/* History table -> stacked cards on small screens */
@media (max-width: 600px) {
  .cf-history-table thead { display: none; }
  .cf-history-table, .cf-history-table tbody, .cf-history-table tr, .cf-history-table td {
    display: block; width: 100%;
  }
  .cf-history-table tr {
    margin-bottom: 12px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
  }
  .cf-history-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding: 6px 0;
    font-size: 12px;
  }
  .cf-history-table td:last-child { border-bottom: none; }
  .cf-history-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
  }
}
