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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f6f8;
    min-height: 100vh;
    padding: 20px;
    color: #0f172a;
}

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

header {
    text-align: center;
    color: #0f172a;
    margin-bottom: 40px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

header p {
    font-size: 1.1rem;
    color: #334155;
}

main {
    background: #ffffff;
    border-radius: 16px;
    padding: 36px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
    border: 1px solid #e2e8f0;
}

.upload-section {
    margin-bottom: 30px;
}

.upload-area {
    border: 2px dashed #cbd5e1;
    border-radius: 14px;
    padding: 50px 20px;
    text-align: center;
    background: #f8fafc;
    transition: all 0.25s ease;
    cursor: pointer;
}

.upload-area:hover {
    border-color: #94a3b8;
    background: #ffffff;
}

.upload-area.dragover {
    border-color: #1f2937;
    background: #e2e8f0;
}

.upload-area svg {
    color: #1f2937;
    margin-bottom: 20px;
}

.upload-area h2 {
    color: #0f172a;
    margin-bottom: 10px;
    font-size: 1.5rem;
}

.upload-area p {
    color: #475569;
    margin-bottom: 20px;
}

.btn-select {
    background: #111827;
    color: #f8fafc;
    border: none;
    padding: 12px 28px;
    border-radius: 14px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
}

.btn-select:hover {
    background: #0b1220;
    transform: translateY(-1px);
}

.file-list {
    margin: 20px 0;
    max-height: 200px;
    overflow-y: auto;
}

.file-item {
    background: #f8fafc;
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #e2e8f0;
}

.file-item span {
    color: #0f172a;
    font-weight: 500;
}

.file-item .file-size {
    color: #475569;
    font-size: 0.9rem;
}

.actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

.btn-process,
.btn-clear {
    padding: 12px 30px;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.btn-process {
    background: #0f172a;
    color: #f8fafc;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
}

.btn-process:hover:not(:disabled) {
    background: #111827;
    transform: translateY(-1px);
}

.btn-process:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-clear {
    background: #e2e8f0;
    color: #0f172a;
}

.btn-clear:hover:not(:disabled) {
    background: #cbd5e1;
    transform: translateY(-1px);
}

.btn-clear:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.embeddings-input {
    margin-top: 24px;
    padding: 20px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #f8fafc;
}

.embeddings-input__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.embeddings-input h3 {
    margin: 0;
    color: #0f172a;
    font-size: 1.2rem;
}

.embeddings-input p {
    margin: 4px 0 0 0;
    color: #475569;
    font-size: 0.95rem;
}

.embeddings-input textarea {
    width: 100%;
    margin-top: 10px;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    font-size: 1rem;
    min-height: 120px;
    resize: vertical;
    color: #0f172a;
    background: #ffffff;
}

.embeddings-input textarea:focus {
    outline: 2px solid #0f172a;
    border-color: #0f172a;
}

.help-text {
    margin-top: 8px;
    font-size: 0.9rem;
    color: #64748b;
}

.pill {
    background: #0f172a;
    color: #f8fafc;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.12);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.loading {
    text-align: center;
    padding: 40px;
}

.spinner {
    border: 4px solid #e2e8f0;
    border-top: 4px solid #0f172a;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.loading p {
    color: #334155;
    font-size: 1.1rem;
}

.results-section {
    margin-top: 40px;
}

.results-section h2 {
    color: #0f172a;
    margin-bottom: 20px;
    font-size: 1.8rem;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 10px;
}

.results-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.result-card {
    background: #ffffff;
    border-radius: 12px;
    padding: 0;
    border: 1px solid #e2e8f0;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.result-card.error {
    border-color: #fca5a5;
    background: #fef2f2;
}

.result-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    transition: background 0.2s ease;
    gap: 15px;
}

.header-left {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.result-header:hover .header-left {
    opacity: 0.8;
}

.header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.result-card h3 {
    color: #0f172a;
    margin: 0;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.cache-badge {
    font-size: 0.75rem;
    background: #d9f99d;
    color: #3f6212;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
    margin-left: 8px;
}

.result-card h3::before {
    content: "📄";
    font-size: 1.5rem;
}

.result-card.error h3::before {
    content: "❌";
}

.collapse-icon {
    font-size: 0.8rem;
    color: #334155;
    transition: transform 0.3s ease;
    margin-left: 10px;
}

.result-card.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.result-content {
    padding: 0 20px 20px 20px;
    transition: all 0.3s ease;
}

.result-card.collapsed .result-content {
    display: none;
}

.result-card .summary {
    color: #334155;
    line-height: 1.6;
    white-space: pre-wrap;
    background: white;
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
}

.result-card .error-message {
    color: #b91c1c;
    font-weight: 500;
    margin-top: 10px;
}

.result-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.btn-regenerate,
.btn-embeddings {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.btn-header {
    padding: 6px 12px;
    font-size: 0.85rem;
    white-space: nowrap;
}

.btn-regenerate {
    background: #0f172a;
    color: #f8fafc;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.12);
}

.btn-regenerate:hover {
    background: #111827;
    transform: translateY(-1px);
}

.btn-embeddings {
    background: #e2e8f0;
    color: #0f172a;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}

.btn-embeddings:hover {
    background: #cbd5e1;
    transform: translateY(-1px);
}

.loading-small {
    text-align: center;
    padding: 20px;
    color: #475569;
    font-weight: 500;
}

.embeddings-preview {
    background: #f8fafc;
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
    font-size: 0.85rem;
    margin-top: 10px;
}

details {
    margin-top: 15px;
}

details summary {
    cursor: pointer;
    font-weight: 600;
    color: #0f172a;
    padding: 8px;
    border-radius: 4px;
    transition: background 0.2s ease, color 0.2s ease;
}

details summary:hover {
    background: #e2e8f0;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.modal {
    background: #ffffff;
    border-radius: 14px;
    padding: 20px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.16);
    border: 1px solid #e2e8f0;
}

.modal-header h3 {
    margin: 0 0 6px 0;
    color: #0f172a;
}

.modal-header p {
    margin: 0;
    color: #475569;
}

.modal-body {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.modal-body input {
    padding: 10px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    font-size: 1rem;
}

.modal-body input:focus {
    outline: 2px solid #0f172a;
    border-color: #0f172a;
}

.modal-actions {
    margin-top: 18px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-error {
    color: #b91c1c;
    font-weight: 600;
    font-size: 0.9rem;
    min-height: 18px;
}

.modal[aria-busy="true"] {
    opacity: 0.8;
    pointer-events: none;
}

@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }

    main {
        padding: 20px;
    }

    .upload-area {
        padding: 40px 15px;
    }

    .actions {
        flex-direction: column;
    }

    .btn-process,
    .btn-clear {
        width: 100%;
    }

    .result-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .header-left {
        width: 100%;
    }

    .header-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .btn-header {
        flex: 1;
    }
}

