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

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

a {
    color: #2563eb;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
header {
    background: #1e3a5f;
    color: white;
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

header h1 a {
    color: white;
    text-decoration: none;
}

.settings-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.settings-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.settings-btn svg {
    width: 20px;
    height: 20px;
}

/* Main content */
main {
    padding: 2rem 0;
    min-height: calc(100vh - 120px);
}

/* Search form */
.search-section {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.search-main {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.search-main input {
    flex: 1;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.search-main input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-main button {
    padding: 0.75rem 1.5rem;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
}

.search-main button:hover {
    background: #1d4ed8;
}

.advanced-toggle {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0;
}

.advanced-toggle:hover {
    color: #333;
}

.advanced-filters {
    display: none;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #eee;
}

.advanced-filters.show {
    display: grid;
}

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

.filter-group label {
    font-size: 0.85rem;
    color: #666;
    font-weight: 500;
}

.filter-group input,
.filter-group select {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: #2563eb;
}

/* Results */
.results-section {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.results-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.results-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: #666;
}

.results-list {
    list-style: none;
}

.result-item {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #eee;
    transition: background 0.15s;
}

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

.result-item:hover {
    background: #f9fafb;
}

.result-item a {
    display: block;
}

.result-name {
    font-weight: 600;
    color: #1e3a5f;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.case-year {
    font-weight: normal;
    color: #666;
    font-size: 0.9em;
}

.result-meta {
    font-size: 0.85rem;
    color: #666;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.result-meta span {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    border-top: 1px solid #eee;
}

.pagination button,
.pagination a {
    padding: 0.5rem 1rem;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    color: #333;
    text-decoration: none;
}

.pagination button:hover,
.pagination a:hover {
    background: #f5f5f5;
    text-decoration: none;
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination .current {
    background: #2563eb;
    color: white;
    border-color: #2563eb;
}

.pagination-info {
    color: #666;
    font-size: 0.9rem;
    margin: 0 1rem;
}

/* Case detail */
.case-header {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

.case-header h1 {
    font-size: 1.5rem;
    color: #1e3a5f;
    margin-bottom: 1rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.case-citations {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.citation-badge {
    background: #e5e7eb;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
}

.case-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.case-full-name {
    margin: 1rem 0;
}

.meta-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.meta-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #888;
    font-weight: 600;
}

.meta-value {
    color: #333;
}

.case-actions {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #eee;
    display: flex;
    gap: 1rem;
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: #2563eb;
    color: white;
    border: none;
}

.btn-primary:hover {
    background: #1d4ed8;
    text-decoration: none;
}

.btn-secondary {
    background: white;
    color: #333;
    border: 1px solid #ddd;
}

.btn-secondary:hover {
    background: #f5f5f5;
    text-decoration: none;
}

/* Case content (Markdown) */
.case-content {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.case-content h2 {
    font-size: 1.25rem;
    color: #1e3a5f;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #e5e7eb;
}

.markdown-content {
    font-size: 1rem;
    line-height: 1.8;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: #1e3a5f;
}

.markdown-content p {
    margin-bottom: 1rem;
}

.markdown-content ul,
.markdown-content ol {
    margin-bottom: 1rem;
    padding-left: 2rem;
}

.markdown-content blockquote {
    border-left: 4px solid #2563eb;
    padding-left: 1rem;
    margin: 1rem 0;
    color: #555;
    font-style: italic;
}

.markdown-content pre {
    background: #f5f5f5;
    padding: 1rem;
    border-radius: 4px;
    overflow-x: auto;
    margin: 1rem 0;
}

.markdown-content code {
    background: #f5f5f5;
    padding: 0.125rem 0.25rem;
    border-radius: 2px;
    font-size: 0.9em;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.modal-overlay.show {
    display: flex;
}

.modal {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    width: 100%;
    max-width: 400px;
    margin: 1rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

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

.modal-header h3 {
    font-size: 1.25rem;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    line-height: 1;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    margin-bottom: 1rem;
}

.api-key-input-group {
    display: flex;
    gap: 0.5rem;
}

.api-key-input-group input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9rem;
}

.api-key-input-group input:focus {
    outline: none;
    border-color: #2563eb;
}

.toggle-visibility {
    padding: 0.75rem;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toggle-visibility:hover {
    background: #eee;
}

.toggle-visibility svg {
    width: 20px;
    height: 20px;
    color: #666;
}

.modal-footer {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

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

.alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.alert-info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

/* Loading */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    color: #666;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e5e7eb;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 0.5rem;
}

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

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: #666;
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
    color: #ccc;
}

.empty-state h3 {
    margin-bottom: 0.5rem;
    color: #333;
}

/* Back link */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 1rem;
    color: #666;
    font-size: 0.9rem;
}

.back-link:hover {
    color: #333;
}

/* Footer */
footer {
    background: #1e3a5f;
    color: rgba(255, 255, 255, 0.7);
    padding: 1rem 0;
    text-align: center;
    font-size: 0.85rem;
}

/* PDF Modal */
.pdf-modal-overlay {
    z-index: 300;
}

.pdf-modal {
    width: 90%;
    max-width: 1200px;
    height: 90vh;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.pdf-modal-body {
    flex: 1;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.pdf-modal-body .loading {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.pdf-modal-body iframe {
    width: 100%;
    flex: 1;
    border: none;
    background: #f5f5f5;
}

/* Responsive */
@media (max-width: 768px) {
    .search-main {
        flex-direction: column;
    }
    
    .advanced-filters {
        grid-template-columns: 1fr;
    }
    
    .case-meta {
        grid-template-columns: 1fr;
    }
    
    .result-meta {
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .pdf-modal {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }
}
