/* Reset and Base Styles */
@import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Noto+Sans+Thai:wght@100..900&display=swap');

* {
    font-family: "Noto Sans Thai", "Inter", sans-serif;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8f9fa;
}

/* Header */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 0;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

nav {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
    text-decoration: none;
    color: white;
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav-links a {
    color: white;
    text-decoration: none;
    transition: opacity 0.3s;
}

.nav-links a:hover {
    opacity: 0.8;
}

.text-overflow {
    text-overflow: ellipsis;
    overflow: hidden;
    display: -webkit-box;
    line-clamp: 1;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}

.nowrap {
    white-space: nowrap;
}

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

/* Hero Section */
.hero {
    text-align: center;
    padding: 4rem 0;
    background: white;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    margin-bottom: 3rem;
}

.hero h1 {
    font-size: 3rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    font-size: 1.2rem;
    color: #666;
    max-width: 600px;
    margin: 0 auto 2rem;
}

/* Search Form */
.search-form {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    margin-bottom: 3rem;
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #333;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.8rem;
    border: 2px solid #e1e5e9;
    border-radius: 5px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
}

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

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.8rem 2rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-decoration: none;
    border-radius: 5px;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
}

.btn-danger {
    background: #dc3545;
}

.btn-success {
    background: #28a745;
}

.btn-full {
    width: 100%;
}

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

/* Results Section */
.results {
    margin-top: 3rem;
}

.results h2 {
    margin-bottom: 1.5rem;
    color: #333;
}

.lead-card {
    background: white;
    border-radius: 10px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 3px 15px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s;
}

.lead-card:hover {
    transform: translateY(-2px);
}

.lead-card h3 {
    color: #667eea;
    margin-bottom: 0.5rem;
}

.lead-card p {
    margin-bottom: 0.5rem;
    color: #666;
}

