/* AdaptUs CRM - Mobile-First Design System */
:root {
  --bg-primary: #0F172A;
  --bg-surface: #1E293B;
  --bg-surface-2: #334155;
  --bg-elevated: #475569;
  --accent: #3B82F6;
  --accent-hover: #2563EB;
  --accent-glow: rgba(59, 130, 246, 0.25);
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --text-primary: #FFFFFF;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;
  --border: rgba(148, 163, 184, 0.15);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --header-h: 56px;
  --nav-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 100vw;
}

/* Header */
.app-header {
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0 12px;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}
.app-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.icon-btn {
  width: 40px;
  height: 40px;
  background: transparent;
  border: 0;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  transition: background 150ms;
}
.icon-btn:active { background: var(--bg-surface); }

/* Main view */
#view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom));
  background: var(--bg-primary);
}

/* Bottom nav */
.bottom-nav {
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(15, 23, 42, 0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
}
.nav-btn {
  background: transparent;
  border: 0;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  padding: 8px 0;
  transition: color 150ms;
}
.nav-btn.active { color: var(--accent); }
.nav-btn[data-view="add"] {
  color: var(--accent);
}
.nav-btn[data-view="add"] svg { background: var(--accent); border-radius: var(--radius-full); padding: 6px; color: white; }

/* Drawer */
.drawer {
  position: fixed;
  top: 0;
  left: -280px;
  width: 280px;
  height: 100%;
  background: var(--bg-surface);
  z-index: 200;
  transition: left 250ms ease;
  padding: calc(var(--safe-top) + 16px) 16px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.drawer.open { left: 0; box-shadow: var(--shadow-md); }
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer-header { padding-bottom: 16px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.drawer-header h2 { font-size: 18px; font-weight: 600; }
.drawer-header p { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.drawer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: transparent;
  border: 0;
  color: var(--text-primary);
  padding: 14px 12px;
  text-align: left;
  font-size: 15px;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background 150ms;
  margin-bottom: 4px;
}
.drawer-item:active { background: var(--bg-surface-2); }
.drawer-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

/* Common */
.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  padding: 16px 16px 8px;
}
.empty {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-secondary);
}
.empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  background: var(--bg-surface);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.empty-title { font-size: 17px; font-weight: 600; color: var(--text-primary); margin-bottom: 8px; }
.empty-text { font-size: 14px; color: var(--text-secondary); margin-bottom: 24px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms, transform 100ms;
}
.btn:active { background: var(--accent-hover); transform: scale(0.98); }
.btn-secondary {
  background: transparent;
  border: 1px solid var(--bg-surface-2);
  color: var(--text-primary);
}
.btn-secondary:active { background: var(--bg-surface-2); }
.btn-danger { background: var(--danger); }
.btn-block { display: flex; width: 100%; }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  left: 16px;
  right: 16px;
  background: var(--bg-elevated);
  color: white;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  z-index: 300;
  transform: translateY(100px);
  opacity: 0;
  transition: all 250ms ease;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 250;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 200ms;
}
.modal {
  background: var(--bg-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  animation: slideUp 250ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--bg-surface-2);
  border-radius: var(--radius-full);
  margin: 0 auto 16px;
}
.modal-title { font-size: 18px; font-weight: 600; margin-bottom: 16px; }
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.form-input, .form-textarea, .form-select {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--bg-surface-2);
  color: var(--text-primary);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-family: inherit;
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-textarea { min-height: 80px; resize: vertical; }
.form-row { display: flex; gap: 8px; }
.form-row > * { flex: 1; }

/* Today view */
.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 16px;
}
.stat-card {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  border: 1px solid var(--border);
}
.stat-num { font-size: 24px; font-weight: 700; line-height: 1; margin-bottom: 4px; }
.stat-num.due { color: var(--warning); }
.stat-num.overdue { color: var(--danger); }
.stat-label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }

