/* ==========================================================================
   Modern Pages — Target Pipeline v2
   Tables, Forms, Buttons, Badges, Cards, Modals
   Based on style_guide.md
   ========================================================================== */

/* ---------- Base Reset & Globals ---------- */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    color: #334155;
    background: #f8fafc;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: #2563eb;
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: #1d4ed8;
}

/* ---------- Page Layout ---------- */
.page-content {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.page-title {
    font-size: 28px;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
}

.page-subtitle {
    font-size: 14px;
    color: #64748b;
    margin-top: 4px;
}

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

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 500;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    padding: 10px 20px;
    text-decoration: none;
    line-height: 1.4;
}

.btn-primary,
input[type="submit"].btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
    color: white;
}

.btn-secondary,
input[type="button"].btn-secondary {
    background: #f1f5f9;
    color: #475569;
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.btn-outline {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    color: #475569;
    padding: 10px 16px;
    border-radius: 8px;
}

.btn-outline:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.btn-danger {
    background: #fef2f2;
    color: #dc2626;
}

.btn-danger:hover {
    background: #fee2e2;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 8px;
}

.btn-icon {
    padding: 8px;
    border-radius: 8px;
    background: transparent;
    color: #64748b;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-icon:hover {
    background: #f1f5f9;
    color: #1e293b;
}

/* ---------- Filter Toggle Button ---------- */
.filter-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 500;
    color: #475569;
    cursor: pointer;
    transition: all 0.15s ease;
}

.filter-toggle-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.filter-toggle-btn.active {
    background: #eff6ff;
    border-color: #3b82f6;
    color: #2563eb;
}

/* ---------- Form Elements ---------- */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="number"],
input[type="date"],
textarea,
select {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    padding: 12px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #ffffff;
    color: #334155;
    transition: all 0.15s ease;
    width: 100%;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

input::placeholder,
textarea::placeholder {
    color: #94a3b8;
}

label {
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 500;
    color: #64748b;
    display: block;
    margin-bottom: 6px;
}

.form-group {
    margin-bottom: 16px;
}

.form-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 200px;
}

/* ---------- Search Input with Icon ---------- */
.search-input-wrapper {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.search-input-wrapper i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
}

.search-input-wrapper input {
    width: 100%;
    padding: 12px 16px 12px 42px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 14px;
    background: #ffffff;
}

/* ---------- Filters Container ---------- */
.filters-container {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 24px 24px 16px 24px;
    margin: 16px 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    margin-bottom: 0;
}

.filter-group select,
.filter-group input {
    min-width: 160px;
    padding: 8px 12px;
    font-size: 13px;
    border-radius: 8px;
}

/* ---------- Tables ---------- */
.table-container {
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.table-container table {
    width: 100%;
    border-collapse: collapse;
}

.table-container th {
    background: #ffffff;
    color: #64748b;
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 14px 20px;
    border: none;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
    white-space: nowrap;
}

.table-container th a {
    color: #64748b;
    text-decoration: none;
}

.table-container th a:hover {
    color: #1e293b;
}

.table-container tbody tr {
    background: #ffffff;
    transition: all 0.15s ease;
    border-bottom: 1px solid #f1f5f9;
}

.table-container tbody tr:hover {
    background: #f8fafc;
}

.table-container tbody tr:last-child {
    border-bottom: none;
}

.table-container td {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    color: #334155;
    padding: 14px 20px;
    vertical-align: middle;
}

.table-container td a {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.15s ease;
}

.table-container td a:hover {
    color: #1d4ed8;
}

/* ---------- Cards ---------- */
.card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: #1e293b;
    margin: 0;
}

.card-body {
    color: #334155;
}

/* ---------- Stat Cards ---------- */
.stats-row {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.stat-card {
    flex: 1;
    min-width: 180px;
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    border: 1px solid #e5e7eb;
}

.stat-card .stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    margin-bottom: 12px;
}

.stat-card .stat-icon.blue {
    background: #eff6ff;
    color: #3b82f6;
}

.stat-card .stat-icon.green {
    background: #f0fdf4;
    color: #22c55e;
}

.stat-card .stat-icon.orange {
    background: #fff7ed;
    color: #f97316;
}

.stat-card .stat-icon.purple {
    background: #faf5ff;
    color: #a855f7;
}

.stat-card .stat-label {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 8px;
    font-weight: 500;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #1e293b;
}

.stat-card .stat-value.currency {
    color: #059669;
}

/* ---------- Badges & Tags ---------- */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 500;
}

.badge-success {
    background: #f0fdf4;
    color: #15803d;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fef2f2;
    color: #dc2626;
}

.badge-info {
    background: #eff6ff;
    color: #1d4ed8;
}

.badge-orange {
    background: #fff7ed;
    color: #c2410c;
}

