/* ========================================
   GeneRx Portal - Modern CSS Stylesheet
   ======================================== */

/* CSS Variables */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --success-light: #d1fae5;
    --warning-color: #f59e0b;
    --warning-light: #fef3c7;
    --error-color: #ef4444;
    --error-light: #fee2e2;
    
    --bg-color: #f8fafc;
    --sidebar-bg: #1e293b;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    --transition: all 0.2s ease;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

/* App Container */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.logo {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.25rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo i {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.nav-menu {
    padding: 16px 12px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: var(--transition);
    margin-bottom: 4px;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.nav-item.active {
    background: var(--primary-color);
    color: white;
}

.nav-item i {
    width: 20px;
    text-align: center;
}

.sidebar-stats {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

.stat-item i {
    font-size: 1.25rem;
    color: var(--primary-color);
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Sidebar User Section */
.sidebar-user {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    margin-bottom: 10px;
}

.user-info i {
    color: var(--success-color);
}

.user-info span {
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.9);
}

.sidebar-user .btn-logout {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.sidebar-user .btn-logout:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.sidebar-user .btn-login {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.sidebar-user .btn-login:hover {
    background: var(--primary-hover);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 32px;
    max-width: 1200px;
}

/* Page Header */
.page-header {
    margin-bottom: 32px;
}

.header-content h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.header-content p {
    color: var(--text-secondary);
    font-size: 1rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    margin-bottom: 16px;
    transition: var(--transition);
}

.back-link:hover {
    color: var(--primary-hover);
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 24px;
    overflow: visible;
    position: relative;
}

/* First card (disease selector) needs higher z-index for dropdown */
.card:first-of-type {
    z-index: 100;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(to right, var(--primary-light), transparent);
}

.card-header i {
    font-size: 1.25rem;
    color: var(--primary-color);
}

.card-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    flex: 1;
}

.card-actions {
    margin-left: auto;
}

.card-body {
    padding: 24px;
    overflow: visible;
    position: relative;
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
    position: relative;
    padding-bottom: 10px;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    padding: 14px 16px;
    padding-left: 44px;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: var(--transition);
    background: white;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-hint {
    display: block;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 8px;
}

.form-hint i {
    margin-right: 4px;
}

/* Autocomplete */
.autocomplete-wrapper {
    position: relative;
    z-index: 100;
}

.autocomplete-wrapper:focus-within {
    z-index: 1000;
}

.input-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.suggestions-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid var(--primary-color);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    max-height: 350px;
    overflow-y: auto;
    z-index: 9999;
    display: none;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
}

.suggestions-dropdown::-webkit-scrollbar {
    width: 8px;
}

.suggestions-dropdown::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.suggestions-dropdown::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.suggestions-dropdown::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

.suggestions-count {
    padding: 8px 16px;
    background: #f8fafc;
    font-size: 0.8rem;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    z-index: 1;
}

.suggestion-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 1px solid var(--border-color);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover,
.suggestion-item.active {
    background: var(--primary-light);
    color: var(--primary-color);
}

/* Highlight matching text in suggestions */
.suggestion-item mark.highlight {
    background: var(--warning-light);
    color: var(--primary-hover);
    font-weight: 600;
    padding: 1px 2px;
    border-radius: 3px;
}

.suggestion-item.active mark.highlight,
.suggestion-item:hover mark.highlight {
    background: var(--primary-color);
    color: white;
}

/* Prescriptions Container */
#prescriptions-container {
    position: relative;
    min-height: 120px;
    padding-bottom: 20px;
}

/* Prescription Cards */
.prescription-card {
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    transition: var(--transition);
    overflow: visible;
    position: relative;
}

/* When herb suggestions are open, give the card higher z-index */
.prescription-card:focus-within {
    z-index: 100;
}

.prescription-card:hover {
    border-color: var(--primary-color);
}

.prescription-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
}

.prescription-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: var(--radius-full);
}

.prescription-badge.large {
    padding: 10px 20px;
    font-size: 1rem;
}

.prescription-body {
    padding: 16px;
    min-height: 80px;
    position: relative;
    overflow: visible;
}

/* Tags Input Container - Tags and Input in same box */
.tags-input-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    min-height: 52px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: white;
    cursor: text;
    transition: var(--transition);
}

.tags-input-container:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.tags-input {
    flex: 1;
    min-width: 150px;
    border: none;
    outline: none;
    font-size: 1rem;
    padding: 4px 0;
    background: transparent;
}

.tags-input::placeholder {
    color: var(--text-muted);
}

/* Herb Tags */
.herbs-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
    min-height: 20px;
}

