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

:root {
    --ink: #0a0a0a;
    --paper: #fafaf8;
    --accent: #1a5cff;
    --accent-hover: #1248d4;
    --accent-light: #e8eeff;
    --gray-50: #fafaf9;
    --gray-100: #f5f5f3;
    --gray-200: #e8e8e4;
    --gray-300: #d4d4cf;
    --gray-400: #9a9a94;
    --gray-600: #5a5a56;
    --warm: #ff6b35;
    --green: #22c55e;
    --green-light: #dcfce7;
    --red: #ef4444;
    --red-light: #fee2e2;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.08);
}

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--gray-100);
    color: var(--ink);
    line-height: 1.6;
    min-height: 100vh;
}

/* ============ Auth ============ */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--paper);
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
}

.auth-logo {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--ink);
    text-decoration: none;
    display: block;
    margin-bottom: 48px;
    letter-spacing: -0.5px;
}

.auth-card h2 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -1px;
    margin-bottom: 6px;
}

.auth-sub {
    color: var(--gray-400);
    margin-bottom: 32px;
    font-size: 0.95rem;
}

.auth-switch {
    margin-top: 24px;
    text-align: center;
    font-size: 0.9rem;
    color: var(--gray-600);
}

.auth-switch a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

/* ============ Forms ============ */
.form-group {
    margin-bottom: 20px;
}

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

.form-group input,
.icp-textarea,
.select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.95rem;
    color: var(--ink);
    background: white;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.form-group input:focus,
.icp-textarea:focus,
.select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-group input::placeholder,
.icp-textarea::placeholder {
    color: var(--gray-400);
}

.form-error {
    background: var(--red-light);
    color: var(--red);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: 16px;
}

/* ============ Buttons ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

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

.btn-accent:hover:not(:disabled) {
    background: #e55d2d;
}

.btn-ghost {
    background: transparent;
    color: var(--gray-600);
    border: 1px solid var(--gray-200);
}

.btn-ghost:hover:not(:disabled) {
    background: var(--gray-100);
    border-color: var(--gray-300);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.82rem;
}

.btn-full {
    width: 100%;
}

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

.btn-success:hover:not(:disabled) {
    background: #1ea74e;
}

/* ============ App Nav ============ */
.app-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    height: 64px;
    background: white;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-nav-left {
    display: flex;
    align-items: center;
}

.app-logo {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1.3rem;
    color: var(--ink);
    text-decoration: none;
    letter-spacing: -0.5px;
}

.app-nav-tabs {
    display: flex;
    gap: 4px;
}

.nav-tab {
    padding: 8px 16px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-600);
    cursor: pointer;
    transition: all 0.15s;
}

.nav-tab:hover {
    color: var(--ink);
    background: var(--gray-100);
}

.nav-tab.active {
    color: var(--accent);
    background: var(--accent-light);
    font-weight: 600;
}

.app-nav-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-email {
    font-size: 0.85rem;
    color: var(--gray-400);
}

/* ============ Main Content ============ */
.app-main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px;
}

.view-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
}

.view-header h1 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -1px;
    margin-bottom: 4px;
}

.view-header p {
    color: var(--gray-400);
    font-size: 0.95rem;
}

.view-header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.section-heading {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.3px;
    margin-bottom: 16px;
    color: var(--ink);
}

/* ============ Stats ============ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 40px;
}

.stat-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
}

.stat-value {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--ink);
    letter-spacing: -1px;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.82rem;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* ============ Empty State ============ */
.empty-state {
    text-align: center;
    padding: 80px 24px;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
}

.empty-icon {
    color: var(--gray-300);
    margin-bottom: 20px;
}

.empty-state h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: -0.3px;
}

.empty-state p {
    color: var(--gray-400);
    max-width: 400px;
    margin: 0 auto 24px;
    font-size: 0.95rem;
}

/* ============ ICP ============ */
.icp-form-wrap {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 24px;
}

.icp-textarea {
    min-height: 140px;
    resize: vertical;
    margin-bottom: 16px;
    line-height: 1.7;
}

.icp-actions {
    display: flex;
    gap: 12px;
}

.icp-criteria {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 28px;
}

