/* Template Panel - Excel-Style Layout v2.1 */

.template-panel {
    display: none;
    flex-direction: column;
    height: 100%;
    width: 100%;
    background: #fff;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.template-panel.active {
    display: flex;
}

/* Header - minimal */
.template-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.template-panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
    font-weight: 600;
    color: #212529;
}

.template-panel-title i {
    color: #6c757d;
}

/* Content */
.template-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
    width: 100%;
    box-sizing: border-box;
}

/* Auto-expand textareas in template panel - no scrollbar, resize handle only */
.template-panel textarea,
.template-panel .cell-input,
.template-panel .template-input {
    overflow-y: hidden;
    resize: vertical;
    max-height: 50vh;
}

/* Sections */
.template-section {
    margin-bottom: 12px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background: #fff;
}

.template-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    cursor: pointer;
    background: #f8f9fa;
    border-bottom: 1px solid transparent;
}

.template-section.open .template-section-header {
    border-bottom-color: #dee2e6;
}

.template-section-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.template-section-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 12px;
    color: white;
}

.template-section-name {
    font-size: var(--font-size-sm, 0.875rem);
    font-weight: 600;
    color: #212529;
}

.template-section-chevron {
    color: #6c757d;
    font-size: var(--font-size-base);
    transition: transform 0.2s;
}

.template-section.open .template-section-chevron {
    transform: rotate(180deg);
}

.template-section-content {
    display: none;
    padding: 12px;
}

.template-section.open .template-section-content {
    display: block;
}

/* Fields */
.template-field {
    margin-bottom: 12px;
}

.template-field-label {
    display: block;
    font-size: var(--font-size-sm, 0.875rem);
    font-weight: 500;
    color: #4b5563;
    margin-bottom: 4px;
}

.template-field-label .required {
    color: #dc3545;
}

/* Help toggle button */
.field-help-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 0 4px;
    margin-left: 4px;
    cursor: pointer;
    color: #9ca3af;
    font-size: 14px;
    vertical-align: middle;
    transition: color 0.2s;
}

.field-help-toggle:hover {
    color: #3b82f6;
}

.field-help-toggle.active {
    color: #3b82f6;
}

/* Help content (expandable) */
.field-help-content {
    display: none;
    padding: 10px 12px;
    margin-bottom: 8px;
    background: #f1f5f9;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.5;
    color: #64748b;
    white-space: pre-wrap;
}

.field-help-content.show {
    display: block;
}

body.dark-mode .field-help-content {
    background: #374151;
    color: #d1d5db;
}

body.dark-mode .field-help-toggle {
    color: #d1d5db;
}

body.dark-mode .field-help-toggle:hover,
body.dark-mode .field-help-toggle.active {
    color: #60a5fa;
}

/* Template input wrapper for AI dropdown positioning */
.template-input-wrapper {
    position: relative;
}

/* Table cell wrapper for inline controls - Gemini style */
.cell-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: block;
    background: transparent;
}

/* Inline controls container - positioned at top-right */
.cell-input-controls {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 2px;
    padding: 2px 4px;
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
}

/* Shared button styles for cell-input-controls and template-input-icons */
.cell-input-controls button,
.template-input-icons button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    font-size: var(--font-size-input-icon);
    color: #4b5563;
    border-radius: 4px;
    transition: all 0.2s;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell-input-controls button:hover,
.template-input-icons button:hover {
    background: none;
    color: #3b82f6;
}

/* Listening state for STT buttons */
.cell-input-controls .cell-stt-btn.listening,
.template-input-icons .template-stt-btn.listening {
    color: #ef4444;
    animation: pulse 1s infinite;
}

/* Loading state for AI assist buttons */
.cell-ai-assist.loading,
.template-input-icons .template-ai-assist.loading {
    animation: pulse 1s infinite;
}

/* Tooltip z-index fix - ensure tooltips appear above all controls */
.cell-input-controls [data-tooltip]:before,
.template-input-icons [data-tooltip]:before {
    z-index: 10002;
}

/* Dark mode cell/template controls */
body.dark-mode .cell-wrapper {
    background: #111827;
}

body.dark-mode .cell-input-controls button,
body.dark-mode .template-input-icons button {
    color: #d1d5db;
}

body.dark-mode .cell-input-controls button:hover,
body.dark-mode .template-input-icons button:hover {
    background: none;
    color: #60a5fa;
}

/* Template input icons - horizontal layout inside input wrapper */
.template-input-icons {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 4px;
    flex-shrink: 0;
    background: transparent;
}

/* Expandable icons - allow use of icons-expandable class */
.template-input-icons.icons-expandable {
    position: relative;
    display: flex;
    align-items: center;
}

.cell-input-controls.icons-expandable {
    display: flex;
    align-items: center;
    /* position: absolute is set in main .cell-input-controls rule */
}

.template-input-icons .icons-hidden-group,
.cell-input-controls .icons-hidden-group {
    display: none;
    flex-direction: row;
    align-items: center;
    gap: 2px;
}

/* Chevron trigger size — keep the FA icon visually proportionate to the SVG dropdown chevron */
.template-input-icons .icons-expand-trigger,
.cell-input-controls .icons-expand-trigger {
    width: 24px;
    height: 24px;
    font-size: var(--font-size-xs);
}

