/* ============================================
   CSS Design System - Factory Search
   ============================================ */

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

:root {
    /* Define base colors */
    --primary: #4f46e5;
    --primary-light: #6366f1;
    --primary-dark: #3730a3;
    --primary-glow: rgba(79, 70, 229, 0.15);
    --accent: #0ea5e9;
    --accent-light: #38bdf8;

    /* Light Theme Backgrounds */
    --bg-base: #f1f5f9;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-card-hover: rgba(255, 255, 255, 1);
    --bg-glass: rgba(255, 255, 255, 0.65);
    --bg-input: #ffffff;

    /* Light Theme Text */
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;

    /* Light Theme Borders */
    --border: rgba(15, 23, 42, 0.08);
    --border-focus: rgba(79, 70, 229, 0.4);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Light Theme Shadows */
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 8px 32px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 16px 64px rgba(15, 23, 42, 0.12);
    --shadow-glow: 0 0 30px var(--primary-glow);

    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Animated Background Blobs --- */
.bg-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.2;
    animation: blobFloat 20s ease-in-out infinite;
}

.blob-1 {
    width: 500px;
    height: 500px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    top: -10%;
    right: -5%;
    animation-delay: 0s;
}

.blob-2 {
    width: 400px;
    height: 400px;
    background: linear-gradient(135deg, #06b6d4, #3b82f6);
    bottom: -10%;
    left: -5%;
    animation-delay: -7s;
}

.blob-3 {
    width: 300px;
    height: 300px;
    background: linear-gradient(135deg, #ec4899, #8b5cf6);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -14s;
}

@keyframes blobFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -50px) scale(1.1); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(40px, 30px) scale(1.05); }
}

/* --- Container --- */
.container {
    position: relative;
    z-index: 1;
    max-width: 900px;
    margin: 0 auto;
    padding: 40px 24px 60px;
}

/* --- Header --- */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 48px;
    animation: fadeInDown 0.6s ease-out;
}

.logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius-md);
    color: white;
    box-shadow: var(--shadow-glow);
}

.logo-text h1 {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-top: 2px;
}

.header-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-glass);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 100px;
    backdrop-filter: blur(10px);
}

.badge-dot {
    width: 6px;
    height: 6px;
    background: #22c55e;
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
    50% { opacity: 0.8; box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}

/* --- Search Section --- */
.search-section {
    margin-bottom: 40px;
    animation: fadeInUp 0.6s ease-out 0.1s both;
}

.search-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 40px;
    backdrop-filter: blur(20px);
    transition: var(--transition-base);
}

.search-card:hover {
    border-color: rgba(99, 102, 241, 0.2);
    box-shadow: var(--shadow-glow);
}

.search-header {
    text-align: center;
    margin-bottom: 32px;
}

.search-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.search-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Search Mode Toggle */
.search-mode-toggle {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 24px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 100px;
    padding: 4px;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}

.mode-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background: transparent;
    border: none;
    border-radius: 100px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition-base);
}

.mode-btn:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.04);
}

.mode-btn.active {
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.1), rgba(14, 165, 233, 0.1));
    color: var(--primary-dark);
    box-shadow: 0 2px 12px rgba(79, 70, 229, 0.1);
    border: 1px solid rgba(79, 70, 229, 0.2);
}

.mode-btn svg {
    flex-shrink: 0;
}

/* --- Company Info Section --- */
.company-section {
    margin-bottom: 28px;
    animation: fadeInUp 0.5s ease-out;
}

.company-card {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(6, 182, 212, 0.05));
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: var(--radius-xl);
    padding: 32px;
    backdrop-filter: blur(20px);
    position: relative;
    overflow: hidden;
}

.company-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.company-header {
    text-align: center;
    margin-bottom: 28px;
}

.company-status {
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 4px 14px;
    border-radius: 100px;
    background: rgba(22, 163, 74, 0.1);
    color: #16a34a;
    margin-bottom: 12px;
    letter-spacing: 0.02em;
}

.company-header h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 6px;
    letter-spacing: -0.02em;
}

.company-taxid {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.company-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 12px;
}

.company-field {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    transition: var(--transition-fast);
}

.company-field:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(99, 102, 241, 0.15);
}

.company-field-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.company-field-content {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.company-field-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.company-field-value {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 500;
    line-height: 1.4;
    word-break: break-all;
}

.company-source {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 0.72rem;
    color: var(--text-muted);
    opacity: 0.7;
}

.search-input-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 6px 6px 6px 20px;
    transition: var(--transition-base);
}

.search-input-wrapper:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 4px var(--primary-glow), var(--shadow-sm);
    background: rgba(255, 255, 255, 0.1);
}

.search-icon {
    color: var(--text-muted);
    flex-shrink: 0;
    display: flex;
}

#searchInput {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    padding: 12px 0;
}

#searchInput::placeholder {
    color: var(--text-muted);
}

.search-btn {
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 14px 32px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-btn:hover {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    transform: translateY(-1px);
    box-shadow: 0 4px 20px var(--primary-glow);
}

.search-btn:active {
    transform: translateY(0);
}

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

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

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

/* Search Hints */
.search-hints {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.hint-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.hint-tag {
    background: var(--bg-glass);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 100px;
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition-fast);
}

.hint-tag:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--primary-light);
}

