/* TheGrantScout CRM - Mobile-First Styles */
/* Inspired by HubSpot, Pipedrive, and modern CRM best practices */

/* ============================================
   CSS Variables - Clean, Professional Palette
   ============================================ */
:root {
    /* Primary - Warm, trustworthy blue */
    --primary: #3b82f6;
    --primary-light: #eff6ff;
    --primary-dark: #2563eb;
    --primary-hover: #1d4ed8;

    /* Semantic Colors - Softer, less jarring */
    --success: #22c55e;
    --success-light: #dcfce7;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;

    /* Neutral Grays - Warm undertone */
    --gray-50: #fafafa;
    --gray-100: #f5f5f5;
    --gray-200: #e5e5e5;
    --gray-300: #d4d4d4;
    --gray-400: #a3a3a3;
    --gray-500: #737373;
    --gray-600: #525252;
    --gray-700: #404040;
    --gray-800: #262626;
    --gray-900: #171717;
    --white: #ffffff;

    /* Layout */
    --nav-height: 64px;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-full: 9999px;

    /* Shadows - Softer, more subtle */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.04), 0 2px 4px rgba(0, 0, 0, 0.02);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.05), 0 4px 6px rgba(0, 0, 0, 0.03);

    /* Touch targets - 44px minimum (Apple HIG) */
    --touch-target: 44px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
}

/* ============================================
   Reset & Base Typography
   ============================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.6;
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
    font-feature-settings: 'cv11', 'ss01'; /* OpenType features for better numbers */
}

/* Smooth scrolling but respect reduced motion */
@media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
}

/* ============================================
   Navigation - Clean iOS-style tab bar
   ============================================ */
.nav-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: var(--touch-target);
    padding: 8px 4px;
    background: none;
    border: none;
    color: var(--gray-400);
    font-size: 0.625rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    cursor: pointer;
    transition: color var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.nav-btn:active {
    opacity: 0.7;
}

.nav-btn.active {
    color: var(--primary);
}

.nav-icon {
    font-size: 1.5rem;
    margin-bottom: 4px;
    line-height: 1;
}

.nav-label {
    margin-top: 2px;
}

/* ============================================
   Main Content Area
   ============================================ */
#app {
    padding: 20px 16px;
    max-width: 720px;
    margin: 0 auto;
}

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-top: 4px;
}

.view-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.02em;
}

/* ============================================
   Cards - Clean, elevated surfaces
   ============================================ */
.card {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
    margin-bottom: 12px;
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.card h3 {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.card-title {
    font-weight: 600;
    font-size: 1.0625rem;
    color: var(--gray-900);
    line-height: 1.4;
}

.card-subtitle {
    font-size: 0.9375rem;
    color: var(--gray-500);
    margin-top: 3px;
}

.card-meta {
    font-size: 0.8125rem;
    color: var(--gray-400);
    margin-top: 10px;
    line-height: 1.5;
}

.card-meta a {
    color: var(--primary);
    text-decoration: none;
}

/* ============================================
   Prospect Cards - Tappable, clear hierarchy
   ============================================ */
.prospect-card {
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
}

.prospect-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--border-radius);
    box-shadow: 0 0 0 0 var(--primary);
    opacity: 0;
    transition: all var(--transition-normal);
    pointer-events: none;
}

.prospect-card:active {
    transform: scale(0.98);
}

.prospect-card:active::after {
    box-shadow: 0 0 0 3px var(--primary);
    opacity: 0.15;
}

.prospect-phone {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
    color: var(--gray-700);
    margin: 12px 0;
    padding: 10px 14px;
    background: var(--gray-50);
    border-radius: var(--border-radius-sm);
}

.prospect-phone a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.prospect-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

/* ============================================
   Buttons - Large touch targets, clear states
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--touch-target);
    padding: 12px 20px;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover, .btn-primary:active {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-700);
}

.btn-secondary:hover, .btn-secondary:active {
    background: var(--gray-200);
}

.btn-success {
    background: var(--success);
    color: var(--white);
}

.btn-success:hover, .btn-success:active {
    background: #16a34a;
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-danger:hover, .btn-danger:active {
    background: #dc2626;
}

.btn-small {
    min-height: 36px;
    padding: 8px 14px;
    font-size: 0.875rem;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    padding: 10px;
    min-width: var(--touch-target);
}

/* Ghost/Outline buttons */
.btn-ghost {
    background: transparent;
    color: var(--primary);
}

