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

body {
    font-family: 'Source Sans 3', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: #f8fafc;
    color: #333;
    line-height: 1.6;
}

/* ─── Header & Nav ──────────────────────────────────────────────── */

.header {
    background: #0f172a;
    color: white;
    padding: 1.5rem 2rem 0;
    text-align: center;
}

.header h1 {
    font-family: 'Instrument Serif', Georgia, serif;
    font-weight: 400;
    font-size: 1.6rem;
    margin-bottom: 0.25rem;
    letter-spacing: 0.5px;
}

.header p {
    opacity: 0.85;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.nav-bar {
    display: flex;
    justify-content: center;
    gap: 0;
    flex-wrap: wrap;
}

.nav-bar a {
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
    padding: 0.6rem 1.2rem;
    font-size: 0.85rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.nav-bar a:hover {
    color: white;
}

.nav-bar a.active {
    color: #60a5fa;
    border-bottom-color: #60a5fa;
}

/* ─── Layout ────────────────────────────────────────────────────── */

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* ─── Search Section ────────────────────────────────────────────── */

.search-section {
    margin-bottom: 1rem;
}

.search-heading {
    font-size: 1.15rem;
    color: #1e293b;
    margin-bottom: 0.75rem;
    font-weight: 600;
}

.search-bar {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.search-input-wrap {
    flex: 1;
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    pointer-events: none;
}

.search-input-wrap input {
    width: 100%;
    padding: 0.75rem 0.75rem 0.75rem 2.5rem;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: white;
}

.search-input-wrap input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn-search {
    padding: 0.75rem 1.5rem;
    white-space: nowrap;
    font-size: 0.95rem;
}

/* ─── Buttons ───────────────────────────────────────────────────── */

.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.2s, transform 0.1s;
}

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

.btn-primary {
    background-color: #2563eb;
    color: white;
}

.btn-primary:hover {
    background-color: #1d4ed8;
}

.btn-primary:disabled {
    background-color: #aaa;
    cursor: not-allowed;
}

.btn-outline {
    background: transparent;
    border: 1px solid #e2e8f0;
    color: #1e293b;
    text-decoration: none;
}

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

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.btn-gold {
    background-color: #2563eb;
    color: white;
}

.btn-gold:hover {
    background-color: #1d4ed8;
}

/* ─── Saved Searches Bar ────────────────────────────────────────── */

.saved-searches-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.saved-label {
    font-size: 0.8rem;
    color: #888;
    font-weight: 500;
}

.saved-tabs {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.saved-tab {
    padding: 0.3rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    background: #e8ecf1;
    color: #1e293b;
    border: 1px solid transparent;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.saved-tab:hover {
    background: #d0d7e2;
}

.saved-tab.active {
    background: #0f172a;
    color: white;
}

.saved-tab .tab-delete {
    display: none;
    font-size: 0.7rem;
    opacity: 0.6;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
}

.saved-tab:hover .tab-delete {
    display: inline;
}

.saved-tab.active .tab-delete {
    display: inline;
    opacity: 0.8;
}

.btn-add-search {
    padding: 0.3rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    cursor: pointer;
    background: none;
    color: #1e293b;
    border: 1px dashed #aab;
    transition: all 0.2s;
}

.btn-add-search:hover {
    border-color: #1e293b;
    background: #f5f7fa;
}

/* ─── Advanced Filters ──────────────────────────────────────────── */

.filters-toggle-wrap {
    margin-bottom: 0.75rem;
}

.filters-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: none;
    border: none;
    color: #1e293b;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.3rem 0;
}

.filters-toggle:hover {
    color: #2563eb;
}

.filters-toggle.open svg {
    transform: rotate(180deg);
}

.filter-count {
    background: #2563eb;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
}

.advanced-filters {
    background: white;
    border: 1px solid #e0e3e8;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

.filter-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem 1.25rem;
}

.filter-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 0.3rem;
}

.filter-group input,
.filter-group select {
    padding: 0.4rem 0.6rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.85rem;
    background: white;
    width: 100%;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: #2563eb;
}

.filter-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

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

.filter-sep {
    font-size: 0.8rem;
    color: #888;
    white-space: nowrap;
}

.filter-group-wide {
    grid-column: 1 / -1;
}

/* ─── Results Info ──────────────────────────────────────────────── */

.results-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    padding: 0 0.25rem;
}

.results-count {
    font-size: 0.9rem;
    color: #555;
    font-weight: 500;
}

.results-sort {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.results-sort label {
    font-size: 0.8rem;
    color: #888;
}

.results-sort select {
    padding: 0.3rem 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.8rem;
    background: white;
}

/* ─── Status Messages ───────────────────────────────────────────── */

.status {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    display: none;
    font-size: 0.9rem;
}

.status.loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: #eff6ff;
    color: #1e293b;
    border: 1px solid #bfdbfe;
}

.status.error {
    display: block;
    background-color: #fde8e8;
    color: #9b2c2c;
    border: 1px solid #f5c6c6;
}

.status.success {
    display: block;
    background-color: #e6f9ed;
    color: #276749;
    border: 1px solid #a7e8c0;
}

.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(37, 99, 235, 0.2);
    border-radius: 50%;
    border-top-color: #2563eb;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

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

/* ─── Profile Banner ────────────────────────────────────────────── */

.profile-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: #fef9e7;
    border: 1px solid #f0e0a0;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    color: #7a6a20;
}

.profile-banner a {
    color: #2563eb;
    font-weight: 600;
}