/* Dark mode chevron - match input-group (#94a3b8) */
body.dark-mode .template-input-icons .icons-expand-trigger,
body.dark-mode .cell-input-controls .icons-expand-trigger {
    color: #94a3b8;
}

body.dark-mode .template-input-icons .icons-expand-trigger:hover,
body.dark-mode .cell-input-controls .icons-expand-trigger:hover {
    color: #60a5fa;
}

/* Rotate chevron when expanded (don't hide it, so user can collapse) */
.template-input-icons.icons-expandable.expanded .icons-expand-trigger i,
.cell-input-controls.icons-expandable.expanded .icons-expand-trigger i {
    transform: rotate(180deg);
}

.template-input-icons.icons-expandable.expanded .icons-hidden-group,
.cell-input-controls.icons-expandable.expanded .icons-hidden-group {
    display: flex;
}

/* Template input container for horizontal layout with icons */
.template-input-container {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 4px;
    width: 100%;
}

.template-input-container .template-input {
    flex: 1;
    min-width: 0;
}

.template-input-container .template-textarea-wrapper {
    flex: 1;
    min-width: 0;
}

/* AI Dropdown - positioned ABOVE input like chat-completion-dropdown */
.template-ai-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    bottom: auto;
    left: 0;
    right: 0;
    z-index: 100;
    margin-top: 4px;
    margin-bottom: 0;
    max-height: 200px;
    min-width: 200px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.template-ai-dropdown.visible {
    display: block;
}

.template-ai-dropdown-close {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    font-size: 14px;
    border-radius: 3px;
    z-index: 1;
    padding: 0;
    line-height: 1;
}

.template-ai-dropdown-close:hover {
    color: #374151;
    background: #f3f4f6;
}

body.dark-mode .template-ai-dropdown-close {
    color: #6b7280;
}

body.dark-mode .template-ai-dropdown-close:hover {
    color: #e5e7eb;
    background: #374151;
}

.template-ai-dropdown-item {
    padding: 4px 8px;
    font-size: var(--font-size-xs);
    color: #6b7280;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    line-height: 1.2;
    transition: background 0.1s;
}

.template-ai-dropdown-item:last-child {
    border-bottom: none;
}

.template-ai-dropdown-item:hover,
.template-ai-dropdown-item.highlighted {
    background: #f3f4f6;
}

.template-ai-dropdown-loading {
    padding: 6px 8px;
    text-align: center;
    color: #9ca3af;
    font-size: var(--font-size-2xs);
}

body.dark-mode .template-ai-dropdown {
    background: #1e293b;
    border-color: #475569;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

body.dark-mode .template-ai-dropdown-item {
    color: #e2e8f0;
    border-bottom-color: #334155;
}

body.dark-mode .template-ai-dropdown-item:hover,
body.dark-mode .template-ai-dropdown-item.highlighted {
    background: #334155;
}

body.dark-mode .template-ai-dropdown-loading {
    color: #64748b;
}

/* Ghost text prediction overlay for inline auto-complete */
.template-textarea-wrapper,
.cell-textarea-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.template-ghost-text,
.cell-ghost-text {
    position: absolute;
    top: 1px;
    left: 1px;
    right: 1px;
    bottom: 1px;
    padding: 8px 10px;
    font-size: 1rem;
    line-height: 1.5;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: #9ca3af;
    pointer-events: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow: hidden;
    z-index: 3;
    box-sizing: border-box;
    border-radius: 3px;
}

body.dark-mode .template-ghost-text,
body.dark-mode .cell-ghost-text {
    color: #6b7280;
}

.cell-ghost-text {
    padding-top: 28px;
    font-size: var(--font-size-sm, 0.875rem);
}

.template-ghost-spacer,
.cell-ghost-spacer {
    visibility: hidden;
    white-space: pre-wrap;
}

.template-ghost-prediction,
.cell-ghost-prediction {
    color: #9ca3af;
    font-style: normal;
    opacity: 0.8;
    pointer-events: auto;
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.template-ghost-prediction:hover,
.cell-ghost-prediction:hover {
    background: rgba(59, 130, 246, 0.12);
    color: #1d4ed8;
    opacity: 1;
}

body.dark-mode .template-ghost-prediction,
body.dark-mode .cell-ghost-prediction {
    color: #6b7280;
    opacity: 0.9;
}

body.dark-mode .template-ghost-prediction:hover,
body.dark-mode .cell-ghost-prediction:hover {
    background: rgba(96, 165, 250, 0.18);
    color: #bfdbfe;
    opacity: 1;
}

/* Textarea must be transparent when inside ghost text wrapper */
.template-textarea-wrapper .template-input,
.cell-textarea-wrapper .cell-input {
    position: relative;
    z-index: 2;
    background: transparent !important;
    background-color: transparent !important;
}

body.dark-mode .template-textarea-wrapper .template-input,
body.dark-mode .cell-textarea-wrapper .cell-input {
    background: transparent !important;
    background-color: transparent !important;
}

.template-input,
.template-panel input[type="text"],
.template-panel input[type="text"].template-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #e5e7eb !important;
    border-radius: 4px;
    font-size: 1rem;
    line-height: 1.5;
    color: #212529;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    box-sizing: border-box;
    background-color: #fff;
}

.template-input[data-ai-filled="true"],
.cell-input[data-ai-filled="true"] {
    color: #9ca3af;
}

body.dark-mode .template-input[data-ai-filled="true"],
body.dark-mode .cell-input[data-ai-filled="true"] {
    color: #6b7280;
}

.template-input:focus,
.template-input:focus-visible,
.template-panel input[type="text"]:focus,
.template-panel input[type="text"]:focus-visible {
    outline: none !important;
    border-color: #93c5fd !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1) !important;
}

textarea.template-input {
    min-height: 60px;
    resize: vertical;
    font-size: 1rem;
    line-height: 1.5;
}

select.template-input {
    background-color: #fff;
    cursor: pointer;
    font-size: 1rem;
    /* Replace tiny native dropdown arrow with a larger custom chevron */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234b5563' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 22px 22px;
    padding-right: 42px !important;
}

body.dark-mode select.template-input {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23cbd5e1' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

/* Excel-Style Table */
.template-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm, 0.875rem);
}