/* Contact list */
.contact-list { padding: 0; }
.contact-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 0;
  border-bottom: 1px solid var(--border);
  width: 100%;
  text-align: left;
  cursor: pointer;
  color: var(--text-primary);
  transition: background 150ms;
}
.contact-card:active { background: var(--bg-surface-2); }
.contact-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
  color: var(--accent);
}
.contact-info { flex: 1; min-width: 0; }
.contact-name { font-size: 15px; font-weight: 600; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-meta { font-size: 13px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.status-dot.new { background: var(--text-muted); }
.status-dot.contacted { background: var(--accent); }
.status-dot.meeting { background: var(--warning); }
.status-dot.proposal { background: #8b5cf6; }
.status-dot.closed { background: var(--success); }
.status-dot.lost { background: var(--danger); }

.contact-quick-actions { display: flex; gap: 4px; }
.quick-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: var(--bg-primary);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.quick-btn:active { background: var(--bg-surface-2); }
.quick-btn.wa { color: #25D366; }
.quick-btn.email { color: var(--accent); }

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  overflow-x: auto;
  background: var(--bg-primary);
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--border);
}
.filter-chip {
  padding: 6px 14px;
  background: var(--bg-surface);
  border: 0;
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.filter-chip.active { background: var(--accent); color: white; }

/* Contact detail */
.detail-header {
  background: linear-gradient(135deg, var(--bg-surface) 0%, var(--bg-surface-2) 100%);
  padding: 24px 20px;
  text-align: center;
}
.detail-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--bg-primary);
  margin: 0 auto 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}
.detail-name { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.detail-company { font-size: 14px; color: var(--text-secondary); margin-bottom: 12px; }
.detail-status {
  display: inline-block;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-primary);
}
.detail-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 16px;
}
.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 8px;
  color: var(--text-primary);
  cursor: pointer;
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  transition: background 150ms;
}
.action-btn:active { background: var(--bg-surface-2); }
.action-btn.call { color: var(--accent); }
.action-btn.wa { color: #25D366; }
.action-btn.email { color: var(--warning); }
.action-btn.log { color: var(--success); }

/* Detail sections */
.detail-section {
  background: var(--bg-surface);
  margin: 8px 0;
  padding: 16px 20px;
}
.detail-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.detail-row:last-child { border-bottom: 0; }
.detail-row-label { color: var(--text-secondary); }
.detail-row-value { color: var(--text-primary); font-weight: 500; }

/* Timeline */
.timeline-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: 0; }
.timeline-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
}
.timeline-body { flex: 1; }
.timeline-title { font-size: 14px; font-weight: 500; margin-bottom: 2px; }
.timeline-meta { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.timeline-notes { font-size: 13px; color: var(--text-secondary); }

/* Pipeline */
.kanban {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 16px;
  height: calc(100vh - var(--header-h) - var(--nav-h) - var(--safe-top) - var(--safe-bottom));
  scroll-snap-type: x mandatory;
}
.kanban-col {
  flex: 0 0 280px;
  scroll-snap-align: start;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  max-height: 100%;
}
.kanban-col-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.kanban-col-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.kanban-col-count { background: var(--bg-primary); color: var(--text-secondary); padding: 2px 8px; border-radius: var(--radius-full); font-size: 11px; font-weight: 600; }
.kanban-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kanban-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
}
.kanban-card-name { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.kanban-card-meta { font-size: 11px; color: var(--text-secondary); }

/* Search overlay */
.search-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 250;
  padding: calc(var(--safe-top) + 8px) 16px 16px;
  transform: translateY(-100%);
  transition: transform 200ms;
}
.search-overlay.open { transform: translateY(0); }
.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-surface);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}
.search-input { flex: 1; background: transparent; border: 0; color: var(--text-primary); font-size: 16px; outline: none; }
.search-input::placeholder { color: var(--text-muted); }
.search-results { display: flex; flex-direction: column; }
.search-results .contact-card { background: var(--bg-surface); border-bottom: 0; margin-bottom: 4px; border-radius: var(--radius-md); }

/* Back button */
.back-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  background: rgba(0,0,0,0.3);
  border: 0;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.back-btn svg { stroke-width: 2.5; }

/* Intent badge */
.intent-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
}
.intent-badge.hot { background: rgba(239, 68, 68, 0.2); color: var(--danger); }
.intent-badge.warm { background: rgba(245, 158, 11, 0.2); color: var(--warning); }
.intent-badge.cold { background: rgba(148, 163, 184, 0.2); color: var(--text-secondary); }
.intent-badge.none { background: rgba(148, 163, 184, 0.1); color: var(--text-muted); }

/* Signal chips */
.signal-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.signal {
  display: inline-block;
  padding: 4px 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 12px;
  color: var(--text-secondary);
}
.signal.high { background: rgba(245, 158, 11, 0.15); color: var(--warning); border-color: rgba(245, 158, 11, 0.3); }
.signal-empty { color: var(--text-muted); font-size: 13px; font-style: italic; }

/* Script card */
.script-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  margin: 8px 0;
  padding: 14px 16px;
}
.script-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.script-chips { display: flex; gap: 4px; }
.script-chip {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.script-chip.active { background: var(--accent); color: white; border-color: var(--accent); }
.script-regen {
  background: transparent;
  border: 0;
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 50%;
}
.script-regen:active { background: var(--bg-surface-2); }
.script-body {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-wrap: break-word;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}
.script-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.script-actions .btn { flex: 1; min-width: 0; padding: 8px 12px; font-size: 13px; text-decoration: none; }

/* Empty timeline */
.empty-timeline { color: var(--text-muted); font-size: 13px; font-style: italic; padding: 16px 0; }

/* Modal tweaks */
.form-row.tight { gap: 6px; }
.form-row.tight .btn { padding: 8px 12px; font-size: 13px; }

.outcome-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-bottom: 14px; }
.outcome-btn {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px;
  border-radius: var(--radius-md);
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}
.outcome-btn:active { background: var(--bg-surface-2); }
.outcome-btn.selected { background: var(--accent); color: white; border-color: var(--accent); }

/* Responsive desktop tweaks */
@media (min-width: 768px) {
  body { font-size: 16px; }
  #view { max-width: 720px; margin: 0 auto; }
  .bottom-nav { max-width: 720px; left: 50%; transform: translateX(-50%); }
}