/* Compact Tabular Design for Chinese Herbs Database */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background: #f8f9fa;
    min-height: 100vh;
    padding: 0;
    overflow-x: hidden;
    width: 100vw;
}

.container {
    max-width: 100%;
    margin: 0;
    overflow-x: hidden;
}

/* Header Section */
header {
    background: linear-gradient(to bottom, #d4a574 0%, #b8956a 100%);
    padding: 12px 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 3px solid #8b6f47;
    width: 100%;
    box-sizing: border-box;
}

.header-content {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

h1 {
    color: #2d1810;
    font-size: 1.3rem;
    font-weight: 700;
    margin: 0;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.3);
    letter-spacing: 0.5px;
    font-family: 'Georgia', 'Times New Roman', serif;
}

h1::before {
    content: '中藥本草 • ';
    color: #5a3a1a;
    margin-right: 6px;
    font-size: 1.1rem;
}

/* Search Section */
.search-container {
    display: flex;
    gap: 8px;
    flex: 1;
    max-width: 500px;
    min-width: 0;
}

#searchInput {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    font-size: 14px;
    border: 2px solid #8b6f47;
    border-radius: 6px;
    outline: none;
    transition: all 0.2s;
    background: #faf8f3;
}

#searchInput:focus {
    background: white;
    border-color: #5a3a1a;
    box-shadow: 0 2px 8px rgba(90, 58, 26, 0.2);
}

#searchBtn {
    padding: 8px 16px;
    background: #5a3a1a;
    color: #f5e6d3;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    white-space: nowrap;
}

#searchBtn:hover {
    background: #4a2f15;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

#resetBtn {
    padding: 8px 16px;
    background: #8b6f47;
    color: #f5e6d3;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    white-space: nowrap;
}

#resetBtn:hover {
    background: #6f5635;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

/* Back to Top Button */
#backToTop {
    position: fixed;
    bottom: 40px;
    right: 40px;
    padding: 15px 20px;
    background: #5a3a1a;
    color: #f5e6d3;
    border: none;
    border-radius: 50px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.3s;
    opacity: 0;
    visibility: hidden;
    z-index: 1000;
}

#backToTop.show {
    opacity: 1;
    visibility: visible;
}

#backToTop:hover {
    background: #4a2f15;
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

/* Main Content */
main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px 30px;
}

/* Herb Count Display */
.herb-count {
    background: linear-gradient(to right, #f7fafc, #edf2f7);
    padding: 15px 25px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid #5a3a1a;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

#countText {
    font-size: 15px;
    font-weight: 600;
    color: #2d3748;
}

/* Table Layout */
.herb-list {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.herb-table-header {
    display: grid;
    grid-template-columns: 40px 1fr 200px 250px 150px;
    gap: 15px;
    padding: 12px 20px;
    background: #f7fafc;
    border-bottom: 2px solid #e2e8f0;
    font-weight: 600;
    font-size: 13px;
    color: #4a5568;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.herb-row {
    display: grid;
    grid-template-columns: 40px 1fr 200px 250px 150px;
    gap: 15px;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: all 0.15s;
    align-items: center;
}

.herb-row:hover {
    background: #f7fafc;
}

.herb-row.expanded {
    background: #edf2f7;
    border-left: 4px solid #4299e1;
}

.expand-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #718096;
    font-size: 18px;
    transition: transform 0.2s;
}

.herb-row.expanded .expand-icon {
    transform: rotate(90deg);
    color: #4299e1;
}

.herb-name-col {
    font-weight: 600;
    color: #2d3748;
    font-size: 15px;
    text-transform: capitalize;
}

.herb-chinese {
    color: #718096;
    font-size: 13px;
    margin-top: 2px;
}

.herb-latin {
    font-style: italic;
    color: #718096;
    font-size: 13px;
}

.herb-family {
    color: #4299e1;
    font-size: 13px;
    font-weight: 500;
}

.herb-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    padding: 6px 12px;
    background: #edf2f7;
    color: #4a5568;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:hover {
    background: #e2e8f0;
    color: #2d3748;
}

/* Expanded Detail View */
.herb-detail {
    grid-column: 1 / -1;
    padding: 30px;
    background: white;
    border-top: 1px solid #e2e8f0;
    animation: slideDown 0.2s ease;
}

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

.detail-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 1200px;
}

.detail-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 6px;
    border-left: 3px solid #cbd5e0;
}