.btn-ghost:hover, .btn-ghost:active {
    background: var(--primary-light);
}

/* ============================================
   Forms - Generous spacing, clear labels
   ============================================ */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 8px;
}

.form-input {
    width: 100%;
    min-height: var(--touch-target);
    padding: 12px 14px;
    border: 1.5px solid var(--gray-300);
    border-radius: var(--border-radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--white);
    color: var(--gray-800);
    transition: all var(--transition-fast);
}

.form-input::placeholder {
    color: var(--gray-400);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-textarea {
    min-height: 120px;
    resize: vertical;
    line-height: 1.6;
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23737373'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-position: right 12px center;
    background-repeat: no-repeat;
    background-size: 18px;
    padding-right: 44px;
}

/* ============================================
   Chips / Selection Pills
   ============================================ */
.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--touch-target);
    padding: 10px 18px;
    border-radius: var(--border-radius-full);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    border: 2px solid var(--gray-200);
    background: var(--white);
    color: var(--gray-600);
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.chip:active {
    transform: scale(0.95);
}

.chip.selected {
    border-color: var(--primary);
    background: var(--primary);
    color: var(--white);
}

.chip:not(.selected):hover {
    border-color: var(--gray-300);
    background: var(--gray-50);
}

/* ============================================
   Status Badges - Clear visual coding
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: var(--border-radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

/* Status badges */
.badge-not_contacted, .badge-not-contacted {
    background: var(--gray-100);
    color: var(--gray-600);
}

.badge-contacted {
    background: #dbeafe;
    color: #1e40af;
}

.badge-interested {
    background: var(--success-light);
    color: #15803d;
}

.badge-converted {
    background: var(--success);
    color: var(--white);
}

.badge-not_interested, .badge-not-interested {
    background: var(--danger-light);
    color: #b91c1c;
}

/* Segment badges */
.badge-nonprofit {
    background: #e0e7ff;
    color: #4338ca;
}

.badge-foundation {
    background: var(--warning-light);
    color: #b45309;
}

.badge-foundation_mgmt {
    background: #f3e8ff;
    color: #7c3aed;
}

/* ============================================
   Filter Bar - Scrollable, clear selection
   ============================================ */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    overflow-x: auto;
    padding: 4px 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.filter-bar::-webkit-scrollbar {
    display: none;
}

.filter-btn {
    min-height: 40px;
    padding: 10px 18px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--border-radius-full);
    background: var(--white);
    font-size: 0.9375rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.filter-btn:active {
    transform: scale(0.95);
}

.filter-btn.active {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

/* Filter Row - Multiple filters in a row */
.filter-row {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.filter-row .filter-select {
    flex: 1;
    min-width: 0;
}

.filter-select {
    min-height: 40px;
    padding: 8px 36px 8px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--border-radius-sm);
    background: var(--white);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--gray-700);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Badge Group - Multiple badges together */
.badge-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

/* State badge */
.badge-state {
    background: var(--gray-100);
    color: var(--gray-700);
    font-weight: 700;
    font-size: 0.6875rem;
    padding: 3px 8px;
    letter-spacing: 0.04em;
}

/* ============================================
   Modals - Full-screen on mobile
   ============================================ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--gray-50);
    z-index: 200;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal.hidden {
    display: none;
}

.modal-content {
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: 100px;
}

.modal-header {
    position: sticky;
    top: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--gray-200);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--gray-900);
}

.back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--primary);
    margin-left: -12px;
    border-radius: var(--border-radius-sm);
    transition: background var(--transition-fast);
}

.back-btn:active {
    background: var(--gray-100);
}

.modal-body {
    padding: 20px 16px;
}

/* ============================================
   Search - Prominent, easy to use
   ============================================ */
.search-container {
    position: relative;
    margin-bottom: 20px;
}

.search-input {
    width: 100%;
    min-height: 50px;
    padding: 14px 14px 14px 48px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--border-radius);
    font-size: 1rem;
    background: var(--white);
    transition: all var(--transition-fast);
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    font-size: 1.25rem;
}