.template-table th,
.template-table td {
    border: 1px solid #dee2e6;
    padding: 0;
    vertical-align: top;
}

.template-table th {
    background: #f8f9fa;
    padding: 8px 10px;
    font-weight: 500;
    font-size: var(--font-size-sm, 0.875rem);
    color: #4b5563;
    text-align: left;
}

.template-table .row-label-col {
    width: 120px;
}

.template-table .row-actions-col {
    width: 40px;
}

.template-table .row-label {
    background: #f1f3f4;
    padding: 8px 10px;
    font-weight: 500;
    font-size: var(--font-size-sm, 0.875rem);
    color: #4b5563;
    white-space: nowrap;
}

.template-table .row-actions {
    background: #f8f9fa;
    text-align: center;
    vertical-align: middle;
}

.cell-input {
    width: 100%;
    height: 100%;
    min-height: 80px;
    padding: 8px 10px;
    padding-top: 28px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: var(--font-size-sm, 0.875rem);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.5;
    color: #212529;
    resize: vertical;
    overflow-y: hidden;
    background: #fff;
}

.cell-input:focus {
    outline: none;
    background: #fff;
}

.cell-input::placeholder {
    color: #9ca3af !important;
}

/* Standardized placeholder color for all template inputs */
.template-input::placeholder,
.template-panel input::placeholder,
.template-panel textarea::placeholder,
.template-panel select::placeholder,
.track-changes-edit::placeholder,
.refine-revision-input::placeholder {
    color: #9ca3af !important;
}

/* Dark mode placeholder - lighter color for visibility */
body.dark-mode .template-input::placeholder,
body.dark-mode .template-panel input::placeholder,
body.dark-mode .template-panel textarea::placeholder,
body.dark-mode .cell-input::placeholder,
body.dark-mode .track-changes-edit::placeholder,
body.dark-mode .refine-revision-input::placeholder {
    color: #6b7280 !important;
}

/* Row controls */
.add-row-btn {
    margin-top: 8px;
    padding: 6px 12px;
    background: #fff;
    border: 1px dashed #adb5bd;
    border-radius: 4px;
    font-size: 13px;
    color: #6c757d;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.add-row-btn:hover {
    border-color: #4b5563;
    color: #4b5563;
}

.remove-row-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 12px;
    opacity: 0.5;
}

.remove-row-btn:hover {
    opacity: 1;
}

/* Footer */
.template-panel-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 4px 16px;
    padding-bottom: max(4px, env(safe-area-inset-bottom));
    position: fixed;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: var(--sidebar-width);
    right: 0;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.95);
    z-index: 99;
    transition: left var(--sidebar-transition);
}

.template-panel-footer .footer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

body.sidebar-collapsed-mode .template-panel-footer {
    left: var(--sidebar-collapsed-width);
}

@media (max-width: 1023px) {
    .template-panel-footer {
        left: 0;
    }
}

@media (max-width: 768px) {
    .template-panel-footer .footer-actions .template-footer-btn span {
        display: none;
    }
}

@media (max-width: 600px) {
    .template-panel-footer {
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 4px;
        padding: 4px 8px;
    }

    .template-panel-footer .footer-actions {
        gap: 4px;
    }

    .template-panel-footer .footer-actions .template-footer-btn {
        padding: 6px 8px;
    }
}

.template-footer-btn {
    padding: 8px 16px;
    border-radius: 4px;
    font-size: var(--font-size-sm, 0.875rem);
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.template-footer-btn.secondary {
    background: #fff;
    border: 1px solid #dee2e6;
    color: #4b5563;
}

.template-footer-btn.secondary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.template-footer-btn.secondary:disabled:hover {
    background: #fff;
}

/* Icon-only buttons (undo/redo) - same style as other secondary buttons */
.template-footer-btn[data-action="undo"],
.template-footer-btn[data-action="redo"] {
    padding: 8px 10px;
    min-width: 36px;
}

.template-footer-btn.primary {
    background: #3b82f6;
    border: none;
    color: white;
}

.template-footer-btn.primary:hover {
    background: #2563eb;
}

/* Error state */
.template-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #6c757d;
    text-align: center;
}

