/* === RIGHT SIDEBAR - REDESIGNED === */
.right-sidebar {
    width: 30vw;
    min-width: 380px;
    max-width: 550px;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}


.sidebar-header-right {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 0 24px;
    height: 80px;
    /* Uniform height */
    flex-shrink: 0;
    display: flex;
    align-items: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
}

.header-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.header-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.patient-details-subtitle {
    display: flex;
    gap: 12px;
    font-size: 0.85rem;
    opacity: 0.9;
    color: rgba(255, 255, 255, 0.9);
}

.pd-item.meta {
    font-weight: 500;
}

.header-icon {
    width: 40px;
    height: 40px;
    filter: brightness(0) invert(1);
}

.header-text h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 4px 0;
}

.header-text p {
    margin: 0;
    opacity: 0.9;
    font-size: 0.9rem;
}

/* === TAB NAVIGATION === */
.tab-navigation {
    display: flex;
    gap: 4px;
    padding: 12px;
    background: white;
    border-bottom: 2px solid #e5e7eb;
    flex-shrink: 0;
    overflow-x: auto;
}

.tab-btn {
    flex: 1;
    min-width: 110px;
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    white-space: nowrap;
}

.tab-btn:hover {
    background: #f3f4f6;
    color: #0d9488;
}

.tab-btn.active {
    background: #0d9488;
    color: white;
}

/* === TAB CONTENT === */
.tab-content-wrapper {
    flex: 1;
    overflow-y: auto;
    background: #fafafa;
}

.tab-content {
    display: none;
    padding: 12px;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.25s ease;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* === HISTORY SECTION === */
.history-section {
    margin-bottom: 16px;
    /* Reduced */
}

.section-title {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 2px solid #0d9488;
}

.section-title-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.section-title h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0d9488;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.2;
}

.section-subtitle {
    font-size: 0.75rem;
    color: #64748b;
    font-weight: 500;
    font-style: italic;
    letter-spacing: 0.3px;
}

.record-count {
    background: #e2e8f0;
    color: #475569;
    padding: 2px 8px;
    /* Reduced padding */
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.btn-add-instance {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #0d9488;
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(13, 148, 136, 0.2);
}

.btn-add-instance:hover {
    background: #0f766e;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(13, 148, 136, 0.3);
}

.btn-add-instance:active {
    transform: translateY(0);
}

/* === RECORDS CONTAINER === */
.records-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}

/* Inline Field Reference (in section title) */
.field-reference-inline {
    position: relative;
}

.field-reference-inline summary {
    cursor: pointer;
    font-size: 1rem;
    color: #64748b;
    list-style: none;
    padding: 2px 6px;
    border-radius: 50%;
    transition: all 0.2s;
}

.field-reference-inline summary:hover {
    background: #e2e8f0;
    color: #0d9488;
}

.field-reference-inline summary::-webkit-details-marker {
    display: none;
}

.field-grid-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 100;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    padding: 12px;
    min-width: 220px;
    max-height: 300px;
    overflow-y: auto;
}

.field-item-mini {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px 0;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.8rem;
}

.field-item-mini:last-child {
    border-bottom: none;
}

.field-item-mini strong {
    color: #334155;
    font-weight: 600;
}

.field-item-mini .type-info {
    color: #94a3b8;
    font-size: 0.75rem;
}

/* === RECORD CARD === */
.record-card {
    background: white;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    transition: all 0.2s ease;
    position: relative;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.record-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: #0d9488;
    opacity: 0.7;
}

.record-card:hover {
    border-color: #0d9488;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.record-header {
    padding: 8px 12px;
    /* Compact */
    background: #f8fafc;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.record-title {
    font-size: 0.95rem;
    /* Smaller */
    font-weight: 600;
    color: #1e293b;
    line-height: 1.3;
}

.record-label {
    font-size: 0.6rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 700;
}

