:root {
    --primary-color: #0066cc;
    --primary-hover: #0052a3;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --error-color: #dc3545;
    --info-color: #17a2b8;
    --background: #f8f9fa;
    --card-background: #ffffff;
    --text-color: #212529;
    --border-color: #dee2e6;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.15);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.subtitle {
    font-size: 1.1rem;
    color: var(--secondary-color);
}

.input-section {
    background: var(--card-background);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.quick-select {
    margin-bottom: 1.5rem;
}

.quick-select-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-color);
    margin-bottom: 0.6rem;
}

.country-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.country-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.9rem;
    border: 2px solid var(--border-color);
    border-radius: 999px;
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.country-pill:hover {
    border-color: var(--primary-color);
}

.country-pill:has(input:checked) {
    border-color: var(--primary-color);
    background-color: #e8f1ff;
    color: var(--primary-color);
}

.country-pill input[type="checkbox"] {
    width: auto;
    margin: 0;
    accent-color: var(--primary-color);
    cursor: pointer;
}

.country-pill-count {
    color: var(--secondary-color);
    font-size: 0.8rem;
    font-weight: 400;
}

.country-pill:has(input:checked) .country-pill-count {
    color: inherit;
    opacity: 0.75;
}

.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-color);
}

.input-group input,
.input-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.3s ease;
}

.input-group textarea {
    resize: vertical;
    line-height: 1.5;
}

.input-group input:focus,
.input-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.label-hint {
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--secondary-color);
}

.filters-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.primary-btn, .secondary-btn {
    padding: 0.875rem 2rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

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

.primary-btn:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

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

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

.secondary-btn:hover {
    background-color: #5a6268;
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.csv-btn {
    padding: 0.875rem 2rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background-color: var(--success-color);
    color: white;
}

.csv-btn:hover {
    background-color: #218838;
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

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

.spinner {
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.error, .info {
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
}

.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

.results-section {
    animation: fadeIn 0.5s ease;
}

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

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.results-header h2 {
    font-size: 1.75rem;
    color: var(--text-color);
}

#badge-count {
    color: var(--secondary-color);
    font-size: 1.25rem;
    font-weight: 400;
}

.results-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid var(--border-color);
}

.tab-btn {
    padding: 0.6rem 1.5rem;
    border: none;
    background: none;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--secondary-color);
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.tab-btn--active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-btn:hover:not(.tab-btn--active) {
    color: var(--text-color);
}

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

.no-common-msg {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--secondary-color);
    padding: 2rem;
}

.holders-count {
    font-weight: 600;
    color: var(--primary-color);
}

.holders-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.75rem;
}

.holder-tag {
    background-color: var(--primary-color);
    color: white;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.profile-header {
    grid-column: 1 / -1;
    padding: 0.6rem 1rem;
    background-color: var(--primary-color);
    color: white;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    margin-top: 0.5rem;
}

.profile-header:first-child {
    margin-top: 0;
}

.profile-header--error {
    background-color: var(--error-color);
}

.badge-card {
    background: var(--card-background);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    animation: slideIn 0.5s ease;
}

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

.badge-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.badge-image-container {
    width: 100%;
    aspect-ratio: 512 / 254;
    background-color: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
}

.badge-image-container canvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

.badge-image-container.loading {
    display: flex;
    align-items: center;
    justify-content: center;
}

.badge-image-container .spinner {
    border-color: var(--border-color);
    border-top-color: var(--primary-color);
}

.badge-info {
    margin-bottom: 1rem;
}

.badge-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text-color);
    line-height: 1.4;
}

.badge-meta {
    font-size: 0.875rem;
    color: var(--secondary-color);
}

.badge-actions {
    display: flex;
    gap: 0.5rem;
}

.badge-actions button {
    flex: 1;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

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

.download-btn:hover {
    background-color: #218838;
    transform: translateY(-1px);
}

.view-original-btn {
    background-color: var(--info-color);
    color: white;
}

.view-original-btn:hover {
    background-color: #138496;
    transform: translateY(-1px);
}

footer {
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
    color: var(--secondary-color);
    font-size: 0.875rem;
}

footer p {
    margin-bottom: 0.5rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

footer a:hover {
    text-decoration: underline;
}

/* Add Profile button */
.add-profile-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.9rem;
    border: 2px dashed var(--border-color);
    border-radius: 999px;
    background: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--secondary-color);
    transition: border-color 0.2s ease, color 0.2s ease;
}

.add-profile-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.add-profile-btn .plus-icon {
    font-size: 1.1rem;
    line-height: 1;
}

/* Modal */
.modal {
    border: none;
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    max-width: 480px;
    width: calc(100% - 2rem);
    margin: auto;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.modal::backdrop {
    background: rgba(0, 0, 0, 0.4);
}

.modal-content {
    padding: 2rem;
}

.modal-content h3 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    color: var(--text-color);
}

.modal-content select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    background: var(--card-background);
    transition: border-color 0.3s ease;
    cursor: pointer;
}

.modal-content select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.modal-btn {
    padding: 0.6rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-btn--cancel {
    background: var(--background);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.modal-btn--cancel:hover {
    background: var(--border-color);
}

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

.modal-btn--save:hover {
    background: var(--primary-hover);
}

/* Custom profile pill indicator */
.country-pill--custom {
    border-style: dashed;
}

.country-pill--custom:has(input:checked) {
    border-style: solid;
}

/* Custom profiles list */
.custom-profiles-list {
    margin-top: 1rem;
}

.custom-profiles-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.custom-profile-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.5rem 0.25rem 0.7rem;
    background: #e8f1ff;
    border: 1px solid var(--primary-color);
    border-radius: 999px;
    font-size: 0.8rem;
    color: var(--primary-color);
}

.custom-profile-tag small {
    color: var(--secondary-color);
    font-weight: 400;
}

.custom-profile-remove {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0 0.15rem;
    color: var(--secondary-color);
    transition: color 0.2s ease;
    border-radius: 50%;
}

.custom-profile-remove:hover {
    color: var(--error-color);
}

/* Certification table */
.certification-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-background);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.certification-table thead {
    background: var(--primary-color);
    color: white;
}

.certification-table th,
.certification-table td {
    padding: 0.75rem 1rem;
    text-align: left;
}

.certification-table th {
    font-weight: 600;
    font-size: 0.95rem;
}

.certification-table th:last-child,
.certification-table td:last-child {
    text-align: center;
    width: 100px;
}

.certification-table tbody tr {
    border-bottom: 1px solid var(--border-color);
}

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

.certification-table tbody tr:hover {
    background: #f0f6ff;
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    header h1 {
        font-size: 2rem;
    }

    .filters-group {
        grid-template-columns: 1fr;
    }

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

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

    .results-header h2 {
        text-align: center;
    }
}
