/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

.container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

.header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

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

.header p {
    opacity: 0.9;
    font-size: 0.95rem;
}

/* Main content */
.main {
    flex: 1;
    padding: 2rem;
}

.law-browser {
    display: grid;
    grid-template-columns: 350px 1fr 400px;
    gap: 1.5rem;
    height: calc(100vh - 200px);
    max-width: 1600px;
    margin: 0 auto;
}

/* Panel styles */
.left-panel, .middle-panel, .right-panel {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-header {
    background: #f8fafc;
    padding: 1.25rem;
    border-bottom: 1px solid #e2e8f0;
}

.panel-header h2 {
    font-size: 1.25rem;
    color: #1a202c;
    font-weight: 600;
}

/* Left panel - Laws list */
.laws-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Folder tree structure */
.law-folder {
    margin-bottom: 0.5rem;
}

.folder-header {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.2s ease;
    font-weight: 600;
    color: #2d3748;
}

.folder-header:hover {
    background: #f7fafc;
}

.folder-header.expanded {
    background: #edf2f7;
}

.folder-icon {
    margin-right: 0.5rem;
    font-size: 1rem;
    transition: transform 0.2s ease;
}

.folder-header.expanded .folder-icon {
    transform: rotate(90deg);
}

.law-title-folder {
    flex: 1;
    margin-left: 0.5rem;
}

.law-stats-folder {
    font-size: 0.8rem;
    color: #718096;
}

.paragraphs-tree {
    margin-left: 1.5rem;
    border-left: 2px solid #e2e8f0;
    padding-left: 1rem;
    margin-top: 0.5rem;
    display: none;
}

.paragraphs-tree.expanded {
    display: block;
}

.paragraph-tree-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    border-radius: 4px;
    margin-bottom: 0.25rem;
    transition: all 0.2s ease;
}

.paragraph-tree-item:hover {
    background: #f7fafc;
    border-color: #667eea;
}

.paragraph-number-tree {
    font-size: 0.85rem;
    font-weight: 600;
    color: #667eea;
    min-width: 2.5rem;
}

.paragraph-title-tree {
    flex: 1;
    margin-left: 0.75rem;
    font-size: 0.85rem;
    color: #4a5568;
}

.reference-count-tree {
    font-size: 0.75rem;
    color: #718096;
    background: #e2e8f0;
    padding: 0.2rem 0.4rem;
    border-radius: 10px;
}

.paragraph-tree-item.selected {
    background: #667eea;
    color: white;
}

.paragraph-tree-item.selected .paragraph-number-tree,
.paragraph-tree-item.selected .paragraph-title-tree {
    color: white;
}

/* Law content styles */
.law-full-content {
    padding: 2rem;
}

.law-header-content h1 {
    font-size: 2rem;
    color: #2d3748;
    margin-bottom: 1.5rem;
    border-bottom: 3px solid #667eea;
    padding-bottom: 1rem;
}

.law-description {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: #f8fafc;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.law-description h3 {
    color: #2d3748;
    margin-bottom: 1rem;
}

.law-full-text {
    line-height: 1.7;
    color: #4a5568;
    font-size: 1rem;
}

.law-meta-content {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
    padding: 1rem;
    background: #edf2f7;
    border-radius: 8px;
}

.law-meta-content .meta-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #4a5568;
    font-weight: 500;
}

.paragraphs-content h2 {
    font-size: 1.5rem;
    color: #2d3748;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 0.5rem;
}

.paragraph-content-item {
    margin-bottom: 2rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}

.paragraph-content-header {
    background: #f8fafc;
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.paragraph-content-header h3 {
    color: #2d3748;
    margin: 0;
    font-size: 1.1rem;
}

.references-btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.2s ease;
}

.references-btn:hover {
    background: #5a67d8;
}

.paragraph-content-text {
    padding: 1.5rem;
    line-height: 1.6;
    color: #4a5568;
}

.references-container {
    border-top: 1px solid #e2e8f0;
    background: #f7fafc;
}

.law-item {
    margin-bottom: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.2s ease;
}

.law-item:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15);
}

.law-header {
    padding: 1rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.law-header:hover {
    background: #f7fafc;
}

.law-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #2d3748;
    margin-bottom: 0.5rem;
}

.law-description {
    color: #718096;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.law-stats {
    display: flex;
    gap: 1rem;
}

.stat {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: #718096;
}

.stat-icon {
    font-size: 0.8rem;
}

