:root {
    --primary: var(--wk-primary, #1e3a8a);
    --primary-light: var(--wk-primary-light, #3b82f6);
    --primary-dark: var(--wk-primary-dark, #1e40af);
    --accent: var(--wk-accent, #c9a227);
    --accent-light: var(--wk-accent-light, #f59e0b);
    --text: #333;
    --text-light: #6b7280;
    --border: #ddd;
    --bg: #f5f7fa;
    --white: #fff;
    --gray-light: #f8f9fa;
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --info: #2563eb;
    --shadow: 0 4px 20px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.3s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', Arial, sans-serif;
    background: linear-gradient(135deg, var(--bg) 0%, #e4e8eb 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--text);
}

body[dir="rtl"] { font-family: 'Heebo', Arial, sans-serif; }

.container { max-width: 1200px; margin: 0 auto; }

/* Language Selector */
.lang-bar {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
}
.lang-btn {
    padding: 8px 18px;
    border: 2px solid var(--border);
    border-radius: 25px;
    background: var(--white);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
}
.lang-btn:hover { border-color: var(--primary); color: var(--primary); }
.lang-btn.active {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    padding: 35px 40px;
    border-radius: var(--radius) var(--radius) 0 0;
    text-align: center;
    box-shadow: var(--shadow);
    position: relative;
}
.header-logo {
    width: 80px;
    height: 80px;
    background: var(--white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 15px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    padding: 5px;
}
.header-logo img { width: 100%; height: 100%; object-fit: contain; }
.header h1 { font-size: 2rem; font-weight: 700; margin-bottom: 8px; }
.header .subtitle { font-size: 1.1rem; opacity: 0.9; }
.header .badge {
    display: inline-block;
    background: var(--accent);
    padding: 6px 20px;
    border-radius: 25px;
    margin-top: 12px;
    font-weight: 600;
    font-size: 0.85rem;
    letter-spacing: 1px;
}

/* Form Container */
.form-container {
    background: var(--white);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* Progress */
.progress-wrap { padding: 20px 40px; background: var(--gray-light); border-bottom: 1px solid var(--border); }
.progress-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 4px; transition: width 0.5s ease; width: 0%; }
.progress-info { display: flex; justify-content: space-between; margin-top: 8px; font-size: 0.85rem; color: var(--text-light); }

/* Navigation Tabs */
.nav-tabs {
    display: flex;
    background: var(--gray-light);
    border-bottom: 2px solid var(--border);
    overflow-x: auto;
}
.nav-tab {
    flex: 1;
    padding: 16px 20px;
    text-align: center;
    cursor: pointer;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-light);
    transition: var(--transition);
    white-space: nowrap;
    position: relative;
}
.nav-tab:hover { background: rgba(26,95,42,0.08); color: var(--primary); }
.nav-tab.active { background: var(--white); color: var(--primary); font-weight: 600; }
.nav-tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary);
}
.tab-icon { margin-right: 6px; font-size: 1.1rem; }
[dir="rtl"] .tab-icon { margin-right: 0; margin-left: 6px; }

/* Tab Content */
.tab-content { display: none; padding: 35px 40px; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Section */
.section { margin-bottom: 30px; }
.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary-light);
}
.section-title .icon {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: var(--white);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

/* Form Grid */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.form-group { margin-bottom: 4px; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label { display: block; font-weight: 500; margin-bottom: 6px; color: var(--text); font-size: 0.95rem; }
.form-group .required { color: var(--danger); margin-right: 2px; }
[dir="rtl"] .form-group .required { margin-right: 0; margin-left: 2px; }
.hp-trap {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.template-links { margin-top: 10px; font-size: 0.9rem; display: flex; flex-wrap: wrap; gap: 12px; }
.template-links a { color: var(--primary-dark); font-weight: 600; text-decoration: underline; }

.form-control {
    width: 100%;
    padding: 11px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
    background: var(--white);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,95,42,0.12); }
.form-control::placeholder { color: #aaa; }
select.form-control { cursor: pointer; }
textarea.form-control { min-height: 90px; resize: vertical; }

/* Info Box */
.info-box {
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}
[dir="rtl"] .info-box { border-right: 4px solid var(--primary); border-left: none; }
[dir="ltr"] .info-box { border-left: 4px solid var(--primary); }
.info-box h4 { color: var(--primary); margin-bottom: 6px; font-size: 1rem; }
.info-box p { color: #2e7d32; font-size: 0.9rem; line-height: 1.6; }

/* Table */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); margin-top: 15px; }
.data-table { width: 100%; border-collapse: collapse; min-width: 800px; }
.data-table th {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: var(--white);
    padding: 13px 10px;
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
}
[dir="ltr"] .data-table th { text-align: left; }
[dir="rtl"] .data-table th { text-align: right; }
.data-table td { padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:hover { background: rgba(26,95,42,0.04); }
.data-table tbody tr:nth-child(even) { background: var(--gray-light); }
.data-table tbody tr:nth-child(even):hover { background: rgba(26,95,42,0.06); }
.table-input {
    width: 100%;
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-family: inherit;
    font-size: 0.85rem;
    transition: border-color 0.3s;
}
.table-input:focus { outline: none; border-color: var(--primary); }
select.table-input { cursor: pointer; background: var(--white); }

/* Product Selector for Ingredients */
.selector-wrapper { position: relative; }
.product-selector-btn {
    padding: 7px 10px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.82rem;
    min-width: 130px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}
.product-selector-btn:hover { border-color: var(--primary); }
.product-dropdown {
    position: fixed;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    min-width: 220px;
    max-height: 250px;
    overflow-y: auto;
    display: none;
}
.product-dropdown.show { display: block; }
.product-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    cursor: pointer;
    transition: background 0.2s;
}
.product-dropdown-item:hover { background: var(--gray-light); }
.product-dropdown-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); }
.product-dropdown-item label { cursor: pointer; flex: 1; font-size: 0.85rem; }
.selected-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag {
    background: var(--primary);
    color: var(--white);
    padding: 2px 7px;
    border-radius: 10px;
    font-size: 0.72rem;
    display: flex;
    align-items: center;
    gap: 4px;
}
.tag .remove-tag { cursor: pointer; font-weight: bold; }

/* File Upload */
.file-btn {
    padding: 5px 8px;
    background: var(--gray-light);
    border: 1px dashed var(--border);
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.78rem;
    text-align: center;
    transition: var(--transition);
    display: inline-block;
}
.file-btn:hover { background: #e9ecef; border-color: var(--primary); }
.file-btn.has-file { background: #d4edda; border-color: var(--success); border-style: solid; }
.file-btn input { display: none; }
.file-name { font-size: 0.72rem; color: var(--text-light); margin-top: 2px; word-break: break-all; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 11px 22px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: var(--white); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 5px 18px rgba(26,95,42,0.3); }
.btn-secondary { background: var(--gray-light); color: var(--text); border: 2px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-success { background: linear-gradient(135deg, var(--success), #218838); color: var(--white); }
.btn-success:hover { transform: translateY(-2px); box-shadow: 0 5px 18px rgba(40,167,69,0.3); }
.btn-danger { background: var(--danger); color: var(--white); padding: 5px 10px; font-size: 0.82rem; }
.btn-danger:hover { background: #c82333; }
.btn-add { background: var(--accent); color: var(--white); margin-bottom: 12px; }
.btn-add:hover { background: #b8911f; }
.btn-group { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 25px; }

/* Empty State */
.empty-state { text-align: center; padding: 30px; color: var(--text-light); }
.empty-state .icon { font-size: 3rem; margin-bottom: 10px; }
.empty-state p { font-size: 1rem; margin-bottom: 15px; }

/* Footer Actions */
.footer-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    padding: 20px 40px;
    background: var(--gray-light);
    border-top: 1px solid var(--border);
    gap: 15px;
}
.footer-actions-buttons {
    flex: 1;
    min-width: 280px;
    display: flex;
    justify-content: flex-end;
}
.footer-btn-group {
    flex-wrap: wrap;
    justify-content: flex-end;
}
.btn-footer-nav {
    font-weight: 600;
    box-shadow: 0 2px 10px rgba(30, 58, 138, 0.2);
}
[dir="rtl"] .btn-footer-nav span + span,
[dir="rtl"] .btn-footer-nav {
    flex-direction: row-reverse;
}
.auto-save { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--text-light); }
.auto-save .dot { width: 8px; height: 8px; background: var(--success); border-radius: 50%; animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--white);
    border-radius: var(--radius);
    max-width: 500px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.modal-header { padding: 25px; text-align: center; }
.modal-header h3 { font-size: 1.3rem; color: var(--primary); }
.modal-body { padding: 0 25px 20px; text-align: center; line-height: 1.7; }
.modal-footer { padding: 15px 25px; text-align: center; border-top: 1px solid var(--border); }

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    flex-direction: column;
    gap: 15px;
}
.loading-overlay.active { display: flex; }
.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 1.1rem; color: var(--primary); font-weight: 500; }

/* Responsive */
@media (max-width: 768px) {
    body { padding: 10px; }
    .header { padding: 25px 15px; }
    .header h1 { font-size: 1.5rem; }
    .tab-content, .footer-actions, .progress-wrap { padding: 20px 15px; }
    .form-grid { grid-template-columns: 1fr; }
    .nav-tab { padding: 12px 10px; font-size: 0.82rem; }
    .btn-group { flex-direction: column; }
    .btn { width: 100%; justify-content: center; }
    .footer-actions { flex-direction: column; }
}

@media print {
    .lang-bar, .nav-tabs, .footer-actions, .btn-group, .btn { display: none; }
    .tab-content { display: block !important; padding: 15px; }
    .header { padding: 15px; }
}

/* Accordion panels */
.wk-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    background: var(--white);
    overflow: hidden;
}
.wk-panel-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border: none;
    background: var(--gray-light);
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    text-align: inherit;
}
.wk-panel-header:hover { background: #eef2f7; }
.wk-panel-header .panel-chevron { transition: transform 0.25s ease; font-size: 0.85rem; opacity: 0.7; }
.wk-panel.is-open .wk-panel-header .panel-chevron { transform: rotate(180deg); }
.wk-panel-body {
    display: none;
    padding: 18px;
    border-top: 1px solid var(--border);
}
.wk-panel.is-open .wk-panel-body { display: block; }
.wk-panel-hint {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-light);
    margin-top: 4px;
    line-height: 1.4;
}
.update-mode-link-wrap { text-align: center; margin-bottom: 16px; }
.update-mode-link {
    background: none;
    border: none;
    color: var(--primary);
    text-decoration: underline;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
}
#updateModeBar { display: none; margin-bottom: 16px; padding: 14px; background: var(--gray-light); border-radius: var(--radius-sm); }
#updateModeBar.is-visible { display: block; }
.same-person-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 12px 0;
    padding: 12px;
    background: var(--gray-light);
    border-radius: var(--radius-sm);
}
.same-person-row input { margin-top: 4px; accent-color: var(--primary); }
.field-error {
    display: none;
    font-size: 0.8rem;
    color: var(--danger);
    margin-top: 4px;
}
.form-group.has-error .form-control { border-color: var(--danger); }
.form-group.has-error .field-error { display: block; }
.optional-hint {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-bottom: 14px;
    padding: 10px 14px;
    background: #f0f4ff;
    border-radius: var(--radius-sm);
    border-inline-start: 3px solid var(--info);
}
.cards-list { display: none; flex-direction: column; gap: 12px; margin-top: 15px; }
.row-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    background: var(--gray-light);
}
.row-card-title { font-weight: 600; margin-bottom: 10px; color: var(--primary); }
.row-card .form-group { margin-bottom: 12px; }
.row-card-actions { display: flex; justify-content: flex-end; margin-top: 8px; }

@media (max-width: 768px) {
    .table-wrap.desktop-only { display: none !important; }
    .cards-list.mobile-only { display: flex; }
}
.section-subblock {
    margin: 18px 0 22px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
}
.subsection-title {
    font-size: 1.05rem;
    color: var(--primary);
    margin-bottom: 8px;
}
.questionnaire-catalog-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}
.questionnaire-catalog-row .form-control {
    flex: 1 1 220px;
    min-width: 180px;
}
.questionnaire-catalog-results {
    margin-top: 8px;
    max-height: 220px;
    overflow: auto;
    border-radius: var(--radius-sm);
}
.questionnaire-catalog-results.is-open {
    border: 1px solid var(--border);
    background: var(--gray-light);
}
.questionnaire-catalog-hit {
    display: block;
    width: 100%;
    text-align: start;
    padding: 10px 12px;
    border: none;
    border-bottom: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    font: inherit;
}
.questionnaire-catalog-hit:hover {
    background: #e8eef9;
}
.questionnaire-catalog-empty {
    padding: 10px 12px;
    color: var(--text-light);
    font-size: 0.9rem;
}
.catalog-badge {
    font-size: 0.75rem;
    color: var(--info);
    margin-top: 4px;
}
#questionnaireCertBatch .wkrmib {
    margin-top: 8px;
}

@media (min-width: 769px) {
    .cards-list.mobile-only { display: none !important; }
    .table-wrap.desktop-only { display: block; }
