:root {
    --green: #2B8C5E;
    --green-light: #E8F5EE;
    --green-hover: #237A4F;
    --mauve: #8B5C8E;
    --mauve-light: #F3EBF4;
    --mauve-hover: #7A4D7D;
    --white: #FFFFFF;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-500: #6B7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.5;
}

/* Header */
header {
    background: #283048;
    padding: 1.25rem 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    box-shadow: var(--shadow);
    position: relative;
}

header .logo {
    height: 44px;
    width: auto;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--white);
}

.header-user {
    position: absolute;
    right: 2rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-email {
    color: rgba(255,255,255,0.6);
    font-size: 0.75rem;
}

.logout-form {
    margin: 0;
}

.btn-logout {
    background: transparent;
    color: rgba(255,255,255,0.7);
    border: 1px solid rgba(255,255,255,0.3);
    padding: 0.35rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.btn-logout:hover {
    color: white;
    border-color: rgba(255,255,255,0.6);
}

/* Main layout */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Search form */
.search-form {
    background: var(--white);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.search-form h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--gray-200);
}

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

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.form-group input[type="text"],
.form-group select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--gray-900);
    background: var(--white);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input[type="text"]:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(43, 140, 94, 0.15);
}

.form-group input[type="text"]::placeholder {
    color: var(--gray-300);
}

/* Tag multi-select */
.tag-select {
    position: relative;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    background: var(--white);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.tag-select:focus-within {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(43, 140, 94, 0.15);
}

.tag-select-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem 0.5rem;
    min-height: 38px;
}

.tag-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    background: var(--green-light);
    color: var(--green);
    border: 1px solid var(--green);
    border-radius: 4px;
    padding: 0.15rem 0.4rem;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.tag-remove {
    background: none;
    border: none;
    color: var(--green);
    cursor: pointer;
    font-size: 0.875rem;
    line-height: 1;
    padding: 0;
    margin-left: 0.1rem;
    opacity: 0.7;
}

.tag-remove:hover {
    opacity: 1;
    color: var(--green-hover);
}

.tag-input {
    flex: 1;
    min-width: 100px;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    padding: 0.15rem 0.25rem !important;
    font-size: 0.8125rem;
    background: transparent;
}

.tag-input:focus {
    border: none !important;
    box-shadow: none !important;
}

.state-dropdown {
    position: absolute;
    top: 100%;
    left: -1px;
    right: -1px;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: var(--shadow-lg);
    z-index: 50;
    max-height: 200px;
    overflow-y: auto;
}

.state-option {
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    font-size: 0.8125rem;
    color: var(--gray-700);
    transition: background 0.1s;
}

.state-option:hover {
    background: var(--green-light);
    color: var(--green);
}

/* Autocomplete */
.autocomplete-wrapper {
    position: relative;
}

.autocomplete-wrapper .selected-tax {
    display: inline-block;
    font-size: 0.75rem;
    color: var(--green);
    margin-top: 0.25rem;
}

.autocomplete-wrapper .clear-btn {
    position: absolute;
    right: 8px;
    top: 8px;
    background: var(--gray-200);
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gray-700);
}

.autocomplete-wrapper .clear-btn:hover {
    background: var(--gray-300);
}

.dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    box-shadow: var(--shadow-lg);
    z-index: 50;
    max-height: 250px;
    overflow-y: auto;
}

.dropdown:empty {
    display: none;
}

.dropdown-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.8125rem;
    border-bottom: 1px solid var(--gray-100);
    transition: background 0.1s;
}

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

.dropdown-item:hover {
    background: var(--green-light);
}

.dropdown-item strong {
    color: var(--green);
    font-size: 0.75rem;
}

/* Action row */
.action-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--gray-200);
}

.btn-primary {
    background: var(--green);
    color: white;
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    min-width: 140px;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

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

.btn-primary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    background: var(--green);
}

.btn-loading {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.spinner {
    animation: spin 0.8s linear infinite;
}

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

.btn-secondary {
    background: var(--white);
    color: var(--mauve);
    border: 1px solid var(--mauve);
    padding: 0.6rem 1.5rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

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

.result-count {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-left: auto;
}

/* Results section */
.results-section {
    background: var(--white);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.results-section .placeholder {
    padding: 3rem;
    text-align: center;
    color: var(--gray-500);
    font-size: 0.875rem;
}

.results-section .error {
    padding: 1rem;
    text-align: center;
    color: #DC2626;
    background: #FEF2F2;
}

.results-table-wrapper {
    overflow: auto;
    height: calc((100vh - 280px) / 2);
    min-height: 200px;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.results-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.results-table th {
    background: var(--green-light);
    color: var(--green);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    font-size: 0.75rem;
    padding: 0.75rem;
    text-align: left;
    border-bottom: 2px solid var(--green);
    white-space: nowrap;
}

.results-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--gray-100);
    white-space: nowrap;
}

.results-table tbody tr:nth-child(even) {
    background: var(--gray-100);
}

.results-table tbody tr:hover {
    background: var(--green-light);
}

/* Limit select in action row */
.action-row .form-group {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.action-row .form-group label {
    text-transform: none;
    font-size: 0.875rem;
    white-space: nowrap;
}

.action-row select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 0.875rem;
}

/* Slow search warning */
.slow-warning {
    font-size: 0.8125rem;
    color: var(--mauve);
    font-style: italic;
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Infinite scroll sentinel */
.loading-more, .end-of-results {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    color: var(--gray-500);
    font-size: 0.8125rem;
}

.end-of-results {
    color: var(--gray-300);
    font-style: italic;
}

/* Login page */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--gray-50);
}

.login-card {
    background: var(--white);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    text-align: center;
    max-width: 380px;
    width: 100%;
}

.login-logo {
    height: 48px;
    margin-bottom: 1.5rem;
}

.login-card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 0.25rem;
}

.login-subtitle {
    color: var(--gray-500);
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
}

.login-error {
    background: #FEF2F2;
    color: #DC2626;
    padding: 0.75rem;
    border-radius: 6px;
    font-size: 0.8125rem;
    margin-bottom: 1rem;
}

.btn-google {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--white);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
    padding: 0.7rem 1.5rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s;
    width: 100%;
    justify-content: center;
}

.btn-google:hover {
    border-color: var(--gray-500);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Responsive */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    .form-group.full-width {
        grid-column: 1;
    }
    header {
        padding: 0.75rem 1rem;
    }
    header h1 {
        font-size: 1rem;
    }
    main {
        padding: 0.75rem;
    }
    .search-form {
        padding: 1rem;
    }
    .action-row {
        flex-direction: column;
        align-items: stretch;
    }
    .action-row .form-group {
        justify-content: space-between;
    }
    .btn-primary,
    .btn-secondary {
        width: 100%;
        text-align: center;
        justify-content: center;
    }
    .result-count {
        margin-left: 0;
        text-align: center;
    }
    .slow-warning {
        text-align: center;
    }
    .results-table-wrapper {
        height: calc(100vh - 200px);
    }
    .tag-select-inner {
        min-height: 34px;
    }
    .header-user {
        position: static;
        margin-top: 0.5rem;
    }
    .user-email {
        display: none;
    }
    .login-card {
        margin: 1rem;
    }
    .state-dropdown {
        max-height: 150px;
    }
}