.template-error i {
    font-size: 2rem;
    color: #ffc107;
    margin-bottom: 12px;
}

/* Dark mode - Matching Chat dark mode exactly */
body.dark-mode .template-panel {
    background: #111827;
}

body.dark-mode .template-panel-header {
    background: #1f2937;
    border-color: #374151;
}

body.dark-mode .template-panel-title {
    color: #f3f4f6;
}

body.dark-mode .template-section {
    background: #1f2937;
    border-color: #374151;
}

body.dark-mode .template-section-header {
    background: #111827;
}

body.dark-mode .template-section-name,
body.dark-mode .template-field-label {
    color: #f3f4f6;
}

body.dark-mode .template-input,
body.dark-mode .template-panel input[type="text"],
body.dark-mode .template-panel textarea,
body.dark-mode .cell-input {
    background: #111827 !important;
    background-color: #111827 !important;
    border-color: #374151 !important;
    color: #f3f4f6 !important;
}

body.dark-mode .template-table th,
body.dark-mode .template-table .row-label {
    background: #1f2937;
    color: #e5e7eb;
}

/* Dark mode for Add Row button */
body.dark-mode .add-row-btn {
    background: #111827;
    border-color: #374151;
    color: #e5e7eb;
}

body.dark-mode .add-row-btn:hover {
    border-color: #4b5563;
    background: #1f2937;
    color: #f9fafb;
}

/* Override section icon colors in dark mode - use gray instead of colored badges */
body.dark-mode .template-section-icon {
    background: #374151 !important;
}

body.dark-mode .template-panel-footer {
    background: transparent;
}

body.dark-mode .template-footer-btn.secondary {
    background: transparent;
    border: 1px solid #e5e7eb;
    color: #e5e7eb;
}

/* Mobile */
@media (max-width: 1024px) {
    .template-panel {
        max-width: 100%;
    }

    .template-panel-content {
        padding: 12px 16px;
    }
}

@media (max-width: 768px) {
    .template-panel {
        width: 100%;
    }

    .template-panel-content {
        padding: 12px 8px;
    }

    .template-panel-header {
        padding: 10px 12px;
    }

    .template-section {
        margin-bottom: 8px;
    }

    .template-section-header {
        padding: 8px 12px;
    }

    .template-section-content {
        padding: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .template-table {
        font-size: 1rem;
        min-width: 100%;
    }

    .template-table .row-label-col {
        width: 70px;
    }

    .template-table .row-label {
        font-size: 1rem;
        padding: 6px 8px;
        white-space: normal;
        word-break: break-word;
    }

    .cell-input {
        min-height: 50px;
        font-size: 1rem;
        padding: 28px 8px 6px 8px;
    }

    .template-table .cell-input-controls button,
    .template-panel .template-input-icons button {
        font-size: 1rem;
    }

    .template-panel-footer {
        flex-wrap: wrap;
        gap: 6px;
        padding: 4px 8px;
    }

    .template-footer-btn {
        padding: 6px 12px;
        font-size: 1rem;
    }
}

/* Stacked-card layout for narrow screens — each row renders as a card
   with fields stacked vertically. Column headers hidden; field labels
   surfaced from data-label attribute on each cell. */
@media (max-width: 640px) {
    .template-panel-content {
        padding: 8px 4px;
    }

    .template-section-content {
        overflow-x: visible;
        padding: 6px 4px;
    }

    .template-table,
    .template-table thead,
    .template-table tbody,
    .template-table tr,
    .template-table th,
    .template-table td {
        display: block;
        width: 100% !important;
        box-sizing: border-box;
    }

    .template-table thead {
        position: absolute;
        left: -9999px;
        top: -9999px;
        width: 1px;
        height: 1px;
        overflow: hidden;
    }

    .template-table tr {
        border: 1px solid #dee2e6;
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 0;
        background: #fff;
        overflow: hidden;
    }

    .template-table td {
        border: none;
        border-bottom: 1px solid #f1f3f4;
        padding: 10px 12px;
    }

    .template-table td:last-child {
        border-bottom: none;
    }

    .template-table .row-label {
        background: #f8fafc;
        border-bottom: 1px solid #e5e7eb;
        padding: 10px 12px;
        font-weight: 600;
        color: #1f2937;
        font-size: 1rem;
    }

    .template-table .row-label-input {
        width: 100%;
        box-sizing: border-box;
    }

    .template-table td.has-ai-assist::before {
        content: attr(data-label);
        display: block;
        font-size: 1rem;
        font-weight: 600;
        color: #6b7280;
        margin-bottom: 6px;
    }

    .template-table .row-actions {
        background: transparent;
        text-align: right;
        padding: 6px 12px 10px;
    }

    .cell-input {
        min-height: 72px;
        padding: 8px 10px;
    }

    body.dark-mode .template-table tr {
        background: #111827;
        border-color: #374151;
    }

    body.dark-mode .template-table .row-label {
        background: #1f2937;
        color: #f9fafb;
        border-bottom-color: #374151;
    }

    body.dark-mode .template-table td {
        border-bottom-color: #1f2937;
    }

    body.dark-mode .template-table td.has-ai-assist::before {
        color: #9ca3af;
    }
}

@media (max-width: 480px) {
    .template-table th:not(.row-label-col):not(.row-actions-col) {
        min-width: 100px;
    }
}

/* Self-check styles consolidated in style.css */

.refine-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: min(400px, 100vw);
    height: 100vh;
    background: #fff;
    border-left: 1px solid #e5e7eb;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
}

.refine-panel.open {
    right: 0;
}

.refine-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e5e7eb;
}

.refine-panel-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #1f2937;
    display: flex;
    align-items: center;
    gap: 8px;
}

.refine-panel-header h3 i {
    color: #3B82F6;
}

.refine-panel-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: #4b5563;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.refine-panel-close:hover {
    background: #e5e7eb;
    color: #1f2937;
}

.refine-panel-actions {
    display: flex;
    gap: 8px;
    padding: 12px 20px;
    border-bottom: 1px solid #e5e7eb;
    background: #fafafa;
}

.refine-action-btn {
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    background: #3b82f6;
    border: none;
    color: white;
}

.refine-action-btn:hover {
    background: #2563eb;
}

.refine-action-btn.secondary {
    background: #fff;
    border: 1px solid #d1d5db;
    color: #374151;
}

.refine-action-btn.secondary:hover {
    background: #f3f4f6;
}

.refine-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.refine-loading,
.refine-error,
.refine-no-suggestions {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: #4b5563;
}

.refine-loading i,
.refine-error i,
.refine-no-suggestions i {
    font-size: 2rem;
    margin-bottom: 12px;
}

.refine-no-suggestions i {
    color: #10b981;
}

.refine-error i {
    color: #ef4444;
}

/* Individual suggestion */
.refine-suggestion {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.refine-suggestion.accepted {
    border-color: #10b981;
    background: #ecfdf5;
}

.refine-suggestion.rejected {
    border-color: #ef4444;
    background: #fef2f2;
    opacity: 0.6;
}

.refine-suggestion.revised {
    border-color: #3b82f6;
    background: #eff6ff;
}

.refine-suggestion-header {
    margin-bottom: 12px;
}

.refine-field-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #4b5563;
    display: flex;
    align-items: center;
    gap: 6px;
}

.refine-field-label i {
    color: #3B82F6;
}

.refine-original,
.refine-suggested {
    margin-bottom: 12px;
}

.refine-original strong,
.refine-suggested strong {
    display: block;
    font-size: 0.8rem;
    color: #4b5563;
    margin-bottom: 4px;
}

.refine-original p {
    margin: 0;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 0.9rem;
    color: #374151;
}

.refine-suggested p {
    margin: 0;
    padding: 8px 12px;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 4px;
    font-size: 0.9rem;
    color: #92400e;
}

.refine-revision {
    margin-bottom: 12px;
}

.refine-revision strong {
    display: block;
    font-size: 0.8rem;
    color: #4b5563;
    margin-bottom: 4px;
}

.refine-revision-input {
    width: 100%;
    min-height: 80px;
    padding: 8px 12px;
    border: 1px solid #3b82f6;
    border-radius: 4px;
    font-size: 0.9rem;
    resize: vertical;
    margin-bottom: 8px;
}

.refine-suggestion-actions {
    display: flex;
    gap: 8px;
}

.refine-btn {
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
}

.refine-btn:hover {
    background: #f3f4f6;
}

.refine-btn.accept {
    background: #10b981;
    border-color: #10b981;
    color: white;
}

.refine-btn.accept:hover {
    background: #059669;
}

.refine-btn.reject {
    background: #ef4444;
    border-color: #ef4444;
    color: white;
}

.refine-btn.reject:hover {
    background: #dc2626;
}

.refine-btn.revise {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
}

.refine-btn.revise:hover {
    background: #2563eb;
}

.refine-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 500;
}

.refine-status.accepted {
    color: #10b981;
}

.refine-status.rejected {
    color: #ef4444;
}

.refine-status.revised {
    color: #3b82f6;
}

/* Alignment Check Results */
.alignment-results {
    padding: 20px 0;
}

.alignment-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 24px;
}

.score-circle {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 700;
    color: white;
    margin-bottom: 8px;
}