.herb-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
    font-weight: 500;
    font-size: 0.875rem;
    border-radius: var(--radius-full);
    animation: tagEnter 0.2s ease;
    white-space: nowrap;
}

@keyframes tagEnter {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.herb-tag .remove-tag {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.75rem;
}

.herb-tag .remove-tag:hover {
    background: rgba(255, 255, 255, 0.4);
}

.herb-chip {
    display: inline-block;
    padding: 6px 12px;
    background: var(--primary-light);
    color: var(--primary-color);
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-full);
    margin: 2px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-outline {
    background: transparent;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-outline:hover {
    background: var(--primary-light);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.875rem;
}

.btn-lg {
    padding: 16px 32px;
    font-size: 1rem;
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--error-light);
    color: var(--error-color);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 16px;
    margin-top: 24px;
}

/* Alerts */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px 20px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
}

.alert i {
    font-size: 1.25rem;
    margin-top: 2px;
}

.alert-error {
    background: var(--error-light);
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-warning {
    background: var(--warning-light);
    color: #92400e;
    border: 1px solid #fde68a;
}

.alert ul {
    margin: 8px 0 0 20px;
}

/* Summary Grid */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.summary-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.summary-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    font-size: 1.5rem;
}

.summary-icon.blue {
    background: var(--primary-light);
    color: var(--primary-color);
}

.summary-icon.green {
    background: var(--success-light);
    color: var(--success-color);
}

.summary-content {
    display: flex;
    flex-direction: column;
}

.summary-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.summary-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Prescription Summary */
.prescription-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.prescription-summary-card {
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.prescription-summary-header {
    padding: 16px;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
}

.prescription-summary-body {
    padding: 16px;
}

.herbs-list {
    margin-bottom: 16px;
}

.prescription-stats {
    display: flex;
    justify-content: space-around;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.prescription-stats .stat {
    text-align: center;
}

.prescription-stats .stat-num {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.prescription-stats .stat-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Enrichment Results */
.enrichment-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 24px;
}

.enrichment-card {
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.enrichment-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
}

.result-count {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.enrichment-table-wrapper {
    max-height: 400px;
    overflow-y: auto;
}

.enrichment-table {
    width: 100%;
    border-collapse: collapse;
}

.enrichment-table th {
    position: sticky;
    top: 0;
    background: var(--bg-color);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-color);
}

.enrichment-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

.enrichment-table tr:hover {
    background: var(--bg-color);
}

.term-cell {
    max-width: 200px;
}

.term-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pvalue {
    color: var(--success-color);
    font-weight: 500;
    font-family: monospace;
}

.score {
    font-weight: 600;
    color: var(--primary-color);
}

/* No Results */
.no-results {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}

.no-results i {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.no-results h3 {
    color: var(--text-primary);
    margin-bottom: 8px;
}

.no-results p {
    margin-bottom: 24px;
}

/* Loading State */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    color: var(--text-muted);
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================
   Korean Language Support Styles
   ========================================== */

/* Korean text in suggestions */
.herb-english {
    color: var(--text-muted);
    font-size: 0.85em;
}

.suggestion-item .herb-english {
    margin-left: 4px;
}

/* Herb tags with Korean names */
.herb-tag {
    font-size: 0.85rem;
}

/* Ensure Korean characters display properly */
.suggestion-item,
.herb-tag,
.tags-input {
    font-family: 'Inter', 'Malgun Gothic', '맑은 고딕', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Print Styles */
@media print {
    .sidebar,
    .form-actions,
    .back-link {
        display: none !important;
    }
    
    .main-content {
        margin: 0;
        padding: 20px;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