/* --- Results Section --- */
.results-section {
    margin-bottom: 32px;
    animation: fadeInUp 0.4s ease-out;
}

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding: 0 4px;
}

.results-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.results-info h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.results-count {
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--bg-glass);
    padding: 4px 12px;
    border-radius: 100px;
    border: 1px solid var(--border);
}

.results-keyword {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.results-keyword span {
    color: var(--primary-light);
    font-weight: 500;
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.factory-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.factory-loading .spinner {
    color: var(--primary-light);
    width: 24px;
    height: 24px;
}

.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    cursor: pointer;
    transition: var(--transition-base);
    display: flex;
    align-items: flex-start;
    gap: 20px;
    backdrop-filter: blur(10px);
    animation: fadeInUp 0.3s ease-out both;
}

.result-card:hover {
    background: var(--bg-card-hover);
    border-color: rgba(99, 102, 241, 0.25);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.result-card:active {
    transform: translateY(0);
}

.result-index {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.15), rgba(14, 165, 233, 0.15));
    border-radius: var(--radius-sm);
    color: var(--primary-dark);
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.result-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.result-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-id {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

/* --- Qualification UI --- */
.qualification-container {
    margin-top: 4px;
    padding-top: 16px;
    border-top: 1px dashed var(--border);
}

.qual-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.qual-loading .spinner {
    color: var(--primary-light);
}

.qual-badge {
    background: var(--bg-glass);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    border: 1px solid var(--border);
}

.qual-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.qual-criteria {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-left: 4px;
    margin-top: 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.04);
    padding-top: 10px;
}

.qual-item {
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.qual-item span {
    font-size: 0.75rem;
    width: 16px;
    text-align: center;
}

.qual-item.pass { color: #15803d; }
.qual-item.fail { color: #b91c1c; opacity: 0.85; }
.qual-item.warn { color: #b45309; }

.qual-msg {
    margin-top: 10px;
    font-size: 0.8rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.6);
    padding: 8px 12px;
    border-radius: 6px;
    border-left: 3px solid var(--border);
}

.qual-qualified { background: rgba(22, 163, 74, 0.03); border-color: rgba(22, 163, 74, 0.15); }
.qual-warning { background: rgba(217, 119, 6, 0.03); border-color: rgba(217, 119, 6, 0.15); }
.qual-failed { background: rgba(220, 38, 38, 0.03); border-color: rgba(220, 38, 38, 0.15); }

.qual-qualified .qual-title { color: #16a34a; }
.qual-warning .qual-title { color: #d97706; }
.qual-failed .qual-title { color: #dc2626; }

.result-arrow {
    color: var(--text-muted);
    flex-shrink: 0;
    transition: var(--transition-fast);
}

.result-card:hover .result-arrow {
    color: var(--primary-light);
    transform: translateX(4px);
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: fadeIn 0.2s ease-out;
}

.modal {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 640px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    animation: modalSlideUp 0.3s ease-out;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 28px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.15rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
    display: flex;
}

.modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-glass);
}

.modal-body {
    padding: 28px;
    overflow-y: auto;
    max-height: calc(80vh - 80px);
}

.detail-grid {
    display: grid;
    gap: 16px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 16px;
    background: var(--bg-glass);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.detail-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.detail-value {
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 500;
    line-height: 1.5;
}

/* Loading state for modal */
.modal-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 0;
    gap: 16px;
}

.modal-loading .spinner {
    width: 32px;
    height: 32px;
    color: var(--primary-light);
}

.modal-loading p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* --- Empty & Error States --- */
.empty-state, .error-state {
    text-align: center;
    padding: 60px 24px;
    animation: fadeInUp 0.4s ease-out;
}

.empty-icon, .error-icon {
    color: var(--text-muted);
    margin-bottom: 16px;
    opacity: 0.5;
}

.error-icon {
    color: #f87171;
}

.empty-state h3, .error-state h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.empty-state p, .error-state p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* --- Footer --- */
.footer {
    text-align: center;
    margin-top: 60px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    animation: fadeInUp 0.6s ease-out 0.3s both;
}

.footer p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.footer a {
    color: var(--primary-light);
    text-decoration: none;
    transition: var(--transition-fast);
}

.footer a:hover {
    color: var(--accent-light);
    text-decoration: underline;
}

.footer-note {
    margin-top: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.7;
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(40px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .container {
        padding: 24px 16px 48px;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 32px;
    }

    .search-card {
        padding: 24px 20px;
    }

    .search-header h2 {
        font-size: 1.4rem;
    }

    .search-input-wrapper {
        flex-direction: column;
        padding: 16px;
        gap: 12px;
    }

    .search-icon {
        display: none;
    }

    #searchInput {
        width: 100%;
        padding: 8px 0;
    }

    .search-btn {
        width: 100%;
        justify-content: center;
        padding: 14px;
    }

    .results-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .result-card {
        padding: 16px;
    }

    .result-name {
        white-space: normal;
    }

    .modal {
        max-height: 90vh;
        margin: 16px;
    }
}

@media (max-width: 480px) {
    .logo-text h1 {
        font-size: 1.1rem;
    }

    .header-badge {
        font-size: 0.7rem;
    }

    .blob-1 { width: 300px; height: 300px; }
    .blob-2 { width: 250px; height: 250px; }
    .blob-3 { width: 200px; height: 200px; }
}
