/* ========== 病歷紀錄頁 ========== */
.medical-page {
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem;
}

.medical-hero {
    text-align: center;
    margin-bottom: 2.5rem;
}

.medical-hero h1 {
    font-family: "Outfit", sans-serif;
    font-weight: 600;
    font-size: 1.75rem;
    color: var(--forest);
    margin-bottom: 0.5rem;
}

.medical-hero p {
    color: var(--charcoal);
    opacity: 0.85;
    font-size: 1rem;
}

/* ---- No pets prompt ---- */
.no-pets-prompt {
    text-align: center;
    padding: 2rem;
    margin-bottom: 1.5rem;
    background: white;
    border-radius: 16px;
    box-shadow: var(--soft-shadow);
    border: 1px dashed rgba(125, 155, 118, 0.35);
}

.no-pets-prompt p {
    color: var(--charcoal);
    font-size: 0.95rem;
    margin-bottom: 1.25rem;
    opacity: 0.85;
}

/* ---- Tabs ---- */
.medical-tabs-container {
    background: white;
    border-radius: 16px;
    box-shadow: var(--soft-shadow);
    border: 1px solid rgba(125, 155, 118, 0.15);
    margin-bottom: 2rem;
    overflow: hidden;
}

.medical-tabs-header {
    display: flex;
    border-bottom: 2px solid rgba(125, 155, 118, 0.15);
}

.medical-tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 1rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--charcoal);
    opacity: 0.55;
    cursor: pointer;
    transition: all 0.25s;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
}

.medical-tab-btn:hover {
    opacity: 0.85;
    color: var(--forest);
}

.medical-tab-btn.active {
    opacity: 1;
    color: var(--forest);
    font-weight: 600;
    border-bottom-color: var(--forest);
}

.medical-tab-content {
    display: none;
    padding: 1.5rem 2rem;
    animation: fadeIn 0.3s ease-in-out;
}

.medical-tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- Summary tab ---- */
.summary-content {
    min-height: 80px;
    margin-bottom: 1.25rem;
}

.summary-text {
    font-size: 0.95rem;
    color: var(--charcoal);
    line-height: 1.8;
    white-space: pre-wrap;
    background: var(--cream);
    border-radius: 12px;
    padding: 1.25rem;
    border: 1px solid rgba(125, 155, 118, 0.2);
}

.summary-content .empty-state {
    padding: 2rem;
}

.btn-summarize {
    width: 100%;
}

/* ---- New record tab ---- */
.medical-upload {
    position: relative;
    z-index: 1;
}

.medical-upload #btnAnalyze {
    width: 100%;
    margin-top: 1.25rem;
    position: relative;
    z-index: 100;
}

.medical-ai-toggle {
    margin-top: 1rem;
    margin-bottom: 0.25rem;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--charcoal);
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--sage);
}

.toggle-text {
    font-weight: 500;
}

.medical-result {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(125, 155, 118, 0.2);
}

.medical-result h3 {
    font-size: 1rem;
    color: var(--forest);
    margin-bottom: 1rem;
    font-weight: 600;
}

.edit-hint {
    font-weight: 400;
    font-size: 0.85rem;
    opacity: 0.7;
}

.medical-form-card {
    background: var(--cream);
    border-radius: 12px;
    padding: 1.25rem;
    border: 1px solid rgba(125, 155, 118, 0.2);
}

.medical-edit-form .form-group {
    margin-bottom: 1.25rem;
}

.medical-edit-form label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--charcoal);
    margin-bottom: 0.4rem;
}

.medical-edit-form input,
.medical-edit-form textarea,
.medical-edit-form select {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-family: inherit;
    border: 1px solid rgba(125, 155, 118, 0.3);
    border-radius: 10px;
    background: var(--cream);
    color: var(--charcoal);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.medical-edit-form input:focus,
.medical-edit-form textarea:focus,
.medical-edit-form select:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 3px rgba(125, 155, 118, 0.1);
}

.required {
    color: var(--terracotta);
    font-weight: 600;
}

.medical-edit-form textarea {
    resize: vertical;
    min-height: 80px;
}