.detail-section h3 {
    color: #2d3748;
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-section h4 {
    color: #4a5568;
    font-size: 15px;
    font-weight: 600;
    margin: 15px 0 8px 0;
}

.detail-content {
    color: #4a5568;
    font-size: 15px;
    line-height: 1.7;
    white-space: pre-wrap;
}

/* Property Tags */
.property-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.property-tag {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 15px;
}

.property-tag .label {
    font-weight: 600;
    color: #718096;
    margin-right: 8px;
}

.property-tag .value {
    color: #2d3748;
    font-size: 15px;
}

/* Functions Section */
.function-item {
    background: #e6fffa;
    padding: 16px;
    border-radius: 6px;
    border-left: 3px solid #38b2ac;
    margin-bottom: 10px;
    font-size: 15px;
}

.function-item strong {
    color: #234e52;
    display: block;
    margin-bottom: 8px;
    font-size: 15px;
}

/* Prescriptions */
.prescription-item {
    background: #ebf8ff;
    padding: 18px;
    border-radius: 6px;
    border-left: 3px solid #4299e1;
    margin-bottom: 12px;
    position: relative;
    font-size: 15px;
}

.prescription-number {
    position: absolute;
    top: -8px;
    left: 12px;
    background: #4299e1;
    color: white;
    padding: 5px 12px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
}

.prescription-diagnosis {
    font-weight: 600;
    color: #2c5282;
    margin-bottom: 8px;
    margin-top: 8px;
    font-size: 15px;
}

/* Annotations */
.annotation-item {
    background: #fffaf0;
    padding: 14px;
    border-radius: 6px;
    border-left: 3px solid #ed8936;
    margin-bottom: 8px;
    font-size: 15px;
}

.contraindication-item {
    background: #fff5f5;
    padding: 14px;
    border-radius: 6px;
    border-left: 3px solid #fc8181;
    margin-bottom: 8px;
    font-size: 15px;
}

/* Dosage Section */
.dosage-section {
    background: #f0fff4;
    border-left-color: #48bb78;
}

.dosage-info {
    display: flex;
    gap: 20px;
    margin-top: 10px;
}

.dosage-item {
    display: flex;
    flex-direction: column;
}

.dosage-item .label {
    font-size: 11px;
    color: #718096;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.dosage-item .value {
    font-size: 16px;
    color: #2d3748;
    font-weight: 600;
}

/* Loading States */
.loading, .no-results {
    text-align: center;
    padding: 60px 20px;
    font-size: 15px;
    color: #718096;
}

/* Close Button for Detail View */
.close-detail {
    position: absolute;
    top: 20px;
    right: 20px;
    background: #e2e8f0;
    color: #4a5568;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 18px;
    border: none;
}

.close-detail:hover {
    background: #cbd5e0;
    color: #2d3748;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 30px;
    padding: 20px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.page-btn {
    padding: 12px 24px;
    background: #5a3a1a;
    color: #f5e6d3;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.page-btn:hover:not(:disabled) {
    background: #4a2f15;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.page-btn:disabled {
    background: #cbd5e0;
    color: #a0aec0;
    cursor: not-allowed;
    box-shadow: none;
}

.page-info {
    font-size: 15px;
    font-weight: 600;
    color: #2d3748;
    padding: 0 15px;
}

.page-info span {
    color: #5a3a1a;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to bottom, #d4a574 0%, #b8956a 100%);
    border-top: 2px solid #8b6f47;
    display: flex;
    justify-content: space-around;
    padding: 8px 0 calc(12px + env(safe-area-inset-bottom)) 0;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1000;
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    padding: 8px 30px;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 8px;
    color: #5a3a1a;
}

.nav-btn:hover {
    background: rgba(90, 58, 26, 0.1);
}

.nav-btn.active {
    background: rgba(90, 58, 26, 0.2);
    color: #2d1810;
}

.nav-icon {
    font-size: 24px;
}

.nav-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Screen Container */
.screen-container {
    padding-bottom: calc(80px + env(safe-area-inset-bottom)); /* Space for bottom nav + safe area */
    min-height: 100vh;
}

/* Formula Styles */
.formula-list {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.formula-table-header {
    display: grid;
    grid-template-columns: 40px 2fr 120px 3fr;
    gap: 15px;
    padding: 12px 20px;
    background: #f7fafc;
    border-bottom: 2px solid #e2e8f0;
    font-weight: 600;
    font-size: 13px;
    color: #4a5568;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.formula-row {
    display: grid;
    grid-template-columns: 40px 2fr 120px 3fr;
    gap: 15px;
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: all 0.15s;
    align-items: center;
}

.formula-row:hover {
    background: #f7fafc;
}

.formula-row.expanded {
    background: #edf2f7;
    border-left: 4px solid #48bb78;
}

.formula-name-col {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.formula-english {
    font-weight: 600;
    color: #2d3748;
    font-size: 15px;
}

.formula-pinyin {
    font-size: 13px;
    color: #718096;
    font-style: italic;
}

.formula-code {
    color: #4299e1;
    font-weight: 600;
    font-size: 13px;
}

.formula-functions {
    color: #4a5568;
    font-size: 14px;
    line-height: 1.5;
}

.formula-detail {
    grid-column: 1 / -1;
    padding: 30px;
    background: white;
    border-top: 1px solid #e2e8f0;
    animation: slideDown 0.2s ease;
}

.formula-herbs-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px;
    margin-top: 10px;
}

.formula-herb-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: #f0fff4;
    border-radius: 6px;
    border-left: 3px solid #48bb78;
}

.formula-herb-item .herb-name {
    font-weight: 600;
    color: #2d3748;
    font-size: 14px;
}

.formula-herb-item .herb-pinyin {
    font-size: 12px;
    color: #718096;
    font-style: italic;
    margin-top: 2px;
}

.formula-herb-item .herb-percentage {
    font-weight: 700;
    color: #48bb78;
    font-size: 14px;
}

.modification-item {
    background: #fff5f5;
    padding: 12px 16px;
    border-radius: 6px;
    border-left: 3px solid #fc8181;
    margin-bottom: 8px;
    font-size: 14px;
    color: #4a5568;
    line-height: 1.6;
}

/* Detail Page Styles */
.detail-page-content {
    max-width: 100%;
    padding: 20px;
}

.detail-page-header {
    background: linear-gradient(to bottom, #f7fafc, #edf2f7);
    padding: 30px;
    border-radius: 12px;
    margin-bottom: 30px;
    border-left: 6px solid #5a3a1a;
}

.herb-name-large, .formula-name-large {
    font-size: 28px;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 10px;
}

.herb-chinese-large {
    font-size: 24px;
    color: #4a5568;
    margin-bottom: 8px;
}

.herb-alternate-names {
    font-size: 16px;
    font-style: italic;
    color: #718096;
    margin-bottom: 8px;
}

.herb-latin-large {
    font-size: 18px;
    font-style: italic;
    color: #718096;
}

.formula-pinyin-large {
    font-size: 20px;
    font-style: italic;
    color: #4a5568;
    margin-bottom: 8px;
}

.formula-code-large {
    font-size: 16px;
    color: #4299e1;
    font-weight: 600;
}

.formula-herbs-list-page {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 15px;
}

.formula-herb-item-page {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: #f0fff4;
    border-radius: 8px;
    border-left: 4px solid #48bb78;
}

.formula-herb-item-page .herb-info {
    flex: 1;
}

.formula-herb-item-page .herb-name {
    font-weight: 600;
    color: #2d3748;
    font-size: 16px;
    margin-bottom: 4px;
}

.formula-herb-item-page .herb-pinyin {
    font-size: 14px;
    color: #718096;
    font-style: italic;
}

.formula-herb-item-page .herb-percentage {
    font-weight: 700;
    color: #48bb78;
    font-size: 20px;
    min-width: 60px;
    text-align: right;
}

/* Responsive */
@media (max-width: 1024px) {
    .herb-table-header,
    .herb-row {
        grid-template-columns: 40px 1fr 180px 120px;
    }

    .herb-latin {
        display: none;
    }

    .formula-table-header,
    .formula-row {
        grid-template-columns: 40px 1fr 100px 2fr;
    }

    .formula-herbs-list {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    /* Reduce side padding on mobile */
    header {
        padding: 10px 12px;
    }

    .header-content {
        flex-direction: column;
        gap: 10px;
    }

    h1 {
        font-size: 1.1rem;
        text-align: center;
    }

    h1::before {
        font-size: 0.95rem;
    }

    .search-container {
        max-width: 100%;
        width: 100%;
    }

    #searchInput {
        padding: 8px 10px;
        font-size: 14px;
    }

    #searchBtn, #resetBtn {
        padding: 8px 12px;
        font-size: 13px;
    }

    main {
        padding: 15px 10px;
    }

    .herb-count {
        padding: 12px 15px;
        margin-bottom: 15px;
    }

    .herb-list, .formula-list {
        border-radius: 4px;
    }

    .herb-table-header, .formula-table-header {
        display: none;
    }

    .herb-row {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 12px 10px;
    }

    .formula-row {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 12px 10px;
    }

    .formula-name-col {
        order: 1;
    }

    .formula-code {
        order: 2;
        font-size: 11px;
    }

    .formula-functions {
        order: 3;
        font-size: 13px;
    }

    .formula-herbs-list {
        grid-template-columns: 1fr;
    }

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

    .detail-section {
        padding: 15px;
    }

    .pagination {
        flex-direction: column;
        gap: 15px;
        padding: 15px 10px;
        margin-bottom: calc(80px + env(safe-area-inset-bottom)); /* Extra space for bottom nav + safe area */
    }

    .page-btn {
        width: 100%;
        padding: 14px 20px;
    }

    .bottom-nav {
        padding: 6px 0 calc(10px + env(safe-area-inset-bottom)) 0;
    }

    .nav-btn {
        padding: 6px 20px;
    }

    .nav-icon {
        font-size: 20px;
    }

    .nav-label {
        font-size: 11px;
    }

    #backToTop {
        bottom: 80px; /* Above bottom nav */
        right: 20px;
        padding: 12px 16px;
        font-size: 14px;
    }
}