/* Middle panel - Law details */
.law-details {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.welcome-message {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.welcome-content h3 {
    font-size: 1.5rem;
    color: #2d3748;
    margin-bottom: 1rem;
}

.welcome-content p {
    color: #718096;
    margin-bottom: 2rem;
}

.features {
    display: grid;
    gap: 1.5rem;
    text-align: left;
    max-width: 400px;
}

.feature {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.feature-icon {
    font-size: 1.5rem;
    margin-top: 0.25rem;
}

.feature h4 {
    color: #2d3748;
    margin-bottom: 0.5rem;
}

.feature p {
    color: #718096;
    font-size: 0.9rem;
    margin: 0;
}

/* Law detail content */
.law-header-detail {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #e2e8f0;
}

.law-header-detail h2 {
    font-size: 1.75rem;
    color: #2d3748;
    margin-bottom: 0.75rem;
}

.law-meta {
    display: flex;
    gap: 1.5rem;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #718096;
    font-size: 0.9rem;
}

.meta-icon {
    font-size: 0.85rem;
}

.section {
    margin-bottom: 2rem;
}

.section h3 {
    font-size: 1.25rem;
    color: #2d3748;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e2e8f0;
}

/* Paragraphs */
.paragraphs-list {
    display: grid;
    gap: 0.75rem;
}

.paragraph-item {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.paragraph-item:hover {
    border-color: #667eea;
    background: #f7fafc;
}

.paragraph-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.paragraph-number {
    font-size: 1rem;
    font-weight: 600;
    color: #667eea;
}

.paragraph-title {
    flex: 1;
    margin: 0 1rem;
    color: #2d3748;
    font-size: 0.95rem;
}

.reference-badge {
    background: #667eea;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.paragraph-text {
    color: #718096;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Right panel - References */
.references {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.paragraph-references {
    height: 100%;
}

.references-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e2e8f0;
}

.references-header h3 {
    font-size: 1.1rem;
    color: #2d3748;
    margin-bottom: 0.5rem;
}

.references-header .paragraph-title {
    color: #718096;
    font-size: 0.9rem;
    margin: 0;
}

.paragraph-full-content {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: #f7fafc;
    border-radius: 8px;
}

.paragraph-full-content h4 {
    font-size: 1rem;
    color: #2d3748;
    margin-bottom: 0.75rem;
}

.paragraph-text-full {
    color: #4a5568;
    line-height: 1.6;
    font-size: 0.9rem;
}

/* References list */
.references-section h4 {
    font-size: 1rem;
    color: #2d3748;
    margin-bottom: 1rem;
}

.references-list {
    display: grid;
    gap: 1rem;
}

.reference-item {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    background: white;
}

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

.reference-target {
    font-size: 0.95rem;
    color: #2d3748;
}

.confidence-badge {
    background: #48bb78;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.reference-text {
    color: #718096;
    font-style: italic;
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    background: #f7fafc;
    border-radius: 6px;
    border-left: 3px solid #667eea;
}

.reference-actions {
    display: flex;
    gap: 0.5rem;
}

/* Buttons */
.btn-link, .btn-secondary {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
}

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

.btn-link:hover {
    background: #5a67d8;
}

.btn-secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.btn-secondary:hover {
    background: #cbd5e0;
}

/* Empty states */
.empty-state {
    text-align: center;
    padding: 2rem;
    color: #718096;
}

.empty-icon {
    font-size: 2rem;
    margin-bottom: 1rem;
    display: block;
}

.no-references .empty-state {
    padding: 3rem 1rem;
}

.no-references h4 {
    color: #4a5568;
    margin-bottom: 0.5rem;
}

/* Loading states */
.loading {
    text-align: center;
    padding: 2rem;
    color: #718096;
}

/* Simplified reference list styles */
.references-simple-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.reference-list-item {
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.reference-list-item:hover {
    background: #f7fafc;
    border-left-color: #667eea;
}

.reference-target {
    font-weight: 600;
    color: #2d3748;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.reference-list-item .reference-text {
    font-size: 0.8rem;
    color: #718096;
    font-style: italic;
    line-height: 1.3;
}

/* Paragraph content styles */
.paragraph-content {
    margin-top: 0.75rem;
}

.paragraph-text {
    font-size: 0.9rem;
    color: #4a5568;
    line-height: 1.5;
    margin-bottom: 0.5rem;
}

.reference-hint {
    font-size: 0.8rem;
    color: #667eea;
    font-style: italic;
    margin: 0;
}

/* Back action */
.back-action {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid #e2e8f0;
}

/* Footer */
.footer {
    background: #2d3748;
    color: #cbd5e0;
    text-align: center;
    padding: 1rem 2rem;
    font-size: 0.9rem;
}

/* Responsive design */
@media (max-width: 1200px) {
    .law-browser {
        grid-template-columns: 300px 1fr 350px;
    }
}

@media (max-width: 768px) {
    .law-browser {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        height: auto;
    }
    
    .left-panel, .middle-panel, .right-panel {
        height: 400px;
    }
    
    .main {
        padding: 1rem;
    }
    
    .header {
        padding: 1rem;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
}

/* Loading indicator */
.loading-indicator {
    display: none;
    color: #667eea;
    font-size: 0.85rem;
    font-weight: 500;
}

.loading-indicator.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: block;
}

.loading-spinner {
    margin-right: 0.5rem;
}

/* Click to load styling */
.paragraph-preview {
    padding: 0.75rem;
    margin-top: 0.5rem;
}

.click-to-load {
    color: #718096;
    font-style: italic;
    font-size: 0.9rem;
    text-align: center;
    padding: 1rem;
    background: #f7fafc;
    border: 1px dashed #e2e8f0;
    border-radius: 6px;
    margin: 0;
    transition: all 0.2s ease;
}

.paragraph-item:hover .click-to-load {
    color: #667eea;
    border-color: #667eea;
    background: #edf2f7;
}

/* Enhanced paragraph item styling */
.paragraph-item {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 0.5rem;
}

.paragraph-item:hover {
    border-color: #667eea;
    background: #f7fafc;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}

.paragraph-item.htmx-request {
    border-color: #667eea;
    background: #f0f4ff;
}

/* Panel header improvements */
.panel-header {
    background: #f8fafc;
    padding: 1.25rem;
    border-bottom: 1px solid #e2e8f0;
    position: relative;
}

.panel-header .loading-indicator {
    position: absolute;
    right: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
}

/* Utility classes */
.text-center { text-align: center; }
.text-sm { font-size: 0.875rem; }
.font-bold { font-weight: 600; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }