/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #64748b;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --border: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --sidebar-width: 260px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

/* Utility Classes */
.hidden { display: none !important; }

/* Screen Layout */
.screen {
    min-height: 100vh;
}

/* Login Screen */
#loginScreen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--background) 0%, #1e293b 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 40px;
}

.login-header {
    text-align: center;
    margin-bottom: 40px;
}

.logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: 20px;
    color: white;
    margin-bottom: 20px;
}

.login-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-secondary);
}

.login-form {
    background: var(--surface);
    padding: 32px;
    border-radius: 16px;
    border: 1px solid var(--border);
}

.login-hint {
    text-align: center;
    margin-top: 20px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px 16px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-muted);
}

.form-group small {
    display: block;
    margin-top: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.btn-full {
    width: 100%;
}

/* Dashboard Layout */
#dashboardScreen {
    display: flex;
}

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.logo-small {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 10px;
    color: white;
}

.sidebar-header span {
    font-weight: 600;
    font-size: 1rem;
}

.nav-menu {
    list-style: none;
    padding: 16px 12px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 4px;
}

.nav-item:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--primary);
    color: white;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.sidebar-footer .btn {
    width: 100%;
    justify-content: flex-start;
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 32px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.top-bar h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-info span {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.avatar {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

/* Page Content */
.page {
    padding: 32px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-card.clickable {
    cursor: pointer;
    transition: all 0.2s ease;
}

.stat-card.clickable:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
    transform: translateY(-2px);
}

/* Clickable list items */
.clickable-item {
    transition: background 0.15s ease;
    border-radius: 6px;
    margin: 0 -8px;
    padding-left: 8px !important;
    padding-right: 8px !important;
}

.clickable-item:hover {
    background: rgba(59, 130, 246, 0.08);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon.blue { background: rgba(59, 130, 246, 0.2); color: #3b82f6; }
.stat-icon.green { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.stat-icon.orange { background: rgba(245, 158, 11, 0.2); color: #f59e0b; }
.stat-icon.red { background: rgba(239, 68, 68, 0.2); color: #ef4444; }

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Content Grid */
.content-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.card-body {
    padding: 24px;
}

.link {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.875rem;
}

.link:hover {
    text-decoration: underline;
}

/* Empty State */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
}

/* Page Header */
.page-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 16px;
    flex: 1;
    max-width: 400px;
}

.search-box input {
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.875rem;
    flex: 1;
    outline: none;
}

.search-box svg {
    color: var(--text-muted);
}

.filter-group select {
    padding: 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
}

/* Data Table */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table tr:hover td {
    background: var(--surface-hover);
}

/* Config Grid */
.config-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.config-grid .full-width {
    grid-column: 1 / -1;
}

.form-actions {
    margin-top: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
}

#configSaveStatus {
    color: var(--success);
    font-size: 0.875rem;
}

/* Status Badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--background);
    border-radius: 20px;
    font-size: 0.75rem;
}

.status-badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
}

.status-badge.configured .dot {
    background: var(--success);
}

/* Severity Badges */
.severity-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.severity-badge.critical { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
.severity-badge.high { background: rgba(249, 115, 22, 0.2); color: #f97316; }
.severity-badge.medium { background: rgba(245, 158, 11, 0.2); color: #f59e0b; }
.severity-badge.low { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.severity-badge.none { background: rgba(100, 116, 139, 0.2); color: #64748b; }

/* Status Badges */
.status-pill {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-pill.completed { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.status-pill.in_progress { background: rgba(59, 130, 246, 0.2); color: #3b82f6; }
.status-pill.draft { background: rgba(100, 116, 139, 0.2); color: #64748b; }

/* Responsive */
@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .content-grid {
        grid-template-columns: 1fr;
    }
    .config-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .main-content {
        margin-left: 0;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border-radius: 16px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.btn-close:hover {
    color: var(--text-primary);
}

.modal-content form {
    padding: 24px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

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

/* Button Sizes */
.btn-sm {
    padding: 8px 16px;
    font-size: 0.75rem;
}

/* Logo Upload Area */
.logo-upload-area {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.logo-upload-area input[type="file"] {
    width: 100%;
}

/* Role status pills */
.status-pill.admin { background: rgba(139, 92, 246, 0.2); color: #8b5cf6; }
.status-pill.assessor { background: rgba(59, 130, 246, 0.2); color: #3b82f6; }
.status-pill.collaborator { background: rgba(100, 116, 139, 0.2); color: #94a3b8; }

/* Large Modal */
.modal-large {
    max-width: 800px;
}

/* Form Rows */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.tab-btn {
    padding: 12px 24px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    padding: 20px;
}

.tab-content.hidden {
    display: none;
}

/* Survey Detail Content */
.survey-detail-content {
    max-height: 70vh;
    overflow-y: auto;
}

/* Areas List */
.area-card {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
}

.area-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.area-card-header h4 {
    margin: 0;
    font-size: 1rem;
}

.area-card-details {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.area-card-details span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.evidence-thumbnails {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.evidence-thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border);
}

/* AI Chat */
.ai-chat-container {
    display: flex;
    flex-direction: column;
    height: 400px;
}

.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 16px;
}

.ai-message {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 85%;
}

.ai-message.user {
    background: var(--primary);
    color: white;
    margin-left: auto;
}

.ai-message.assistant {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.ai-message p {
    margin: 0;
    line-height: 1.5;
}

.ai-message.loading p::after {
    content: '...';
    animation: dots 1s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

.ai-input-container {
    display: flex;
    gap: 12px;
}

.ai-input-container input {
    flex: 1;
    padding: 12px 16px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.ai-input-container input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Actions Cell */
.actions-cell {
    white-space: nowrap;
}

.actions-cell .btn {
    margin-right: 4px;
}

.actions-cell .btn:last-child {
    margin-right: 0;
}

/* Danger Button */
.btn-danger {
    color: var(--danger);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

/* Archived Row */
.archived-row {
    opacity: 0.6;
}

.archived-row td {
    background: rgba(100, 116, 139, 0.05);
}

/* Archived Status */
.status-pill.archived {
    background: rgba(100, 116, 139, 0.2);
    color: #64748b;
}

/* Checkbox inline for filters */
.checkbox-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
}

.checkbox-inline input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

/* Filter group improvements */
.filter-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Image Lightbox */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.lightbox img {
    max-width: 90vw;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    background: none;
    border: none;
    color: white;
    font-size: 40px;
    cursor: pointer;
    z-index: 2001;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.lightbox-close:hover {
    opacity: 1;
}

.lightbox-prev,
.lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 30px;
    padding: 20px 15px;
    cursor: pointer;
    border-radius: 4px;
    opacity: 0.8;
    transition: all 0.2s;
}

.lightbox-prev:hover,
.lightbox-next:hover {
    background: rgba(255, 255, 255, 0.2);
    opacity: 1;
}

.lightbox-prev {
    left: 20px;
}

.lightbox-next {
    right: 20px;
}

.lightbox-caption {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    max-width: 80%;
    text-align: center;
}

.lightbox-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
}

/* Clickable evidence thumbnails */
.evidence-thumb {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.evidence-thumb:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Auto-resizing textarea for AI Diagnosis */
#editAreaDiagnosis {
    min-height: 100px;
    max-height: 300px;
    resize: vertical;
}

/* Larger textarea for notes and diagnosis */
.form-group textarea {
    min-height: 80px;
}

/* Evidence Editing Grid */
.evidence-grid-editable {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.evidence-item-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.evidence-item-card .evidence-thumb {
    width: 100%;
    height: 100px;
    object-fit: cover;
    display: block;
    border-radius: 0;
}

.evidence-item-card .evidence-actions {
    display: flex;
    justify-content: space-between;
    padding: 6px 8px;
    background: var(--background);
    border-top: 1px solid var(--border);
}

.evidence-item-card .evidence-caption {
    padding: 6px 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--background);
    border-top: 1px solid var(--border);
    margin: 0;
}

.evidence-note-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
}

.evidence-note-card p {
    margin: 0 0 8px 0;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.evidence-note-card .evidence-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Extra small buttons */
.btn-xs {
    padding: 4px 8px;
    font-size: 0.7rem;
}

/* Small form group text */
.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Clickable Survey Rows */
.survey-row {
    transition: background-color 0.15s ease, transform 0.1s ease;
}

.survey-row:hover {
    background-color: var(--surface-hover) !important;
}

.survey-row:hover td {
    color: var(--text-primary);
}

.survey-row:active {
    background-color: var(--primary) !important;
    transform: scale(0.995);
}

/* Click hint on hover */
.survey-row td:first-child::before {
    content: '';
    display: inline-block;
    width: 0;
    transition: width 0.2s ease, margin-right 0.2s ease;
}

.survey-row:hover td:first-child::before {
    content: '→ ';
    width: 20px;
    margin-right: 4px;
    color: var(--primary);
}

/* Areas Tab Header */
.areas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.areas-hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
}

/* Clickable Area Cards */
.area-card {
    cursor: pointer;
    transition: all 0.15s ease;
}

.area-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.area-card-header {
    position: relative;
}

.area-card-header .btn {
    opacity: 0.7;
    transition: opacity 0.2s;
}

.area-card:hover .area-card-header .btn {
    opacity: 1;
}

/* Delete area button */
.btn-delete-area {
    color: var(--danger);
    margin-left: 8px;
}

/* ============================================
   WYSIWYG Report Editor Styles
   ============================================ */

.modal-report {
    max-width: 900px;
    height: 90vh;
    display: flex;
    flex-direction: column;
}

.report-header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.report-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.report-header-left h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.edit-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--background);
    padding: 4px 10px;
    border-radius: 12px;
}

.report-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.report-preview-container {
    flex: 1;
    overflow-y: auto;
    background: #e5e7eb;
    padding: 24px;
}

.report-preview {
    background: white;
    max-width: 210mm;
    margin: 0 auto;
    padding: 40px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    color: #1e293b;
    font-size: 14px;
    line-height: 1.6;
}

.report-section {
    margin-bottom: 30px;
}

.report-title-section {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding-bottom: 20px;
    border-bottom: 3px solid #3b82f6;
}

.report-title-left h1 {
    font-size: 22px;
    color: #1e40af;
    margin-bottom: 4px;
}

.report-title-left p {
    color: #64748b;
    font-size: 13px;
}

.report-title-right {
    text-align: right;
    padding: 10px;
    border-radius: 8px;
    min-width: 160px;
}

.company-info-preview {
    font-size: 12px;
    color: #64748b;
}

.company-info-preview .placeholder {
    color: #94a3b8;
    font-style: italic;
}

.company-info-preview strong {
    display: block;
    color: #1e293b;
    margin-bottom: 4px;
}

#reportCompanyLogo img {
    max-width: 120px;
    max-height: 60px;
    object-fit: contain;
    margin-bottom: 8px;
}

/* Editable Fields */
.editable-field {
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s ease;
    position: relative;
}

.editable-field:hover {
    background: #fef3c7;
}

.editable-field::after {
    content: '✎';
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 10px;
    color: #94a3b8;
    opacity: 0;
    transition: opacity 0.15s;
}

.editable-field:hover::after {
    opacity: 1;
}

/* Summary Box Preview */
.summary-box-preview {
    background: #f1f5f9;
    padding: 24px;
    border-radius: 8px;
}

.summary-grid-preview {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.summary-item-preview {
    padding: 8px;
}

.summary-item-preview label {
    display: block;
    font-size: 11px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.summary-item-preview span {
    font-size: 15px;
    font-weight: 600;
    color: #1e293b;
}

/* Severity Badges */
.severity-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 12px;
}

.severity-critical { background: #fee2e2; color: #dc2626; }
.severity-high { background: #ffedd5; color: #ea580c; }
.severity-medium { background: #fef9c3; color: #ca8a04; }
.severity-low { background: #dcfce7; color: #16a34a; }
.severity-none { background: #f1f5f9; color: #64748b; }

/* Areas Section */
.areas-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.areas-section-header h2 {
    font-size: 18px;
    color: #1e40af;
}

/* Area Card in Report */
.report-area-card {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    background: white;
}

.report-area-card:hover {
    border-color: #3b82f6;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
}

.report-area-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.report-area-header h3 {
    font-size: 16px;
    color: #1e40af;
    margin: 0;
}

.report-area-actions {
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.report-area-card:hover .report-area-actions {
    opacity: 1;
}

.report-area-info {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 16px;
    font-size: 13px;
}

.report-area-info-item {
    padding: 8px 12px;
    background: #f8fafc;
    border-radius: 6px;
}

.report-area-info-item strong {
    color: #64748b;
    font-weight: 500;
}

.report-area-diagnosis,
.report-area-notes {
    background: #f8fafc;
    padding: 12px 16px;
    border-radius: 6px;
    margin-top: 12px;
    font-size: 13px;
}

.report-area-diagnosis strong,
.report-area-notes strong {
    color: #1e40af;
    display: block;
    margin-bottom: 6px;
}

/* Evidence Grid in Report */
.report-evidence-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.report-evidence-item {
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    overflow: hidden;
    position: relative;
}

.report-evidence-item img {
    width: 100%;
    height: 100px;
    object-fit: cover;
}

.report-evidence-item .caption {
    padding: 6px 8px;
    font-size: 11px;
    color: #64748b;
    background: #f8fafc;
}

.report-evidence-item .evidence-actions {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.report-evidence-item:hover .evidence-actions {
    opacity: 1;
}

.report-evidence-note {
    padding: 12px;
    background: #fef3c7;
    border-radius: 6px;
    font-size: 13px;
    position: relative;
}

.report-evidence-note .evidence-actions {
    position: absolute;
    top: 4px;
    right: 4px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.report-evidence-note:hover .evidence-actions {
    opacity: 1;
}

/* AI Assistant Slide Panel */
.slide-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 400px;
    height: 100vh;
    background: var(--surface);
    box-shadow: -4px 0 20px rgba(0,0,0,0.3);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.slide-panel:not(.hidden) {
    transform: translateX(0);
}

.slide-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.slide-panel .ai-chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Quick Edit Popover */
.popover {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    z-index: 1200;
    min-width: 280px;
}

.popover-content {
    padding: 12px;
}

.popover-content input,
.popover-content select,
.popover-content textarea {
    width: 100%;
    margin-bottom: 12px;
}

.popover-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Button sizes */
.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-xs {
    padding: 2px 6px;
    font-size: 11px;
}

/* ============================================
   Final Comments Section
   ============================================ */

.add-comments-placeholder {
    border: 2px dashed #cbd5e1;
    border-radius: 8px;
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #f8fafc;
}

.add-comments-placeholder:hover {
    border-color: #3b82f6;
    background: #eff6ff;
}

.add-comments-placeholder svg {
    color: #94a3b8;
    margin-bottom: 12px;
}

.add-comments-placeholder:hover svg {
    color: #3b82f6;
}

.add-comments-placeholder p {
    font-size: 16px;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 4px;
}

.add-comments-placeholder span {
    font-size: 13px;
    color: #64748b;
}

/* Final Comments Preview */
.final-comments-preview {
    background: #f8fafc;
    border-radius: 8px;
    padding: 20px;
}

.final-comments-preview h4 {
    font-size: 14px;
    color: #1e40af;
    margin-bottom: 12px;
}

.final-comments-preview p {
    font-size: 13px;
    color: #1e293b;
    line-height: 1.6;
    white-space: pre-wrap;
}

.final-comments-preview .recommendations {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e2e8f0;
}

.final-comments-images-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.final-comments-images-preview img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}

.final-comments-edit-btn {
    margin-top: 16px;
    text-align: right;
}

/* Final Comments Modal */
.final-comments-editor {
    padding: 20px;
}

.final-images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.final-image-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.final-image-item img {
    width: 100%;
    height: 100px;
    object-fit: cover;
}

.final-image-item .caption-input {
    width: 100%;
    padding: 6px 8px;
    font-size: 11px;
    border: none;
    border-top: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-primary);
}

.final-image-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0,0,0,0.7);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.final-image-item .remove-btn:hover {
    background: var(--danger);
}

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

.image-upload-actions .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* ============================================
   Modal Window Controls & Sizing
   ============================================ */

/* Sticky Header */
.sticky-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
}

/* Window Controls */
.window-controls {
    display: flex;
    gap: 4px;
    background: var(--background);
    padding: 4px;
    border-radius: 6px;
}

.window-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.window-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.window-btn:active {
    transform: scale(0.95);
}

.header-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 8px;
}

/* Save Button */
.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #16a34a;
}

.btn-save-sticky {
    animation: pulse-subtle 2s infinite;
}

@keyframes pulse-subtle {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
    50% { box-shadow: 0 0 0 4px rgba(34, 197, 94, 0); }
}

/* Modal Sizing States */
.modal-report {
    transition: all 0.3s ease;
}

/* Normal (default) */
.modal-report.size-normal {
    max-width: 900px;
    width: 90%;
    height: 90vh;
    margin: 5vh auto;
}

/* Fullscreen */
.modal-report.size-fullscreen {
    max-width: 100%;
    width: 100%;
    height: 100vh;
    margin: 0;
    border-radius: 0;
}

.modal-report.size-fullscreen .report-preview-container {
    padding: 24px 10%;
}

/* Minimized */
.modal-report.size-minimized {
    max-width: 400px;
    width: 400px;
    height: auto;
    max-height: 60px;
    position: fixed;
    bottom: 20px;
    right: 20px;
    top: auto;
    left: auto;
    margin: 0;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

.modal-report.size-minimized .report-preview-container,
.modal-report.size-minimized .report-header-left .edit-hint {
    display: none;
}

.modal-report.size-minimized .report-header-bar {
    padding: 12px 16px;
}

.modal-report.size-minimized .report-header-actions .btn:not(.window-btn):not(:last-child),
.modal-report.size-minimized .header-divider {
    display: none;
}

.modal-report.size-minimized .window-controls {
    margin-left: auto;
}

/* Minimized modal background should not block page */
.modal.minimized-mode {
    pointer-events: none;
    background: transparent;
}

.modal.minimized-mode .modal-content {
    pointer-events: all;
}

/* Active window button indicator */
.window-btn.active {
    background: var(--primary);
    color: white;
}

.window-btn.active:hover {
    background: var(--primary-dark);
}

/* Spin animation for loading */
.spin {
    animation: spin 1s linear infinite;
}

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

/* ========================
   Treatments Page Styles
   ======================== */

/* Category Tabs */
.category-tabs {
    display: flex;
    gap: 8px;
    padding: 16px 0;
    margin-bottom: 16px;
    overflow-x: auto;
    scrollbar-width: thin;
}

.category-tab {
    padding: 8px 16px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s;
}

.category-tab:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.category-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Treatments Grid */
.treatments-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

/* Treatment Card */
.treatment-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.2s;
    cursor: pointer;
}

.treatment-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.treatment-card-header {
    padding: 16px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.treatment-icon {
    width: 48px;
    height: 48px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.treatment-icon svg {
    width: 24px;
    height: 24px;
    color: white;
}

.treatment-info {
    flex: 1;
    min-width: 0;
}

.treatment-info h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.treatment-info p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.treatment-card-body {
    padding: 0 16px 16px;
}

.treatment-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.treatment-badge {
    padding: 4px 8px;
    background: var(--surface-hover);
    border-radius: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.treatment-badge.category {
    background: rgba(59, 130, 246, 0.2);
    color: var(--primary);
}

.treatment-rating {
    display: flex;
    gap: 2px;
}

.treatment-rating .star {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
}

.treatment-rating .star.filled {
    color: #f59e0b;
}

.treatment-cost {
    font-size: 0.875rem;
    color: var(--success);
    font-weight: 500;
}

.treatment-products {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
}

/* Treatment Modal Condition Mappings */
.condition-mappings {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
}

.condition-section {
    margin-bottom: 16px;
}

.condition-section:last-child {
    margin-bottom: 0;
}

.condition-section strong {
    display: block;
    margin-bottom: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
}

.checkbox-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
}

.checkbox-grid input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.checkbox-inline {
    margin-top: 8px;
}

.checkbox-inline label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
}

/* Empty state for treatments */
.treatments-grid .empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

/* Treatment inactive state */
.treatment-card.inactive {
    opacity: 0.6;
}

.treatment-card.inactive .treatment-badge.status {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

/* ========================
   AI Report Generation UI
   ======================== */

/* AI Button Style */
.btn-ai {
    background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%);
    color: white;
    border: none;
}

.btn-ai:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%);
}

.btn-ai.loading {
    pointer-events: none;
    opacity: 0.7;
}

.btn-ai svg {
    flex-shrink: 0;
}

/* AI Report Modal Styles */
.ai-report-content {
    padding: 20px;
}

.ai-report-section {
    margin-bottom: 24px;
}

.ai-report-section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.ai-report-section-header h4 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.ai-badge {
    padding: 4px 10px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(99, 102, 241, 0.2));
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 500;
    color: #a78bfa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-report-content textarea {
    width: 100%;
    padding: 12px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
    line-height: 1.6;
    resize: vertical;
    min-height: 120px;
}

.ai-report-content textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.ai-report-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.suggested-treatments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.suggested-treatment-tag {
    padding: 6px 12px;
    background: var(--surface-hover);
    border-radius: 16px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.loading-content {
    text-align: center;
    max-width: 400px;
    padding: 40px;
}

.loading-spinner {
    margin-bottom: 24px;
}

.loading-spinner svg {
    color: #8b5cf6;
}

.loading-content h3 {
    font-size: 1.25rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.loading-content p {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.loading-steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-align: left;
}

.loading-step {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border-radius: 8px;
    border: 1px solid var(--border);
    opacity: 0.5;
    transition: all 0.3s;
}

.loading-step.active {
    opacity: 1;
    border-color: #8b5cf6;
    background: rgba(139, 92, 246, 0.1);
}

.loading-step.completed {
    opacity: 1;
    border-color: var(--success);
}

.loading-step.completed .step-icon {
    background: var(--success);
}

.step-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--surface-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.loading-step.active .step-icon {
    background: #8b5cf6;
    color: white;
}

.loading-step span:last-child {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.loading-step.active span:last-child {
    color: var(--text-primary);
}

/* Toast Notification */
.toast-notification {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--success);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 3000;
    opacity: 0;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.toast-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Save button changes indicator */
.btn-save-sticky.has-changes {
    animation: pulse-save 2s infinite;
}

@keyframes pulse-save {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
}