.tag-badge {
    display: inline-block;
    margin: 2px 4px 2px 0;
    padding: 3px 8px;
    background: #e0f2fe;
    color: #0369a1;
    font-size: 11px;
    border-radius: 4px;
    font-weight: 500;
}

.campaign-badge {
    display: inline-block;
    margin: 2px 4px 2px 0;
    padding: 3px 8px;
    background: #f0fdf4;
    color: #15803d;
    font-size: 11px;
    border-radius: 4px;
    font-weight: 500;
}

/* ---------- Grade Badge (Circular) ---------- */
.grade-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 14px;
    font-weight: 700;
}

.grade-badge.grade-a { background: #d1fae5; color: #065f46; }
.grade-badge.grade-b { background: #dbeafe; color: #1e40af; }
.grade-badge.grade-c { background: #fef3c7; color: #92400e; }
.grade-badge.grade-d { background: #fee2e2; color: #991b1b; }

/* ---------- Stage Badge (Pill) ---------- */
.stage-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}

.stage-badge.stage-prospect { background: #dbeafe; color: #1e40af; }
.stage-badge.stage-inprocess { background: #fef3c7; color: #92400e; }
.stage-badge.stage-forecasted { background: #e0e7ff; color: #4338ca; }
.stage-badge.stage-evaluation { background: #fff7ed; color: #c2410c; }
.stage-badge.stage-won { background: #d1fae5; color: #065f46; }
.stage-badge.stage-lost { background: #fee2e2; color: #991b1b; }
.stage-badge.stage-cancelled { background: #f1f5f9; color: #64748b; }

/* ---------- Signal Badge ---------- */
.signal-badge {
    display: inline-block;
    margin: 2px 4px 2px 0;
    padding: 3px 8px;
    font-size: 11px;
    border-radius: 4px;
    font-weight: 500;
    white-space: nowrap;
}

.signal-badge.signal-warning {
    background: #fff3cd;
    color: #856404;
}

.signal-badge.signal-danger {
    background: #f8d7da;
    color: #721c24;
}

/* ---------- Modals ---------- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    border: none;
    background: #ffffff;
    padding: 0;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h2 {
    font-family: 'Inter', sans-serif;
    font-size: 18px;
    font-weight: 600;
    color: #1e293b;
    margin: 0;
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid #f1f5f9;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ---------- Loading Overlay ---------- */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    z-index: 9998;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
}

.loading-overlay.active {
    display: flex;
}

.loading-overlay .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-overlay .loading-text {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    color: #64748b;
    font-weight: 500;
}

/* ---------- Tabs ---------- */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 24px;
}

.tab {
    padding: 12px 20px;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 500;
    color: #64748b;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s ease;
    text-decoration: none;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}

.tab:hover {
    color: #1e293b;
}

.tab.active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
    font-weight: 600;
}

/* ---------- Empty State ---------- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #94a3b8;
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 18px;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    color: #94a3b8;
}

/* ---------- Pagination ---------- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 20px 0;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 8px;
    border-radius: 8px;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 500;
    color: #475569;
    text-decoration: none;
    transition: all 0.15s ease;
}

.pagination a:hover {
    background: #f1f5f9;
}

.pagination .active {
    background: #3b82f6;
    color: white;
}

/* ---------- SumoSelect Overrides ---------- */
.SumoSelect > .CaptionCont {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #ffffff;
    padding: 8px 32px 8px 12px;
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    min-height: 38px;
    transition: all 0.15s ease;
}

.SumoSelect:hover > .CaptionCont,
.SumoSelect.open > .CaptionCont {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.SumoSelect > .optWrapper {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    margin-top: 4px;
    overflow: hidden;
}

.SumoSelect > .optWrapper > .options li label {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    padding: 12px 16px;
    color: #334155;
}

.SumoSelect > .optWrapper > .options li:hover label {
    background: #f8fafc;
}

.SumoSelect > .optWrapper > .options li.selected label {
    background: #eff6ff;
    color: #1e40af;
}

/* ---------- Utility Classes ---------- */
.text-muted { color: #94a3b8; }
.text-secondary { color: #64748b; }
.text-primary { color: #3b82f6; }
.text-success { color: #15803d; }
.text-danger { color: #dc2626; }
.text-warning { color: #92400e; }

.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.gap-3 { gap: 24px; }

.hidden { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .page-content {
        padding: 16px;
    }

    .page-title {
        font-size: 22px;
    }

    .stats-row {
        flex-direction: column;
    }

    .stat-card {
        min-width: 100%;
    }

    .table-container th,
    .table-container td {
        padding: 10px 12px;
        font-size: 13px;
    }

    .filters-container {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group select,
    .filter-group input {
        width: 100%;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }
}
