/* ============================================
   TrovaByte - Module 101 Styles
   Italian Color Scheme: Red (primary) + Green (secondary)
   ============================================ */

:root {
    --primary-color: #CE2B37;
    --primary-dark: #A8222D;
    --primary-light: #E04350;
    --secondary-color: #006341;
    --secondary-dark: #004D32;
    --secondary-light: #007A50;
    --success-color: #006341;
    --warning-color: #d97706;
    --error-color: #CE2B37;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --border-radius: 8px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #faf5f5 0%, #f0e8e8 100%);
    min-height: 100vh;
    color: var(--gray-800);
    line-height: 1.6;
}

/* ============ Navigation ============ */

.navbar {
    background: var(--primary-dark);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-brand a { font-size: 1.25rem; font-weight: 700; color: white; text-decoration: none; }
.nav-brand-link { display: flex; align-items: center; gap: 0.75rem; text-decoration: none; }
.nav-title { font-size: 1.5rem; font-weight: 700; color: white; letter-spacing: 0.5px; }
.nav-links { display: flex; align-items: center; gap: 1rem; }
.user-email { color: rgba(255, 255, 255, 0.75); font-size: 0.875rem; }

/* ============ Main Content ============ */

.main-content { min-height: calc(100vh - 140px); padding: 2rem; }

/* ============ Flash Messages ============ */

.flash-messages { max-width: 600px; margin: 0 auto 2rem; }
.flash { padding: 1rem; border-radius: var(--border-radius); margin-bottom: 0.5rem; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.flash-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.flash-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.flash-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ============ Buttons ============ */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.625rem 1.25rem; font-size: 0.875rem; font-weight: 500;
    border-radius: var(--border-radius); cursor: pointer; transition: all 0.2s ease;
    text-decoration: none; border: none;
}
.btn-primary { background: var(--primary-color); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: transparent; color: rgba(255, 255, 255, 0.85); border: 1px solid rgba(255, 255, 255, 0.4); }
.btn-outline:hover { background: rgba(255, 255, 255, 0.1); color: white; }
.btn-outline-dark { background: transparent; color: var(--gray-600); border: 1px solid var(--gray-300); }
.btn-outline-dark:hover { background: var(--gray-100); }
.btn-secondary { background: var(--secondary-color); color: white; }
.btn-secondary:hover { background: var(--secondary-dark); }
.btn-full { width: 100%; }
.btn-small { padding: 0.25rem 0.75rem; font-size: 0.875rem; }
.btn-danger { background: #e74c3c; color: white; border: none; }
.btn-danger:hover { background: #c0392b; }

/* ============ Auth Pages ============ */

.auth-container { display: flex; justify-content: center; align-items: center; min-height: calc(100vh - 140px); }
.auth-card { background: white; padding: 2.5rem; border-radius: 12px; box-shadow: var(--shadow-lg); width: 100%; max-width: 420px; }
.auth-header { text-align: center; margin-bottom: 2rem; }
.auth-header h1 { font-size: 1.5rem; color: var(--primary-color); margin-bottom: 0.5rem; }
.auth-header p { color: var(--gray-500); }
.auth-form { display: flex; flex-direction: column; gap: 1.25rem; }
.form-group { display: flex; flex-direction: column; gap: 0.5rem; }
.form-group label { font-size: 0.875rem; font-weight: 500; color: var(--gray-700); }
.form-group input {
    padding: 0.75rem 1rem; border: 1px solid var(--gray-300);
    border-radius: var(--border-radius); font-size: 1rem; transition: border-color 0.2s ease;
}
.form-group input:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(206, 43, 55, 0.1); }
.auth-footer { text-align: center; margin-top: 1.5rem; color: var(--gray-500); }
.auth-footer a { color: var(--primary-color); text-decoration: none; font-weight: 500; }

/* ============ Footer ============ */

.footer { text-align: center; padding: 1.5rem; color: var(--gray-400); font-size: 0.8rem; }

/* ============ Search Page ============ */

.search-container { max-width: 800px; margin: 0 auto; }

.search-hero { text-align: center; margin-bottom: 2rem; }
.search-hero h1 { font-size: 2.5rem; font-weight: 700; color: var(--primary-color); margin-bottom: 0.5rem; }
.search-subtitle { font-size: 1.1rem; color: var(--secondary-color); font-weight: 500; margin-bottom: 0.5rem; }
.search-description { color: var(--gray-500); font-size: 0.95rem; }

.search-card {
    background: white; padding: 2rem; border-radius: 12px;
    box-shadow: var(--shadow-lg); margin-bottom: 2rem;
    border-top: 4px solid var(--primary-color);
}

.search-type-toggle { display: flex; gap: 1rem; margin-bottom: 1.5rem; justify-content: center; }
.toggle-option { cursor: pointer; }
.toggle-option input { display: none; }
.toggle-label {
    display: inline-block; padding: 0.5rem 1.5rem;
    border: 2px solid var(--gray-300); border-radius: 20px;
    font-weight: 500; color: var(--gray-500); transition: all 0.2s;
}
.toggle-option input:checked + .toggle-label {
    border-color: var(--primary-color); color: var(--primary-color);
    background: rgba(206, 43, 55, 0.05);
}

.search-input-group { display: flex; gap: 0.75rem; }
.search-input-group input {
    flex: 1; padding: 0.875rem 1rem; border: 2px solid var(--gray-200);
    border-radius: var(--border-radius); font-size: 1rem; transition: border-color 0.2s;
}
.search-input-group input:focus { outline: none; border-color: var(--primary-color); }
.btn-search { padding: 0.875rem 2rem; font-size: 1rem; }

.quick-search { margin-top: 1.25rem; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.quick-search-label { font-size: 0.85rem; color: var(--gray-500); }
.quick-btn {
    padding: 0.375rem 0.875rem; border: 1px solid var(--gray-200);
    border-radius: 16px; background: var(--gray-50); color: var(--gray-600);
    font-size: 0.8rem; cursor: pointer; transition: all 0.2s;
}
.quick-btn:hover { border-color: var(--primary-color); color: var(--primary-color); background: rgba(206, 43, 55, 0.05); }

.stats-bar {
    display: flex; justify-content: center; gap: 3rem;
    padding: 1rem; color: var(--gray-500); font-size: 0.9rem;
}
.stat-item { text-align: center; }
.stat-value { display: block; font-size: 1.5rem; font-weight: 700; color: var(--primary-color); }
.stat-label { font-size: 0.8rem; }

/* ============ Results Page ============ */

.results-container { max-width: 1800px; margin: 0 auto; }

.results-header { margin-bottom: 2rem; }
.results-header h1 { font-size: 1.75rem; color: var(--primary-dark); margin: 0.75rem 0 0.25rem; }
.brand-name { font-weight: 400; color: var(--gray-500); font-size: 0.85em; }
.results-summary { color: var(--gray-500); }
.btn-back { margin-bottom: 0.5rem; color: var(--gray-600); border-color: var(--gray-300); }
.btn-back:hover { background: var(--gray-100); }

/* ============ Indication Cards ============ */

.indication-cards {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.indication-card {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    padding: 1.25rem 1.5rem;
    border-left: 4px solid var(--secondary-color);
    transition: box-shadow 0.2s;
}
.indication-card:hover {
    box-shadow: var(--shadow-lg);
}

/* Tags Row */
.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.tag {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: 0.2px;
}
.tag-reimbursed { background: #dcfce7; color: #166534; }
.tag-not-reimbursed { background: #fee2e2; color: #991b1b; }
.tag-restricted { background: #fef3c7; color: #92400e; }
.tag-class { background: #dbeafe; color: #1e40af; }
.tag-disease { background: #f3e8ff; color: #6b21a8; }
.tag-product { background: #e0f2fe; color: #0369a1; }

/* Indication Text */
.card-indication {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--gray-800);
    margin-bottom: 0.75rem;
}

/* Population (when different from indication) */
.card-population {
    padding: 0.6rem 0.75rem;
    background: rgba(0, 99, 65, 0.04);
    border-left: 3px solid var(--secondary-color);
    border-radius: 0 6px 6px 0;
    margin-bottom: 0.75rem;
}

.pop-label {
    display: block;
    font-weight: 600;
    color: var(--secondary-dark);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 0.2rem;
}

.pop-text {
    font-size: 0.88rem;
    line-height: 1.5;
    color: var(--gray-700);
}

/* Rejection Reason */
.card-rejection {
    padding: 0.5rem 0.75rem;
    background: rgba(206, 43, 55, 0.04);
    border-left: 3px solid var(--primary-color);
    border-radius: 0 6px 6px 0;
    margin-bottom: 0.75rem;
    font-size: 0.88rem;
    color: var(--primary-dark);
    font-style: italic;
}

/* Metadata Row */
.card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    font-size: 0.8rem;
    color: var(--gray-500);
    padding-top: 0.5rem;
    border-top: 1px solid var(--gray-100);
}

.meta-det {
    font-weight: 600;
    color: var(--gray-700);
}

.meta-item {
    color: var(--gray-500);
}

.meta-duration {
    font-weight: 600;
    color: var(--primary-dark);
    background: rgba(206, 43, 55, 0.08);
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
}

/* Expandable Details */
.card-expand {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
    padding: 0.4rem 0;
    cursor: pointer;
    user-select: none;
    border-top: 1px dashed var(--gray-200);
}

.expand-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--gray-500);
}

.expand-arrow {
    font-size: 1rem;
    font-weight: 700;
    color: var(--gray-400);
    transition: transform 0.2s;
}

.card-expand.open .expand-arrow {
    transform: rotate(45deg);
}

.card-details {
    display: none;
    padding: 0.75rem 0 0;
}

.detail-row {
    font-size: 0.85rem;
    color: var(--gray-600);
    margin-bottom: 0.35rem;
    line-height: 1.4;
}

.detail-row strong {
    color: var(--gray-700);
}

/* No Results */

.no-results {
    text-align: center; padding: 3rem; background: white;
    border-radius: 12px; box-shadow: var(--shadow-md); color: var(--gray-500);
}

/* ============ Language Toggle ============ */

.lang-toggle {
    display: flex;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px;
    overflow: hidden;
}

.lang-btn {
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    border: none;
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.lang-btn.active {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.lang-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.85);
}

/* ============ Admin Page ============ */

.admin-container { max-width: 1200px; margin: 2rem auto; padding: 0 1rem; }
.admin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; padding-bottom: 1rem; border-bottom: 2px solid var(--gray-200); }
.admin-header h1 { margin: 0; color: var(--primary-dark); }
.admin-nav { display: flex; gap: 0.5rem; }
.admin-nav .btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.admin-nav .btn-secondary:hover { background: var(--gray-300); }
.admin-section { background: white; padding: 1.5rem; margin-bottom: 2rem; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.admin-section h2 { margin-top: 0; color: var(--primary-dark); border-bottom: 2px solid var(--primary-color); padding-bottom: 0.5rem; margin-bottom: 1rem; }
.admin-form .form-row { display: flex; gap: 1rem; align-items: flex-end; }
.admin-form .form-group { flex: 1; }
.admin-table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.admin-table th { background: #f8f9fa; padding: 0.75rem; text-align: left; border-bottom: 2px solid #dee2e6; font-weight: 600; color: #495057; }
.admin-table td { padding: 0.75rem; border-bottom: 1px solid #e9ecef; }
.admin-table tbody tr:hover { background: #f8f9fa; }
.status-confirmed { color: var(--secondary-color); font-weight: 600; }
.status-pending { color: #f39c12; font-weight: 600; }
.no-data { color: #7f8c8d; font-style: italic; padding: 1rem 0; }

/* ============ Split Layout (PDF Viewer) ============ */

.results-split {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
}

.results-left {
    flex: 1;
    min-width: 0;
    max-width: 1100px;
}

.results-split.has-pdf .results-left {
    max-width: none;
    flex: 1;
}

.results-right {
    flex: 0 0 50%;
    max-width: 50%;
    position: sticky;
    top: 80px;
    height: calc(100vh - 100px);
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    border: 1px solid var(--gray-200);
}

/* PDF Panel Toolbar (tabs + actions in one row) */
.pdf-panel-toolbar {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-100);
    flex-shrink: 0;
}

.pdf-panel-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0 0.5rem;
    flex-shrink: 0;
}

.pdf-panel-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--gray-400);
    cursor: pointer;
    padding: 0;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.pdf-panel-close:hover {
    background: var(--gray-200);
    color: var(--gray-700);
}

/* PDF Tabs */
.pdf-tabs {
    display: flex;
    flex: 1;
    overflow-x: auto;
    min-width: 0;
    scrollbar-width: thin;
}

.pdf-tabs::-webkit-scrollbar {
    height: 3px;
}

.pdf-tabs::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 3px;
}

.pdf-tab {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.5rem 0.4rem 0.75rem;
    font-size: 0.78rem;
    color: var(--gray-500);
    background: transparent;
    border-right: 1px solid var(--gray-200);
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.15s;
    min-width: 0;
}

.pdf-tab:hover {
    background: var(--gray-50);
    color: var(--gray-700);
}

.pdf-tab.active {
    background: white;
    color: var(--gray-800);
    font-weight: 600;
    border-bottom: 2px solid var(--primary-color);
    margin-bottom: -1px;
}

.pdf-tab-label {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.pdf-tab-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 3px;
    font-size: 0.9rem;
    color: var(--gray-400);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s;
}

.pdf-tab-close:hover {
    background: var(--gray-300);
    color: var(--gray-700);
}

.pdf-tab.active .pdf-tab-close:hover {
    background: rgba(206, 43, 55, 0.15);
    color: var(--primary-color);
}

/* PDF Panel Body */
.pdf-panel-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pdf-iframe {
    width: 100%;
    height: 100%;
    border: none;
    flex: 1;
}

.pdf-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--gray-500);
    gap: 1rem;
}

.pdf-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.pdf-error {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
    color: var(--error-color);
    text-align: center;
}

/* Clickable Determina Link */
.meta-det-link {
    font-weight: 600;
    color: var(--secondary-color);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.meta-det-link:hover {
    color: var(--secondary-dark);
    text-decoration: underline;
}

.meta-det-link.active {
    color: var(--primary-color);
    font-weight: 700;
}

/* ============ Extracted Data Panel ============ */

.extracted-panel {
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
    flex-shrink: 0;
}

.extracted-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0.75rem;
    cursor: pointer;
    user-select: none;
    background: linear-gradient(135deg, rgba(0,99,65,0.06), rgba(206,43,55,0.04));
    border-bottom: 1px solid var(--gray-200);
}

.extracted-toggle-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--secondary-dark);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.extracted-toggle-arrow {
    font-size: 0.65rem;
    color: var(--gray-400);
    transition: transform 0.2s;
}

.extracted-content {
    padding: 0.5rem 0.75rem;
    max-height: 140px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.extracted-dates {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.4rem;
}

.extracted-date-badge {
    display: inline-flex;
    flex-direction: column;
    padding: 0.2rem 0.5rem;
    background: white;
    border-radius: 6px;
    border-left: 3px solid #3b82f6;
    font-size: 0.7rem;
    box-shadow: var(--shadow-sm);
}

.edb-label {
    font-weight: 600;
    color: var(--gray-500);
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.2px;
}

.edb-value {
    color: var(--gray-800);
    font-weight: 500;
    font-size: 0.75rem;
}

.extracted-indications {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.extracted-ind-card {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    background: white;
    border-radius: 6px;
    box-shadow: var(--shadow-sm);
}

.ext-status-badge {
    flex-shrink: 0;
    padding: 0.1rem 0.45rem;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 600;
    white-space: nowrap;
    margin-top: 0.1rem;
}

.ext-status-reimbursed {
    background: #dcfce7;
    color: #166534;
}

.ext-status-not-reimbursed {
    background: #fee2e2;
    color: #991b1b;
}

.ext-ind-text {
    font-size: 0.75rem;
    line-height: 1.4;
    color: var(--gray-700);
}

/* ============ Responsive: PDF panel overlay on small screens ============ */

@media (max-width: 1024px) {
    .results-right {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        max-width: 100%;
        flex: none;
        z-index: 9999;
        border-radius: 0;
        height: 100vh;
    }

    .results-split {
        flex-direction: column;
    }

    .results-left {
        width: 100%;
        max-width: 1100px;
    }
}