.btn-save-record {
    display: block;
    width: 100%;
    margin-top: 1.5rem;
}

.medical-error .error-msg {
    margin-top: 0.5rem;
}

/* ---- Record list ---- */
.medical-list-section {
    margin-bottom: 2rem;
}

.medical-records-list {
    margin-top: 1rem;
}

.medical-record-card {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    background: white;
    border-radius: 14px;
    padding: 1.25rem 1.5rem;
    box-shadow: var(--soft-shadow);
    border: 1px solid rgba(125, 155, 118, 0.15);
}

.medical-card-body {
    flex: 1;
    min-width: 0;
}

.medical-image-wrapper {
    margin-bottom: 1rem;
    max-width: 100%;
}

.medical-thumbnail {
    max-height: 200px;
    max-width: 100%;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid rgba(125, 155, 118, 0.2);
}

.medical-attachment-wrapper {
    margin-bottom: 1rem;
    max-width: 100%;
}

.medical-pdf-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1rem;
    background: var(--cream);
    border: 1px solid rgba(125, 155, 118, 0.3);
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--forest);
}

.medical-card-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.medical-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    color: var(--charcoal);
    opacity: 0.75;
}

.medical-id {
    font-weight: 500;
    color: var(--forest);
}

.medical-date {
    font-size: 0.78rem;
}

.medical-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--forest);
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.medical-description {
    font-size: 0.95rem;
    color: var(--charcoal);
    line-height: 1.65;
    margin-bottom: 0.75rem;
}

/* ---- Edit modal ---- */
.modal-content h3 {
    font-size: 1.1rem;
    color: var(--forest);
    margin-bottom: 1.25rem;
    font-weight: 600;
}

.edit-image-section {
    margin-bottom: 1.25rem;
}

.edit-image-preview {
    margin-bottom: 0.75rem;
}

.edit-image-preview img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid rgba(125, 155, 118, 0.2);
}

.edit-image-preview .no-image {
    font-size: 0.85rem;
    color: var(--charcoal);
    opacity: 0.5;
    padding: 1rem;
    text-align: center;
    background: var(--cream);
    border-radius: 8px;
    border: 1px dashed rgba(125, 155, 118, 0.3);
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.25rem;
}

.form-actions .btn {
    flex: 1;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
    .medical-page {
        padding: 1rem;
    }

    .medical-tab-content {
        padding: 1.25rem;
    }
}

/* ---- PDF thumbnail in record list ---- */
.pdf-attachment {
    cursor: pointer;
    position: relative;
    display: inline-block;
    max-width: 100%;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid rgba(125, 155, 118, 0.2);
    transition: box-shadow 0.2s;
}

.pdf-attachment:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
}

.pdf-attachment .medical-thumbnail.pdf-thumb {
    display: block;
    max-height: 260px;
    max-width: 100%;
    object-fit: contain;
    background: #f5f5f5;
}

.pdf-page-count {
    position: absolute;
    top: 8px;
    right: 8px;
}

.pdf-page-badge {
    display: inline-block;
    padding: 3px 10px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 500;
}

.pdf-thumb-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    background: var(--cream);
    border-radius: 8px;
}

.spinner-sm {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(125, 155, 118, 0.25);
    border-top-color: var(--sage);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ---- PDF Viewer Modal ---- */
.pdf-viewer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.88);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.2s ease;
}

.pdf-viewer-overlay.hidden {
    display: none;
}

.pdf-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    flex-shrink: 0;
    gap: 1rem;
}

.pdf-viewer-title {
    font-size: 0.95rem;
    font-weight: 500;
    opacity: 0.9;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.pdf-viewer-controls {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.pdf-viewer-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.pdf-viewer-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.pdf-viewer-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.pdf-viewer-close {
    margin-left: 0.5rem;
    background: rgba(220, 80, 60, 0.6);
}

.pdf-viewer-close:hover {
    background: rgba(220, 80, 60, 0.9);
}

.pdf-page-info,
.pdf-zoom-info {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.85);
    min-width: 60px;
    text-align: center;
    user-select: none;
}

.pdf-viewer-body {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 1rem;
}

.pdf-viewer-body canvas {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}
