.task-engine-module {
    --tem-c-bg: #f5f6fa;
    --tem-c-surface: #ffffff;
    --tem-c-border: rgba(0,0,0,0.08);
    --tem-c-border-strong: rgba(0,0,0,0.14);
    --tem-c-text: #1a1a2e;
    --tem-c-text-2: #5a5a6e;
    --tem-c-text-3: #9a9aac;
    --tem-c-accent: #2563eb;
    --tem-c-accent-bg: #eff6ff;
    --tem-c-accent-text: #1d4ed8;
    --tem-c-success: #16a34a;
    --tem-c-success-bg: #f0fdf4;
    --tem-c-warning: #d97706;
    --tem-c-warning-bg: #fffbeb;
    --tem-c-danger: #dc2626;
    --tem-c-danger-bg: #fef2f2;
    --tem-transition: 150ms ease;

    direction: rtl;
    font-family: inherit;
    color: var(--tem-c-text);
}

/* ---------- Header ---------- */
.tem-page-hdr {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    margin-bottom: 18px; flex-wrap: wrap;
}
.tem-page-title { font-size: 20px; font-weight: 800; }
.tem-page-desc { font-size: 12.5px; color: var(--tem-c-text-2); margin-top: 4px; }
.tem-meta-badge {
    font-size: 11.5px; color: var(--tem-c-text-3); background: var(--tem-c-bg);
    border: 1px solid var(--tem-c-border); border-radius: 20px; padding: 6px 14px;
    display: inline-flex; align-items: center; gap: 6px;
}

/* ---------- Nav (quick jump) ---------- */
.tem-quick-nav {
    display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px;
    background: var(--tem-c-surface); border: 1px solid var(--tem-c-border);
    border-radius: 12px; padding: 10px;
}
.tem-quick-nav a {
    font-size: 11.5px; font-weight: 600; color: var(--tem-c-text-2); text-decoration: none;
    padding: 6px 12px; border-radius: 8px; transition: all var(--tem-transition);
}
.tem-quick-nav a:hover { background: var(--tem-c-accent-bg); color: var(--tem-c-accent-text); }

/* ---------- Section cards ---------- */
.tem-section {
    background: var(--tem-c-surface); border: 1px solid var(--tem-c-border);
    border-radius: 14px; padding: 18px 20px; margin-bottom: 16px;
    scroll-margin-top: 16px;
}
.tem-section-hdr { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.tem-section-title { font-size: 14.5px; font-weight: 800; }
.tem-section-desc { font-size: 11.5px; color: var(--tem-c-text-3); margin-bottom: 14px; }
.tem-section-icon {
    width: 30px; height: 30px; border-radius: 8px; display: flex; align-items: center;
    justify-content: center; background: var(--tem-c-accent-bg); color: var(--tem-c-accent-text); font-size: 15px;
}

.tem-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px;
}
.tem-item { display: flex; flex-direction: column; gap: 5px; }
.tem-item label { font-size: 11.5px; font-weight: 700; color: var(--tem-c-text-2); }
.tem-item input[type="number"], .tem-item input[type="text"], .tem-item select {
    border: 1px solid var(--tem-c-border-strong); border-radius: 8px; padding: 8px 10px;
    font-size: 12.5px; font-family: inherit; background: var(--tem-c-bg); color: var(--tem-c-text);
    transition: border-color var(--tem-transition);
}
.tem-item input:focus, .tem-item select:focus { outline: none; border-color: var(--tem-c-accent); background: var(--tem-c-surface); }
.tem-item-hint { font-size: 10.5px; color: var(--tem-c-text-3); }

/* Toggle switch */
.tem-toggle-row {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 9px 12px; border: 1px solid var(--tem-c-border); border-radius: 10px; background: var(--tem-c-bg);
}
.tem-toggle-row .tem-toggle-label { font-size: 12px; font-weight: 700; }
.tem-toggle-row .tem-toggle-hint { font-size: 10.5px; color: var(--tem-c-text-3); margin-top: 2px; }
.tem-switch { position: relative; width: 38px; height: 22px; flex: none; }
.tem-switch input { opacity: 0; width: 0; height: 0; }
.tem-switch .tem-slider {
    position: absolute; inset: 0; background: #d1d5db; border-radius: 22px; cursor: pointer; transition: background var(--tem-transition);
}
.tem-switch .tem-slider::before {
    content: ""; position: absolute; height: 16px; width: 16px; right: 3px; top: 3px;
    background: #fff; border-radius: 50%; transition: transform var(--tem-transition);
}
.tem-switch input:checked + .tem-slider { background: var(--tem-c-accent); }
.tem-switch input:checked + .tem-slider::before { transform: translateX(-16px); }

/* Duration template mini-table */
.tem-template-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px; }
.tem-template-table th, .tem-template-table td { padding: 7px 10px; border-bottom: 1px solid var(--tem-c-border); text-align: center; }
.tem-template-table th { color: var(--tem-c-text-3); font-weight: 700; font-size: 11px; }

/* ---------- Actions bar ---------- */
.tem-actions-bar {
    position: sticky; bottom: 0; display: flex; gap: 10px; justify-content: flex-end;
    background: var(--tem-c-surface); border: 1px solid var(--tem-c-border); border-radius: 12px;
    padding: 12px 16px; margin-top: 8px; box-shadow: 0 -4px 14px rgba(0,0,0,0.05);
}
.tem-btn {
    display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700;
    border-radius: 9px; padding: 9px 18px; border: 1px solid var(--tem-c-border-strong);
    background: var(--tem-c-surface); color: var(--tem-c-text-2); cursor: pointer; transition: all var(--tem-transition);
}
.tem-btn:hover { background: var(--tem-c-bg); }
.tem-btn-primary { background: var(--tem-c-accent); border-color: var(--tem-c-accent); color: #fff; }
.tem-btn-primary:hover { filter: brightness(1.08); }
.tem-btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- Access-denied banner ---------- */
.tem-denied {
    display: flex; align-items: center; gap: 10px; background: var(--tem-c-danger-bg);
    color: var(--tem-c-danger); border: 1px solid var(--tem-c-danger); border-radius: 12px; padding: 16px 20px; font-size: 13px; font-weight: 700;
}

/* ---------- Toasts ---------- */
.tem-toast-wrap { position: fixed; top: 18px; left: 18px; z-index: 10000; display: flex; flex-direction: column; gap: 8px; }
.tem-toast {
    display: flex; align-items: center; gap: 8px; background: var(--tem-c-surface); border: 1px solid var(--tem-c-border-strong);
    border-radius: 10px; padding: 10px 16px; font-size: 12.5px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    cursor: pointer; min-width: 220px; direction: rtl;
}
.tem-toast-success { border-color: var(--tem-c-success); color: var(--tem-c-success); }
.tem-toast-error { border-color: var(--tem-c-danger); color: var(--tem-c-danger); }
.tem-toast-warning { border-color: var(--tem-c-warning); color: var(--tem-c-warning); }
.tem-toast-info { border-color: var(--tem-c-accent); color: var(--tem-c-accent-text); }

@media (max-width: 640px) {
    .tem-grid { grid-template-columns: 1fr 1fr; }
}