.score-circle.good {
    background: linear-gradient(135deg, #10b981, #059669);
}

.score-circle.fair {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

.score-circle.needs-work {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

.alignment-score span {
    font-size: 0.9rem;
    color: #4b5563;
}

.alignment-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.alignment-check {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    background: #f9fafb;
}

.alignment-check.pass {
    background: #ecfdf5;
}

.alignment-check.pass i {
    color: #10b981;
}

.alignment-check.warning {
    background: #fffbeb;
}

.alignment-check.warning i {
    color: #f59e0b;
}

.alignment-check.fail {
    background: #fef2f2;
}

.alignment-check.fail i {
    color: #ef4444;
}

.alignment-check i {
    font-size: 1.2rem;
    margin-top: 2px;
}

.alignment-check strong {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.alignment-check p {
    margin: 0;
    font-size: 0.85rem;
    color: #4b5563;
}

/* Dark mode for refine panel */
body.dark-mode .refine-panel {
    background: #1f2937;
    border-color: #374151;
}

body.dark-mode .refine-panel-header {
    background: #111827;
    border-color: #374151;
}

body.dark-mode .refine-panel-header h3 {
    color: #f3f4f6;
}

body.dark-mode .refine-panel-close {
    color: #9ca3af;
}

body.dark-mode .refine-panel-close:hover {
    background: #374151;
    color: #f3f4f6;
}

body.dark-mode .refine-panel-actions {
    background: #111827;
    border-color: #374151;
}

body.dark-mode .refine-suggestion {
    background: #111827;
    border-color: #374151;
}

body.dark-mode .refine-original p {
    background: #1f2937;
    border-color: #374151;
    color: #e5e7eb;
}

body.dark-mode .refine-suggested p {
    background: #78350f;
    border-color: #92400e;
    color: #fef3c7;
}

body.dark-mode .refine-revision-input {
    background: #1f2937;
    border-color: #3b82f6;
    color: #e5e7eb;
}

body.dark-mode .refine-field-label {
    color: #9ca3af;
}

body.dark-mode .alignment-check {
    background: #111827;
}

body.dark-mode .alignment-check strong {
    color: #e5e7eb;
}

body.dark-mode .alignment-check p {
    color: #9ca3af;
}

/* Mobile responsive */
@media (max-width: 500px) {
    .refine-panel {
        width: 100%;
        right: -100%;
    }
}

/* Completeness Check Styles */
.completeness-details {
    padding: 16px 0;
}

.completeness-details h4 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    margin: 16px 0 8px 0;
    color: #374151;
}

.completeness-details h4:first-child {
    margin-top: 0;
}

.completeness-details ul {
    margin: 0;
    padding-left: 24px;
    list-style: disc;
}

.completeness-details li {
    font-size: 0.85rem;
    color: #4b5563;
    padding: 4px 0;
}

/* Quality Review Styles */
.quality-feedback {
    padding: 16px 0;
}

.quality-feedback h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 16px 0 8px 0;
    color: #374151;
}

.quality-feedback h4:first-child {
    margin-top: 0;
}

.quality-feedback ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.quality-feedback li {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.85rem;
    color: #4b5563;
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
}

.quality-feedback li:last-child {
    border-bottom: none;
}

.quality-feedback li i {
    margin-top: 2px;
    flex-shrink: 0;
}

/* Dark mode for completeness and quality */
body.dark-mode .completeness-details h4,
body.dark-mode .quality-feedback h4 {
    color: #e5e7eb;
}

body.dark-mode .completeness-details li,
body.dark-mode .quality-feedback li {
    color: #9ca3af;
}

body.dark-mode .quality-feedback li {
    border-bottom-color: #374151;
}

.track-changes-container {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-radius: 8px;
    margin-top: 4px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.track-changes-header {
    padding: 8px 12px;
    border-bottom: 1px solid #fcd34d;
    font-size: 0.8rem;
    font-weight: 600;
    color: #92400e;
    display: flex;
    align-items: center;
    gap: 6px;
}

.track-changes-loading,
.track-changes-error {
    padding: 16px;
    text-align: center;
    color: #92400e;
    font-size: 0.85rem;
}

.track-changes-error {
    color: #dc2626;
}

.track-changes-diff {
    padding: 12px;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #374151;
    max-height: 150px;
    overflow-y: auto;
}

.track-deleted {
    background: #fee2e2;
    color: #dc2626;
    text-decoration: line-through;
    padding: 1px 2px;
    border-radius: 2px;
}

.track-added {
    background: #dcfce7;
    color: #16a34a;
    padding: 1px 2px;
    border-radius: 2px;
}

.track-changes-actions {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid #fcd34d;
    background: #fef3c7;
    border-radius: 0 0 8px 8px;
}

.track-changes-btn {
    flex: 1;
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.15s;
}

.track-changes-btn.accept {
    background: #10b981;
    color: white;
}

.track-changes-btn.accept:hover {
    background: #059669;
}

.track-changes-btn.reject {
    background: #ef4444;
    color: white;
}

.track-changes-btn.reject:hover {
    background: #dc2626;
}

.track-changes-btn.revise {
    background: #3b82f6;
    color: white;
}

.track-changes-btn.revise:hover {
    background: #2563eb;
}

.track-changes-edit {
    min-height: 80px;
    padding: 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    margin: 8px 12px;
    font-size: 0.9rem;
    resize: vertical;
    box-sizing: border-box;
    width: calc(100% - 24px);
}

/* Dark mode track changes */
body.dark-mode .track-changes-container {
    background: #292524;
    border-color: #a16207;
}

body.dark-mode .track-changes-header {
    border-color: #a16207;
    color: #fbbf24;
}

body.dark-mode .track-changes-diff {
    color: #e5e7eb;
}

body.dark-mode .track-deleted {
    background: #450a0a;
    color: #fca5a5;
}

body.dark-mode .track-added {
    background: #052e16;
    color: #86efac;
}

body.dark-mode .track-changes-actions {
    background: #44403c;
    border-color: #a16207;
}

body.dark-mode .track-changes-edit {
    background: #1f2937;
    border-color: #4b5563;
    color: #e5e7eb;
}

.dropdown-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 8px;
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    background: #f3f4f6;
    color: #374151;
    transition: all 0.15s;
}

.dropdown-action-btn:hover {
    background: #e5e7eb;
}

.dropdown-action-btn i {
    font-size: 0.7rem;
}

body.dark-mode .dropdown-action-btn {
    background: #374151;
    color: #e5e7eb;
}

body.dark-mode .dropdown-action-btn:hover {
    background: #4b5563;
}

.autocomplete-container {
    position: relative;
}

.autocomplete-input {
    width: 100%;
    padding-right: 24px;
}

.autocomplete-suggestions {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #dee2e6;
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 280px;
    overflow-y: auto;
    z-index: 1000;
}

.autocomplete-suggestions.visible {
    display: block;
}

.autocomplete-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f1f3f4;
    transition: background 0.15s;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background: #f0f7ff;
}

.autocomplete-item-label {
    font-size: var(--font-size-sm, 0.875rem);
    font-weight: 500;
    color: #212529;
}

.autocomplete-item-desc {
    font-size: var(--font-size-xs, 0.75rem);
    color: #6c757d;
    margin-top: 2px;
    line-height: 1.3;
}

.autocomplete-empty {
    padding: 12px;
    text-align: center;
    color: #6c757d;
    font-size: var(--font-size-sm, 0.875rem);
    font-style: italic;
}

/* Dark mode autocomplete */
body.dark-mode .autocomplete-suggestions {
    background: #1f2937;
    border-color: #374151;
}

body.dark-mode .autocomplete-item {
    border-bottom-color: #374151;
}

body.dark-mode .autocomplete-item:hover {
    background: #374151;
}

body.dark-mode .autocomplete-item-label {
    color: #f3f4f6;
}

body.dark-mode .autocomplete-item-desc {
    color: #9ca3af;
}

body.dark-mode .autocomplete-empty {
    color: #9ca3af;
}

/* Import Toolbar */
.template-import-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
}