.icp-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.icp-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--gray-100);
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--gray-600);
}

.icp-tag .tag-label {
    font-weight: 600;
    color: var(--ink);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============ Leads Grid ============ */
.leads-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.lead-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 24px;
    transition: box-shadow 0.15s;
}

.lead-card:hover {
    box-shadow: var(--shadow);
}

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

.lead-name {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 1.05rem;
    letter-spacing: -0.3px;
}

.lead-title {
    color: var(--gray-600);
    font-size: 0.875rem;
    margin-bottom: 4px;
}

.lead-company {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--ink);
    margin-bottom: 8px;
}

.lead-description {
    font-size: 0.85rem;
    color: var(--gray-400);
    line-height: 1.5;
    margin-bottom: 12px;
}

.lead-match {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
}

.lead-match.high {
    background: var(--green-light);
    color: #166534;
}

.lead-match.medium {
    background: #fef3c7;
    color: #92400e;
}

.lead-reason {
    font-size: 0.82rem;
    color: var(--gray-400);
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--gray-100);
    font-style: italic;
}

.lead-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

/* ============ Campaigns List ============ */
.campaigns-list {
    display: grid;
    gap: 12px;
}

.campaign-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: box-shadow 0.15s;
}

.campaign-card:hover {
    box-shadow: var(--shadow-sm);
}

.campaign-info h4 {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: -0.2px;
}

.campaign-info p {
    font-size: 0.82rem;
    color: var(--gray-400);
    margin-top: 2px;
}

.campaign-stats {
    display: flex;
    gap: 20px;
}

.campaign-stat {
    text-align: center;
}

.campaign-stat-value {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--ink);
}

.campaign-stat-label {
    font-size: 0.72rem;
    color: var(--gray-400);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============ Emails List ============ */
.emails-list {
    display: grid;
    gap: 12px;
}

.email-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: box-shadow 0.15s;
}

.email-card:hover {
    box-shadow: var(--shadow-sm);
}

.email-info {
    flex: 1;
    min-width: 0;
}

.email-to {
    font-size: 0.82rem;
    color: var(--gray-400);
    margin-bottom: 2px;
}

.email-subject {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-preview-text {
    font-size: 0.85rem;
    color: var(--gray-400);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.email-status {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    margin-left: 16px;
}

.email-status.draft {
    background: var(--gray-100);
    color: var(--gray-600);
}

.email-status.sent {
    background: var(--green-light);
    color: #166534;
}

/* ============ Modal ============ */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
    backdrop-filter: blur(2px);
}

.modal-content {
    background: white;
    border-radius: var(--radius);
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: -0.3px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--gray-400);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--ink);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.email-meta {
    margin-bottom: 20px;
}

.email-meta-row {
    display: flex;
    gap: 8px;
    padding: 6px 0;
    font-size: 0.9rem;
}

.email-meta-label {
    color: var(--gray-400);
    min-width: 60px;
}

.email-body-text {
    font-size: 0.95rem;
    line-height: 1.8;
    color: var(--gray-600);
    white-space: pre-wrap;
}

/* ============ Toast ============ */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 24px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 2000;
    animation: slideIn 0.3s ease;
    box-shadow: var(--shadow-lg);
}

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

.toast.error {
    background: var(--red);
    color: white;
}

@keyframes slideIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ============ Loading ============ */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(250, 250, 248, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    backdrop-filter: blur(4px);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

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

#loading-text {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.95rem;
    color: var(--gray-600);
    font-weight: 500;
}

/* ============ Select ============ */
.select {
    width: auto;
    min-width: 180px;
    padding: 8px 12px;
    font-size: 0.85rem;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239a9a94' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
    .app-nav {
        flex-direction: column;
        height: auto;
        padding: 16px;
        gap: 12px;
    }

    .app-nav-tabs {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .app-nav-right {
        width: 100%;
        justify-content: space-between;
    }

    .app-main {
        padding: 20px 16px;
    }

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

    .leads-grid {
        grid-template-columns: 1fr;
    }

    .view-header {
        flex-direction: column;
        gap: 12px;
    }

    .view-header-actions {
        width: 100%;
    }
}