.lead-card .contact-info {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.lead-card .contact-info span {
    background: #f8f9fa;
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.9rem;
}

/* CTA Banner */
.cta-banner {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-align: center;
    padding: 2rem;
    border-radius: 10px;
    margin: 2rem 0;
}

.cta-banner h3 {
    margin-bottom: 1rem;
}

.cta-banner .btn {
    background: white;
    color: #667eea;
}

/* Auth Forms */
.auth-form {
    max-width: 400px;
    margin: 4rem auto;
    background: white;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
}

.auth-form h2 {
    text-align: center;
    margin-bottom: 2rem;
    color: #333;
}

.auth-form .form-group {
    margin-bottom: 1.5rem;
}

.auth-form .btn {
    width: 100%;
    margin-bottom: 1rem;
}

.auth-form .auth-links {
    text-align: center;
}

.auth-form .auth-links a {
    color: #667eea;
    text-decoration: none;
}

/* Dashboard */
.dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.dashboard-card {
    background: white;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 3px 15px rgba(0, 0, 0, 0.1);
}

.dashboard-card h3 {
    color: #667eea;
    margin-bottom: 1rem;
}

.dashboard-card .metric {
    font-size: 2rem;
    font-weight: bold;
    color: #333;
}

/* Admin Styles */
.admin-header {
    background: #343a40;
    color: white;
    padding: 1rem 0;
}

.admin-nav {
    display: flex;
    gap: 2rem;
}

.admin-nav a {
    color: white;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 5px;
    transition: background-color 0.3s;
}

.admin-nav a:hover,
.admin-nav a.active {
    background: #495057;
}

.admin-table {
    width: 100%;
    background: white;
    border-radius: 10px;
    box-shadow: 0 3px 15px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

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

.admin-table th,
.admin-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #e1e5e9;
}

.admin-table th {
    background: #f8f9fa;
    font-weight: 600;
}

.admin-table tr:hover {
    background: #f8f9fa;
}

/* Loading Spinner */
.loading {
    display: none;
    text-align: center;
    padding: 2rem;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

    100% {
        transform: rotate(360deg);
    }
}

/* Progressive Search Styles */
.progressive-search {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
    border: 1px solid #e9ecef;
}

.progress-header h2 {
    margin: 0 0 10px 0;
    color: #2563eb;
    font-size: 1.5rem;
}

.progress-stats {
    color: #6b7280;
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.progress-separator {
    margin: 0 8px;
    color: #d1d5db;
}

.progress-container {
    margin: 20px 0;
}

.progress-bar {
    background: #e5e7eb;
    border-radius: 10px;
    height: 20px;
    position: relative;
    overflow: hidden;
}

.progress-fill {
    background: linear-gradient(90deg, #2563eb, #3b82f6);
    height: 100%;
    border-radius: 10px;
    transition: width 0.3s ease;
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

.progress-percentage {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: bold;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    font-size: 0.8rem;
}

.progress-message {
    text-align: center;
    margin: 15px 0;
    font-style: italic;
    color: #4b5563;
}

.progress-details {
    display: flex;
    justify-content: space-between;
    margin: 20px 0;
    padding: 15px;
    background: white;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}

.detail-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
}

.detail-label {
    font-size: 0.8rem;
    color: #6b7280;
    margin-bottom: 5px;
}

.detail-item span:last-child {
    font-weight: bold;
    color: #111827;
}

.live-results {
    margin-top: 20px;
}

.live-results h3 {
    margin: 0 0 15px 0;
    color: #1f2937;
    font-size: 1.2rem;
}

.live-results-list {
    max-height: 300px;
    overflow-y: auto;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 10px;
}

.waiting-message {
    text-align: center;
    color: #6b7280;
    font-style: italic;
    padding: 20px;
}

.live-result-item {
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.9rem;
}

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

.live-result-name {
    font-weight: bold;
    color: #1f2937;
}

.live-result-address {
    color: #6b7280;
    font-size: 0.8rem;
}

/* Responsive adjustments for progressive search */
@media (max-width: 768px) {
    .progress-details {
        flex-direction: column;
    }

    .detail-item {
        margin-bottom: 10px;
    }

    .detail-item:last-child {
        margin-bottom: 0;
    }
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 5px;
    margin-bottom: 1rem;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

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

.alert-info {
    background: #cce7ff;
    color: #004085;
    border: 1px solid #b8daff;
}

/* Footer */
footer {
    background: #343a40;
    color: white;
    text-align: center;
    padding: 2rem 0;
    margin-top: 4rem;
}

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

    .hero h1 {
        font-size: 2rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .nav-links {
        flex-direction: column;
        gap: 1rem;
    }

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

    .admin-nav {
        flex-direction: column;
        gap: 0.5rem;
    }

    .admin-table {
        overflow-x: auto;
    }
}

/* PWA Styles */
@media (display-mode: standalone) {
    body {
        padding-top: env(safe-area-inset-top);
    }

    .container {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Utility Classes */
.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.mt-1 {
    margin-top: 0.5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mt-3 {
    margin-top: 1.5rem;
}

.mb-1 {
    margin-bottom: 0.5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mb-3 {
    margin-bottom: 1.5rem;
}

.hidden {
    display: none;
}

.visible {
    display: block;
}

/* Credit System Styles */
.credit-info {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.credit-used {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.9em;
}

.credits-remaining {
    font-weight: bold;
    font-size: 1.1em;
}

.free-credits {
    background: rgba(46, 204, 113, 0.2);
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.9em;
    animation: pulse 2s infinite;
}

.user-credits {
    background: rgba(255, 255, 255, 0.1);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: bold;
}

.guest-info {
    background: rgba(255, 193, 7, 0.2);
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.9em;
    color: #fff;
}

.api-limit-info {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
    color: white;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 15px;
    text-align: center;
}

.limit-warning {
    font-size: 0.9em;
    font-weight: bold;
}

/* Search Information */
.search-info {
    background: #d1ecf1;
    border: 1px solid #bee5eb;
    color: #0c5460;
    padding: 10px;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 0.9em;
    text-align: center;
}

.search-message {
    font-weight: 500;
}

/* Advanced Search Suggestion */
.advanced-search-suggestion {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
    padding: 10px;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 0.9em;
    text-align: center;
}

.suggestion {
    font-weight: 500;
}

/* Request More Suggestion */
.request-more-suggestion {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
    padding: 10px;
    border-radius: 8px;
    margin: 10px 0;
    font-size: 0.9em;
    text-align: center;
}

/* Efficiency Information */
.efficiency-info {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    color: #495057;
    padding: 8px;
    border-radius: 6px;
    margin: 8px 0;
    font-size: 0.85em;
    text-align: center;
}

/* Form styling improvements */
.form-text {
    display: block;
    margin-top: 5px;
    color: #6c757d;
    font-size: 0.875em;
}

.form-row {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
}

.form-row .form-group {
    flex: 1;
}

@media (max-width: 768px) {
    .form-row {
        flex-direction: column;
        gap: 0;
    }
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }

    100% {
        opacity: 1;
    }
}

@media (max-width: 768px) {
    .credit-info {
        flex-direction: column;
        text-align: center;
    }
}

/* Search History Styles */
.search-history-list {
    max-height: 400px;
    overflow-y: auto;
}

.history-item {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    background: #fafafa;
    transition: background-color 0.2s;
}

.history-item:hover {
    background: #f0f8ff;
}

.history-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.result-count {
    background: #007bff;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: bold;
}

.history-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.time-ago {
    color: #666;
}

.btn-repeat {
    background: #28a745;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-repeat:hover {
    background: #218838;
}

@media (max-width: 768px) {
    .history-main {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .history-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
}