.record-actions-btns {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.record-card:hover .record-actions-btns {
    opacity: 1;
}

.btn-record-edit,
.btn-record-delete {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    padding: 4px;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-record-edit:hover {
    background: #f0f9ff;
    color: #0ea5e9;
    border-color: #0ea5e9;
}

.btn-record-delete:hover {
    background: #fef2f2;
    color: #ef4444;
    border-color: #ef4444;
}

.record-details {
    padding: 10px 12px;
    /* Type compact */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    /* Smaller grid min */
    gap: 8px;
    /* Reduced gap */
}

.record-field {
    display: flex;
    flex-direction: column;
    gap: 0px;
    /* Minimal gap */
}

.field-key {
    font-size: 0.7rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.field-val {
    font-size: 0.9rem;
    color: #334155;
    font-weight: 500;
}

.record-meta {
    padding: 8px 20px;
    background: #f8fafc;
    border-top: 1px solid #f1f5f9;
    font-size: 0.75rem;
    color: #94a3b8;
    display: flex;
    justify-content: flex-end;
}

/* === FIELD REFERENCE (COLLAPSE) === */
.field-reference {
    background: white;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    margin-top: 24px;
}

.field-reference summary {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: #6b7280;
    background: #f9fafb;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.field-reference summary:hover {
    background: #f3f4f6;
    color: #0d9488;
}

.field-reference[open] summary {
    border-bottom: 1px solid #e5e7eb;
    background: white;
}

.field-grid {
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.field-item {
    padding: 6px 10px;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field-item strong {
    color: #334155;
    font-weight: 600;
    font-family: monospace;
    font-size: 0.9rem;
}

.field-item .req {
    color: #ef4444;
    font-weight: 700;
    margin-left: 2px;
}

.type-info {
    font-size: 0.75rem;
    color: #64748b;
}

/* === MODAL STYLES === */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    animation: fadeIn 0.3s forwards;
}

.modal-backdrop.closing {
    animation: fadeOut 0.2s forwards;
}

.modal-content {
    background: white;
    width: 500px;
    max-width: 90%;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    animation: scaleUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes scaleUp {
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: #1e293b;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #94a3b8;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.close-modal:hover {
    color: #ef4444;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: #475569;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.95rem;
    transition: all 0.2s;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #0d9488;
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.1);
}

.help-text {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-top: 2px;
}

/* Date Range Group */
.date-range-group {
    display: flex;
    gap: 12px;
}

.half-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.btn-secondary {
    padding: 10px 20px;
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    color: #475569;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

.btn-primary {
    padding: 10px 24px;
    background: #0d9488;
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: #0f766e;
    box-shadow: 0 4px 6px -1px rgba(13, 148, 136, 0.2);
}

.btn-primary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}


/* === TOAST === */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 24px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    transform: translateY(20px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 2000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast-success {
    background: #10b981;
}

.toast-error {
    background: #ef4444;
}

.spinner-small {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 6px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}


/* === SCROLLBAR === */
.tab-content-wrapper::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
    width: 8px;
}

.tab-content-wrapper::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.tab-content-wrapper::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.tab-content-wrapper::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* === RESPONSIVE === */
/* === RESPONSIVE & SELECT STYLING === */
#sidebar-section-select {
    padding: 6px 10px;
    font-size: 0.9rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border-radius: 6px;
    outline: none;
    cursor: pointer;
    max-width: 180px;
    /* Constrain width */
}

#sidebar-section-select option {
    background: #333;
    color: white;
}

/* === PDF IMPORT BUTTON IN HEADER === */
.sidebar-header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn-export-chat-pdf,
.btn-sidebar-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-sidebar-logout {
    padding: 6px;
    width: 34px;
    height: 34px;
}

.btn-export-chat-pdf:hover,
.btn-sidebar-logout:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
}

.btn-export-chat-pdf:active,
.btn-sidebar-logout:active {
    transform: translateY(0);
}

.btn-export-chat-pdf .spinner-small {
    width: 14px;
    height: 14px;
    border-width: 2px;
}