/* Highlighted search results */
mark {
    background: var(--warning-light);
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

/* ============================================
   Import / Drop Zone
   ============================================ */
.drop-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--border-radius);
    padding: 48px 24px;
    text-align: center;
    background: var(--white);
    cursor: pointer;
    transition: all var(--transition-normal);
}

.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.drop-zone-text {
    color: var(--gray-500);
}

.drop-zone-text p:first-child {
    font-size: 1.125rem;
    color: var(--gray-700);
    margin-bottom: 4px;
}

.file-input {
    display: none;
}

/* ============================================
   Dashboard Stats - Clear data visualization
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--border-radius);
    padding: 20px 16px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.stat-value {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.1;
    font-feature-settings: 'tnum';
}

.stat-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--gray-500);
    margin-top: 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* ============================================
   Activity Feed - Timeline style
   ============================================ */
.activity-item {
    display: flex;
    gap: 14px;
    padding: 14px 0;
    border-bottom: 1px solid var(--gray-100);
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-full);
    background: var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
}

.activity-content {
    flex: 1;
    min-width: 0; /* Prevent text overflow */
}

.activity-title {
    font-weight: 600;
    color: var(--gray-800);
    line-height: 1.4;
}

.activity-title a {
    color: var(--primary);
    text-decoration: none;
}

.activity-meta {
    font-size: 0.875rem;
    color: var(--gray-400);
    margin-top: 2px;
}

/* ============================================
   Toast Notifications - Non-intrusive
   ============================================ */
.toast {
    position: fixed;
    bottom: calc(var(--nav-height) + 24px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    background: var(--gray-800);
    color: var(--white);
    padding: 14px 24px;
    border-radius: var(--border-radius);
    font-size: 0.9375rem;
    font-weight: 500;
    z-index: 300;
    box-shadow: var(--shadow-lg);
    animation: toastSlideUp 0.3s ease;
}

.toast.hidden {
    display: none;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

@keyframes toastSlideUp {
    from {
        transform: translate(-50%, 20px);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

/* ============================================
   Loading Overlay
   ============================================ */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 400;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: var(--border-radius-full);
    animation: spin 0.8s linear infinite;
}

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

.loading-inline {
    color: var(--gray-400);
    text-align: center;
    padding: 24px;
}

/* ============================================
   Empty States - Friendly, encouraging
   ============================================ */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    max-width: 320px;
    margin: 0 auto;
}

.empty-state-icon {
    font-size: 3.5rem;
    margin-bottom: 20px;
    line-height: 1;
    opacity: 0.9;
}

.empty-state-title {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--gray-800);
    margin-bottom: 10px;
}

.empty-state p {
    font-size: 1rem;
    color: var(--gray-500);
    line-height: 1.6;
}

/* ============================================
   Utility Classes
   ============================================ */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* ============================================
   Desktop Enhancements (768px+)
   ============================================ */
@media (min-width: 768px) {
    .nav-bar {
        top: 0;
        bottom: auto;
        border-top: none;
        border-bottom: 1px solid var(--gray-200);
        padding-bottom: 0;
    }

    body {
        padding-top: var(--nav-height);
        padding-bottom: 0;
    }

    #app {
        padding: 32px 24px;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .card {
        padding: 20px 24px;
    }

    /* Hover states for desktop */
    .prospect-card:hover {
        box-shadow: var(--shadow-md);
    }

    .btn:hover {
        transform: translateY(-1px);
    }

    .chip:hover {
        transform: none;
    }

    /* Toast position on desktop */
    .toast {
        bottom: 32px;
    }
}

/* ============================================
   Dark Mode Support (opt-in via preference)
   ============================================ */
@media (prefers-color-scheme: dark) {
    /* Future: Add dark mode variables here */
}

/* ============================================
   Reduced Motion - Accessibility
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .nav-bar, .modal, .toast, .loading {
        display: none !important;
    }

    body {
        padding: 0;
        background: white;
    }
}