.import-toolbar-actions {
    display: flex;
    gap: 8px;
}

.import-toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: var(--font-size-sm, 0.875rem);
    color: #374151;
    cursor: pointer;
    transition: all 0.2s ease;
}

.import-toolbar-btn:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.import-toolbar-btn.primary {
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
}

.import-toolbar-btn.primary:hover {
    background: #15803d;
    border-color: #15803d;
}

.import-toolbar-btn i {
    font-size: 0.875rem;
}

/* Template Download Dropdown */
.template-download-wrapper {
    position: relative;
}

/* Unified container — 10px radius matches .media-options + .save-draft-menu. */
.template-download-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    padding: 4px;
    z-index: 100;
    min-width: 160px;
}

.template-download-menu.show {
    display: block;
}

/* Matches .media-options button.media-option (chat plus-button dropdown) for a
   consistent look across all dropdowns: 16px font, 8px icon-text gap, 32px
   minimum row height (40px on touch), 20px icon column. */
.template-download-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 12px;
    background: none;
    border: none;
    border-radius: 6px;
    font-size: var(--font-size-sm);
    font-weight: 500;
    line-height: 1.3;
    min-height: 32px;
    color: #374151;
    cursor: pointer;
    transition: background 0.15s ease;
    text-align: left;
    white-space: nowrap;
}

.template-download-option:hover {
    background: #f3f4f6;
}

.template-download-option i {
    width: 20px;
    text-align: center;
    font-size: var(--font-size-sm);
    color: #4b5563;
}

@media (pointer: coarse) {
    .template-download-option { min-height: 40px; }
}

.template-download-option i.fa-file-excel {
    color: #22c55e;
}

.template-download-option i.fa-file-word {
    color: #2563eb;
}

/* Dark Mode Template Download Menu */
body.dark-mode .template-download-menu {
    background: #1f2937;
    border-color: #374151;
}

body.dark-mode .template-download-option {
    color: #e5e7eb;
}

body.dark-mode .template-download-option:hover {
    background: #374151;
}

body.dark-mode .template-download-option:first-child {
    border-bottom-color: #374151;
}

/* Dark Mode Import Toolbar */
body.dark-mode .template-import-toolbar {
    background: #1f2937;
    border-bottom-color: #374151;
}

body.dark-mode .import-toolbar-btn {
    background: #1f2937;
    border-color: #374151;
    color: #e5e7eb;
}

body.dark-mode .import-toolbar-btn:hover {
    background: #374151;
    border-color: #4b5563;
}

body.dark-mode .import-toolbar-btn.primary {
    background: #16a34a;
    border-color: #16a34a;
}

body.dark-mode .import-toolbar-btn.primary:hover {
    background: #15803d;
}

/* Import Preview Modal */
.import-preview-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.import-preview-content {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.import-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
}

.import-preview-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #111827;
    display: flex;
    align-items: center;
    gap: 8px;
}

.import-preview-header h3 i {
    color: #22c55e;
}

.import-preview-close {
    background: none;
    border: none;
    padding: 6px;
    cursor: pointer;
    color: #4b5563;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.import-preview-close:hover {
    background: #f3f4f6;
    color: #111827;
}

.import-preview-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.import-filename {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    margin: 0 0 16px 0;
    font-size: var(--font-size-sm, 0.875rem);
    color: #166534;
}

.import-filename i {
    color: #22c55e;
}

.import-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.import-stat {
    flex: 1;
    text-align: center;
    padding: 12px;
    background: #f9fafb;
    border-radius: 8px;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: #22c55e;
}

