:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-card: #18181f;
    --bg-hover: #1f1f28;
    --text-primary: #f5f5f7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent: #6366f1;
    --accent-light: #818cf8;
    --border: rgba(255, 255, 255, 0.08);
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
}

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

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

.app {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden;
}

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

.sidebar-header h1 {
    font-size: 1rem;
    font-weight: 600;
}

.badge {
    background: var(--accent);
    color: white;
    padding: 0.25rem 0.625rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.chapters-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.chapter-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
}

.chapter-item:hover {
    background: var(--bg-hover);
}

.chapter-item.active {
    background: var(--accent);
}

.chapter-num {
    width: 28px;
    height: 28px;
    background: var(--bg-card);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.chapter-item.active .chapter-num {
    background: rgba(255, 255, 255, 0.2);
}

.chapter-info {
    flex: 1;
    min-width: 0;
}

.chapter-name {
    font-size: 0.8125rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chapter-count {
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.chapter-item.active .chapter-count {
    color: rgba(255, 255, 255, 0.7);
}

/* Main Content */
.main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.main-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.main-header p {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.treatments-grid {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1rem;
    align-content: start;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    padding: 4rem 1rem;
}

/* Treatment Card */
.treatment-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.25rem;
    cursor: pointer;
    transition: all 0.2s;
}

.treatment-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.card-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.type-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.type-icon.supplement {
    background: rgba(99, 102, 241, 0.2);
}

.type-icon.dietary {
    background: rgba(34, 211, 238, 0.2);
}

.type-icon.lifestyle {
    background: rgba(52, 211, 153, 0.2);
}

.type-icon.medication {
    background: rgba(248, 113, 113, 0.2);
}

.card-title {
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.3;
}

.card-summary {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.meta-tag {
    padding: 0.25rem 0.5rem;
    background: var(--bg-hover);
    border-radius: 4px;
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.meta-tag.type {
    color: var(--accent-light);
}

.meta-tag.safety-general {
    color: var(--success);
}

.meta-tag.safety-caution {
    color: var(--warning);
}

.meta-tag.safety-prescription_only {
    color: var(--danger);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    max-width: 640px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    transform: scale(0.95);
    transition: transform 0.2s;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    background: var(--bg-card);
    border: none;
    border-radius: 50%;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    z-index: 10;
}

.modal-close:hover {
    background: var(--danger);
    color: white;
}

.modal-body {
    padding: 1.5rem;
}

.modal-header {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-right: 2rem;
}

.modal-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.modal-icon.supplement {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

.modal-icon.dietary {
    background: linear-gradient(135deg, #22d3ee, #0ea5e9);
}

.modal-icon.lifestyle {
    background: linear-gradient(135deg, #34d399, #10b981);
}

.modal-icon.medication {
    background: linear-gradient(135deg, #f87171, #ef4444);
}

.modal-title h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.modal-title p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.modal-section {
    margin-bottom: 1.25rem;
}

.modal-section h3 {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.modal-section p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.info-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.info-box {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 0.75rem;
}

.info-box label {
    display: block;
    font-size: 0.625rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.info-box span {
    font-size: 0.875rem;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.tag {
    padding: 0.25rem 0.625rem;
    background: rgba(99, 102, 241, 0.15);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--accent-light);
}

.list-item {
    padding: 0.5rem 0.75rem;
    background: var(--bg-card);
    border-radius: 6px;
    font-size: 0.8125rem;
    margin-bottom: 0.375rem;
}

.excerpt {
    background: var(--bg-card);
    border-left: 3px solid var(--accent);
    padding: 0.75rem;
    border-radius: 0 8px 8px 0;
    margin-bottom: 0.5rem;
}

.excerpt p {
    font-style: italic;
    margin-bottom: 0.25rem;
}

.excerpt span {
    font-size: 0.6875rem;
    color: var(--text-muted);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 768px) {
    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: auto;
        border-right: none;
        border-top: 1px solid var(--border);
        flex-direction: row;
        z-index: 50;
    }

    .sidebar-header {
        display: none;
    }

    .chapters-nav {
        display: flex;
        overflow-x: auto;
        padding: 0.5rem;
    }

    .chapter-item {
        flex-direction: column;
        padding: 0.5rem;
        min-width: 70px;
    }

    .chapter-info {
        text-align: center;
    }

    .main {
        padding-bottom: 80px;
    }

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