/* ─── Contract Cards ────────────────────────────────────────────── */

.contracts-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.contract-card {
    background: white;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.2s;
    overflow: hidden;
    display: flex;
    border-left: 4px solid #ddd;
}

.contract-card:hover {
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.12);
}

.contract-card.score-strong { border-left-color: #1B7A3D; }
.contract-card.score-good { border-left-color: #2E7D32; }
.contract-card.score-possible { border-left-color: #D4880F; }
.contract-card.score-stretch { border-left-color: #E65100; }
.contract-card.score-poor { border-left-color: #B83230; }
.contract-card.score-none { border-left-color: #bbb; }
.contract-card.expired { opacity: 0.6; }

/* Score Badge */
.score-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 70px;
    padding: 1rem 0.5rem;
    text-align: center;
    flex-shrink: 0;
}

.score-number {
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1;
    color: white;
}

.score-label {
    font-size: 0.55rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: white;
    margin-top: 0.3rem;
    opacity: 0.9;
}

.score-badge.bg-strong { background: #1B7A3D; }
.score-badge.bg-good { background: #2E7D32; }
.score-badge.bg-possible { background: #D4880F; }
.score-badge.bg-stretch { background: #E65100; }
.score-badge.bg-poor { background: #B83230; }

/* Card Body */
.card-body {
    flex: 1;
    padding: 1rem 1.25rem;
    min-width: 0;
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 0.25rem;
    line-height: 1.35;
}

.card-buyer {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 0.6rem;
}

.card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    margin-bottom: 0.6rem;
    font-size: 0.82rem;
    color: #555;
}

.card-meta .meta-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.meta-label {
    font-weight: 600;
    color: #444;
}

.deadline-days {
    font-size: 0.75rem;
    color: #888;
}

.deadline-urgent {
    color: #c53030;
    font-weight: 600;
}

/* Match Analysis */
.match-analysis {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #f0f0f0;
}

.match-analysis-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 0.35rem;
}

.match-items {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.match-item {
    font-size: 0.8rem;
    display: flex;
    align-items: flex-start;
    gap: 0.35rem;
    line-height: 1.4;
}

.match-icon-positive { color: #1B7A3D; }
.match-icon-warning { color: #D4880F; }
.match-icon-negative { color: #B83230; }

/* Card Actions */
.card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

/* Expanded Details */
.card-details {
    display: none;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid #eee;
}

.card-details.open {
    display: block;
}

.card-description {
    font-size: 0.85rem;
    color: #555;
    line-height: 1.5;
    margin-bottom: 0.75rem;
}

.score-breakdown {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.score-breakdown th {
    text-align: left;
    padding: 0.4rem 0.6rem;
    background: #f5f7fa;
    color: #555;
    font-weight: 600;
    border-bottom: 1px solid #e0e3e8;
}

.score-breakdown td {
    padding: 0.35rem 0.6rem;
    border-bottom: 1px solid #f0f0f0;
}

.score-breakdown .score-cell {
    font-weight: 700;
    text-align: center;
    width: 60px;
}

.score-breakdown .overall-row {
    font-weight: 700;
    background: #f5f7fa;
}

.score-bar-cell {
    width: 80px;
}

.score-bar {
    height: 6px;
    border-radius: 3px;
    background: #e0e3e8;
    overflow: hidden;
}

.score-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}

/* ─── Empty State ───────────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #999;
}

.empty-state svg {
    margin-bottom: 0.75rem;
}

.empty-state h3 {
    margin-bottom: 0.4rem;
    font-size: 1.1rem;
    color: #777;
}

.empty-state p {
    font-size: 0.9rem;
}

/* ─── Modal ─────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

.modal h3 {
    font-size: 1.1rem;
    color: #1e293b;
    margin-bottom: 1rem;
}

.modal .form-group {
    margin-bottom: 1rem;
}

.modal .form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 0.3rem;
}

.modal .form-group input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* ─── Footer ────────────────────────────────────────────────────── */

.footer {
    text-align: center;
    padding: 2rem;
    color: #94a3b8;
    font-size: 0.8rem;
    border-top: 1px solid #e2e8f0;
}

/* ─── Legacy compat ─────────────────────────────────────────────── */

.controls {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-weight: 600;
    font-size: 0.875rem;
    color: #555;
}

.control-group select,
.control-group input {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95rem;
    background: white;
}

.contracts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
}

.contract-meta {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.contract-meta span {
    font-size: 0.85rem;
    color: #666;
}

.contract-meta strong {
    color: #333;
}

.contract-description {
    font-size: 0.9rem;
    color: #555;
    margin-bottom: 1rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.contract-actions {
    display: flex;
    gap: 0.75rem;
}

/* ─── Responsive ────────────────────────────────────────────────── */

@media (max-width: 700px) {
    .header {
        padding: 1rem 1rem 0;
    }

    .header h1 {
        font-size: 1.3rem;
    }

    .nav-bar a {
        padding: 0.5rem 0.6rem;
        font-size: 0.75rem;
    }

    .container {
        padding: 1rem;
    }

    .search-bar {
        flex-direction: column;
    }

    .btn-search {
        width: 100%;
    }

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

    .contract-card {
        flex-direction: column;
    }

    .score-badge {
        flex-direction: row;
        min-width: auto;
        padding: 0.5rem 1rem;
        gap: 0.5rem;
    }

    .score-number {
        font-size: 1.2rem;
    }

    .score-label {
        margin-top: 0;
    }

    .card-meta {
        flex-direction: column;
        gap: 0.25rem;
    }

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

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