.stat-label {
    font-size: var(--font-size-xs, 0.75rem);
    color: #4b5563;
}

.import-warning {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    background: #fffbeb;
    border: 1px solid #fbbf24;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: var(--font-size-sm, 0.875rem);
    color: #92400e;
}

.import-warning i {
    color: #f59e0b;
    flex-shrink: 0;
    margin-top: 2px;
}

.import-preview-fields h4 {
    margin: 0 0 10px 0;
    font-size: var(--font-size-sm, 0.875rem);
    font-weight: 600;
    color: #374151;
}

.import-preview-fields ul {
    margin: 0;
    padding: 0 0 0 20px;
    font-size: var(--font-size-sm, 0.875rem);
    color: #4b5563;
}

.import-preview-fields li {
    margin-bottom: 6px;
    line-height: 1.4;
}

.import-preview-fields li strong {
    color: #374151;
    font-weight: 500;
}

.import-preview-fields .more-fields {
    color: #9ca3af;
    font-style: italic;
}

.import-preview-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
}

.import-preview-btn {
    padding: 8px 20px;
    border-radius: 6px;
    font-size: var(--font-size-sm, 0.875rem);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.import-preview-btn.cancel {
    background: #fff;
    border: 1px solid #d1d5db;
    color: #374151;
}

.import-preview-btn.cancel:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.import-preview-btn.primary {
    background: #22c55e;
    border: none;
    color: #fff;
}

.import-preview-btn.primary:hover {
    background: #16a34a;
}

/* Dark Mode Import Modal */
body.dark-mode .import-preview-content {
    background: #1f2937;
}

body.dark-mode .import-preview-header {
    border-bottom-color: #374151;
}

body.dark-mode .import-preview-header h3 {
    color: #f3f4f6;
}

body.dark-mode .import-preview-close {
    color: #9ca3af;
}

body.dark-mode .import-preview-close:hover {
    background: #374151;
    color: #f3f4f6;
}

body.dark-mode .import-filename {
    background: #064e3b;
    border-color: #166534;
    color: #86efac;
}

body.dark-mode .import-stat {
    background: #374151;
}

body.dark-mode .stat-label {
    color: #9ca3af;
}

body.dark-mode .import-warning {
    background: #451a03;
    border-color: #78350f;
    color: #fbbf24;
}

body.dark-mode .import-preview-fields h4 {
    color: #e5e7eb;
}

body.dark-mode .import-preview-fields ul {
    color: #d1d5db;
}

body.dark-mode .import-preview-fields li strong {
    color: #f3f4f6;
}

body.dark-mode .import-preview-footer {
    border-top-color: #374151;
}

body.dark-mode .import-preview-btn.cancel {
    background: #374151;
    border-color: #4b5563;
    color: #e5e7eb;
}

body.dark-mode .import-preview-btn.cancel:hover {
    background: #4b5563;
}


/* Template translation loading state - hide content while translations load */
#templatePanelContainer.translating .template-panel-content {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

#templatePanelContainer.translating .template-panel::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    border: 2px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

#templatePanelContainer.translating .template-panel {
    position: relative;
    min-height: 100px;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

@media (max-width: 768px) {
    .remove-row-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
    }

    .template-footer-btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ======== Cell resource embed picker ======== */
.cell-resource-picker {
    position: fixed;
    inset: 0;
    z-index: 11000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell-resource-picker-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.cell-resource-picker-panel {
    position: relative;
    width: min(440px, calc(100vw - 32px));
    max-height: calc(100vh - 64px);
    overflow-y: auto;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.25);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cell-resource-picker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 15px;
}

.cell-resource-close {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: #475569;
    min-width: 44px;
    min-height: 44px;
}

.cell-resource-picker-hint {
    margin: 0;
    font-size: 13px;
    color: #475569;
    line-height: 1.4;
}

.cell-resource-url {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    box-sizing: border-box;
}

.cell-resource-quick {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 6px;
}

.cell-resource-quick-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 13px;
    color: #0f172a;
    cursor: pointer;
    text-align: left;
}

.cell-resource-quick-btn:hover {
    background: #e2e8f0;
}

.cell-resource-picker-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.cell-resource-picker-actions button {
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    cursor: pointer;
    font-size: 14px;
    min-height: 44px;
}

.cell-resource-insert {
    background: #2563eb !important;
    color: #ffffff !important;
    border-color: #2563eb !important;
}

body.dark-mode .cell-resource-picker-panel {
    background: #1f2937;
    color: #e5e7eb;
}

body.dark-mode .cell-resource-url,
body.dark-mode .cell-resource-quick-btn,
body.dark-mode .cell-resource-picker-actions button {
    background: #111827;
    color: #e5e7eb;
    border-color: #374151;
}

body.dark-mode .cell-resource-quick-btn:hover {
    background: #1e293b;
}

.template-cell .cell-embed,
.template-cell-content .cell-embed {
    margin: 8px 0;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    background: #ffffff;
}

.template-cell .cell-embed .resource-embed-iframe,
.template-cell-content .cell-embed .resource-embed-iframe {
    height: clamp(280px, 50vh, 480px);
    width: 100%;
    border: none;
    display: block;
}
